Class AbstractList

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.ExternalArrayData, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
    Direct Known Subclasses:
    HTMLCollection, NodeList

    public class AbstractList
    extends HtmlUnitScriptable
    implements org.htmlunit.corejs.javascript.ExternalArrayData
    The parent class of NodeList and HTMLCollection.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  AbstractList.DomHtmlAttributeChangeListenerImpl  
      static class  AbstractList.EffectOnCache
      Cache effect of some changes.
      • Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        AbstractList()
      Creates an instance.
      protected AbstractList​(DomNode domNode, boolean attributeChangeSensitive, java.util.List<DomNode> initialElements)
      Creates an instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean avoidObjectDetection()
      Only needed to make collections like document.all available but "invisible" when simulating Firefox.
      protected AbstractList create​(DomNode parentScope, java.util.List<DomNode> initialElements)
      Constructs a new instance with an initial cache value.
      void defineProperty​(java.lang.String propertyName, java.lang.Object delegateTo, java.lang.reflect.Method getter, java.lang.reflect.Method setter, int attributes)
      protected java.lang.Object equivalentValues​(java.lang.Object other)
      Called for the js "==".
      java.lang.Object getArrayElement​(int index)  
      int getArrayLength()  
      java.util.List<DomNode> getElements()
      Gets the HTML elements from cache or retrieve them at first call.
      protected java.util.function.Supplier<java.util.List<DomNode>> getElementSupplier()  
      protected java.util.function.Predicate<DomNode> getIsMatchingPredicate()  
      protected java.lang.Object getIt​(java.lang.Object o)
      Private helper that retrieves the item or items corresponding to the specified index or key.
      int getLength()
      Returns the length.
      protected org.htmlunit.corejs.javascript.Scriptable getScriptableForElement​(java.lang.Object object)
      Gets the scriptable for the provided element that may already be the right scriptable.
      protected java.lang.Object getWithPreemption​(java.lang.String name)
      Returns the element or elements that match the specified key.
      protected java.lang.Object getWithPreemptionByName​(java.lang.String name, java.util.List<DomNode> elements)
      Helper for getWithPreemption(String) when finding by id doesn't get results.
      private void registerListener()  
      void setArrayElement​(int index, java.lang.Object value)  
      void setAvoidObjectDetection​(boolean newValue)  
      void setDomNode​(DomNode domNode, boolean assignScriptObject)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Sets the DOM node that corresponds to this JavaScript object.
      void setEffectOnCacheFunction​(java.util.function.Function<HtmlAttributeChangeEvent,​AbstractList.EffectOnCache> effectOnCacheFunction)  
      void setElementsSupplier​(java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier)
      Returns the elements whose associated host objects are available through this collection.
      void setIsMatchingPredicate​(java.util.function.Predicate<DomNode> isMatchingPredicate)
      Indicates if the node should belong to the collection.
      java.lang.String toString()
      • Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        applyDescriptorToAttributeBitset, associateValue, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • avoidObjectDetection_

        private boolean avoidObjectDetection_
      • attributeChangeSensitive_

        private boolean attributeChangeSensitive_
      • cachedElements_

        private java.util.List<DomNode> cachedElements_
        Cache collection elements when possible, so as to avoid expensive XPath expression evaluations.
      • listenerRegistered_

        private boolean listenerRegistered_
      • isMatchingPredicate_

        private java.util.function.Predicate<DomNode> isMatchingPredicate_
      • elementsSupplier_

        private java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier_
    • Constructor Detail

      • AbstractList

        public AbstractList()
        Creates an instance.
      • AbstractList

        protected AbstractList​(DomNode domNode,
                               boolean attributeChangeSensitive,
                               java.util.List<DomNode> initialElements)
        Creates an instance.
        Parameters:
        domNode - the DomNode
        attributeChangeSensitive - indicates if the content of the collection may change when an attribute of a descendant node of parentScope changes (attribute added, modified or removed)
        initialElements - the initial content for the cache
    • Method Detail

      • avoidObjectDetection

        public boolean avoidObjectDetection()
        Only needed to make collections like document.all available but "invisible" when simulating Firefox.
        Overrides:
        avoidObjectDetection in class org.htmlunit.corejs.javascript.ScriptableObject
      • setAvoidObjectDetection

        public void setAvoidObjectDetection​(boolean newValue)
        Parameters:
        newValue - the new value
      • getElementSupplier

        protected java.util.function.Supplier<java.util.List<DomNode>> getElementSupplier()
        Returns:
        elementSupplier
      • setElementsSupplier

        public void setElementsSupplier​(java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier)
        Returns the elements whose associated host objects are available through this collection.
        Parameters:
        elementsSupplier - the new supplier
      • getIsMatchingPredicate

        protected java.util.function.Predicate<DomNode> getIsMatchingPredicate()
        Returns:
        isMatchingPredicate
      • setIsMatchingPredicate

        public void setIsMatchingPredicate​(java.util.function.Predicate<DomNode> isMatchingPredicate)
        Indicates if the node should belong to the collection.
        Parameters:
        isMatchingPredicate - the new predicate
      • getIt

        protected java.lang.Object getIt​(java.lang.Object o)
        Private helper that retrieves the item or items corresponding to the specified index or key.
        Parameters:
        o - the index or key corresponding to the element or elements to return
        Returns:
        the element or elements corresponding to the specified index or key
      • setDomNode

        public void setDomNode​(DomNode domNode,
                               boolean assignScriptObject)
        Description copied from class: HtmlUnitScriptable
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Sets the DOM node that corresponds to this JavaScript object.
        Overrides:
        setDomNode in class HtmlUnitScriptable
        Parameters:
        domNode - the DOM node
        assignScriptObject - If true, call setScriptObject on domNode
      • getElements

        public java.util.List<DomNode> getElements()
        Gets the HTML elements from cache or retrieve them at first call.
        Returns:
        the list of HtmlElement contained in this collection
      • registerListener

        private void registerListener()
      • getWithPreemption

        protected java.lang.Object getWithPreemption​(java.lang.String name)
        Returns the element or elements that match the specified key. If it is the name of a property, the property value is returned. If it is the id of an element in the array, that element is returned. Finally, if it is the name of an element or elements in the array, then all those elements are returned. Otherwise, Scriptable.NOT_FOUND is returned.

        Called by HtmlUnitScriptable.get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.

        IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!

        Overrides:
        getWithPreemption in class HtmlUnitScriptable
        Parameters:
        name - the property name
        Returns:
        Scriptable.NOT_FOUND if not found
      • create

        protected AbstractList create​(DomNode parentScope,
                                      java.util.List<DomNode> initialElements)
        Constructs a new instance with an initial cache value.
        Parameters:
        parentScope - the parent scope, on which we listen for changes
        initialElements - the initial content for the cache
        Returns:
        the newly created instance
      • getWithPreemptionByName

        protected java.lang.Object getWithPreemptionByName​(java.lang.String name,
                                                           java.util.List<DomNode> elements)
        Helper for getWithPreemption(String) when finding by id doesn't get results.
        Parameters:
        name - the property name
        elements - the children elements.
        Returns:
        Scriptable.NOT_FOUND if not found
      • getLength

        public int getLength()
        Returns the length.
        Returns:
        the length
      • toString

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

        protected java.lang.Object equivalentValues​(java.lang.Object other)
        Called for the js "==".
        Overrides:
        equivalentValues in class HtmlUnitScriptable
      • getScriptableForElement

        protected org.htmlunit.corejs.javascript.Scriptable getScriptableForElement​(java.lang.Object object)
        Gets the scriptable for the provided element that may already be the right scriptable.
        Parameters:
        object - the object for which to get the scriptable
        Returns:
        the scriptable
      • defineProperty

        public void defineProperty​(java.lang.String propertyName,
                                   java.lang.Object delegateTo,
                                   java.lang.reflect.Method getter,
                                   java.lang.reflect.Method setter,
                                   int attributes)
        Overrides:
        defineProperty in class org.htmlunit.corejs.javascript.ScriptableObject
      • getArrayElement

        public java.lang.Object getArrayElement​(int index)
        Specified by:
        getArrayElement in interface org.htmlunit.corejs.javascript.ExternalArrayData
      • setArrayElement

        public void setArrayElement​(int index,
                                    java.lang.Object value)
        Specified by:
        setArrayElement in interface org.htmlunit.corejs.javascript.ExternalArrayData
      • getArrayLength

        public int getArrayLength()
        Specified by:
        getArrayLength in interface org.htmlunit.corejs.javascript.ExternalArrayData