/** * Returns the sum of the given lists. This is their intersection * subtracted from their union. * * @param list1 the first list * @param list2 the second list * @return a new list containing the sum of those lists * @throws NullPointerException if either list is null */ public static List sum(final List list1, final List list2) { return subtract(union(list1, list2), intersection(list1, list2)); }
public static boolean areSameColumns(List<FieldSchema> oldCols, List<FieldSchema> newCols) { return ListUtils.isEqualList(oldCols, newCols); }
/** * Returns a collection 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 collection 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>c.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>Collection</code> containing all the elements of <code>collection</code> * that occur at least once in <code>retain</code>. * @throws NullPointerException if either parameter is null * @since Commons Collections 3.2 */ public static Collection retainAll(Collection collection, Collection retain) { return ListUtils.retainAll(collection, retain); }
/** * The accepted data types of a group item is the same as of the underlying base item. * If none is defined, the intersection of all sets of accepted data types of all group * members is used instead. * * @return the accepted data types of this group item */ @Override @SuppressWarnings("unchecked") public List<Class<? extends State>> getAcceptedDataTypes() { if (baseItem != null) { return baseItem.getAcceptedDataTypes(); } else { List<Class<? extends State>> acceptedDataTypes = null; for (Item item : members) { if (acceptedDataTypes == null) { acceptedDataTypes = item.getAcceptedDataTypes(); } else { acceptedDataTypes = ListUtils.intersection(acceptedDataTypes, item.getAcceptedDataTypes()); } } return acceptedDataTypes == null ? ListUtils.EMPTY_LIST : acceptedDataTypes; } }
private void verify(String duration, List<TimestampedDatasetVersion> toBeDeleted, List<TimestampedDatasetVersion> toBeRetained) { @SuppressWarnings("unchecked") List<TimestampedDatasetVersion> allVersions = ListUtils.union(toBeRetained, toBeDeleted); List<TimestampedDatasetVersion> deletableVersions = Lists.newArrayList(new TimeBasedRetentionPolicy(duration).listDeletableVersions(allVersions)); assertThat(deletableVersions, Matchers.containsInAnyOrder(toBeDeleted.toArray())); assertThat(deletableVersions, Matchers.not(Matchers.containsInAnyOrder(toBeRetained.toArray()))); }
public double simJ (ArrayList<Integer> intent1, ArrayList<Integer>intent2){ return 1.*(ListUtils.intersection(intent1,intent2)).size()/(ListUtils.union(intent1,intent2)).size() ; }
private List<?> mergeDeltaContent(List<?> giveValues, List<?> foundValues) { return ListUtils.subtract(giveValues, foundValues); }
private List<?> mergeTargetContent(List<?> giveValues, List<?> foundValues, AtomicBoolean hasChange) { List<?> result = null; if (pull) { result = ListUtils.subtract(foundValues, giveValues); } else { result = ListUtils.sum(foundValues, giveValues); } hasChange.set(!ListUtils.isEqualList(result, foundValues)); return result; } }
diff = !ListUtils.isEqualList(keyObjs.keySet(), keyObject.keySet()); if (!ListUtils.subtract(exsitingOption, info.getIndexOptions()).isEmpty() || !ListUtils.subtract(info.getIndexOptions(), exsitingOption).isEmpty()) { diff = true;
/** * Removes the elements in <code>remove</code> from <code>collection</code>. That is, this * method returns a collection 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 * the collection <code>c</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>Collection</code> containing all the elements of <code>collection</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 Collection removeAll(Collection collection, Collection remove) { return ListUtils.removeAll(collection, remove); }
public void testHashCode() { Collection data = Arrays.asList( new String[] { "a", "b", "c" }); List a = new ArrayList( data ); List b = new ArrayList( data ); assertEquals(true, a.hashCode() == b.hashCode()); assertEquals(true, a.hashCode() == ListUtils.hashCodeForList(a)); assertEquals(true, b.hashCode() == ListUtils.hashCodeForList(b)); assertEquals(true, ListUtils.hashCodeForList(a) == ListUtils.hashCodeForList(b)); a.clear(); assertEquals(false, ListUtils.hashCodeForList(a) == ListUtils.hashCodeForList(b)); assertEquals(0, ListUtils.hashCodeForList(null)); }
/** * The accepted command types of a group item is the same as of the underlying base item. * If none is defined, the intersection of all sets of accepted command types of all group * members is used instead. * * @return the accepted command types of this group item */ @Override @SuppressWarnings("unchecked") public List<Class<? extends Command>> getAcceptedCommandTypes() { if (baseItem != null) { return baseItem.getAcceptedCommandTypes(); } else { List<Class<? extends Command>> acceptedCommandTypes = null; for (Item item : members) { if (acceptedCommandTypes == null) { acceptedCommandTypes = item.getAcceptedCommandTypes(); } else { acceptedCommandTypes = ListUtils.intersection(acceptedCommandTypes, item.getAcceptedCommandTypes()); } } return acceptedCommandTypes == null ? ListUtils.EMPTY_LIST : acceptedCommandTypes; } }
@Test public void updateGetAndReplaceConcurrently() throws Exception { AtomicBoolean condition = new AtomicBoolean( true ); AtomicInteger generator = new AtomicInteger( 10 ); List<Updater> updaters = new ArrayList<>(); for ( int i = 0; i < updatersAmount; i++ ) { Updater updater = new Updater( jobMap, generator, updatersCycles ); updaters.add( updater ); } List<Getter> getters = new ArrayList<>(); for ( int i = 0; i < gettersAmount; i++ ) { getters.add( new Getter( jobMap, condition ) ); } List<Replacer> replacers = new ArrayList<>(); for ( int i = 0; i < replaceAmount; i++ ) { replacers.add( new Replacer( jobMap, condition ) ); } //noinspection unchecked ConcurrencyTestRunner.runAndCheckNoExceptionRaised( updaters, ListUtils.union( replacers, getters ), condition ); }
public double simSMC (ArrayList<Integer> intent1, ArrayList<Integer>intent2){ int tp = (ListUtils.intersection(intent1,intent2)).size(); ArrayList<Integer> fnlst = new ArrayList<Integer>(); fnlst.addAll(this.attributes); fnlst.removeAll(ListUtils.union(intent1,intent2)); int fn = fnlst.size(); return (this.attributes.size()>0) ? 1.*(tp + fn)/this.attributes.size() : 0; }
/** * 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 */ @SuppressWarnings("unchecked") public static <T> List<T> subtract(final List<T> list1, final List<T> list2) { return org.apache.commons.collections.ListUtils.subtract(list1, list2); }
diff = !ListUtils.isEqualList(keyObjs.keySet(), keyObject.keySet()); if (!ListUtils.subtract(exsitingOption, info.getIndexOptions()).isEmpty() || !ListUtils.subtract(info.getIndexOptions(), exsitingOption).isEmpty()) { diff = true;
/** * Removes the elements in <code>remove</code> from <code>collection</code>. That is, this * method returns a collection 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 * the collection <code>c</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>Collection</code> containing all the elements of <code>collection</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 Collection removeAll(Collection collection, Collection remove) { return ListUtils.removeAll(collection, remove); }
@Override public int hashCode() { return ListUtils.hashCodeForList(this); }
/** * Returns the sum of the given lists. This is their intersection * subtracted from their union. * * @param list1 the first list * @param list2 the second list * @return a new list containing the sum of those lists * @throws NullPointerException if either list is null */ public static List sum(final List list1, final List list2) { return subtract(union(list1, list2), intersection(list1, list2)); }
/** * 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 */ @SuppressWarnings("unchecked") public static <T> List<T> intersection(final List<T> list1, final List<T> list2) { return org.apache.commons.collections.ListUtils.intersection(list1, list2); }