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.mauersu.util.redis.DefaultSetOperations.java

public Set<V> intersect(K key, K otherKey) {
    return intersect(key, Collections.singleton(otherKey));
}

From source file:it.anyplace.sync.discovery.protocol.ld.LocalDiscorveryHandler.java

public List<DeviceAddress> queryAndClose(String deviceId) {
    return queryAndClose(Collections.singleton(deviceId));
}

From source file:edu.emory.bmi.aiw.i2b2export.output.VisitDataRowOutputFormatter.java

@Override
protected Collection<Observation> matchingObservations(I2b2ConceptEntity i2b2Concept) throws SQLException {
    switch (StringUtils.upperCase(i2b2Concept.getTableName())) {
    case "CONCEPT_DIMENSION":
        List<Observation> obxs = this.keyToObx.get(i2b2Concept.getI2b2Key());
        if (obxs != null) {
            return Collections.unmodifiableCollection(obxs);
        } else {// w  w w  .  j a  v a  2s . c  o m
            return Collections.emptyList();
        }
    case "PATIENT_DIMENSION":
        Patient patient = this.visit.getPatient();
        if (compareDimensionColumnValue(i2b2Concept, patient)) {
            Observation.Builder b = new Observation.Builder(this.visit).tval(getParam(patient, i2b2Concept));
            Collection<Observation> o = Collections.singleton(b.build());
            return o;
        } else {
            return Collections.emptyList();
        }
    case "VISIT_DIMENSION":
        return null;
    default:
        return Collections.emptyList();
    }

}

From source file:com.mirth.connect.server.api.servlets.CodeTemplateServlet.java

@Override
public CodeTemplate getCodeTemplate(String codeTemplateId) {
    try {// w w  w . j a  v  a2s .  c o  m
        List<CodeTemplate> codeTemplates = codeTemplateController
                .getCodeTemplates(Collections.singleton(codeTemplateId));
        if (CollectionUtils.isEmpty(codeTemplates)) {
            throw new MirthApiException(Status.NOT_FOUND);
        }
        return codeTemplates.iterator().next();
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:com.mirth.connect.server.api.servlets.ChannelStatusServlet.java

@Override
@CheckAuthorizedChannelId//from  w  w w.  j av a  2  s .c  om
public void startChannel(String channelId, boolean returnErrors) {
    ErrorTaskHandler handler = new ErrorTaskHandler();
    engineController.startChannels(Collections.singleton(channelId), handler);
    if (returnErrors && handler.isErrored()) {
        throw new MirthApiException(handler.getError());
    }
}

From source file:ch.cyberduck.cli.CommandLinePathParserTest.java

@Test
public void testParseProfile() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(
            new HashSet<>(Collections.singleton(new SwiftProtocol() {
                @Override/*w w w  .  j av  a2  s . c  o m*/
                public boolean isEnabled() {
                    return true;
                }
            })));
    final ProfilePlistReader reader = new ProfilePlistReader(factory,
            new DeserializerFactory(PlistDeserializer.class.getName()));
    final Profile profile = reader.read(new Local("../profiles/default/Rackspace US.cyberduckprofile"));
    assertNotNull(profile);

    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[] {});

    assertEquals(new Path("/cdn.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input,
                    new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile))))
                            .parse("rackspace://u@cdn.cyberduck.ch/"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input,
                    new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile))))
                            .parse("rackspace:///"));
}

From source file:com.amalto.core.server.MetadataRepositoryAdminImpl.java

public Set<Expression> getIndexedExpressions(String dataModelName) {
    if (XSystemObjects.DM_UPDATEREPORT.getName().equals(dataModelName)) { // Indexed expressions for UpdateReport
        MetadataRepository repository = get(dataModelName);
        // Index Concept field (used in JournalStatistics for the top N types)
        ComplexTypeMetadata updateType = repository.getComplexType("Update"); //$NON-NLS-1$
        return Collections
                .singleton(from(updateType).where(isNull(updateType.getField("Concept"))).getExpression()); //$NON-NLS-1$
    }//from   ww w.  j a v a 2 s .  c o  m
    synchronized (metadataRepository) {
        ViewPOJO view = null;
        try {
            MetadataRepository repository = get(dataModelName);
            View viewCtrlLocal = Util.getViewCtrlLocal();
            Set<Expression> indexedExpressions = new HashSet<Expression>();
            for (Object viewAsObject : viewCtrlLocal.getAllViews(".*")) { //$NON-NLS-1$
                UserQueryBuilder qb = null;
                view = (ViewPOJO) viewAsObject;
                ArrayList<String> searchableElements = view.getSearchableBusinessElements().getList();
                for (String searchableElement : searchableElements) {
                    String typeName = StringUtils.substringBefore(searchableElement, "/"); //$NON-NLS-1$
                    ComplexTypeMetadata userType = repository.getComplexType(typeName);
                    if (userType != null) {
                        if (qb == null) {
                            qb = from(userType);
                        } else {
                            qb.and(userType);
                        }
                        String fieldName = StringUtils.substringAfter(searchableElement, "/"); //$NON-NLS-1$
                        if (userType.hasField(fieldName)) {
                            qb.where(UserQueryBuilder.isEmpty(userType.getField(fieldName)));
                        }
                    } else {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("View '" + view.getPK().getUniqueId()
                                    + "' does not apply to data model '" + dataModelName + "'.");
                        }
                        break; // View does not apply to model
                    }
                }
                if (qb != null) {
                    for (IWhereItem condition : view.getWhereConditions().getList()) {
                        qb.where(UserQueryHelper.buildCondition(qb, condition, repository));
                    }
                    indexedExpressions.add(qb.getExpression());
                }
            }
            return indexedExpressions;
        } catch (Exception e) {
            if (view != null) {
                throw new RuntimeException("Can not use view '" + view.getPK().getUniqueId()
                        + "' with data model '" + dataModelName + "': " + e.getMessage(), e);
            } else {
                throw new RuntimeException("Could not get indexed fields.", e);
            }
        }
    }
}

From source file:com.opengamma.financial.analytics.model.equity.variance.EquityForwardFromSpotAndYieldCurveFunction.java

@Override
public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs,
        ComputationTarget target, Set<ValueRequirement> desiredValues) {

    // 1. Get the expiry _time_ from the trade
    EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) target.getSecurity();
    double expiry = TimeCalculator.getTimeBetween(executionContext.getValuationClock().zonedDateTime(),
            security.getLastObservationDate());

    // ExternalId id = security.getSpotUnderlyingIdentifier();

    // 2. Get the discount curve and spot value
    Object discountObject = inputs.getValue(getDiscountRequirement(security));
    if (discountObject == null) {
        throw new OpenGammaRuntimeException("Could not get Discount Curve");
    }/*  www  . jav a  2 s . c  om*/
    YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) discountObject;

    Object spotObject = inputs.getValue(getSpotRequirement(security));
    if (spotObject == null) {
        throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
    }
    double spot = (Double) spotObject;

    // 3. Compute the forward
    final double discountFactor = discountCurve.getDiscountFactor(expiry);
    Validate.isTrue(discountFactor != 0,
            "The discount curve has returned a zero value for a discount bond. Check rates.");
    final double forward = spot / discountFactor;

    ValueSpecification valueSpec = getValueSpecification(security);
    return Collections.singleton(new ComputedValue(valueSpec, forward));
}

From source file:com.github.rnewson.couchdb.lucene.DocumentConverter.java

public Collection<Document> convert(final CouchDocument doc, final ViewSettings defaults,
        final Database database) throws IOException, ParseException, JSONException {
    final Object result;
    final Scriptable scriptable = convertObject(doc.asJson());

    try {//  w ww  . j  av a 2  s .c  o  m
        result = viewFun.call(context, scope, null, new Object[] { scriptable });
    } catch (final JavaScriptException e) {
        LOG.warn(doc + " caused exception during conversion.", e);
        return NO_DOCUMENTS;
    }

    if (result == null || result instanceof Undefined) {
        return NO_DOCUMENTS;
    }

    if (result instanceof RhinoDocument) {
        final RhinoDocument rhinoDocument = (RhinoDocument) result;
        final Document document = rhinoDocument.toDocument(doc.getId(), defaults, database);
        return Collections.singleton(document);
    }

    if (result instanceof NativeArray) {
        final NativeArray nativeArray = (NativeArray) result;
        final Collection<Document> arrayResult = new ArrayList<Document>((int) nativeArray.getLength());
        for (int i = 0; i < (int) nativeArray.getLength(); i++) {
            if (nativeArray.get(i, null) instanceof RhinoDocument) {
                final RhinoDocument rhinoDocument = (RhinoDocument) nativeArray.get(i, null);
                final Document document = rhinoDocument.toDocument(doc.getId(), defaults, database);
                arrayResult.add(document);
            }
        }
        return arrayResult;
    }

    return null;
}

From source file:app.api.swagger.SwaggerConfig.java

private Set<String> defaultMediaType() {
    return Collections.singleton(MediaType.APPLICATION_JSON_VALUE);
}