public void remove()
        {
            if (canRemove == false)
            {
                throw new java.lang.IllegalStateException("Iterator remove() can only be called once after next()");
            }
            // store value as remove may change the entry in the decorator (eg.TreeMap)
            Object value = last.getValue();

            iterator.remove();
            parent.maps[1].remove(value);
            last      = null;
            canRemove = false;
        }
Exemple #2
0
        // Basics
        //-----------------------------------------------------------------------

        /**
         * Compares this Map Entry with another Map Entry.
         * <p>
         * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
         *
         * @param obj  the object to compare to
         * @return true if equal key and value
         */
        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj is java.util.MapNS.Entry <Object, Object> == false)
            {
                return(false);
            }
            java.util.MapNS.Entry <Object, Object> other = (java.util.MapNS.Entry <Object, Object>)obj;
            return
                ((getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
                 (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())));
        }
        /**
         * Returns a set of attributes present in the {@code AttributedString}.
         * An empty set returned indicates that no attributes where defined.
         *
         * @return a set of attribute keys that may be empty.
         */
        public java.util.Set <AttributedCharacterIteratorNS.Attribute> getAllAttributeKeys()
        {
            if (begin == 0 && end == attrString.text.Length &&
                attributesAllowed == null)
            {
                return(attrString.attributeMap.keySet());
            }

            java.util.Set <AttributedCharacterIteratorNS.Attribute> result = new java.util.HashSet <AttributedCharacterIteratorNS.Attribute>();//(attrString.attributeMap.size() * 4 / 3) + 1);
            java.util.Iterator <java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > > it = attrString.attributeMap
                                                                                                                                    .entrySet().iterator();
            while (it.hasNext())
            {
                java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > entry = it.next();
                if (attributesAllowed == null ||
                    attributesAllowed.contains(entry.getKey()))
                {
                    java.util.List <IAC_Range> ranges = entry.getValue();
                    if (inRange(ranges))
                    {
                        result.add(entry.getKey());
                    }
                }
            }
            return(result);
        }
        /**
         * Create a new Closure that calls one of the closures depending
         * on the predicates.
         * <p>
         * The Map consists of Predicate keys and Closure values. A closure
         * is called if its matching predicate returns true. Each predicate is evaluated
         * until one returns true. If no predicates evaluate to true, the default
         * closure is called. The default closure is set in the map with a
         * null key. The ordering is that of the iterator() method on the entryset
         * collection of the map.
         *
         * @param predicatesAndClosures  a map of predicates to closures
         * @return the <code>switch</code> closure
         * @throws IllegalArgumentException if the map is null
         * @throws IllegalArgumentException if any closure in the map is null
         * @throws ClassCastException  if the map elements are of the wrong type
         */
        public static Closure getInstance(java.util.Map <Object, Object> predicatesAndClosures)
        {
            Closure[]   closures = null;
            Predicate[] preds    = null;
            if (predicatesAndClosures == null)
            {
                throw new java.lang.IllegalArgumentException("The predicate and closure map must not be null");
            }
            if (predicatesAndClosures.size() == 0)
            {
                return(NOPClosure.INSTANCE);
            }
            // convert to array like this to guarantee iterator() ordering
            Closure defaultClosure = (Closure)predicatesAndClosures.remove(null);
            int     size           = predicatesAndClosures.size();

            if (size == 0)
            {
                return(defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure);
            }
            closures = new Closure[size];
            preds    = new Predicate[size];
            int i = 0;

            for (java.util.Iterator <Object> it = (java.util.Iterator <Object>)predicatesAndClosures.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                preds[i]    = (Predicate)entry.getKey();
                closures[i] = (Closure)entry.getValue();
                i++;
            }
            return(new SwitchClosure(preds, closures, defaultClosure));
        }
Exemple #5
0
        /**
         * Create a new Transformer that calls one of the transformers depending
         * on the predicates.
         * <p>
         * The Map consists of Predicate keys and Transformer values. A transformer
         * is called if its matching predicate returns true. Each predicate is evaluated
         * until one returns true. If no predicates evaluate to true, the default
         * transformer is called. The default transformer is set in the map with a
         * null key. The ordering is that of the iterator() method on the entryset
         * collection of the map.
         *
         * @param predicatesAndTransformers  a map of predicates to transformers
         * @return the <code>switch</code> transformer
         * @throws IllegalArgumentException if the map is null
         * @throws IllegalArgumentException if any transformer in the map is null
         * @throws ClassCastException  if the map elements are of the wrong type
         */
        public static Transformer getInstance(java.util.Map <Object, Object> predicatesAndTransformers)
        {
            Transformer[] transformers = null;
            Predicate[]   preds        = null;
            if (predicatesAndTransformers == null)
            {
                throw new java.lang.IllegalArgumentException("The predicate and transformer map must not be null");
            }
            if (predicatesAndTransformers.size() == 0)
            {
                return(ConstantTransformer.NULL_INSTANCE);
            }
            // convert to array like this to guarantee iterator() ordering
            Transformer defaultTransformer = (Transformer)predicatesAndTransformers.remove(null);
            int         size = predicatesAndTransformers.size();

            if (size == 0)
            {
                return(defaultTransformer == null ? ConstantTransformer.NULL_INSTANCE : defaultTransformer);
            }
            transformers = new Transformer[size];
            preds        = new Predicate[size];
            int i = 0;

            for (java.util.Iterator <Object> it = (java.util.Iterator <Object>)predicatesAndTransformers.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                preds[i]        = (Predicate)entry.getKey();
                transformers[i] = (Transformer)entry.getValue();
                i++;
            }
            return(new SwitchTransformer(preds, transformers, defaultTransformer));
        }
        //-----------------------------------------------------------------------

        /**
         * Returns the Map as a string.
         *
         * @return the Map as a String
         */
        public override String ToString()
        {
            if (isEmpty())
            {
                return("{}");
            }
            java.lang.StringBuffer buf = new java.lang.StringBuffer();
            buf.append('{');
            bool first = true;

            java.util.Iterator <Object> it = entrySet().iterator();
            while (it.hasNext())
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                Object key   = entry.getKey();
                Object value = entry.getValue();
                if (first)
                {
                    first = false;
                }
                else
                {
                    buf.append(", ");
                }
                buf.append(key == this ? "(this Map)" : key);
                buf.append('=');
                buf.append(value == this ? "(this Map)" : value);
            }
            buf.append('}');
            return(buf.toString());
        }
Exemple #7
0
            public override bool Equals(Object obj)
            {
                if (obj == this)
                {
                    return(true);
                }
                if (obj is java.util.MapNS.Entry <Object, Object> == false)
                {
                    return(false);
                }

                java.util.MapNS.Entry <Object, Object> e2 = (java.util.MapNS.Entry <Object, Object>)obj;
                return(
                    (key == null ? e2.getKey() == null : key.equals(e2.getKey())) &&
                    (value == null ? e2.getValue() == null : value.equals(e2.getValue())));
            }
        public bool ignoreGlobalAllowedByRobots(java.util.List <String> userAgents, String url)
        {
            String path = getPath(url);

            java.util.MapNS.Entry <Match, Match> matches = computeMatchPriorities(userAgents, path, true);
            return(allowVerdict(matches.getKey(), matches.getValue()));
        }
Exemple #9
0
        /**
         * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>.
         * <p>
         * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
         *
         * @param obj  the object to compare to
         * @return true if equal key and value
         */
        public bool equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj is java.util.MapNS.Entry <Object, Object> == false)
            {
                return(false);
            }
            java.util.MapNS.Entry <Object, Object> other = (java.util.MapNS.Entry <Object, Object>)obj;
            Object value = getValue();

            return
                ((key == null ? other.getKey() == null : key.equals(other.getKey())) &&
                 (value == null ? other.getValue() == null : value.equals(other.getValue())));
        }
 public override void putAll(java.util.Map <Object, Object> map)
 {
     for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
     {
         java.util.MapNS.Entry <Object, Object> entry = it.next();
         put(entry.getKey(), entry.getValue());
     }
 }
 public virtual Object getValue()
 {
     if (last == null)
     {
         throw new java.lang.IllegalStateException("Iterator getValue() can only be called after next() and before remove()");
     }
     return(last.getValue());
 }
Exemple #12
0
 /**
  *  Adds all the mappings in the specified map to this map, replacing any
  *  mappings that already exist (as per {@link Map#putAll(Map)}).  The order
  *  in which the entries are added is determined by the iterator returned
  *  from {@link Map#entrySet()} for the specified map.
  *
  *  @param t the mappings that should be added to this map.
  *
  *  @throws NullPointerException if <code>t</code> is <code>null</code>
  */
 public virtual void putAll(java.util.Map <Object, Object> t)
 {
     java.util.Iterator <java.util.MapNS.Entry <Object, Object> > iter = t.entrySet().iterator();
     while (iter.hasNext())
     {
         java.util.MapNS.Entry <Object, Object> entry = iter.next();
         put(entry.getKey(), entry.getValue());
     }
 }
 /**
  * Constructor copying elements from another map.
  *
  * @param map  the map to copy, must be size 1
  * @throws NullPointerException if the map is null
  * @throws IllegalArgumentException if the size is not 1
  */
 public SingletonMap(java.util.Map <Object, Object> map)
 {
     if (map.size() != 1)
     {
         throw new java.lang.IllegalArgumentException("The map size must be 1");
     }
     java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)map.entrySet().iterator().next();
     this.key   = entry.getKey();
     this.value = entry.getValue();
 }
        //-----------------------------------------------------------------------

        /**
         * Write the map out using a custom routine.
         * @param out  the output stream
         * @throws IOException
         */
        protected virtual void doWriteObject(java.io.ObjectOutputStream outJ)
        {//throws IOException {
            outJ.writeInt(map.size());
            for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                outJ.writeObject(entry.getKey());
                outJ.writeInt(((MutableInteger)entry.getValue()).value);
            }
        }
        public override bool remove(Object obj)
        {
            if (obj is java.util.MapNS.Entry <Object, Object> == false)
            {
                return(false);
            }
            java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)obj;
            Object key = entry.getKey();

            if (parent.containsKey(key))
            {
                Object value = parent.maps[0].get(key);
                if (value == null ? entry.getValue() == null : value.equals(entry.getValue()))
                {
                    parent.maps[0].remove(key);
                    parent.maps[1].remove(value);
                    return(true);
                }
            }
            return(false);
        }
Exemple #16
0
 /**
  * Applies a given set of attributes to the given range of the string.
  *
  * @param attributes
  *            the set of attributes that will be applied to this string.
  * @param start
  *            the start of the range where the attribute will be applied.
  * @param end
  *            the end of the range where the attribute will be applied.
  * @throws IllegalArgumentException
  *             if {@code start < 0}, {@code end} is greater than the length
  *             of this string, or if {@code start >= end}.
  */
 public void addAttributes(
     java.util.Map <AttributedCharacterIteratorNS.Attribute, System.Object> attributes,
     int start, int end)
 {
     java.util.Iterator <java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, System.Object> > it = attributes.entrySet().iterator();
     while (it.hasNext())
     {
         java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, System.Object> entry = it.next();
         addAttribute(entry.getKey(),
                      entry.getValue(), start, end);
     }
 }
Exemple #17
0
 public override void putAll(java.util.Map <Object, Object> mapToCopy)
 {
     java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = mapToCopy.entrySet().iterator();
     while (it.hasNext())
     {
         java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
         Object key   = entry.getKey();
         Object value = entry.getValue();
         validate(key, value);
     }
     map.putAll(mapToCopy);
 }
        /**
         * Gets a hash code for the Bag compatible with the definition of equals.
         * The hash code is defined as the sum total of a hash code for each element.
         * The per element hash code is defined as
         * <code>(e==null ? 0 : e.hashCode()) ^ noOccurances)</code>.
         * This hash code is compatible with the Set interface.
         *
         * @return the hash code of the Bag
         */
        public override int GetHashCode()
        {
            int total = 0;

            for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                Object         element = entry.getKey();
                MutableInteger count   = (MutableInteger)entry.getValue();
                total += (element == null ? 0 : element.GetHashCode()) ^ count.value;
            }
            return(total);
        }
            public bool equals(Object o)
            {
                if (o == null)
                {
                    return(false);
                }
                if (o == this)
                {
                    return(true);
                }

                if (!(o is java.util.MapNS.Entry <Object, Object>))
                {
                    return(false);
                }

                java.util.MapNS.Entry <Object, Object> e2 = (java.util.MapNS.Entry <Object, Object>)o;

                return((key == null ?
                        e2.getKey() == null : key.equals(e2.getKey())) &&
                       (value == null ?
                        e2.getValue() == null : value.equals(e2.getValue())));
            }
 /**
  * Transforms a map.
  * <p>
  * The transformer itself may throw an exception if necessary.
  *
  * @param map  the map to transform
  * @throws the transformed object
  */
 protected virtual java.util.Map <Object, Object> transformMap(java.util.Map <Object, Object> map)
 {
     if (map.isEmpty())
     {
         return(map);
     }
     java.util.Map <Object, Object> result = new LinkedMap(map.size());
     for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
     {
         java.util.MapNS.Entry <Object, Object> entry = it.next();
         result.put(transformKey(entry.getKey()), transformValue(entry.getValue()));
     }
     return(result);
 }
Exemple #21
0
 public override Object[] toArray <Object>(Object[] arr)
 {
     // special implementation to handle disappearing entries
     java.util.ArrayList <Object> list = new java.util.ArrayList <Object>();
     java.util.Iterator <Object>  it   = (java.util.Iterator <Object>) this.iterator();
     while (it.hasNext())
     {
         java.util.MapNS.Entry <Object, Object> e = (java.util.MapNS.Entry <Object, Object>)it.next(); //? right???
         object o  = new DefaultMapEntry(e.getKey(), e.getValue());
         Object o2 = (Object)o;
         list.add(o2);
     }
     return(list.toArray(arr));
 }
 public Object next()
 {
     if (parent.modCount != mods)
     {
         throw new java.util.ConcurrentModificationException();
     }
     if (itemCount == 0)
     {
         current   = (java.util.MapNS.Entry <Object, Object>)entryIterator.next();
         itemCount = ((MutableInteger)current.getValue()).value;
     }
     canRemove = true;
     itemCount--;
     return(current.getKey());
 }
Exemple #23
0
        //-----------------------------------------------------------------------

        /**
         * Constructor that wraps (not copies).
         *
         * @param map  the map to decorate, must not be null
         * @param keyPredicate  the predicate to validate the keys, null means no check
         * @param valuePredicate  the predicate to validate to values, null means no check
         * @throws IllegalArgumentException if the map is null
         */
        protected internal PredicatedMap(java.util.Map <Object, Object> map, Predicate keyPredicate, Predicate valuePredicate)
            : base(map)
        {
            this.keyPredicate   = keyPredicate;
            this.valuePredicate = valuePredicate;

            java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator();
            while (it.hasNext())
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                Object key   = entry.getKey();
                Object value = entry.getValue();
                validate(key, value);
            }
        }
        /**
         * Puts the values from the specified map into this map.
         * <p>
         * The map must be of size 0 or size 1.
         * If it is size 1, the key must match the key of this map otherwise an
         * IllegalArgumentException is thrown.
         *
         * @param map  the map to add, must be size 0 or 1, and the key must match
         * @throws NullPointerException if the map is null
         * @throws IllegalArgumentException if the key does not match
         */
        public virtual void putAll(java.util.Map <Object, Object> map)
        {
            switch (map.size())
            {
            case 0:
                return;

            case 1:
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)map.entrySet().iterator().next();
                put(entry.getKey(), entry.getValue());
                return;

            default:
                throw new java.lang.IllegalArgumentException("The map size must be 0 or 1");
            }
        }
 /**
  * Compares this map with another.
  *
  * @param obj  the object to compare to
  * @return true if equal
  */
 public override bool Equals(Object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj is java.util.Map <Object, Object> == false)
     {
         return(false);
     }
     java.util.Map <Object, Object> other = (java.util.Map <Object, Object>)obj;
     if (other.size() != 1)
     {
         return(false);
     }
     java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)other.entrySet().iterator().next();
     return(isEqualKey(entry.getKey()) && isEqualValue(entry.getValue()));
 }
 /**
  * Override superclass to ensure that MultiMap instances are
  * correctly handled.
  * <p>
  * NOTE: Prior to version 3.2, putAll(map) did not work properly
  * when passed a MultiMap.
  *
  * @param map  the map to copy (either a normal or multi map)
  */
 public override void putAll(java.util.Map <Object, Object> map)
 {
     if (map is MultiMap)
     {
         for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
         {
             java.util.MapNS.Entry <Object, Object> entry = it.next();
             java.util.Collection <Object>          coll  = (java.util.Collection <Object>)entry.getValue();
             putAll(entry.getKey(), coll);
         }
     }
     else
     {
         for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = map.entrySet().iterator(); it.hasNext();)
         {
             java.util.MapNS.Entry <Object, Object> entry = it.next();
             put(entry.getKey(), entry.getValue());
         }
     }
 }
Exemple #27
0
 public java.util.Map <AttributedCharacterIteratorNS.Attribute, System.Object> getAttributes()
 {
     java.util.Map <AttributedCharacterIteratorNS.Attribute, System.Object> result = new java.util.HashMap <AttributedCharacterIteratorNS.Attribute, System.Object>();//(attrString.attributeMap.size() * 4 / 3) + 1);
     java.util.Iterator <java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > > it = attrString.attributeMap
                                                                                                                             .entrySet().iterator();
     while (it.hasNext())
     {
         java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > entry = it.next();
         if (attributesAllowed == null ||
             attributesAllowed.contains(entry.getKey()))
         {
             System.Object value = currentValue(entry.getValue());
             if (value != null)
             {
                 result.put(entry.getKey(), value);
             }
         }
     }
     return(result);
 }
Exemple #28
0
            public override bool Equals(Object obj)
            {
                if (obj == null)
                {
                    return(false);
                }
                if (obj == this)
                {
                    return(true);
                }
                if (!(obj is java.util.MapNS.Entry <Object, Object>))
                {
                    return(false);
                }

                java.util.MapNS.Entry <Object, Object> other = (java.util.MapNS.Entry <Object, Object>)obj;

                // implemented per api docs for java.util.MapNS.Entry<Object,Object>.equals(Object)
                return(
                    (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
                    (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())));
            }
Exemple #29
0
        public void putAll(java.util.Map <Object, Object> m)
        {
            if (m is RenderingHints)
            {
                map.putAll(((RenderingHints)m).map);
            }
            else
            {
                java.util.Set <java.util.MapNS.Entry <Object, Object> > entries = m.entrySet();

                if (entries != null)
                {
                    java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = entries.iterator();
                    while (it.hasNext())
                    {
                        java.util.MapNS.Entry <Object, Object> entry = it.next();
                        Key    key = (Key)entry.getKey();
                        Object val = entry.getValue();
                        put(key, val);
                    }
                }
            }
        }
            public void remove()
            {
                if (parent.modCount != mods)
                {
                    throw new java.util.ConcurrentModificationException();
                }
                if (canRemove == false)
                {
                    throw new java.lang.IllegalStateException();
                }
                MutableInteger mut = (MutableInteger)current.getValue();

                if (mut.value > 1)
                {
                    mut.value--;
                }
                else
                {
                    entryIterator.remove();
                }
                parent.sizeJ--;
                canRemove = false;
            }