List of usage examples for java.util Collections singletonList
public static <T> List<T> singletonList(T o)
From source file:com.cloudera.oryx.ml.param.RandomSearch.java
/** * @param ranges ranges of hyperparameters to try, one per hyperparameters * @param howMany how many combinations of hyperparameters to return * @return combinations of concrete hyperparameter values */// ww w . j ava 2 s .c om static List<List<?>> chooseHyperParameterCombos(Collection<? extends HyperParamValues<?>> ranges, int howMany) { Preconditions.checkArgument(howMany > 0); int numParams = ranges.size(); if (numParams == 0) { return Collections.singletonList(Collections.emptyList()); } RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom()); List<List<?>> allCombinations = new ArrayList<>(howMany); for (int i = 0; i < howMany; i++) { List<Object> combination = new ArrayList<>(numParams); for (HyperParamValues<?> range : ranges) { combination.add(range.getRandomValue(rdg)); } allCombinations.add(combination); } return allCombinations; }
From source file:XMLResourceBundleControl.java
public List<String> getFormats(String baseName) { return Collections.singletonList(XML); }
From source file:Main.java
/** * Returns a collection with fast contains() implementation. The collection * is intended to be reusable. A single use will not be efficient as it * allocates memory for the new collection. * // ww w. ja v a 2 s . c o m * Most efficient with primitive objects (String, Integer...) */ @SuppressWarnings("unchecked") public static <T> Collection<T> fastSearchCollection(List<T> list) { final int size = list.size(); if (size == 0) return Collections.EMPTY_LIST; if (size == 1) Collections.singletonList(list.get(0)); // optimization for short list, avoid hash if (size <= 8) { if (list instanceof ArrayList) // ArrayList similar to Arrays for short lists, save some // memory. return (ArrayList<T>) list; // not ArrayList, play safe with final array type list T[] s = (T[]) list.toArray(); return Arrays.asList(s); } // big lists, use hash (constant time) return new HashSet<T>(list); }
From source file:XMLResourceBundleControl.java
public List<String> getFormats(String baseName) { return Collections.singletonList(XML); }
From source file:com.cognifide.cq.cqsm.core.scripts.ScriptFilters.java
public static Predicate filterByExecutionMode(final ExecutionMode mode) { return filterByExecutionMode(Collections.singletonList(mode)); }
From source file:com.hp.autonomy.aci.content.fieldtext.MATCHALL.java
public MATCHALL(final String field, final String value, final String... values) { this(Collections.singletonList(field), value, values); }
From source file:com.hp.autonomy.aci.content.fieldtext.NOTMATCH.java
public NOTMATCH(final String field, final String value, final String... values) { this(Collections.singletonList(field), value, values); }
From source file:Lists.java
public static <T> List<T> add(List<T> list, int index, T toAdd) { switch (list.size()) { case 0://from www . ja v a 2s .c o m // Empty -> Singleton if (index != 0) { throw newIndexOutOfBounds(list, index); } return Collections.singletonList(toAdd); case 1: { // Singleton -> ArrayList List<T> result = new ArrayList<T>(2); switch (index) { case 0: result.add(toAdd); result.add(list.get(0)); return result; case 1: result.add(list.get(0)); result.add(toAdd); return result; default: throw newIndexOutOfBounds(list, index); } } default: // ArrayList list.add(index, toAdd); return list; } }
From source file:com.royclarkson.springagram.RestUtils.java
public static HttpEntity<Void> getRequestEntity() { if (requestEntity == null) { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "hal+json"))); requestEntity = new HttpEntity<Void>(requestHeaders); }/*from w ww. jav a 2 s . c o m*/ return requestEntity; }
From source file:com.orange.cepheus.broker.Util.java
static public RegisterContext createRegistrationContext(String entityId, String entityType, boolean entityIsPattern, String providingApp, String attr) throws Exception { RegisterContext registerContext = new RegisterContext(); registerContext.setDuration("PT1M"); ContextRegistration contextRegistration = new ContextRegistration(); contextRegistration/*from w w w .j av a2s . co m*/ .setEntityIdList(Collections.singletonList(new EntityId(entityId, entityType, entityIsPattern))); contextRegistration.setContextRegistrationAttributeList( Collections.singletonList(new ContextRegistrationAttribute(attr, false))); contextRegistration.setProvidingApplication(new URI(providingApp)); registerContext.setContextRegistrationList(Collections.singletonList(contextRegistration)); return registerContext; }