Example usage for java.util Collections singletonList

List of usage examples for java.util Collections singletonList

Introduction

In this page you can find the example usage for java.util Collections singletonList.

Prototype

public static <T> List<T> singletonList(T o) 

Source Link

Document

Returns an immutable list containing only the specified object.

Usage

From source file:com.hp.autonomy.aci.content.fieldtext.STRINGALL.java

/**
 * Constructs a new single field STRINGALL fieldtext
 * @param field The field name//from   ww  w  .j  a v a2  s.  c om
 * @param values The field values
 */
public STRINGALL(final String field, final String[] values) {
    this(Collections.singletonList(field), values);
}

From source file:org.elasticsearch.client.sniff.MockNodesSniffer.java

@Override
public List<Node> sniff() {
    return Collections.singletonList(new Node(new HttpHost("localhost", 9200)));
}

From source file:com.create.application.configuration.EndpointsConfiguration.java

@Bean
public List<String> actuatorEndpoints(@Value("${management.context-path}") String actuatorEndpoints) {
    return Collections.singletonList(getWildcardMappings(actuatorEndpoints));
}

From source file:org.elasticsearch.client.sniff.MockHostsSniffer.java

@Override
public List<HttpHost> sniffHosts() throws IOException {
    return Collections.singletonList(new HttpHost("localhost", 9200));
}

From source file:ch.cyberduck.core.PasswordStrengthValidator.java

public Strength getScore(final String password) {
    if (StringUtils.isEmpty(password)) {
        return Strength.veryweak;
    } else {//from w  ww .  j av a2s. co m
        final int score = zxcvbn
                .measure(password,
                        Collections.singletonList(PreferencesFactory.get().getProperty("application.name")))
                .getScore();
        switch (score) {
        case 0:
            return Strength.veryweak;
        case 1:
            return Strength.weak;
        case 2:
            return Strength.fair;
        case 3:
            return Strength.strong;
        case 4:
        default:
            return Strength.verystrong;
        }
    }
}

From source file:com.netflix.spinnaker.orca.clouddriver.pipeline.image.FindImageFromTagsStage.java

@Override
public List<Step> buildSteps(Stage stage) {
    return Collections.singletonList(buildStep(stage, "findImage", FindImageFromTagsTask.class));
}

From source file:com.newtranx.util.io.TestIteratorInputStream.java

@Test
public void testString() throws IOException {
    List<String> list = Collections.singletonList("abc");
    IteratorInputStream<String> is = IteratorInputStream.newBuilder(list.iterator()).bufferSize(10240)
            .encoder((s, buf) -> buf.put(s.getBytes(cs))).build();

    String abc = IOUtils.toString(is, cs);
    assertEquals("abc", abc);
}

From source file:com.hp.autonomy.aci.content.identifier.id.Id.java

@Override
public Iterator<Id> iterator() {
    // Should probably rewrite this to use a custom iterator
    return Collections.singletonList(this).iterator();
}

From source file:de.codecentric.boot.admin.services.ApplicationRegistrator.java

private static HttpHeaders createHttpHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    return HttpHeaders.readOnlyHttpHeaders(headers);
}

From source file:com.cloudera.oryx.ml.param.GridSearch.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. For example, for 5 parameters each
 *  with 3 values to try, the total number of combinations returned could be up to pow(3,5)
 *  or 243. The number could be less if the ranges do not actually have that many distinct
 *  values. If {@code howMany} is smaller than the total number of combinations, a random
 *  subset of all combinations are returned. The order is shuffled randomly. If no parameters
 *  are specified or {@code perParam} is 0, a single empty combination is returned.
 *//*from w  w w .  j ava2 s  .c o  m*/
static List<List<?>> chooseHyperParameterCombos(List<HyperParamValues<?>> ranges, int howMany) {
    // Put some reasonable upper limit on the number of combos
    Preconditions.checkArgument(howMany > 0 && howMany <= MAX_COMBOS);

    int numParams = ranges.size();
    int perParam = chooseValuesPerHyperParam(ranges, howMany);
    if (numParams == 0 || perParam == 0) {
        return Collections.singletonList(Collections.emptyList());
    }

    int howManyCombos = 1;
    List<List<?>> paramRanges = new ArrayList<>(numParams);
    for (HyperParamValues<?> range : ranges) {
        List<?> values = range.getTrialValues(perParam);
        paramRanges.add(values);
        howManyCombos *= values.size();
    }

    List<List<?>> allCombinations = new ArrayList<>(howManyCombos);
    for (int combo = 0; combo < howManyCombos; combo++) {
        List<Object> combination = new ArrayList<>(numParams);
        for (int param = 0; param < numParams; param++) {
            int whichValueToTry = combo;
            for (int i = 0; i < param; i++) {
                whichValueToTry /= paramRanges.get(i).size();
            }
            whichValueToTry %= paramRanges.get(param).size();
            combination.add(paramRanges.get(param).get(whichValueToTry));
        }
        allCombinations.add(combination);
    }

    if (howMany >= howManyCombos) {
        Collections.shuffle(allCombinations);
        return allCombinations;
    }
    RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
    int[] indices = rdg.nextPermutation(howManyCombos, howMany);
    List<List<?>> result = new ArrayList<>(indices.length);
    for (int i = 0; i < indices.length; i++) {
        result.add(allCombinations.get(i));
    }
    Collections.shuffle(result);
    return result;
}