org.dbpedia.extraction.live.util.CollectionUtil Maven / Gradle / Ivy
The newest version!
package org.dbpedia.extraction.live.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.dbpedia.extraction.live.util.collections.SetDiff;
public class CollectionUtil
{
public static Set set(T ... items)
{
return new HashSet(Arrays.asList(items));
}
public static ArrayList newList(T ... items)
{
return new ArrayList(Arrays.asList(items));
}
/**
* Returns the size of the specified collection or 0 on null.
* @param
* @param collection
* @return
*/
public static int size(Collection collection)
{
return collection == null ? 0 : collection.size();
}
public static SetDiff diff(Collection extends T> old, Collection extends T> n)
{
// All new triples which were not present in old
Set added = new HashSet(n);
added.removeAll(old);
// All old triples which are not present in new
Set removed = new HashSet(old);
removed.removeAll(n);
// Triples which are common in both
Set retained = new HashSet(old);
retained.retainAll(n);
return new SetDiff(added, removed, retained);
}
}