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.cloudera.oryx.ml.param.ContinuousAround.java

@Override
public List<Double> getTrialValues(int num) {
    Preconditions.checkArgument(num > 0);
    if (num == 1) {
        return Collections.singletonList(around);
    }/*from  w  ww.ja v  a  2s  .c  om*/
    List<Double> values = new ArrayList<>(num);
    double value = around - ((num - 1.0) / 2.0) * step;
    for (int i = 0; i < num; i++) {
        values.add(value);
        value += step;
    }
    // Make sure middle value is exact
    if (num % 2 != 0) {
        values.set(num / 2, around);
    }
    return values;
}

From source file:com.cloudera.cdk.morphline.stdlib.DecodeBase64Builder.java

@Override
public Collection<String> getNames() {
    return Collections.singletonList("decodeBase64");
}

From source file:com.soprasteria.initiatives.auth.config.SwaggerConfig.java

@Bean
public Docket swaggerDocket() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(getApiInfo())
            .globalOperationParameters(Collections.singletonList(
                    new ParameterBuilder().name("Authorization").description("Provide if necessary")
                            .modelRef(new ModelRef("string")).parameterType("header").build()))
            .forCodeGeneration(true).select().paths(regex(DEFAULT_INCLUDE_PATTERN)).build();
}

From source file:com.todo.backend.security.JWTUtils.java

public static Authentication getAuthentication(String token, String secretKey) {

    final Claims claims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody();
    final Long userId = Long.valueOf(claims.getSubject());
    final String userRole = claims.get(AUTHORITIES_KEY).toString();

    return new PreAuthenticatedAuthenticationToken(userId, null,
            Collections.singletonList(new SimpleGrantedAuthority(userRole)));
}

From source file:com.cloudera.oryx.ml.param.ContinuousRange.java

@Override
public List<Double> getTrialValues(int num) {
    Preconditions.checkArgument(num > 0);
    if (max == min) {
        return Collections.singletonList(min);
    }/*from   w  ww . j  ava 2s  . c  o  m*/
    if (num == 1) {
        return Collections.singletonList((max + min) / 2.0);
    }
    if (num == 2) {
        return Arrays.asList(min, max);
    }
    List<Double> values = new ArrayList<>(num);
    double diff = (max - min) / (num - 1.0);
    values.add(min);
    for (int i = 1; i < num - 1; i++) {
        values.add(values.get(i - 1) + diff);
    }
    values.add(max);
    return values;
}

From source file:com.cloudera.oryx.ml.param.DiscreteRange.java

@Override
public List<Integer> getTrialValues(int num) {
    Preconditions.checkArgument(num > 0);
    if (max == min) {
        return Collections.singletonList(min);
    }//  www  . j ava  2 s.  co m
    if (num == 1) {
        return Collections.singletonList((max + min) / 2);
    }
    if (num == 2) {
        return Arrays.asList(min, max);
    }
    List<Integer> values;
    if (num > (max - min)) {
        values = new ArrayList<>(max - min + 1);
        for (int i = min; i <= max; i++) {
            values.add(i);
        }
    } else {
        values = new ArrayList<>(num);
        double diff = (max - min) / (num - 1.0);
        values.add(min);
        for (int i = 1; i < num - 1; i++) {
            values.add((int) Math.round(values.get(i - 1) + diff));
        }
        values.add(max);
    }
    return values;
}

From source file:com.sequenceiq.ambari.shell.support.TableRendererTest.java

@Test
public void testRenderMultiValueMap() throws IOException {
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    map.put("HDFS", Collections.singletonList("DATANODE"));
    map.put("MAPREDUCE2", Collections.singletonList("HISTORYSERVER"));
    map.put("ZOOKEEPER", Collections.singletonList("ZOOKEEPER_SERVER"));
    assertEquals(IOUtils.toString(new FileInputStream(new File("src/test/resources/2columns"))),
            TableRenderer.renderMultiValueMap(map, "SERVICE", "COMPONENT"));
}

From source file:com.thoughtworks.go.domain.AccessTokenTest.java

@Test
void shouldValidate() {
    AccessToken.AccessTokenWithDisplayValue token = AccessToken.create(null, null, null, new TestingClock());
    token.validate(null);/* w w  w . ja  v  a 2 s .c  om*/

    assertThat(token.errors()).hasSize(3)
            .containsEntry("authConfigId", Collections.singletonList("must not be blank"))
            .containsEntry("description", Collections.singletonList("must not be blank"))
            .containsEntry("username", Collections.singletonList("must not be blank"));
}

From source file:org.smigo.user.AuthenticatedUser.java

public AuthenticatedUser(int id, String username, String password, String authority) {
    super(username, password, Collections.singletonList(new SimpleGrantedAuthority(authority)));
    this.id = id;
}

From source file:net.community.chest.gitcloud.facade.backend.FacadeEnvironmentInitializer.java

@Override
protected void extractConfigFiles(File confDir) {
    // TODO use some automatic detection mechanism for "META-INF/conf"
    extractConfigFiles(confDir, Collections.singletonList(Pair.<String, Collection<String>>of(
            "META-INF/" + ConfigUtils.CONF_DIR_NAME,
            Collections.unmodifiableList(Arrays.asList(PROPS_FILE_NAME, "gitcloud-backend-log4j.xml")))));
}