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

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

Introduction

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

Prototype

public static <E> LinkedHashSet<E> newLinkedHashSet() 

Source Link

Document

Creates a mutable, empty LinkedHashSet instance.

Usage

From source file:edu.washington.cs.cupid.TypeManager.java

private static Set<Class<?>> getClassesBfs(Class<?> clazz) {
    // adapted from: http://stackoverflow.com/questions/9797212/finding-the-nearest-common-superclass-or-superinterface-of-a-collection-of-cla

    Set<Class<?>> classes = Sets.newLinkedHashSet();
    Set<Class<?>> nextLevel = Sets.newLinkedHashSet();
    nextLevel.add(clazz);/*from w w  w  .j ava 2  s  .c o  m*/
    do {
        classes.addAll(nextLevel);
        Set<Class<?>> thisLevel = Sets.newLinkedHashSet(nextLevel);
        nextLevel.clear();
        for (Class<?> each : thisLevel) {
            Class<?> superClass = each.getSuperclass();
            if (superClass != null && superClass != Object.class) {
                nextLevel.add(superClass);
            }
            for (Class<?> eachInt : each.getInterfaces()) {
                nextLevel.add(eachInt);
            }
        }
    } while (!nextLevel.isEmpty());
    return classes;
}

From source file:com.google.devtools.moe.client.repositories.AbstractRevisionHistory.java

@Override
public <T> T findRevisions(Revision revision, RevisionMatcher<T> matcher, SearchType searchType) {

    List<Revision> startingRevisions = (revision == null) ? findHeadRevisions() : ImmutableList.of(revision);

    if (startingRevisions.size() > 1 && searchType == SearchType.LINEAR) {
        throw new MoeProblem(
                "MOE found a repository (%s) with multiple heads while trying to search linear history.",
                startingRevisions.get(0).repositoryName());
    }//  w  ww  .  ja v a 2 s .c om

    RevisionGraph.Builder nonMatchingBuilder = RevisionGraph.builder(startingRevisions);
    ImmutableList.Builder<Revision> matchingBuilder = ImmutableList.builder();

    Deque<Revision> workList = new ArrayDeque<>();
    workList.addAll(startingRevisions);

    // Keep a visited list to make sure we don't visit the same change twice.
    Set<Revision> visited = Sets.newLinkedHashSet();
    visited.addAll(startingRevisions);

    while (!workList.isEmpty()) {
        Revision current = workList.removeFirst();
        if (!matcher.matches(current)) {
            RevisionMetadata metadata = getMetadata(current);
            nonMatchingBuilder.addRevision(current, metadata);

            List<Revision> parentsToSearch = metadata.parents;
            if (parentsToSearch.size() > 0 && searchType == SearchType.LINEAR) {
                parentsToSearch = parentsToSearch.subList(0, 1);
            }
            for (Revision parent : parentsToSearch) {
                // Don't add a visited parent to the search queue.
                if (visited.add(parent)) {
                    workList.addLast(parent);
                }
            }

            if (visited.size() > MAX_REVISIONS_TO_SEARCH) {
                throw new MoeProblem(
                        "Couldn't find a matching revision for matcher (%s) from %s within %d revisions.",
                        matcher, (revision == null) ? "head" : revision, MAX_REVISIONS_TO_SEARCH);
            }
        } else {
            // Don't search past matching revisions.
            matchingBuilder.add(current);
        }
    }

    return matcher.makeResult(nonMatchingBuilder.build(), matchingBuilder.build());
}

From source file:org.apache.whirr.ClusterControllerFactory.java

/**
 * Return a collection of available {@link ClusterController} names.
 * @return the available service names//from ww  w .  java2  s .  co m
 */
public Set<String> availableServices() {
    Set<String> result = Sets.newLinkedHashSet();
    for (ClusterController s : serviceLoader) {
        result.add(s.getName());
    }
    return result;
}

From source file:com.google.jstestdriver.model.RunData.java

public Set<FileInfo> getFileSet() {
    final Set<FileInfo> fileSet = Sets.newLinkedHashSet();
    for (JstdTestCase testCase : testCases) {
        fileSet.addAll(testCase.toFileSet());
    }/*from   w  ww.  j av  a2  s.  c  o m*/
    return fileSet;
}

From source file:org.grouplens.grapht.graph.MergePool.java

private MergePool() {
    pool = Sets.newLinkedHashSet();
}

From source file:com.github.ferstl.maven.pomenforcers.PedanticModuleOrderEnforcer.java

public PedanticModuleOrderEnforcer() {
    this.ignoredModules = Sets.newLinkedHashSet();
}

From source file:org.eclipse.sirius.properties.core.api.SiriusInputDescriptor.java

/**
 * Returns all the semantic model element associated with the current
 * selection, including secondary associated elements if any.
 * /* www .ja  v  a2  s. com*/
 * @return all the semantic model element associated with the current
 *         selection.
 */
public Collection<EObject> getAllSemanticElements() {
    Collection<EObject> result = Sets.newLinkedHashSet();
    result.add(getSemanticElement());
    Option<Collection<EObject>> additional = context.getAdditionalSemanticElements();
    if (additional.some()) {
        result.addAll(additional.get());
    }
    return result;
}

From source file:org.eclipse.sirius.ui.tools.internal.views.common.navigator.OpenRepresentationListener.java

private Iterable<DRepresentation> getRepresentationsToOpen(List<?> selection) {

    final Set<DRepresentation> representations = Sets.newLinkedHashSet();
    for (final Object obj : selection) {
        if (obj instanceof DRepresentation)
            representations.add((DRepresentation) obj);
        else {/*from w w  w  . j  a va 2  s  . c  om*/
            DRepresentation adapted = adaptToDRepresentation(obj);
            if (adapted != null)
                representations.add(adapted);
        }
    }
    return representations;
}

From source file:com.facebook.buck.simulate.SimulateTimes.java

public static SimulateTimes createFromJsonFile(ObjectMapper jsonConverter, String fileName, long defaultMillis)
        throws IOException {
    File file = new File(fileName);
    JsonFileContent fileContent = new JsonFileContent();
    jsonConverter.readerForUpdating(fileContent).readValue(file);
    LinkedHashSet<String> timeAggregates = Sets.newLinkedHashSet();
    Map<String, ImmutableMap<String, Long>> immutableTimeAggregates = Maps.newHashMap();
    Map<String, Map<String, Long>> allTimings = fileContent.getBuildTargetTimes();
    for (String targetName : allTimings.keySet()) {
        Map<String, Long> timesForKey = Preconditions.checkNotNull(allTimings.get(targetName));
        for (String timeAggregate : timesForKey.keySet()) {
            timeAggregates.add(timeAggregate);
        }/*w  w w .j av  a 2  s  . c  o  m*/

        immutableTimeAggregates.put(targetName, ImmutableMap.copyOf(timesForKey));
    }

    SimulateTimes times = new SimulateTimes(ImmutableMap.copyOf(immutableTimeAggregates),
            ImmutableSortedSet.copyOf(timeAggregates), file.getName(), defaultMillis);
    return times;
}

From source file:org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult.java

@Override
public Set<? extends RenderableDependency> getChildren() {
    final DependencySet dependencies = configuration.getDependencies();
    if (dependencies.isEmpty()) {
        return Collections.emptySet();
    }/*from   www.  ja va  2s .  c  o m*/
    Set<RenderableDependency> children = Sets.newLinkedHashSet();
    for (final Dependency dependency : dependencies) {
        children.add(new RenderableDependency() {
            @Override
            public Object getId() {
                return dependency;
            }

            @Override
            public String getName() {
                String label;
                if (dependency instanceof ProjectDependency) {
                    label = "project " + dependency.getName();
                } else {
                    label = Joiner.on(":").join(Iterables.filter(
                            Arrays.asList(dependency.getGroup(), dependency.getName(), dependency.getVersion()),
                            Predicates.<String>notNull()));
                }
                return label;
            }

            @Override
            public String getDescription() {
                return null;
            }

            @Override
            public ResolutionState getResolutionState() {
                return ResolutionState.UNRESOLVED;
            }

            @Override
            public Set<? extends RenderableDependency> getChildren() {
                return Collections.emptySet();
            }
        });
    }
    return children;
}