Example usage for java.util Collections singleton

List of usage examples for java.util Collections singleton

Introduction

In this page you can find the example usage for java.util Collections singleton.

Prototype

public static <T> Set<T> singleton(T o) 

Source Link

Document

Returns an immutable set containing only the specified object.

Usage

From source file:org.cloudfoundry.identity.uaa.scim.ScimUserTests.java

@Test
public void userWithGroupsMapsToJson() throws Exception {
    ScimUser user = new ScimUser();
    user.setId("123");
    user.setUserName("joe");
    user.setGroups(Collections.singleton(new Group(null, "foo")));

    String json = mapper.writeValueAsString(user);
    // System.err.println(json);
    assertTrue(json.contains("\"groups\":"));
}

From source file:com.opengamma.financial.analytics.UnitPositionOrTradeScalingFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) {
    final ValueSpecification specification = new ValueSpecification(_requirementName, target.toSpecification(),
            getResultProperties(inputs.keySet().iterator().next()));
    return Collections.singleton(specification);
}

From source file:com.stratio.cassandra.lucene.search.sort.GeoDistanceSortField.java

/** {@inheritDoc} */
public Set<String> postProcessingFields() {
    return Collections.singleton(field);
}

From source file:com.nesscomputing.cache.PrefixedCache.java

public boolean add(final P prefix, final K key, final V value) {
    final String keyString = keySerializer.apply(SerializablePair.of(prefix, key));
    final byte[] valueBytes = valueSerializer.apply(value);
    return BooleanUtils
            .toBoolean(/*  w ww . j  a v a 2s  .c o  m*/
                    nessCache
                            .add(namespace,
                                    Collections.singleton(
                                            CacheStores.fromSharedBytes(keyString, valueBytes, getExpiry())))
                            .get(key));
}

From source file:com.xtructure.xevolution.genetics.impl.UTestAbstractPopulation.java

public void addAllBehavesAsExpected() {
    DummyPopulation pop = new DummyPopulation(1);
    Genome<String> genome = new DummyGenome(1, "data");
    assertThat("", //
            pop.get(genome.getId()), isNull());
    pop.addAll(Collections.singleton(genome));
    assertThat("", //
            pop.get(genome.getId()), isSameAs(genome));
}

From source file:edu.harvard.iq.dataverse.DatasetField.java

/**
 * Groups a list of fields by the block they belong to.
 *
 * @param fields well, duh.//from  w w  w . j  av  a  2s  .c  o  m
 * @return a map, mapping each block to the fields that belong to it.
 */
public static Map<MetadataBlock, List<DatasetField>> groupByBlock(List<DatasetField> fields) {
    Map<MetadataBlock, List<DatasetField>> retVal = new HashMap<>();
    for (DatasetField f : fields) {
        MetadataBlock metadataBlock = f.getDatasetFieldType().getMetadataBlock();
        List<DatasetField> lst = retVal.get(metadataBlock);
        if (lst == null) {
            retVal.put(metadataBlock, new LinkedList<>(Collections.singleton(f)));
        } else {
            lst.add(f);
        }
    }
    return retVal;
}

From source file:org.faster.opm.filter.AbstractResourceFilter.java

protected Set<String> getResourceFilterValues() {
    return isMultiResourceFilterValues()
            ? Strings.toStringSet(resourceFilterValue, resourceFilterValueDelimiter)
            : Collections.singleton(resourceFilterValue);
}

From source file:com.google.play.developerapi.samples.AndroidPublisherHelper.java

private static Credential authorizeWithServiceAccount(String serviceAccountEmail)
        throws GeneralSecurityException, IOException {
    log.info(String.format("Authorizing using Service Account: %s", serviceAccountEmail));

    // Build service account credential.
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
            .setJsonFactory(JSON_FACTORY).setServiceAccountId(serviceAccountEmail)
            .setServiceAccountScopes(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
            .setServiceAccountPrivateKeyFromP12File(new File(SRC_RESOURCES_KEY_P12)).build();
    return credential;
}

From source file:org.zenoss.zep.impl.PluginServiceImplTest.java

@Test
public void testCycleDetection() throws MissingDependencyException {
    EventPreCreatePlugin plugin1 = new EventPreCreatePlugin() {
        @Override/*from  w w w  .  j  a  v a  2 s. c  o m*/
        public String getId() {
            return "Plugin1";
        }

        @Override
        public Set<String> getDependencies() {
            return Collections.singleton("Plugin2");
        }

        @Override
        public Event processEvent(Event event, EventPreCreateContext ctx) throws ZepException {
            return event;
        }
    };
    EventPreCreatePlugin plugin2 = new EventPreCreatePlugin() {
        @Override
        public String getId() {
            return "Plugin2";
        }

        @Override
        public Set<String> getDependencies() {
            return Collections.singleton("Plugin3");
        }

        @Override
        public Event processEvent(Event event, EventPreCreateContext ctx) throws ZepException {
            return event;
        }
    };
    EventPreCreatePlugin plugin3 = new EventPreCreatePlugin() {
        @Override
        public String getId() {
            return "Plugin3";
        }

        @Override
        public Set<String> getDependencies() {
            return Collections.singleton("Plugin1");
        }

        @Override
        public Event processEvent(Event event, EventPreCreateContext ctx) throws ZepException {
            return event;
        }
    };
    Map<String, EventPreCreatePlugin> plugins = new HashMap<String, EventPreCreatePlugin>();
    plugins.put(plugin1.getId(), plugin1);
    plugins.put(plugin2.getId(), plugin2);
    plugins.put(plugin3.getId(), plugin3);
    try {
        PluginServiceImpl.detectCycles(plugins, Collections.<String>emptySet());
        fail("Expected to fail with a cycle exception");
    } catch (DependencyCycleException e) {
        /* Expected */
    }
}

From source file:hudson.matrix.MatrixTest.java

/**
 * Test that project level permissions apply to child configurations as well.
 *//* www  . j a  va  2  s. c  o m*/
@Issue("JENKINS-9293")
@Test
public void configurationACL() throws Exception {
    j.jenkins.setAuthorizationStrategy(new ProjectMatrixAuthorizationStrategy());
    MatrixProject mp = j.createProject(MatrixProject.class);
    mp.setAxes(new AxisList(new Axis("foo", "a", "b")));
    MatrixConfiguration mc = mp.getItem("foo=a");
    assertNotNull(mc);
    SecurityContextHolder.clearContext();
    assertFalse(mc.getACL().hasPermission(Item.READ));
    mp.addProperty(new AuthorizationMatrixProperty(
            Collections.singletonMap(Item.READ, Collections.singleton("anonymous"))));
    // Project-level permission should apply to single configuration too:
    assertTrue(mc.getACL().hasPermission(Item.READ));
}