Class Choice

  • All Implemented Interfaces:
    com.yahoo.component.provider.Freezable, PageElement

    public final class Choice
    extends AbstractChoice
    A choice between some alternative lists of page elements.
    Author:
    bratseth
    • Constructor Summary

      Constructors 
      Constructor Description
      Choice()
      Creates an empty choice
      Choice​(java.util.List<java.util.List<PageElement>> alternatives)
      Creates a choice between some alternatives.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(PageTemplateVisitor visitor)
      Accepts a visitor to this structure
      void add​(java.util.List<PageElement> alternative)
      Convenience shorthand for if (alternative!=null) alternatives().add(alternative)
      java.util.List<java.util.List<PageElement>> alternatives()
      Returns the alternatives of this as a live reference to the alternatives of this.
      static Choice createSingleton​(PageElement singletonAlternative)
      Creates a choice having a single alternative having a single page element
      static Choice createSingletons​(java.util.List<PageElement> alternatives)
      Creates a choice in which each alternative consists of a single element
      void freeze()  
      java.util.List<PageElement> get​(int index)
      Convenience shorthand of return alternatives().get(index)
      boolean isChoiceBetween​(java.lang.Class pageTemplateModelElementClass)
      Answers true if this is either a choice between the given class, or between Lists of the given class
      boolean isEmpty()
      Returns true only if there are no alternatives in this
      java.lang.String toString()  
      • Methods inherited from class com.yahoo.component.provider.FreezableClass

        clone, ensureNotFrozen, isFrozen
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.yahoo.component.provider.Freezable

        isFrozen
    • Constructor Detail

      • Choice

        public Choice()
        Creates an empty choice
      • Choice

        public Choice​(java.util.List<java.util.List<PageElement>> alternatives)
        Creates a choice between some alternatives. This method takes a copy of the given lists.
    • Method Detail

      • createSingleton

        public static Choice createSingleton​(PageElement singletonAlternative)
        Creates a choice having a single alternative having a single page element
      • createSingletons

        public static Choice createSingletons​(java.util.List<PageElement> alternatives)
        Creates a choice in which each alternative consists of a single element
      • alternatives

        public java.util.List<java.util.List<PageElement>> alternatives()
        Returns the alternatives of this as a live reference to the alternatives of this. The list and elements may be modified unless this is frozen. This is never null.
      • get

        public java.util.List<PageElement> get​(int index)
        Convenience shorthand of return alternatives().get(index)
      • add

        public void add​(java.util.List<PageElement> alternative)
        Convenience shorthand for if (alternative!=null) alternatives().add(alternative)
      • isEmpty

        public boolean isEmpty()
        Returns true only if there are no alternatives in this
      • isChoiceBetween

        public boolean isChoiceBetween​(java.lang.Class pageTemplateModelElementClass)
        Answers true if this is either a choice between the given class, or between Lists of the given class
        Specified by:
        isChoiceBetween in class AbstractChoice
      • freeze

        public void freeze()
        Specified by:
        freeze in interface com.yahoo.component.provider.Freezable
        Overrides:
        freeze in class com.yahoo.component.provider.FreezableClass
      • accept

        public void accept​(PageTemplateVisitor visitor)
        Accepts a visitor to this structure
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object