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.jboss.spring.factory.NamedXmlBeanFactory.java

private void initializeNames(Resource resource) {
    try {//from   www. j av  a 2 s.  com
        XPath xPath = XPathFactory.newInstance().newXPath();
        xPath.setNamespaceContext(new NamespaceContext() {
            @Override
            public String getNamespaceURI(String prefix) {
                return "http://www.springframework.org/schema/beans";
            }

            @Override
            public String getPrefix(String namespaceURI) {
                return "beans";
            }

            @Override
            public Iterator getPrefixes(String namespaceURI) {
                return Collections.singleton("beans").iterator();
            }
        });
        String expression = "/beans:beans/beans:description";
        InputSource inputSource = new InputSource(resource.getInputStream());
        String description = xPath.evaluate(expression, inputSource);
        if (description != null) {
            Matcher bfm = Pattern.compile(Constants.BEAN_FACTORY_ELEMENT).matcher(description);
            if (bfm.find()) {
                this.name = bfm.group(1);
            }
            Matcher pbfm = Pattern.compile(Constants.PARENT_BEAN_FACTORY_ELEMENT).matcher(description);
            if (pbfm.find()) {
                String parentName = pbfm.group(1);
                try {
                    this.setParentBeanFactory((BeanFactory) Util.lookup(parentName, BeanFactory.class));
                } catch (Exception e) {
                    throw new BeanDefinitionStoreException(
                            "Failure during parent bean factory JNDI lookup: " + parentName, e);
                }
            }
            Matcher inst = Pattern.compile(Constants.INSTANTIATION_ELEMENT).matcher(description);
            if (inst.find()) {
                instantiate = Boolean.parseBoolean(inst.group(1));
            }
        }
        if (this.name == null || "".equals(StringUtils.trimAllWhitespace(this.name))) {
            this.name = this.defaultName;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.couchbase.trombi.TrombinoscopeApplication.java

@Bean
CommandLineRunner userCreation(CoworkerRepository repo) {
    return args -> {
        Map<String, String> snowIm = new HashMap<>();
        snowIm.put("twitter", "@therealjohnsnowofficial");
        snowIm.put("hipchat", "snow");
        Coworker sample1 = Coworker.builder().id("coworker1").name("John Snow").description("Knows Nothing")
                .mainLocation(new Location("Winterfell", "My former home", -12, -10, 21))
                .lastCheckin(new Location("Paris", "Visiting some friends", +2, 98, 201)).imHandles(snowIm)
                .skills(Collections.singleton("fight")).team("stark").build();

        Coworker sample1b = Coworker.builder().id("coworker3").name("Arya Stark")
                .description("A Girl Is No One").mainLocation(new Location("Winterfell", "Home", -12, -10, 21))
                .skills(Collections.singleton("fight")).team("stark").build();

        Map<String, String> simonIm = new HashMap<>();
        simonIm.put("twitter", "@simonbasle");
        simonIm.put("hipchat", "simonbasle");
        Coworker sample2 = Coworker.builder().id("coworker2").name("Simon Basl")
                .description("Sometimes Coder")
                .mainLocation(new Location("Paris", "That's where I live", +2, 100, 200)).imHandles(simonIm)
                .skills(Collections.singleton("code")).team("couchbase").build();

        repo.save(Arrays.asList(sample1, sample1b, sample2));

        repo.findOne("coworker2");
    };//from  w  w w . j av  a 2s. co m
}

From source file:com.hortonworks.streamline.streams.runtime.rule.sql.SqlBasicExprScriptTest.java

@Test
public void testBasic() throws Exception {
    Condition condition = new Condition();
    Expression x = new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER));
    condition.setExpression(new BinaryExpression(Operator.EQUALS, x, new Literal("100")));
    sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(),
            new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("x")));

    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 100);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Collection<StreamlineEvent> result = sqlScript.evaluate(event);
    Assert.assertEquals(1, result.size());

    StreamlineEvent resultEvent = result.iterator().next();
    Assert.assertTrue(EventCorrelationInjector.containsParentIds(resultEvent));
    Assert.assertEquals(Collections.singleton(event.getId()),
            EventCorrelationInjector.getParentIds(resultEvent));
}

From source file:com.devicehive.handler.command.CommandSubscribeRequestHandler.java

private Collection<DeviceCommand> findCommands(String device, Collection<String> names, Date timestamp) {
    return Optional.ofNullable(timestamp).map(t -> hazelcastService.find(null, names,
            Collections.singleton(device), LIMIT, t, null, null, DeviceCommand.class))
            .orElse(Collections.emptyList());
}

From source file:org.cloudfoundry.identity.uaa.user.JdbcUaaUserDatabaseTests.java

@Before
public void initializeDb() throws Exception {

    template = new JdbcTemplate(dataSource);

    db = new JdbcUaaUserDatabase(template);
    db.setDefaultAuthorities(Collections.singleton("uaa.user"));

    TestUtils.assertNoSuchUser(template, "id", JOE_ID);
    TestUtils.assertNoSuchUser(template, "id", MABEL_ID);
    TestUtils.assertNoSuchUser(template, "userName", "jo@foo.com");

    addUser(JOE_ID, "Joe", "joespassword");
    addUser(MABEL_ID, "mabel", "mabelspassword");

}

From source file:com.opengamma.engine.test.MockFunction.java

public void addRequirement(ValueRequirement requirement) {
    addRequirements(Collections.singleton(requirement));
}

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

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    final Security security = target.getPositionOrTrade().getSecurity();
    final ValueRequirement requirement = new ValueRequirement(_requirementName, ComputationTargetType.SECURITY,
            security.getUniqueId(), desiredValue.getConstraints().withoutAny(ValuePropertyNames.FUNCTION));
    return Collections.singleton(requirement);
}

From source file:org.mascherl.example.service.SignUpService.java

@Transactional
public void signUp(SignUpRequest signUpRequest) {
    boolean userExists = !em.createQuery("select u.uuid from UserEntity u where u.email = :email")
            .setParameter("email", signUpRequest.getEmail()).getResultList().isEmpty();
    if (userExists) {
        throw new IllegalStateException("User with given email already exists");
    }//from   w  w  w  .j  a va 2 s .c  o  m

    UserEntity entity = new UserEntity();
    entity.setFirstName(signUpRequest.getFirstName());
    entity.setLastName(signUpRequest.getLastName());
    entity.setEmail(signUpRequest.getEmail());
    entity.setPasswordHash(sha256(signUpRequest.getPassword()));
    entity.setDateOfBirth(signUpRequest.getDateOfBirth());
    entity.setCountry(signUpRequest.getCountry());
    entity.setState(signUpRequest.getState());
    em.persist(entity);
    em.flush();

    sendMailService.sendMailFromSystem(new Mail(new MailAddress("webmail@mascherl.org"),
            Collections.singleton(new MailAddress(signUpRequest.getEmail())), null, null,
            "Welcome to Mascherl WebMail",
            "Hello " + signUpRequest.getFirstName() + " " + signUpRequest.getLastName() + "!\n" + "\n"
                    + "Your e-mail address is: " + signUpRequest.getEmail() + "\n" + "\n"
                    + "We wish you a lot of fun with Mascherl WebMail.\n" + "\n" + "Cheers,\n"
                    + "Your Mascherl WebMail team.\n"));
}

From source file:com.bennavetta.appsite.util.DatastoreConfig.java

protected Object getPropertyDirect(String key) {
    Key k = KeyFactory.createKey(ENTITY, key);
    return datastore.get(Collections.singleton(k)).get(k).getProperty(VALUE_PROPERTY);
}