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.core.region.RegionUtils.java

/**
 * Creates a set of regions from a region id.
 * This is useful in the case where the region is compound (e.g. NY+LON).
 * //from   w w w  . ja  v  a2s  . c  o m
 * @param regionSource The region source, not null
 * @param regionId The region id, not null
 * @return a set of the region(s)
 */
public static Set<Region> getRegions(RegionSource regionSource, final ExternalId regionId) {
    Validate.notNull(regionSource, "region source");
    Validate.notNull(regionId, "region id");
    if (regionId.isScheme(ExternalSchemes.FINANCIAL) && regionId.getValue().contains("+")) {
        final String[] regions = regionId.getValue().split("\\+");
        final Set<Region> resultRegions = new HashSet<Region>();
        for (final String region : regions) {
            resultRegions.add(regionSource.getHighestLevelRegion(ExternalSchemes.financialRegionId(region)));
        }
        return resultRegions;
    }
    return Collections.singleton(regionSource.getHighestLevelRegion(regionId));
}

From source file:io.pivotal.cla.security.WithAdminUserFactory.java

public static User create() {
    User user = new User();
    user.setAccessToken("mocked_access_token");
    user.setAvatarUrl("https://avatars.githubusercontent.com/u/362503?v=3");
    user.setEmails(Collections.singleton("rob@pivotal.io"));
    user.setGitHubLogin("rwinch");
    user.setAdmin(true);/*w ww.  j av a  2  s. co  m*/
    return user;
}

From source file:Main.java

private static <T> Set<T> _asSet(T[] a, boolean makeImmutable) {
    int count = (a != null) ? a.length : 0;

    Set<T> outSet;/*  ww  w  . ja  va 2  s  . c o  m*/

    if (count == 0) {
        outSet = Collections.emptySet();
    } else {
        if (count == 1) {
            outSet = Collections.singleton(a[0]);
        } else {
            // make the initial size big enough that we don't have to rehash to fit the array, for
            // the .75 load factor we pass in
            int initialSize = (int) Math.ceil(count / .75d);

            outSet = new HashSet<T>(initialSize, .75f);

            for (int i = 0; i < count; i++) {
                outSet.add(a[i]);
            }

            if (makeImmutable) {
                outSet = Collections.unmodifiableSet(outSet);
            }
        }
    }

    return outSet;
}

From source file:io.pivotal.cla.security.WithSigningUserFactory.java

public static User create() {
    User user = new User();
    user.setAccessToken("mocked_access_token");
    user.setAvatarUrl("https://avatars.githubusercontent.com/u/362503?v=3");
    user.setEmails(Collections.singleton("rob@gmail.com"));
    user.setGitHubLogin("robwinch");
    return user;//from   ww  w.j  a va2 s.  c  o  m
}

From source file:bz.tsung.jsonapi4j.models.SingleElementSet.java

@Override
public Iterator<T> iterator() {
    return Collections.singleton(value).iterator();
}

From source file:com.yahoo.elide.jsonapi.models.SingleElementSet.java

@Override
public Iterator<T> iterator() {
    return value == null ? Collections.emptyIterator() : Collections.singleton(value).iterator();
}

From source file:me.ferrybig.javacoding.webmapper.test.session.DefaultDataStorageTest.java

@Test
public void setAndGetDataTest() {
    data.setData(Collections.emptyList());
    assertEquals(0, data.getData().size());
    data.setData(Collections.singleton(new Object()));
    assertEquals(1, data.getData().size());
}

From source file:samples.jaas.RoleUserAuthorityGranter.java

public Set<String> grant(Principal principal) {
    return Collections.singleton("ROLE_USER");
}

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

/**
 * /*from w  ww .  j  av a  2  s . c  om*/
 * @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 all 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.
 */
@SuppressWarnings("unchecked")
public static boolean contains(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);
    }

    return collection.containsAll(asCollection);
}

From source file:org.gridobservatory.greencomputing.dao.RoomDao.java

public void insert(Room room) {
    this.insert(Collections.singleton(room));
}