public virtual void add(java.lang.Iterable i, params org.openrdf.model.Resource[] rarr)
 {
     IEnumerable<Uri> contexts = rarr.ToContexts(this._mapping);
     Graph g = new Graph();
     g.Assert(new JavaIteratorWrapper<dotSesame.Statement>(i.iterator()).Select(s => SesameConverter.FromSesame(s, this._mapping)));
     this.AddInternal(g, contexts);
 }
Beispiel #2
0
 public static ArrayList ToArrayList(java.util.ArrayList jalist)
 {
     if(jalist == null) return null;
     ArrayList alist = new ArrayList();
     java.util.Iterator it = jalist.iterator();
     while(it.hasNext())
     {
         alist.Add(it.next());
     }
     return alist;
 }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  * <p>
  * If there are any elements already in the collection being decorated, they
  * are validated.
  *
  * @param coll  the collection to decorate, must not be null
  * @param predicate  the predicate to use for validation, must not be null
  * @throws IllegalArgumentException if collection or predicate is null
  * @throws IllegalArgumentException if the collection contains invalid elements
  */
 protected internal PredicatedCollection(java.util.Collection<Object> coll, Predicate predicate)
     : base(coll)
 {
     if (predicate == null)
     {
         throw new java.lang.IllegalArgumentException("Predicate must not be null");
     }
     this.predicate = predicate;
     for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
     {
         validate(it.next());
     }
 }
 /**
  * Returns <code>true</code> iff at least one element is in both collections.
  * <p>
  * In other words, this method returns <code>true</code> iff the
  * {@link #intersection} of <i>coll1</i> and <i>coll2</i> is not empty.
  *
  * @param coll1  the first collection, must not be null
  * @param coll2  the first collection, must not be null
  * @return <code>true</code> iff the intersection of the collections is non-empty
  * @since 2.1
  * @see #intersection
  */
 public static bool containsAny(java.util.Collection<Object> coll1, java.util.Collection<Object> coll2)
 {
     if (coll1.size() < coll2.size())
     {
         for (java.util.Iterator<Object> it = coll1.iterator(); it.hasNext(); )
         {
             if (coll2.contains(it.next()))
             {
                 return true;
             }
         }
     }
     else
     {
         for (java.util.Iterator<Object> it = coll2.iterator(); it.hasNext(); )
         {
             if (coll1.contains(it.next()))
             {
                 return true;
             }
         }
     }
     return false;
 }
        /**
         * Generates a hash code using the algorithm specified in
         * {@link java.util.List#hashCode()}.
         * <p>
         * This method is useful for implementing <code>List</code> when you cannot
         * extend AbstractList. The method takes Collection instances to enable other
         * collection types to use the List implementation algorithm.
         *
         * @see java.util.List#hashCode()
         * @param list  the list to generate the hashCode for, may be null
         * @return the hash code
         */
        public static int hashCodeForList(java.util.Collection<Object> list)
        {
            if (list == null)
            {
                return 0;
            }
            int hashCode = 1;
            java.util.Iterator<Object> it = list.iterator();
            Object obj = null;

            while (it.hasNext())
            {
                obj = it.next();
                hashCode = 31 * hashCode + (obj == null ? 0 : obj.GetHashCode());
            }
            return hashCode;
        }
        /**
         * Adds a collection of objects to the end of the list avoiding duplicates.
         * <p>
         * Only elements that are not already in this list will be added, and
         * duplicates from the specified collection will be ignored.
         * <p>
         * <i>(Violation)</i>
         * The <code>List</code> interface makes the assumption that the elements
         * are always inserted. This may not happen with this implementation.
         *
         * @param index  the index to insert at
         * @param coll  the collection to add in iterator order
         * @return true if this collection changed
         */
        public override bool addAll(int index, java.util.Collection<Object> coll)
        {
            // gets initial size
            int sizeBefore = size();

            // adds all elements
            for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
            {
                add(it.next());
            }

            // compares sizes to detect if collection changed
            return sizeBefore != size();
        }
 /**
  * Override to validate the objects being added to ensure they match
  * the predicate. If any one fails, no update is made to the underlying
  * collection.
  *
  * @param coll  the collection being added
  * @return the result of adding to the underlying collection
  * @throws IllegalArgumentException if the add is invalid
  */
 public override bool addAll(java.util.Collection<Object> coll)
 {
     for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
     {
         validate(it.next());
     }
     return getCollection().addAll(coll);
 }
        public bool removeAll(java.util.Collection c)
        {
            JavaIteratorWrapper<dotSesame.Statement> stmtIter = new JavaIteratorWrapper<org.openrdf.model.Statement>(c.iterator());
            bool removed = false;
            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (this._g.ContainsTriple(t))
                {
                    this._g.Retract(t);
                    removed = removed || true;
                }
            }

            return removed;
        }
 /**
  * Transforms a collection.
  * <p>
  * The transformer itself may throw an exception if necessary.
  *
  * @param coll  the collection to transform
  * @return a transformed object
  */
 protected virtual java.util.Collection<Object> transform(java.util.Collection<Object> coll)
 {
     java.util.List<Object> list = new java.util.ArrayList<Object>(coll.size());
     for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
     {
         list.add(transform(it.next()));
     }
     return list;
 }
 /**
  * Returns a {@link Map} mapping each unique element in the given
  * {@link Collection} to an {@link Integer} representing the number
  * of occurrences of that element in the {@link Collection}.
  * <p>
  * Only those elements present in the collection will appear as
  * keys in the map.
  *
  * @param coll  the collection to get the cardinality map for, must not be null
  * @return the populated cardinality map
  */
 public static java.util.Map<Object, Object> getCardinalityMap(java.util.Collection<Object> coll)
 {
     java.util.Map<Object, Object> count = new java.util.HashMap<Object, Object>();
     for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
     {
         Object obj = it.next();
         java.lang.Integer c = (java.lang.Integer)(count.get(obj));
         if (c == null)
         {
             count.put(obj, INTEGER_ONE);
         }
         else
         {
             count.put(obj, new java.lang.Integer(c.intValue() + 1));
         }
     }
     return count;
 }
 public bool addAll(java.util.Collection c)
 {
     JavaIteratorWrapper<dotSesame.Statement> stmtIter = new JavaIteratorWrapper<dotSesame.Statement>(c.iterator());
     bool added = false;
     foreach (dotSesame.Statement stmt in stmtIter)
     {
         Triple t = SesameConverter.FromSesame(stmt, this._mapping);
         if (!this._g.ContainsTriple(t))
         {
             this._g.Assert(t);
             added = added || true;
         }
     }
     return added;
 }
 /**
  * Finds the first element in the given collection which matches the given predicate.
  * <p>
  * If the input collection or predicate is null, or no element of the collection
  * matches the predicate, null is returned.
  *
  * @param collection  the collection to search, may be null
  * @param predicate  the predicate to use, may be null
  * @return the first element of the collection which matches the predicate or null if none could be found
  */
 public static Object find(java.util.Collection<Object> collection, Predicate predicate)
 {
     if (collection != null && predicate != null)
     {
         for (java.util.Iterator<Object> iter = collection.iterator(); iter.hasNext(); )
         {
             Object item = iter.next();
             if (predicate.evaluate(item))
             {
                 return item;
             }
         }
     }
     return null;
 }
 /**
  * Executes the given closure on each element in the collection.
  * <p>
  * If the input collection or closure is null, there is no change made.
  *
  * @param collection  the collection to get the input from, may be null
  * @param closure  the closure to perform, may be null
  */
 public static void forAllDo(java.util.Collection<Object> collection, Closure closure)
 {
     if (collection != null && closure != null)
     {
         for (java.util.Iterator<Object> it = collection.iterator(); it.hasNext(); )
         {
             closure.execute(it.next());
         }
     }
 }
 /**
  * Filter the collection by applying a Predicate to each element. If the
  * predicate returns false, remove the element.
  * <p>
  * If the input collection or predicate is null, there is no change made.
  *
  * @param collection  the collection to get the input from, may be null
  * @param predicate  the predicate to use as a filter, may be null
  */
 public static void filter(java.util.Collection<Object> collection, Predicate predicate)
 {
     if (collection != null && predicate != null)
     {
         for (java.util.Iterator<Object> it = collection.iterator(); it.hasNext(); )
         {
             if (predicate.evaluate(it.next()) == false)
             {
                 it.remove();
             }
         }
     }
 }
 /**
  * Answers true if a predicate is true for at least one element of a collection.
  * <p>
  * A <code>null</code> collection or predicate returns false.
  *
  * @param collection the collection to get the input from, may be null
  * @param predicate the predicate to use, may be null
  * @return true if at least one element of the collection matches the predicate
  */
 public static bool exists(java.util.Collection<Object> collection, Predicate predicate)
 {
     if (collection != null && predicate != null)
     {
         for (java.util.Iterator<Object> it = collection.iterator(); it.hasNext(); )
         {
             if (predicate.evaluate(it.next()))
             {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Counts the number of elements in the input collection that match the predicate.
  * <p>
  * A <code>null</code> collection or predicate matches no elements.
  *
  * @param inputCollection  the collection to get the input from, may be null
  * @param predicate  the predicate to use, may be null
  * @return the number of matches for the predicate in the collection
  */
 public static int countMatches(java.util.Collection<Object> inputCollection, Predicate predicate)
 {
     int count = 0;
     if (inputCollection != null && predicate != null)
     {
         for (java.util.Iterator<Object> it = inputCollection.iterator(); it.hasNext(); )
         {
             if (predicate.evaluate(it.next()))
             {
                 count++;
             }
         }
     }
     return count;
 }
 /**
  * Returns the number of occurrences of <i>obj</i> in <i>coll</i>.
  *
  * @param obj  the object to find the cardinality of
  * @param coll  the collection to search
  * @return the the number of occurrences of obj in coll
  */
 public static int cardinality(Object obj, java.util.Collection<Object> coll)
 {
     if (coll is java.util.Set<Object>)
     {
         return (coll.contains(obj) ? 1 : 0);
     }
     if (coll is Bag)
     {
         return ((Bag)coll).getCount(obj);
     }
     int count = 0;
     if (obj == null)
     {
         for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
         {
             if (it.next() == null)
             {
                 count++;
             }
         }
     }
     else
     {
         for (java.util.Iterator<Object> it = coll.iterator(); it.hasNext(); )
         {
             if (obj.equals(it.next()))
             {
                 count++;
             }
         }
     }
     return count;
 }
 /**
  * Returns <tt>true</tt> iff <i>a</i> is a sub-collection of <i>b</i>,
  * that is, iff the cardinality of <i>e</i> in <i>a</i> is less
  * than or equal to the cardinality of <i>e</i> in <i>b</i>,
  * for each element <i>e</i> in <i>a</i>.
  *
  * @param a  the first (sub?) collection, must not be null
  * @param b  the second (super?) collection, must not be null
  * @return <code>true</code> iff <i>a</i> is a sub-collection of <i>b</i>
  * @see #isProperSubCollection
  * @see Collection#containsAll
  */
 public static bool isSubCollection(java.util.Collection<Object> a, java.util.Collection<Object> b)
 {
     java.util.Map<Object, Object> mapa = getCardinalityMap(a);
     java.util.Map<Object, Object> mapb = getCardinalityMap(b);
     java.util.Iterator<Object> it = a.iterator();
     while (it.hasNext())
     {
         Object obj = it.next();
         if (getFreq(obj, mapa) > getFreq(obj, mapb))
         {
             return false;
         }
     }
     return true;
 }
 /**
  * Create a new Transformer that calls each transformer in turn, passing the
  * result into the next transformer. The ordering is that of the iterator()
  * method on the collection.
  *
  * @param transformers  a collection of transformers to chain
  * @return the <code>chained</code> transformer
  * @throws IllegalArgumentException if the transformers collection is null
  * @throws IllegalArgumentException if any transformer in the collection is null
  */
 public static Transformer getInstance(java.util.Collection<Object> transformers)
 {
     if (transformers == null)
     {
         throw new java.lang.IllegalArgumentException("Transformer collection must not be null");
     }
     if (transformers.size() == 0)
     {
         return NOPTransformer.INSTANCE;
     }
     // convert to array like this to guarantee iterator() ordering
     Transformer[] cmds = new Transformer[transformers.size()];
     int i = 0;
     for (java.util.Iterator<Object> it = transformers.iterator(); it.hasNext(); )
     {
         cmds[i++] = (Transformer)it.next();
     }
     FunctorUtils.validate(cmds);
     return new ChainedTransformer(cmds);
 }
        //-----------------------------------------------------------------------
        /**
         * Returns a new list containing all elements that are contained in
         * both given lists.
         *
         * @param list1  the first list
         * @param list2  the second list
         * @return  the intersection of those two lists
         * @throws NullPointerException if either list is null
         */
        public static java.util.List<Object> intersection(java.util.List<Object> list1, java.util.List<Object> list2)
        {
            java.util.ArrayList<Object> result = new java.util.ArrayList<Object>();
            java.util.Iterator<Object> iterator = list2.iterator();

            while (iterator.hasNext())
            {
                Object o = iterator.next();

                if (list1.contains(o))
                {
                    result.add(o);
                }
            }

            return result;
        }
        public bool containsAll(java.util.Collection c)
        {
            JavaIteratorWrapper<dotSesame.Statement> stmtIter = new JavaIteratorWrapper<org.openrdf.model.Statement>(c.iterator());
            bool contains = true;
            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (!this._g.ContainsTriple(t))
                {
                    contains = false;
                    break;
                }
            }

            return contains;
        }
        /**
         * Tests two lists for value-equality as per the equality contract in
         * {@link java.util.List#equals(java.lang.Object)}.
         * <p>
         * This method is useful for implementing <code>List</code> when you cannot
         * extend AbstractList. The method takes Collection instances to enable other
         * collection types to use the List implementation algorithm.
         * <p>
         * The relevant text (slightly paraphrased as this is a static method) is:
         * <blockquote>
         * Compares the two list objects for equality.  Returns
         * <tt>true</tt> if and only if both
         * lists have the same size, and all corresponding pairs of elements in
         * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
         * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
         * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
         * equal if they contain the same elements in the same order.  This
         * definition ensures that the equals method works properly across
         * different implementations of the <tt>List</tt> interface.
         * </blockquote>
         *
         * <b>Note:</b> The behaviour of this method is undefined if the lists are
         * modified during the equals comparison.
         *
         * @see java.util.List
         * @param list1  the first list, may be null
         * @param list2  the second list, may be null
         * @return whether the lists are equal by value comparison
         */
        public static bool isEqualList(java.util.Collection<Object> list1, java.util.Collection<Object> list2)
        {
            if (list1 == list2)
            {
                return true;
            }
            if (list1 == null || list2 == null || list1.size() != list2.size())
            {
                return false;
            }

            java.util.Iterator<Object> it1 = list1.iterator();
            java.util.Iterator<Object> it2 = list2.iterator();
            Object obj1 = null;
            Object obj2 = null;

            while (it1.hasNext() && it2.hasNext())
            {
                obj1 = it1.next();
                obj2 = it2.next();

                if (!(obj1 == null ? obj2 == null : obj1.equals(obj2)))
                {
                    return false;
                }
            }

            return !(it1.hasNext() || it2.hasNext());
        }
 public bool retainAll(java.util.Collection c)
 {
     JavaIteratorWrapper<dotSesame.Statement> stmtIter = new JavaIteratorWrapper<org.openrdf.model.Statement>(c.iterator());
     HashSet<Triple> retained = new HashSet<Triple>();
     bool changed = false;
     foreach (dotSesame.Statement stmt in stmtIter)
     {
         retained.Add(SesameConverter.FromSesame(stmt, this._mapping));
     }
     foreach (Triple t in this._g.Triples.ToList())
     {
         if (!retained.Contains(t))
         {
             changed = true;
             this._g.Retract(t);
         }
     }
     return changed;
 }
 /**
  * Removes the elements in <code>remove</code> from <code>collection</code>. That is, this
  * method returns a list containing all the elements in <code>c</code>
  * that are not in <code>remove</code>. The cardinality of an element <code>e</code>
  * in the returned collection is the same as the cardinality of <code>e</code>
  * in <code>collection</code> unless <code>remove</code> contains <code>e</code>, in which
  * case the cardinality is zero. This method is useful if you do not wish to modify
  * <code>collection</code> and thus cannot call <code>collection.removeAll(remove);</code>.
  *
  * @param collection  the collection from which items are removed (in the returned collection)
  * @param remove  the items to be removed from the returned <code>collection</code>
  * @return a <code>List</code> containing all the elements of <code>c</code> except
  * any elements that also occur in <code>remove</code>.
  * @throws NullPointerException if either parameter is null
  * @since Commons Collections 3.2
  */
 public static java.util.List<Object> removeAll(java.util.Collection<Object> collection, java.util.Collection<Object> remove)
 {
     java.util.List<Object> list = new java.util.ArrayList<Object>();
     for (java.util.Iterator<Object> iter = collection.iterator(); iter.hasNext(); )
     {
         Object obj = iter.next();
         if (remove.contains(obj) == false)
         {
             list.add(obj);
         }
     }
     return list;
 }
 /**
  * Validate the predicates to ensure that all is well.
  *
  * @param predicates  the predicates to validate
  * @return predicate array
  */
 internal static Predicate[] validate(java.util.Collection<Predicate> predicates)
 {
     if (predicates == null)
     {
         throw new java.lang.IllegalArgumentException("The predicate collection must not be null");
     }
     // convert to array like this to guarantee iterator() ordering
     Predicate[] preds = new Predicate[predicates.size()];
     int i = 0;
     for (java.util.Iterator<Predicate> it = predicates.iterator(); it.hasNext(); )
     {
         preds[i] = it.next();
         if (preds[i] == null)
         {
             throw new java.lang.IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null");
         }
         i++;
     }
     return preds;
 }
 /**
  * Returns a new {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>.
  * The cardinality of each element <i>e</i> in the returned {@link Collection}
  * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality
  * of <i>e</i> in <i>b</i>, or zero, whichever is greater.
  *
  * @param a  the collection to subtract from, must not be null
  * @param b  the collection to subtract, must not be null
  * @return a new collection with the results
  * @see Collection#removeAll
  */
 public static java.util.Collection<Object> subtract(java.util.Collection<Object> a, java.util.Collection<Object> b)
 {
     java.util.ArrayList<Object> list = new java.util.ArrayList<Object>(a);
     for (java.util.Iterator<Object> it = b.iterator(); it.hasNext(); )
     {
         list.remove(it.next());
     }
     return list;
 }
        /**
         * Generates a hash code using the algorithm specified in
         * {@link java.util.Set#hashCode()}.
         * <p>
         * This method is useful for implementing <code>Set</code> when you cannot
         * extend AbstractSet. The method takes Collection instances to enable other
         * collection types to use the Set implementation algorithm.
         *
         * @see java.util.Set#hashCode()
         * @param set  the set to calculate the hash code for, may be null
         * @return the hash code
         */
        public static int hashCodeForSet(java.util.Collection<Object> set)
        {
            if (set == null)
            {
                return 0;
            }
            int hashCode = 0;
            java.util.Iterator<Object> it = set.iterator();
            Object obj = null;

            while (it.hasNext())
            {
                obj = it.next();
                if (obj != null)
                {
                    hashCode += obj.GetHashCode();
                }
            }
            return hashCode;
        }
        /**
         * Subtracts all elements in the second list from the first list,
         * placing the results in a new list.
         * <p>
         * This differs from {@link List#removeAll(Collection)} in that
         * cardinality is respected; if <Code>list1</Code> contains two
         * occurrences of <Code>null</Code> and <Code>list2</Code> only
         * contains one occurrence, then the returned list will still contain
         * one occurrence.
         *
         * @param list1  the list to subtract from
         * @param list2  the list to subtract
         * @return  a new list containing the results
         * @throws NullPointerException if either list is null
         */
        public static java.util.List<Object> subtract(java.util.List<Object> list1, java.util.List<Object> list2)
        {
            java.util.ArrayList<Object> result = new java.util.ArrayList<Object>(list1);
            java.util.Iterator<Object> iterator = list2.iterator();

            while (iterator.hasNext())
            {
                result.remove(iterator.next());
            }

            return result;
        }
        //-----------------------------------------------------------------------
        /**
         * Returns a List containing all the elements in <code>collection</code>
         * that are also in <code>retain</code>. The cardinality of an element <code>e</code>
         * in the returned list is the same as the cardinality of <code>e</code>
         * in <code>collection</code> unless <code>retain</code> does not contain <code>e</code>, in which
         * case the cardinality is zero. This method is useful if you do not wish to modify
         * the collection <code>c</code> and thus cannot call <code>collection.retainAll(retain);</code>.
         *
         * @param collection  the collection whose contents are the target of the #retailAll operation
         * @param retain  the collection containing the elements to be retained in the returned collection
         * @return a <code>List</code> containing all the elements of <code>c</code>
         * that occur at least once in <code>retain</code>.
         * @throws NullPointerException if either parameter is null
         * @since Commons Collections 3.2
         */
        public static java.util.List<Object> retainAll(java.util.Collection<Object> collection, java.util.Collection<Object> retain)
        {
            java.util.List<Object> list = new java.util.ArrayList<Object>(java.lang.Math.min(collection.size(), retain.size()));

            for (java.util.Iterator<Object> iter = collection.iterator(); iter.hasNext(); )
            {
                Object obj = iter.next();
                if (retain.contains(obj))
                {
                    list.add(obj);
                }
            }
            return list;
        }
 /**
  * Transforms all elements from inputCollection with the given transformer
  * and adds them to the outputCollection.
  * <p>
  * If the input collection or transformer is null, there is no change to the
  * output collection.
  *
  * @param inputCollection  the collection to get the input from, may be null
  * @param transformer  the transformer to use, may be null
  * @param outputCollection  the collection to output into, may not be null
  * @return the outputCollection with the transformed input added
  * @throws NullPointerException if the output collection is null
  */
 public static java.util.Collection<Object> collect(java.util.Collection<Object> inputCollection, Transformer transformer, java.util.Collection<Object> outputCollection)
 {
     if (inputCollection != null)
     {
         return collect(inputCollection.iterator(), transformer, outputCollection);
     }
     return outputCollection;
 }