Example usage for com.google.common.collect Lists newArrayList

List of usage examples for com.google.common.collect Lists newArrayList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayList.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList() 

Source Link

Document

Creates a mutable, empty ArrayList instance (for Java 6 and earlier).

Usage

From source file:org.glowroot.storage.util.ServerRollups.java

public static List<String> getServerRollups(String serverId) {
    List<String> serverRollups = Lists.newArrayList();
    int lastFoundIndex = -1;
    int nextFoundIndex;
    while ((nextFoundIndex = serverId.indexOf('/', lastFoundIndex)) != -1) {
        serverRollups.add(serverId.substring(0, nextFoundIndex));
        lastFoundIndex = nextFoundIndex + 1;
    }//  w w w .j  av  a 2 s .  c o m
    serverRollups.add(serverId);
    return serverRollups;
}

From source file:com.sccl.attech.common.utils.excel.fieldtype.RoleListType.java

/**
 * ?//from w w w .ja  v  a 2  s  .  com
 */
public static Object getValue(String val) {
    List<Role> roleList = Lists.newArrayList();
    List<Role> allRoleList = systemService.findAllRole();
    for (String s : StringUtils.split(val, ",")) {
        for (Role e : allRoleList) {
            if (e.getName().equals(s)) {
                roleList.add(e);
            }
        }
    }
    return roleList.size() > 0 ? roleList : null;
}

From source file:com.mgmtp.jfunk.core.JFunk.java

/**
 * Starts jFunk.// w w w  . j a  v  a 2s. c o m
 * 
 * <pre>
 * -threadcount=&lt;count&gt;    Optional    Number of threads to be used. Allows for parallel
 *                                     execution of test scripts.
 * -parallel               Optional    Allows a single script to be executed in parallel
 *                                     depending on the number of threads specified. The
 *                                     argument is ignored if multiple scripts are specified.
 * &lt;script parameters&gt     Optional    Similar to Java system properties they can be provided
 *                                     as key-value-pairs preceded by -S, e.g. -Skey=value.
 *                                     These parameters are then available in the script as
 *                                     Groovy variables.
 * &lt;script(s)&gt;             Required    At least one test script must be specified.
 *
 * Example:
 * java -cp &lt;jFunkClasspath&gt; com.mgmtp.jfunk.core.JFunk -Skey=value -threadcount=4 -parallel mytest.script
 * </pre>
 * 
 * @param args
 *            The program arguments.
 */
public static void main(final String[] args) {
    SLF4JBridgeHandler.install();

    boolean exitWithError = true;
    StopWatch stopWatch = new StopWatch();

    try {
        RESULT_LOG.info("jFunk started");
        stopWatch.start();

        int threadCount = 1;
        boolean parallel = false;
        Properties scriptProperties = new Properties();
        List<File> scripts = Lists.newArrayList();

        for (String arg : args) {
            if (arg.startsWith("-threadcount")) {
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "The number of threads must be specified as follows: -threadcount=<value>");
                threadCount = Integer.parseInt(split[1]);
                RESULT_LOG.info("Using " + threadCount + (threadCount == 1 ? " thread" : " threads"));
            } else if (arg.startsWith("-S")) {
                arg = arg.substring(2);
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "Script parameters must be given in the form -S<name>=<value>");
                scriptProperties.setProperty(split[0], normalizeScriptParameterValue(split[1]));
                RESULT_LOG.info("Using script parameter " + split[0] + " with value " + split[1]);
            } else if (arg.equals("-parallel")) {
                parallel = true;
                RESULT_LOG.info("Using parallel mode");
            } else {
                scripts.add(new File(arg));
            }
        }

        if (scripts.isEmpty()) {
            scripts.addAll(requestScriptsViaGui());

            if (scripts.isEmpty()) {
                RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
                System.exit(0);
            }
        }

        String propsFileName = System.getProperty("jfunk.props.file", "jfunk.properties");
        Module module = ModulesLoader.loadModulesFromProperties(new JFunkDefaultModule(), propsFileName);
        Injector injector = Guice.createInjector(module);

        JFunkFactory factory = injector.getInstance(JFunkFactory.class);
        JFunkBase jFunk = factory.create(threadCount, parallel, scripts, scriptProperties);
        jFunk.execute();

        exitWithError = false;
    } catch (JFunkExecutionException ex) {
        // no logging necessary
    } catch (Exception ex) {
        Logger.getLogger(JFunk.class).error("jFunk terminated unexpectedly.", ex);
    } finally {
        stopWatch.stop();
        RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
    }

    System.exit(exitWithError ? -1 : 0);
}

From source file:co.cask.cdap.api.security.Principals.java

public static List<Principal> fromIds(PrincipalType type, List<String> ids) {
    List<Principal> result = Lists.newArrayList();
    for (String id : ids) {
        result.add(new Principal(type, id));
    }//from   w w  w  .  ja  v a 2  s  .c  om
    return result;
}

From source file:com.tjtolley.roborally.game.Course.java

public static Course fromCourseMap(Map<String, Object> courseMap) {
    List<Map<String, Object>> placedBoards = (List<Map<String, Object>>) courseMap.get("placedBoards");
    List<PlacedBoard> boards = Lists.newArrayList();
    for (Map<String, Object> boardDefinition : placedBoards) {
        final Map<String, Object> positionOffset = (Map<String, Object>) boardDefinition
                .get("boardStartOffset");
        boards.add(new PlacedBoard(
                BoardDefinition.fromBoardMap((Map<String, Object>) boardDefinition.get("boardDefinition")),
                new Position((Integer) positionOffset.get("x"), (Integer) positionOffset.get("y"))));
    }//ww w. j  a  v  a 2s .  c o  m
    return new Course(boards, Lists.<Position>newArrayList(), Lists.<Position>newArrayList());
}

From source file:badminton.common.Util.JsonUtil.java

/**
 * json?list//from   w  w w.  jav  a 2  s . c o  m
 * 
 * @param json
 * @param tClass
 * @param <T>
 * @return
 */
public static <T> List<T> toList(final String json, final Class<T> tClass) {
    final List<T> result = Lists.newArrayList();

    if (StringUtils.isNotBlank(json)) {
        final JsonParser parser = new JsonParser();
        final JsonArray jsonArray = parser.parse(json).getAsJsonArray();
        jsonArray.forEach(node -> {
            final T cse = GSON.fromJson(node, tClass);
            result.add(cse);
        });
    }

    return result;
}

From source file:com.cynnyx.auto.value.map.ConstructorMethod.java

static MethodSpec generateConstructor(List<Property> properties) {
    List<ParameterSpec> params = Lists.newArrayList();
    List<String> keySet = new ArrayList<>();
    for (Property p : properties) {
        params.add(ParameterSpec.builder(p.type, p.humanName).build());
        keySet.add(p.humanName);//  w w w  .j a v a2 s . c o  m
    }

    MethodSpec.Builder builder = MethodSpec.constructorBuilder().addParameters(params);

    StringBuilder superFormat = new StringBuilder("super(");
    for (int i = properties.size(); i > 0; i--) {
        superFormat.append("$N");
        if (i > 1)
            superFormat.append(", ");
    }
    superFormat.append(")");
    builder.addStatement(superFormat.toString(), keySet.toArray());

    return builder.build();
}

From source file:com.yolodata.tbana.hadoop.mapred.splunk.indexer.IndexerProvider.java

public static List<Indexer> getIndexers(Service splunkService) {
    List<Indexer> indexers = Lists.newArrayList();
    Collection<DistributedPeer> distributedPeers = splunkService.getDistributedPeers().values();
    for (DistributedPeer peer : distributedPeers) {
        String[] ipAndPort = peer.getName().split(":");
        indexers.add(new Indexer(ipAndPort[0], Integer.parseInt(ipAndPort[1])));
    }//from w  w w .j av  a2 s .co m

    return indexers;
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.YQLError.java

private static List<StackTrace> extractDetails(Throwable failure) {
    // TODO: be lazy about extracting these details
    List<StackTrace> result = Lists.newArrayList();
    Throwable current = failure;//w w  w .j  a va  2 s .c  om
    while (current != null) {
        if (current instanceof YQLRuntimeException) {
            YQLError error = ((YQLRuntimeException) current).getError();
            result.addAll(error.getDetails());
            break;
        }
        StackTrace trace = extractTrace(failure);
        if (trace != null) {
            result.add(trace);
        }
        current = current.getCause();
    }
    return result;
}

From source file:com.eincs.decanter.utils.Classes.java

public static List<Field> getAllMemberFields(Class<?> clazz) {
    List<Field> result = Lists.newArrayList();
    List<Class<?>> classes = getGenealogyList(clazz);
    for (Class<?> c : classes) {
        List<Field> declaredFields = Lists.newArrayList(c.getDeclaredFields());
        for (Field f : declaredFields) {
            if (!Modifier.isStatic(f.getModifiers())) {
                result.add(f);/*from ww  w.j a va 2s  .  c o m*/
            }
        }
    }
    return result;
}