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:com.opengamma.financial.analytics.PositionWeightFromNAVFunction.java

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    return Collections
            .singleton(new ValueRequirement(ValueRequirementNames.FAIR_VALUE, target.toSpecification()));
}

From source file:com.server.GCS.java

public static void initGCS() {
    try {/*from  ww  w  . j a  va 2s.com*/
        //         httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        httpTransport = AndroidHttp.newCompatibleTransport();
        // Build service account credential.
        creds = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(JSON_FACTORY)
                .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
                .setServiceAccountScopes(Collections.singleton(STORAGE_SCOPE))
                .setServiceAccountPrivateKeyFromP12File(
                        new File("/sdcard/4dc3c5ae7e42a946a5826519451c8b6b21cb566a-privatekey.p12"))
                .build();
        requestFactory = httpTransport.createRequestFactory(creds);
        storage = new Storage(httpTransport, JSON_FACTORY, requestFactory.getInitializer());
    } catch (Exception e) {
        Log.i("HI", "GCS INIT ERROR. PERHAPS YOU'RE MISSING KEY.P12?");
        Log.e(tag, "Exception: " + e.getMessage());
    }
}

From source file:io.syndesis.controllers.extension.ExtensionDataProviderTest.java

@Test
public void shouldGetCorrectDataByExtensionId() throws IOException {
    final DataManager dataManager = mock(DataManager.class);
    final FileStore fileStore = mock(FileStore.class);
    ExtensionDataProvider extensionDataProvider = new ExtensionDataProvider(dataManager, fileStore);

    String sampleBinaryData = "Hello";
    Extension sampleMetadata = new Extension.Builder().id("1234").status(Extension.Status.Installed)
            .extensionId("extensionId").description("Description").build();

    when(fileStore.read("/extensions/1234"))
            .thenReturn(new ByteArrayInputStream(sampleBinaryData.getBytes(StandardCharsets.UTF_8)));
    when(dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", "extensionId", "status",
            Extension.Status.Installed.name())).thenReturn(Collections.singleton("1234"));
    when(dataManager.fetch(Extension.class, "1234")).thenReturn(sampleMetadata);

    assertThat(extensionDataProvider.getExtensionMetadata("extensionId")).isEqualTo(sampleMetadata);
    assertThat(IOUtils.toString(extensionDataProvider.getExtensionBinaryFile("extensionId"),
            StandardCharsets.UTF_8)).isEqualTo(sampleBinaryData);
}

From source file:cop.maven.plugins.RamlMojo.java

@Override
public Set<File> getSourceDirectories() {
    if (CollectionUtils.isEmpty(sourceDirectories))
        return Collections.singleton(new File(project.getBuild().getSourceDirectory()));

    Set<File> dirs = new HashSet<>();

    for (File file : sourceDirectories)
        if (file != null && file.isDirectory())
            dirs.add(file);//from ww w  . j  av  a2 s . c  o  m

    return dirs;
}

From source file:zipkin.autoconfigure.metrics.PrometheusMetricsAutoConfigurationTest.java

@Test
public void detectsCounters() throws Exception {

    PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("counter_mem.free", 1024));
    ResponseEntity<String> response = responseForMetrics(publicMetrics);

    String body = response.getBody();

    assertThat(body, equalTo("#TYPE mem_free counter\n" + "#HELP mem_free mem_free\n" + "mem_free 1024.0\n"));
}

From source file:com.threewks.thundr.view.jsp.el.CollectionFunctions.java

/**
 * @param collectionOrArray a {@link Collection} or array of object
 * @param objectCollectionOrArray a single object, and array of objects or a {@link Collection} of objects
 * @return true if the first argument contains any of the elements in the second argument. If the second argument is an empty collection, returns true. if the second element is null, returns true
 *         if a null is contained in the first argument.
 *///from   w ww .  ja  va  2 s.  c  o m
@SuppressWarnings("unchecked")
public static boolean containsAny(Object collectionOrArray, Object objectCollectionOrArray) {
    Collection<Object> collection = toCollection(collectionOrArray);
    Collection<Object> asCollection = Cast.as(objectCollectionOrArray, Collection.class);
    if (asCollection == null) {
        asCollection = isArray(objectCollectionOrArray) ? Arrays.asList((Object[]) objectCollectionOrArray)
                : Collections.singleton(objectCollectionOrArray);
    }
    for (Object o : asCollection) {
        if (collection.contains(o)) {
            return true;
        }
    }
    return asCollection.isEmpty();
}

From source file:org.apereo.services.persondir.support.AdditionalDescriptorsPersonAttributeDaoTest.java

public void testGetAvailableQueryAttributes() {
    TestCase.assertEquals(getPersonAttributeDaoInstance().getAvailableQueryAttributes(),
            Collections.singleton(USERNAME_ATTRIBUTE));

}

From source file:com.example.app.profile.service.ProfileTypeKindLabelProvider.java

@Nonnull
@Override
protected Set<CmsSite> getDefaultAssignments() {
    return Collections.singleton(_cmsFrontendDAO.getSite(_siteAssignmentId));
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTextArea.java

@Override
protected JTextArea createTextComponentImpl() {
    final JTextArea impl = new TextAreaFlushableField();

    if (isTabTraversal()) {
        Set<KeyStroke> forwardFocusKey = Collections.singleton(getKeyStroke(KeyEvent.VK_TAB, 0));
        impl.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardFocusKey);

        Set<KeyStroke> backwardFocusKey = Collections
                .singleton(getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK));
        impl.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardFocusKey);

        impl.addKeyListener(new KeyAdapter() {
            @Override//  w  w  w .  ja  v  a2s . com
            public void keyPressed(KeyEvent e) {
                if (isEnabled() && isEditable() && e.getKeyCode() == KeyEvent.VK_TAB
                        && e.getModifiers() == KeyEvent.CTRL_MASK) {

                    if (StringUtils.isEmpty(impl.getText())) {
                        impl.setText("\t");
                    } else {
                        impl.append("\t");
                    }
                }
            }
        });
    }

    impl.setLineWrap(true);
    impl.setWrapStyleWord(true);

    int height = (int) impl.getPreferredSize().getHeight();
    impl.setMinimumSize(new Dimension(0, height));

    composition = new JScrollPane(impl);
    composition.setPreferredSize(new Dimension(150, height));
    composition.setMinimumSize(new Dimension(0, height));

    doc.putProperty("filterNewlines", false);

    return impl;
}

From source file:com.opengamma.financial.analytics.model.bond.BondMarketDataFunction.java

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    return Collections.singleton(new ValueRequirement(_requirementName, target.toSpecification()));
}