List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.opengamma.financial.analytics.model.volatility.surface.NonLinearLeastSquaresSurfaceFittingFunction.java
@SuppressWarnings("unused") @Override/*from w ww .ja v a 2 s . co m*/ public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final Object objectSurfaceData = inputs.getValue(_surfaceRequirement); if (objectSurfaceData == null) { throw new OpenGammaRuntimeException("Could not get volatility surface data"); } @SuppressWarnings("unchecked") final VolatilitySurfaceData<Tenor, Double> volatilitySurfaceData = (VolatilitySurfaceData<Tenor, Double>) objectSurfaceData; final Tenor[] tenors = volatilitySurfaceData.getXs(); final Double[] strikes = volatilitySurfaceData.getYs(); return Collections.singleton(new ComputedValue(_resultSpecification, 0)); }
From source file:examples.JsonSerializationProcessor.java
/** * Constructor. Initializes various helper objects we use for the JSON * serialization, and opens the file that we want to write to. * * @throws IOException/*from www.j av a 2s. co m*/ * if there is a problem opening the output file */ public JsonSerializationProcessor() throws IOException { // The converter is used to copy selected parts of the data. We use this // to remove some parts from the documents we serialize. The converter // uses a JacksonObjectFactory to be sure that we create objects for // which we know how to write JSON. A similar converter without the // filtering enabled would also be used to create JSON-serializable // objects from any other implementation of the Wikidata Toolkit // datamodel. this.datamodelConverter = new DatamodelConverter(new JacksonObjectFactory()); // Do not copy references at all: this.datamodelConverter.setOptionDeepCopyReferences(false); // Only copy English labels, descriptions, and aliases: this.datamodelConverter.setOptionLanguageFilter(Collections.singleton("en")); // Only copy statements of some properties: Set<PropertyIdValue> propertyFilter = new HashSet<>(); propertyFilter.add(Datamodel.makeWikidataPropertyIdValue("P18")); // image propertyFilter.add(Datamodel.makeWikidataPropertyIdValue("P106")); // occupation propertyFilter.add(Datamodel.makeWikidataPropertyIdValue("P569")); // birthdate this.datamodelConverter.setOptionPropertyFilter(propertyFilter); // Do not copy any sitelinks: this.datamodelConverter.setOptionSiteLinkFilter(Collections.<String>emptySet()); // The (compressed) file we write to. OutputStream outputStream = new GzipCompressorOutputStream( new BufferedOutputStream(ExampleHelpers.openExampleFileOuputStream(OUTPUT_FILE_NAME))); this.jsonSerializer = new JsonSerializer(outputStream); this.jsonSerializer.open(); }
From source file:com.spankingrpgs.scarletmoon.loader.ItemLoader.java
private List<String> hydrateEquipSlots(JsonNode equipSlots) { if (equipSlots == null) { return Collections.emptyList(); }//w ww . j a va2 s . c o m List<String> equipSlotNames = new ArrayList<>(); Iterator<JsonNode> equipSlotsIterator = equipSlots.elements(); while (equipSlotsIterator.hasNext()) { equipSlotNames .add(EnumUtils.nameToEnum(Collections.singleton(equipSlotsIterator.next().asText())).get(0)); } return equipSlotNames; }
From source file:cop.raml.utils.example.JsonExample.java
/** * Retrieve example for given {@code element}. First of all it checks existed {@link #cache} and if example for given {@code element} was already * in cache, then return it. Then it tries to generate example for simple types (e.g. primitives, Date, UUID). If examples is still not found, * then use {@link Config#ramlSkip} filter to filter out some element types and invoke {@link #getTypeExample(TypeElement, Set)}. Put result to * cache if it is not {@code null}.//from w w w . ja va2s .c om * * @param element element for example * @param visited visited element types (it's used to prevent cycle references) * @return example object ({@link Map} or {@link Set}) or {@code null} if example is not found */ private Object getElementExample(@NotNull Element element, @NotNull Set<String> visited) { try { ThreadLocalContext.getImportScanner().setCurrentElement(element); TypeMirror type = ElementUtils.getType(element); String className = type.toString(); Object res; if (cache.containsKey(className)) res = cache.get(className); else if (ElementUtils.isEnum(type)) res = getEnumExample(type); else if ((res = getAutoGeneratedElementExample(element, random)) == null) { if (String.class.getName().equals(className)) res = element.getSimpleName().toString(); else if (!Config.get().ramlSkip(type.toString())) { TypeElement obj = element instanceof TypeElement ? (TypeElement) element : ElementUtils.asElement(type); if ((res = getTypeExample(obj, visited)) != null) cache.putIfAbsent(className, res); } } if (res == null) return null; if (ElementUtils.isArray(element) || ElementUtils.isCollection(element)) return Collections.singleton(res); return res; } catch (Exception ignored) { return null; } }
From source file:org.apereo.services.persondir.support.rule.StringFormatAttributeRule.java
@Override public Set<String> getPossibleUserAttributeNames() { return Collections.singleton(outputAttribute); }
From source file:com.codeabovelab.dm.mail.template.ResourceMailTemplateProvider.java
public ResourceMailTemplateProvider(Config config, ObjectMapper objectMapper) { this.prefix = config.prefix; this.suffix = config.suffix; this.mimeType = config.mimeType; this.objectMapper = objectMapper; Assert.notNull(this.objectMapper, "'objectMapper' is null"); Assert.hasText(this.prefix, "'prefix' must contains text"); Assert.hasText(this.suffix, "'suffix' must contains text"); Assert.notNull(this.mimeType, "'mimeType' is null"); this.protocols = Collections.singleton(PROTOCOL); }
From source file:com.opengamma.financial.analytics.LastHistoricalValueFunction.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final HistoricalTimeSeries hts = (HistoricalTimeSeries) inputs.getAllValues().iterator().next().getValue(); final ValueRequirement desiredValue = desiredValues.iterator().next(); return Collections.singleton(new ComputedValue(new ValueSpecification(desiredValue.getValueName(), target.toSpecification(), desiredValue.getConstraints()), hts.getTimeSeries().getLatestValue())); }
From source file:com.theoryinpractise.coffeescript.CoffeeScriptCompiler.java
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed) throws URISyntaxException { return new Require(cx, cx.initStandardObjects(), new StrongCachingModuleScriptProvider( new UrlModuleSourceProvider(Collections.singleton(getDirectory()), null)), null, null, sandboxed);//from w w w. j a v a 2 s.com }
From source file:io.coala.experimental.dynabean.DynaBeanTest.java
@Test public void testDynaBeans() throws Exception { // for usage, see // http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description final DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean final MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass(); // get DynaClass dynaClass.add("amount", java.lang.Integer.class); // add property dynaClass.add("myMap", java.util.TreeMap.class); // add mapped property final DynaBean employee = dynaClass.newInstance(); // TODO experiment with Jackson's AnnotationIntrospector to annotate // DynaBean#get(...) method with @JsonAnyGetter and #set(...) method // with @JsonAnySetter employee.set("address", new HashMap<String, String>()); employee.set("activeEmployee", Boolean.FALSE); employee.set("firstName", "Fred"); employee.set("lastName", "Flintstone"); LOG.trace("Employee: " + JsonUtil.toPrettyJSON(employee)); // set all <activeEmployee> attribute values to <true> final BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("activeEmployee", Boolean.TRUE);/*from w w w . j a va2 s . co m*/ final Collection<?> employees = Collections.singleton(employee); LOG.trace("Mutated employees: " + JsonUtil.toPrettyJSON(employees)); // update the Collection CollectionUtils.forAllDo(employees, closure); // filter for beans with <activeEmployee> set to <false> final BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate("lastName", "Flintstone"); // filter the Collection CollectionUtils.filter(employees, predicate); LOG.trace("Filtered employees: " + JsonUtil.toPrettyJSON(employees)); }
From source file:com.parse.ParseRelation.java
/** * Removes an object from this relation. * //from ww w. j a v a 2s .co m * @param object * The object to remove from this relation. */ public void remove(T object) { synchronized (mutex) { ParseRelationOperation<T> operation = new ParseRelationOperation<>(null, Collections.singleton(object)); targetClass = operation.getTargetClass(); getParent().performOperation(key, operation); knownObjects.remove(object); } }