Resource ToRes(object expr, java.util.Map knownValues, bool entities, Hashtable varMap1, Hashtable varMap2, RdfSourceWrapper src, QueryOptions opts, VariableList distinguishedVars, VariableList undistinguishedVars, java.util.Set sparqlDistinguished) { if (expr is SparqlVariable) { Variable v; if (varMap1.ContainsKey(expr)) { v = (Variable)varMap1[expr]; } else { v = new Variable(expr.ToString()); varMap1[expr] = v; varMap2[v] = expr; if (knownValues != null && knownValues.get(expr) != null) { java.util.Set values = (java.util.Set)knownValues.get(expr); VarKnownValuesList values2 = new VarKnownValuesList(); for (java.util.Iterator iter = values.iterator(); iter.hasNext(); ) { Resource r = src.ToResource((name.levering.ryan.sparql.common.Value)iter.next()); if (r != null) values2.Add(r); } opts.VariableKnownValues[v] = values2; } if (sparqlDistinguished != null && sparqlDistinguished.contains(expr)) distinguishedVars.Add(v); else undistinguishedVars.Add(v); } return v; } return entities ? src.ToEntity((name.levering.ryan.sparql.common.Value)expr) : src.ToResource((name.levering.ryan.sparql.common.Value)expr); }
//----------------------------------------------------------------------- /** * 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; }
/** * 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; }
//----------------------------------------------------------------------- /** * 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; }
/** * 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; }
/** * 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; }