Example usage for com.google.common.collect Sets newHashSet

List of usage examples for com.google.common.collect Sets newHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newHashSet.

Prototype

public static <E> HashSet<E> newHashSet() 

Source Link

Document

Creates a mutable, initially empty HashSet instance.

Usage

From source file:org.eclipse.xtext.common.types.util.RawSuperTypes.java

public Set<String> collectNames(JvmType type) {
    Set<JvmType> superTypes = collect(type);
    final Set<String> superTypeNames = Sets.newHashSet();
    for (JvmType collectedSuperType : superTypes) {
        superTypeNames.add(collectedSuperType.getIdentifier());
    }// www .  j  ava2s .  com
    return superTypeNames;
}

From source file:presto.android.gui.PropertyManager.java

public Set<String> getTextsOrTitlesOfView(NObjectNode view) {
    Iterator<NNode> textNodes = view.getTextNodes();
    Set<String> titles = Sets.newHashSet();
    while (textNodes.hasNext()) {
        NNode textNode = textNodes.next();
        String title = textNodeToString(textNode);
        if (title != null) {
            titles.add(title);//  w  ww  .j  av a2  s .  c om
        }
    }
    return titles;
}

From source file:au.edu.uq.nmerge.mvd.CompactNode.java

CompactNode(int index) {
    this.incoming = Sets.newHashSet();
    this.outgoing = Sets.newHashSet();
    this.index = index;
}

From source file:com.censoredsoftware.library.schematic.Schematic.java

public Set<Point> getLocations(Point reference) {
    Set<Point> locations = Sets.newHashSet();
    for (Selection cuboid : this)
        locations.addAll(cuboid.getBlockLocations(reference));
    return locations;
}

From source file:org.eclipse.emf.compare.utils.SimilarityUtil.java

/**
 * Computes the dice coefficient between the two given String's bigrams.
 * <p>//from   ww w  .  j  a v a2s.c om
 * This implementation is case insensitive.
 * </p>
 * 
 * @param first
 *            First of the two Strings to compare.
 * @param second
 *            Second of the two Strings to compare.
 * @return The dice coefficient of the two given String's bigrams, ranging from 0 to 1.
 */
public static double diceCoefficient(String first, String second) {
    final char[] str1 = first.toLowerCase().toCharArray();
    final char[] str2 = second.toLowerCase().toCharArray();

    final double coefficient;

    if (str1.equals(str2)) {
        coefficient = 1d;
    } else if (str1.length <= 2 || str2.length <= 2) {
        int equalChars = 0;

        for (int i = 0; i < Math.min(str1.length, str2.length); i++) {
            if (str1[i] == str2[i]) {
                equalChars++;
            }
        }

        int union = str1.length + str2.length;
        if (str1.length != str2.length) {
            coefficient = (double) equalChars / union;
        } else {
            coefficient = ((double) equalChars * 2) / union;
        }
    } else {
        Set<String> s1Bigrams = Sets.newHashSet();
        Set<String> s2Bigrams = Sets.newHashSet();

        for (int i = 0; i < str1.length - 1; i++) {
            char[] chars = new char[] { str1[i], str1[i + 1], };
            s1Bigrams.add(String.valueOf(chars));
        }
        for (int i = 0; i < str2.length - 1; i++) {
            char[] chars = new char[] { str2[i], str2[i + 1], };
            s2Bigrams.add(String.valueOf(chars));
        }

        Set<String> intersection = Sets.newHashSet(s1Bigrams);
        intersection.retainAll(s2Bigrams);
        coefficient = (2 * intersection.size()) / (s1Bigrams.size() + s2Bigrams.size());
    }

    return coefficient;
}

From source file:com.mysema.query.util.CollectionUtils.java

public static <T> Set<T> add(Set<T> set, T element) {
    final int size = set.size();
    if (size == 0) {
        return ImmutableSet.of(element);
    } else if (set instanceof ImmutableSet) {
        if (size == 1) {
            final T val = set.iterator().next();
            set = Sets.newHashSet();
            set.add(val);
        } else {/*from   w  ww. j  ava 2 s.c o  m*/
            set = Sets.newHashSet(set);
        }
    }
    set.add(element);
    return set;
}

From source file:ru.frostman.web.classloading.ClassPathUtil.java

public static List<ClassFile> findClassFiles(List<String> packageNames) {
    final List<ClassFile> classes = Lists.newLinkedList();
    final Set<String> classNames = Sets.newHashSet();

    for (String packageName : packageNames) {
        try {/*from w  w w . j  av  a  2 s .c  om*/
            String realPath = packageName.replace('.', '/');
            Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(realPath);
            while (resources.hasMoreElements()) {
                URL resource = resources.nextElement();
                Preconditions.checkNotNull(resource, "no resource for: {}", packageName);
                String filePath = resource.getFile();

                File dir = new File(filePath);
                if (dir.exists()) {
                    scanDirectory(packageName, dir, classes, classNames);
                } else if ((filePath.indexOf("!") > 0) && (filePath.indexOf(".jar") > 0)) {
                    String jarPath = filePath.substring(0, filePath.indexOf("!"))
                            .substring(filePath.indexOf(":") + 1);
                    // WINDOWS HACK
                    if (jarPath.contains(":")) {
                        jarPath = jarPath.substring(1);
                    }

                    scanJarFile(packageName, new File(jarPath), classes, classNames);
                }
            }
        } catch (IOException e) {
            log.warn("Error while scanning for class files in package: {}", e);
        }
    }

    return classes;
}

From source file:org.opendaylight.controller.sal.binding.yang.types.UnionDependencySort.java

private static Set<ExtendedType> unionsFromTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
    final Set<ExtendedType> unions = Sets.newHashSet();

    for (final TypeDefinition<?> typedef : typeDefinitions) {
        if ((typedef != null) && (typedef.getBaseType() != null)) {
            if (typedef instanceof ExtendedType && typedef.getBaseType() instanceof UnionTypeDefinition) {
                unions.add((ExtendedType) typedef);
            }/* ww  w.  jav  a 2 s  .  c o m*/
        }
    }
    return unions;
}

From source file:com.romeikat.datamessie.core.processing.task.documentReindexing.DocumentsToBeReindexed.java

DocumentsToBeReindexed() {
    documentsToBeReindexed = Sets.newHashSet();
}

From source file:com.facebook.buck.distributed.RecordedFileHashes.java

public RecordedFileHashes(Integer cellIndex) {
    this.remoteFileHashes = new BuildJobStateFileHashes();
    this.remoteFileHashes.setCellIndex(cellIndex);
    this.seenPaths = Sets.newHashSet();
    this.seenArchiveMemberPaths = Sets.newHashSet();
}