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.apache.drill.exec.rpc.security.AuthStringUtil.java

public static Set<String> asSet(final List<String> list) {
    if (list == null) {
        return Sets.newHashSet();
    }//from   ww w.j a  va2s. c  o  m
    return Sets.newHashSet(Iterators.transform(list.iterator(), new Function<String, String>() {
        @Nullable
        @Override
        public String apply(@Nullable String input) {
            return input == null ? null : input.toUpperCase();
        }
    }));
}

From source file:org.glowroot.ui.LdapAuthentication.java

static Set<String> getGlowrootRoles(Set<String> ldapGroupDns, LdapConfig ldapConfig) {
    Set<String> glowrootRoles = Sets.newHashSet();
    for (String ldapGroupDn : ldapGroupDns) {
        List<String> roles = ldapConfig.roleMappings().get(ldapGroupDn);
        if (roles != null) {
            glowrootRoles.addAll(roles);
        }//  ww w.  java  2s .  c om
    }
    return glowrootRoles;
}

From source file:com.enonic.cms.core.search.query.QueryFieldAndMultipleValues.java

public Object[] getValues() {
    Set<Object> values = Sets.newHashSet();

    if (isQueryValueNumeric()) {
        for (QueryValue value : queryValues) {
            if (!value.isEmpty()) {
                values.add(value.getNumericValue());
            }/*from  w ww  .ja  v  a  2 s.  co  m*/
        }

    } else if (isQueryOnDateValue()) {
        for (QueryValue value : queryValues) {
            if (!value.isEmpty()) {
                values.add(value.getDateTime());
            }
        }
    } else {
        for (QueryValue value : queryValues) {
            if (!value.isEmpty()) {
                values.add(value.getStringValueNormalized());
            }
        }
    }
    return values.toArray();
}

From source file:rapture.kernel.dp.WorkflowValidator.java

public static void validate(Workflow workflow) {
    Set<Step> check = Sets.newHashSet();
    for (Step step : workflow.getSteps()) {
        if (!check.add(step)) {
            throw RaptureExceptionFactory.create(HttpStatus.SC_BAD_REQUEST,
                    String.format("duplicateStep name '%s' not allowed", step.getName()));
        }//from  w  w  w. j a  v  a  2 s.  c om
    }
    validateArgs(workflow.getExpectedArguments());
}

From source file:com.b2international.commons.validation.ConstraintViolations.java

/**
 * Formats the given set of {@link ConstraintViolation} to a list of
 * readable format.//from   w  ww  .j  av a2  s.co m
 * 
 * @param violations
 * @return
 */
public static ImmutableList<String> format(Collection<? extends ConstraintViolation<?>> violations) {
    final Set<String> errors = Sets.newHashSet();
    for (ConstraintViolation<?> v : violations) {
        errors.add(format(v));
    }
    return ImmutableList.copyOf(Ordering.natural().sortedCopy(errors));
}

From source file:org.gradle.api.internal.changedetection.rules.DiscoveredInputFilesStateChangeRule.java

public static DiscoveredTaskStateChanges create(final TaskExecution previousExecution,
        final TaskExecution currentExecution, final FileCollectionSnapshotter inputFilesSnapshotter) {
    return new DiscoveredTaskStateChanges() {
        private final Collection<File> discoveredFiles = Sets.newHashSet();

        public Iterator<TaskStateChange> iterator() {
            if (previousExecution.getDiscoveredInputFilesSnapshot() == null) {
                return Collections
                        .<TaskStateChange>singleton(
                                new DescriptiveChange("Discovered input file history is not available."))
                        .iterator();//  ww  w  . j  a v a 2s.  co m
            }

            Iterables.addAll(discoveredFiles, previousExecution.getDiscoveredInputFilesSnapshot().getFiles());
            final FileCollectionSnapshot discoveredFileSnapshot = inputFilesSnapshotter
                    .snapshot(new SimpleFileCollection(discoveredFiles));

            return new AbstractIterator<TaskStateChange>() {
                final FileCollectionSnapshot.ChangeIterator<String> changeIterator = discoveredFileSnapshot
                        .iterateChangesSince(previousExecution.getDiscoveredInputFilesSnapshot());
                final ChangeListenerAdapter listenerAdapter = new ChangeListenerAdapter();

                @Override
                protected TaskStateChange computeNext() {
                    if (changeIterator.next(listenerAdapter)) {
                        return listenerAdapter.lastChange;
                    }
                    return endOfData();
                }
            };
        }

        @Override
        public void newInputs(Set<File> files) {
            discoveredFiles.clear();
            discoveredFiles.addAll(files);
        }

        public void snapshotAfterTask() {
            currentExecution.setDiscoveredInputFilesSnapshot(
                    inputFilesSnapshotter.snapshot(new SimpleFileCollection(discoveredFiles)));
        }
    };
}

From source file:com.enonic.cms.core.xslt.portal.XsltTrackingUriResolver.java

public XsltTrackingUriResolver(final XsltResourceLoader resourceLoader) {
    this.resourceLoader = resourceLoader;
    this.includeSet = Sets.newHashSet();
}

From source file:com.enonic.cms.core.search.builder.ContentIndexDataSectionFactory.java

public void create(final ContentIndexData contentIndexData, final ContentLocations contentLocations) {
    if (contentLocations == null || !contentLocations.hasLocations()) {
        return;/*  www . j a va2s  . co m*/
    }

    Set<Object> sectionKeysApproved = Sets.newHashSet();
    Set<Object> sectionKeysUnapproved = Sets.newHashSet();

    for (final ContentLocation contentLocation : contentLocations.getAllLocations()) {
        if (!contentLocation.isInSection()) {
            continue;
        }

        final String menuKey = contentLocation.getMenuItemKey().toString();

        if (contentLocation.isApproved()) {
            sectionKeysApproved.add(menuKey);
        } else {
            sectionKeysUnapproved.add(menuKey);
        }
    }

    contentIndexData.addContentIndexDataElement(CONTENTLOCATION_APPROVED_FIELDNAME, sectionKeysApproved);
    contentIndexData.addContentIndexDataElement(CONTENTLOCATION_UNAPPROVED_FIELDNAME, sectionKeysUnapproved);
}

From source file:com.chingo247.structureapi.model.owner.OwnerDomain.java

public OwnerDomain() {
    this.owners = Sets.newHashSet();
    this.masters = Sets.newHashSet();
    this.members = Sets.newHashSet();
}

From source file:com.facebook.buck.jvm.java.JavaLibraryClasspathProvider.java

public static ImmutableSet<Path> getOutputClasspathJars(JavaLibrary javaLibraryRule,
        SourcePathResolver resolver, Optional<SourcePath> outputJar) {
    ImmutableSet.Builder<Path> outputClasspathBuilder = ImmutableSet.builder();
    Iterable<JavaLibrary> javaExportedLibraryDeps;
    if (javaLibraryRule instanceof ExportDependencies) {
        javaExportedLibraryDeps = getJavaLibraryDeps(((ExportDependencies) javaLibraryRule).getExportedDeps());
    } else {/*from   www  .j  a  v a 2 s  .c om*/
        javaExportedLibraryDeps = Sets.newHashSet();
    }

    for (JavaLibrary rule : javaExportedLibraryDeps) {
        outputClasspathBuilder.addAll(rule.getOutputClasspaths());
    }

    if (outputJar.isPresent()) {
        outputClasspathBuilder.add(resolver.getAbsolutePath(outputJar.get()));
    }

    return outputClasspathBuilder.build();
}