//-----------------------------------------------------------------------

        /**
         * 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);
            }
        }
Beispiel #2
0
            internal bool contains(Object provider)
            {
                foreach (java.util.MapNS.Entry <java.lang.Class, ProvidersMap> e in categories.entrySet())
                {
                    ProvidersMap providers = e.getValue();
                    if (providers.contains(provider))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Beispiel #3
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));
        }
Beispiel #4
0
 public CollectionViewIterator(CollectionView view)
 {
     this.root     = view.root;
     this.view     = view;
     this.expected = root.map;
     this.iterator = expected.entrySet().iterator();
 }
        /**
         * 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));
        }
 public virtual void putAll(java.util.Map <Object, Object> map)
 {
     for (java.util.Iterator <Object> it = (java.util.Iterator <Object>)map.entrySet().iterator(); it.hasNext();)
     {
         biz.ritter.javapi.util.MapNS.Entry <Object, Object> entry = (biz.ritter.javapi.util.MapNS.Entry <Object, Object>)it.next();
         put(entry.getKey(), entry.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());
     }
 }
 /**
  * Checks if this Map equals another as per the Map specification.
  *
  * @param obj  the object to compare to
  * @return true if the maps are equal
  */
 public override bool Equals(Object obj)
 {
     if (obj is java.util.Map <Object, Object> )
     {
         java.util.Map <Object, Object> map = (java.util.Map <Object, Object>)obj;
         return(this.entrySet().equals(map.entrySet()));
     }
     return(false);
 }
Beispiel #9
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());
     }
 }
Beispiel #10
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);
 }
Beispiel #11
0
 /**
  * Compares this map to another, as per the Map specification.
  *
  * @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;
     return(entrySet().equals(other.entrySet()));
 }
 /**
  * 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);
 }
Beispiel #13
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);
            }
        }
Beispiel #14
0
            internal void clear(ServiceRegistry registry)
            {
                foreach (java.util.MapNS.Entry <java.lang.Class, Object> e in providers.entrySet())
                {
                    Object provider = e.getValue();

                    if (provider is RegisterableService)
                    {
                        ((RegisterableService)provider).onDeregistration(registry, e.getKey());
                    }
                }

                providers.clear();
                nodeMap.clear();
            }
Beispiel #15
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);
                    }
                }
            }
        }
Beispiel #16
0
        /**
         * Create a new Closure that uses the input object as a key to find the
         * closure to call.
         * <p>
         * The Map consists of object keys and Closure values. A closure
         * is called if the input object equals the key. If there is no match, the
         * default closure is called. The default closure is set in the map
         * using a null key.
         *
         * @see org.apache.commons.collections.functors.SwitchClosure
         *
         * @param objectsAndClosures  a map of objects to closures
         * @return the closure
         * @throws IllegalArgumentException if the map is null
         * @throws IllegalArgumentException if the map is empty
         * @throws IllegalArgumentException if any closure in the map is null
         */
        public static Closure switchMapClosure(java.util.Map <Object, Object> objectsAndClosures)
        {
            Closure[]   trs   = null;
            Predicate[] preds = null;
            if (objectsAndClosures == null)
            {
                throw new java.lang.IllegalArgumentException("The object and closure map must not be null");
            }
            Closure def  = (Closure)objectsAndClosures.remove(null);
            int     size = objectsAndClosures.size();

            trs   = new Closure[size];
            preds = new Predicate[size];
            int i = 0;

            for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = objectsAndClosures.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = it.next();
                preds[i] = EqualPredicate.getInstance(entry.getKey());
                trs[i]   = (Closure)entry.getValue();
                i++;
            }
            return(switchClosure(preds, trs, def));
        }
        /**
         * Create a new Transformer that uses the input object as a key to find the
         * transformer to call.
         * <p>
         * The Map consists of object keys and Transformer values. A transformer
         * is called if the input object equals the key. If there is no match, the
         * default transformer is called. The default transformer is set in the map
         * using a null key. If no default is set, null will be returned in a default case.
         *
         * @see org.apache.commons.collections.functors.SwitchTransformer
         *
         * @param objectsAndTransformers  a map of objects to transformers
         * @return the transformer
         * @throws IllegalArgumentException if the map is null
         * @throws IllegalArgumentException if the map is empty
         * @throws IllegalArgumentException if any transformer in the map is null
         */
        public static Transformer switchMapTransformer(java.util.Map <Object, Object> objectsAndTransformers)
        {
            Transformer[] trs   = null;
            Predicate[]   preds = null;
            if (objectsAndTransformers == null)
            {
                throw new java.lang.IllegalArgumentException("The object and transformer map must not be null");
            }
            Transformer def  = (Transformer)objectsAndTransformers.remove(null);
            int         size = objectsAndTransformers.size();

            trs   = new Transformer[size];
            preds = new Predicate[size];
            int i = 0;

            for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = objectsAndTransformers.entrySet().iterator(); it.hasNext();)
            {
                java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next();
                preds[i] = EqualPredicate.getInstance(entry.getKey());
                trs[i]   = (Transformer)entry.getValue();
                i++;
            }
            return(switchTransformer(preds, trs, def));
        }
 /**
  * Constructor.
  *
  * @param map  the map to iterate over
  */
 public EntrySetMapIterator(java.util.Map<Object, Object> map)
     : base()
 {
     this.map = map;
     this.iterator = (java.util.Iterator<Object>)map.entrySet().iterator();
 }
 /**
  * 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();
 }
        /**
         * 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()));
 }
Beispiel #22
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);
     }
 }
 /**
  * Constructor.
  *
  * @param map  the map to iterate over
  */
 public EntrySetMapIterator(java.util.Map <Object, Object> map)
     : base()
 {
     this.map      = map;
     this.iterator = (java.util.Iterator <Object>)map.entrySet().iterator();
 }
 /**
  * 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());
         }
     }
 }
 public CollectionViewIterator(CollectionView root)
 {
     this.root     = root;
     this.expected = root.root.map;
     this.iterator = expected.entrySet().iterator();
 }
Beispiel #26
0
 /**
  * Creates an {@code AttributedString} from the given text and the
  * attributes. The whole text has the given attributes applied.
  *
  * @param value
  *            the text to take as base for this attributed string.
  * @param attributes
  *            the attributes that the text is associated with.
  * @throws IllegalArgumentException
  *             if the length of {@code value} is 0 but the size of {@code
  *             attributes} is greater than 0.
  * @throws NullPointerException
  *             if {@code value} is {@code null}.
  */
 public AttributedString(System.String value,
                         java.util.Map <AttributedCharacterIteratorNS.Attribute, System.Object> attributes)
 {
     if (value == null)
     {
         throw new java.lang.NullPointerException();
     }
     if (value.Length == 0 && !attributes.isEmpty())
     {
         // text.0B=Cannot add attributes to empty string
         throw new java.lang.IllegalArgumentException("Cannot add attributes to empty string"); //$NON-NLS-1$
     }
     text         = value;
     attributeMap = new java.util.HashMap <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> >();//(attributes.size() * 4 / 3) + 1);
     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();
         java.util.ArrayList <IAC_Range> ranges = new java.util.ArrayList <IAC_Range>(1);
         ranges.add(new IAC_Range(0, text.Length, entry.getValue()));
         attributeMap.put((AttributedCharacterIteratorNS.Attribute)entry
                          .getKey(), ranges);
     }
 }
Beispiel #27
0
 /**
  * Returns the array of providers which meet the user supplied set of
  * filters. The filter must be supplied in one of two formats:
  * <nl>
  * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li>
  * <p/>
  * for example: "MessageDigest.SHA" The value associated with the key must
  * be an empty string. <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li>
  * ATTR_NAME:ATTR_VALUE
  * <p/>
  * for example: "Signature.MD2withRSA KeySize:512" where "KeySize:512" is
  * the value of the filter map entry.
  * </nl>
  *
  * @param filter
  *            case-insensitive filter.
  * @return the providers which meet the user supplied string filter {@code
  *         filter}. A {@code null} value signifies that none of the
  *         installed providers meets the filter specification.
  * @throws InvalidParameterException
  *             if an unusable filter is supplied.
  * @throws NullPointerException
  *             if {@code filter} is {@code null}.
  */
 public static Provider[] getProviders(java.util.Map <String, String> filter)
 {
     lock (lockJ)
     {
         if (filter == null)
         {
             throw new java.lang.NullPointerException("The filter is null"); //$NON-NLS-1$
         }
         if (filter.isEmpty())
         {
             return(null);
         }
         java.util.List <Provider> result = Services.getProvidersList();
         java.util.Set <java.util.MapNS.Entry <String, String> > keys = filter.entrySet();
         java.util.MapNS.Entry <String, String> entry;
         for (java.util.Iterator <java.util.MapNS.Entry <String, String> > it = keys.iterator(); it.hasNext();)
         {
             entry = it.next();
             String key       = entry.getKey();
             String val       = entry.getValue();
             String attribute = null;
             int    i         = key.indexOf(' ');
             int    j         = key.indexOf('.');
             if (j == -1)
             {
                 throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
             }
             if (i == -1)
             { // <crypto_service>.<algorithm_or_type>
                 if (val.length() != 0)
                 {
                     throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
                 }
             }
             else
             { // <crypto_service>.<algorithm_or_type> <attribute_name>
                 if (val.length() == 0)
                 {
                     throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
                 }
                 attribute = key.substring(i + 1);
                 if (attribute.trim().length() == 0)
                 {
                     throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
                 }
                 key = key.substring(0, i);
             }
             String serv = key.substring(0, j);
             String alg  = key.substring(j + 1);
             if (serv.length() == 0 || alg.length() == 0)
             {
                 throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
             }
             Provider p;
             for (int k = 0; k < result.size(); k++)
             {
                 try
                 {
                     p = result.get(k);
                 }
                 catch (java.lang.IndexOutOfBoundsException)
                 {
                     break;
                 }
                 if (!p.implementsAlg(serv, alg, attribute, val))
                 {
                     result.remove(p);
                     k--;
                 }
             }
         }
         if (result.size() > 0)
         {
             return(result.toArray(new Provider[result.size()]));
         }
         return(null);
     }
 }
 public virtual java.util.Set <java.util.MapNS.Entry <Object, Object> > entrySet()
 {
     return(map.entrySet());
 }
        //-----------------------------------------------------------------------

        /**
         * Resets the state of the iterator.
         */
        public void reset()
        {
            iterator  = (java.util.Iterator <Object>)map.entrySet().iterator();
            last      = null;
            canRemove = false;
        }