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:zipkin.autoconfigure.metrics.PrometheusMetricsAutoConfigurationTest.java

private ResponseEntity<String> responseForMetrics(PublicMetrics publicMetrics) {
    PrometheusMetricsAutoConfiguration pmc = new PrometheusMetricsAutoConfiguration(
            Collections.singleton(publicMetrics));

    return pmc.prometheusMetrics();
}

From source file:com.heliosdecompiler.helios.controller.transformers.decompilers.DecompilerController.java

public void decompile(OpenedFile file, String path, BiConsumer<Boolean, String> consumer) {
    backgroundTaskHelper//from   w ww. ja  v a2s.  co m
            .submit(new BackgroundTask(Message.TASK_DECOMPILE_FILE.format(path, getDisplayName()), true, () -> {
                try {
                    String pre = preDecompile(file, path);
                    if (pre != null) {
                        consumer.accept(false, pre);
                    } else {
                        byte[] data = file.getContent(path);
                        ClassData cd = ClassData.construct(data);

                        TransformationResult<String> transformationResult = decompiler
                                .decompile(Collections.singleton(cd), createSettings(), getClasspath(file));

                        Map<String, String> results = transformationResult.getTransformationData();

                        System.out.println("Results: " + results.keySet());
                        System.out
                                .println("Looking for: " + StringEscapeUtils.escapeJava(cd.getInternalName()));

                        if (results.containsKey(cd.getInternalName())) {
                            consumer.accept(true, results.get(cd.getInternalName()));
                        } else {
                            StringBuilder output = new StringBuilder();
                            output.append("An error has occurred while decompiling this file.\r\n").append(
                                    "If you have not tried another decompiler, try that. Otherwise, you're out of luck.\r\n\r\n")
                                    .append("stdout:\r\n").append(transformationResult.getStdout())
                                    .append("\r\nstderr:\r\n").append(transformationResult.getStderr());
                            consumer.accept(false, output.toString());
                        }
                    }
                } catch (Throwable e) {
                    StringWriter writer = new StringWriter();
                    e.printStackTrace(new PrintWriter(writer));

                    StringBuilder output = new StringBuilder();
                    output.append("An error has occurred while decompiling this file.\r\n").append(
                            "If you have not tried another decompiler, try that. Otherwise, you're out of luck.\r\n\r\n")
                            .append("Exception:\r\n").append(writer.toString());
                    consumer.accept(false, output.toString());
                }
            }, () -> {
                consumer.accept(false, "Decompilation aborted");
            }));
}

From source file:com.edmunds.etm.common.api.ClientPaths.java

/**
 * Returns the paths to nodes that are necessary to run ETM.
 *
 * @return an list containing required node paths
 */// w w w .j av a2 s .  com
public Set<String> getStructuralPaths() {
    return Collections.singleton(getConnected());
}

From source file:com.cloudera.oryx.app.als.FeatureVectorsTest.java

@Test
public void testAllIDs() {
    FeatureVectors fv = new FeatureVectors();
    fv.setVector("foo", new float[] { 1.0f });
    Collection<String> allIDs = new HashSet<>();
    fv.addAllIDsTo(allIDs);/*  w  w  w  . j  a  va 2  s . c  o m*/
    assertEquals(Collections.singleton("foo"), allIDs);
    fv.removeAllIDsFrom(allIDs);
    assertEquals(0, allIDs.size());
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.identifier.common.CommonIdentifierBundleFactory.java

private Collection<? extends Identifier> createRootUserIdentifiers(HttpServletRequest req) {
    UserAccount user = LoginStatusBean.getCurrentUser(req);
    if ((user != null) && user.isRootUser()) {
        return Collections.singleton(new IsRootUser());
    } else {/*from   ww w . ja va 2  s .  co m*/
        return Collections.emptySet();
    }
}

From source file:io.apicurio.hub.core.beans.ApiDesignResourceInfoTest.java

/**
 * Test method for {@link io.apicurio.hub.core.beans.ApiDesignResourceInfo#fromContent(java.lang.String)}.
 *///from w  w  w  . ja v  a 2  s. c  o m
@Test
public void testFromContent_30_Yaml() throws Exception {
    String content = IOUtils.toString(
            ApiDesignResourceInfoTest.class.getResourceAsStream("ApiDesignResourceInfoTest_3.0.yaml"));
    ApiDesignResourceInfo info = ApiDesignResourceInfo.fromContent(content);
    Assert.assertNotNull(info);
    Assert.assertEquals(FormatType.YAML, info.getFormat());
    Assert.assertEquals("Simple OAI 3.0.0 API", info.getName());
    Assert.assertEquals("A simple API using OpenAPI 3.0.0.", info.getDescription());
    Assert.assertEquals(Collections.singleton("foo"), info.getTags());
}

From source file:org.keycloak.adapters.springsecurity.authentication.DirectAccessGrantAuthenticationProviderTest.java

@Test
public void testResolveUsernameFromUserDetails() throws Exception {
    User user = new User(AppConfig.KNOWN_USERNAME, AppConfig.KNOWN_PASSWORD,
            Collections.singleton(new KeycloakRole("user")));
    String username = directAccessGrantAuthenticationProvider.resolveUsername(user);
    assertEquals(AppConfig.KNOWN_USERNAME, username);
}

From source file:com.palantir.ptoss.cinch.swing.JPasswordFieldWiringHarness.java

public static Collection<Binding> bindJPasswordField(final BindableModel model, final JPasswordField pwdField,
        final Method getter, final Method setter) {
    pwdField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            updateModel();//from  ww w . j a  v a 2 s.  c  o m
        }

        public void insertUpdate(DocumentEvent e) {
            updateModel();
        }

        public void changedUpdate(DocumentEvent e) {
            updateModel();
        }

        private void updateModel() {
            try {
                setter.invoke(model, pwdField.getPassword());
            } catch (Exception ex) {
                Wiring.logger.error("exception in JPasswordField binding", ex);
            }
        }
    });
    Binding binding = new Binding() {
        public <T extends Enum<?> & ModelUpdate> void update(T... changed) {
            try {
                char[] charArray = (char[]) getter.invoke(model);
                if (charArray == null) {
                    charArray = new char[0];
                }
                if (!Arrays.equals(charArray, pwdField.getPassword())) {
                    pwdField.setText(String.valueOf(charArray));
                }
            } catch (Exception ex) {
                Wiring.logger.error("exception in JPasswordField binding", ex);
            }
        }
    };
    model.bind(binding);
    return Collections.singleton(binding);
}

From source file:cereal.examples.pojo.PojoPersonTest.java

@Test(timeout = 30 * 1000)
public void testSerialization() throws Exception {
    Registry registry = new RegistryImpl();
    PojoPersonMapping mapping = new PojoPersonMapping();
    registry.add(mapping);//from w  ww. j ava2  s  .co  m

    Person p = new Person();
    p.setFirstName("Bob");
    p.setMiddleName("Joe");
    p.setLastName("Franklin");
    p.setAge(30);
    p.setHeight(72);
    p.setWeight(220);

    String tableName = test.getMethodName();
    Connector conn = mac.getConnector("root", PASSWORD);
    conn.tableOperations().create(tableName);

    try (Store store = new StoreImpl(registry, conn, tableName)) {
        store.write(Collections.singleton(p));
        store.flush();

        Text row = mapping.getRowId(p);

        Person copy = store.read(row, Person.class);

        assertEquals(p, copy);
    }
}

From source file:net.ontopia.topicmaps.webed.impl.actions.tmobject.EvaluateLTM.java

@Override
public void perform(ActionParametersIF params, ActionResponseIF response) {

    // test params
    ActionSignature paramsType = ActionSignature.getSignature("m! s!");
    paramsType.validateArguments(params, this);

    TopicMapIF topicmap = (TopicMapIF) params.get(0);
    String template = (String) params.get(1);
    WebEdRequestIF request = params.getRequest();

    Collection values = null;//from  ww w  . jav  a  2  s  .  c o  m
    TMObjectIF object = params.getTMObjectValue();
    if (object == null) {
        String strval = params.getStringValue();
        if (strval != null) {
            // escape quotes so LTM will parse correctly
            String value = StringUtils.replace(strval, "\"", "\"\"");
            values = Collections.singleton(value);
        }
    } else
        values = params.getTMObjectValues();

    String lastid = null;
    if (values == null)
        // no object value; just do it anyway
        importFragment(template, topicmap);
    else {
        // repeat once for each object value
        Iterator it = values.iterator();
        while (it.hasNext()) {
            lastid = makeRandomId(topicmap);
            Map map = new RequestMapWrapper(request, it.next(), lastid, topicmap);
            String tmp = StringTemplateUtils.replace(template, map);
            importFragment(tmp, topicmap);
        }
    }

    // register new topic in response
    TopicIF topic = getTopicById(topicmap, lastid);
    if (lastid != null && topic != null)
        response.addParameter(Constants.RP_TOPIC_ID, topic.getObjectId());
}