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:com.kegare.frozenland.client.config.FrozenConfigGui.java

private static List<IConfigElement> getConfigElements() {
    List<IConfigElement> list = Lists.newArrayList();

    list.addAll(/* w ww.  j a v  a 2  s. c  o  m*/
            new ConfigElement(Config.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements());
    list.addAll(new ConfigElement(Config.config.getCategory("blocks")).getChildElements());
    list.addAll(new ConfigElement(Config.config.getCategory("items")).getChildElements());
    list.addAll(new ConfigElement(Config.config.getCategory("recipes")).getChildElements());
    list.addAll(new ConfigElement(Config.config.getCategory("frozenland")).getChildElements());

    return list;
}

From source file:org.apache.crunch.util.Collects.java

public static <T> Collection<T> newArrayList() {
    return Lists.newArrayList();
}

From source file:qa.qcri.qnoise.QnoiseFacade.java

/**
 * Call with only primitive types./*from   ww  w . java  2s  .  c om*/
 *
 * This is used mainly for cross-language bridging purpose (e.g. call from R).
 */
public static String[][] inject(@NotNull String[][] data, int noiseType, int granularity, double percentage,
        int model, String[] filteredColumns, double seed, double[] distance, String[] constraints,
        String logFile) {
    try {
        List<List<String>> dataList = Lists.newArrayList();
        for (int i = 0; i < data.length; i++) {
            List<String> list = Lists.newArrayList();
            for (int j = 0; j < data[i].length; j++)
                list.add(data[i][j]);
            dataList.add(list);
        }
        DataProfile profile = new DataProfile(dataList);

        NoiseSpec spec = new NoiseSpec();
        spec.noiseType = NoiseType.fromInt(noiseType);
        spec.granularity = GranularityType.fromInt(granularity);
        spec.percentage = percentage;
        spec.model = NoiseModel.fromInt(model);
        spec.filteredColumns = filteredColumns;
        spec.numberOfSeed = seed;
        if (distance != null) {
            spec.distance = new double[distance.length];
            for (int i = 0; i < distance.length; i++)
                spec.distance[i] = distance[i];
        }

        if (constraints != null) {
            spec.constraint = new Constraint[constraints.length];
            for (int i = 0; i < constraints.length; i++)
                spec.constraint[i] = ConstraintFactory.createConstraintFromString(constraints[i]);
        }

        spec.logFile = logFile;
        inject(profile, Lists.newArrayList(spec));

        // copy back the result
        List<List<String>> resultList = profile.getData();
        String[][] result = new String[resultList.size()][];
        for (int i = 0; i < result.length; i++) {
            result[i] = new String[resultList.get(0).size()];
            for (int j = 0; j < resultList.get(0).size(); j++)
                result[i][j] = resultList.get(i).get(j);
        }
        return result;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:org.activityinfo.ui.client.page.config.design.importer.wrapper.Wrappers.java

public static List<EntityDTO> asDto(List<DtoWrapper> wrapperList) {
    List<EntityDTO> result = Lists.newArrayList();
    for (DtoWrapper wrapper : wrapperList) {
        result.add(wrapper.getDto());/*ww  w  . j a  va  2s .  c  om*/
    }
    return result;
}

From source file:com.mangocar.util.BeanMapper.java

/**
 * Dozer?Collection./*w ww. ja v  a  2  s.c  om*/
 */
public static <T> List<T> mapList(Collection<?> sourceList, Class<T> destinationClass) {
    List<T> destinationList = Lists.newArrayList();
    for (Object sourceObject : sourceList) {
        T destinationObject = dozer.map(sourceObject, destinationClass);
        destinationList.add(destinationObject);
    }
    return destinationList;
}

From source file:com.telefonica.iot.cygnus.nodes.CygnusApplication.java

/**
 * Main application to be run when this CygnusApplication is invoked. The only differences with the original one
 * are the CygnusApplication is used instead of the Application one, and the Management Interface port option in
 * the command line./*w w w.ja v  a  2s .  com*/
 * @param args
 */
public static void main(String[] args) {
    try {
        // Print Cygnus starting trace including version
        LOGGER.info("Starting Cygnus, version " + CommonUtils.getCygnusVersion() + "."
                + CommonUtils.getLastCommit());

        // Define the options to be read
        Options options = new Options();

        Option option = new Option("n", "name", true, "the name of this agent");
        option.setRequired(true);
        options.addOption(option);

        option = new Option("f", "conf-file", true, "specify a conf file");
        option.setRequired(true);
        options.addOption(option);

        option = new Option(null, "no-reload-conf", false, "do not reload conf file if changed");
        options.addOption(option);

        option = new Option("h", "help", false, "display help text");
        options.addOption(option);

        option = new Option("p", "mgmt-if-port", true, "the management interface port");
        option.setRequired(false);
        options.addOption(option);

        option = new Option("g", "gui-port", true, "the GUI port");
        option.setRequired(false);
        options.addOption(option);

        option = new Option("t", "polling-interval", true, "polling interval");
        option.setRequired(false);
        options.addOption(option);

        // Read the options
        CommandLineParser parser = new GnuParser();
        CommandLine commandLine = parser.parse(options, args);

        File configurationFile = new File(commandLine.getOptionValue('f'));
        String agentName = commandLine.getOptionValue('n');
        boolean reload = !commandLine.hasOption("no-reload-conf");

        if (commandLine.hasOption('h')) {
            new HelpFormatter().printHelp("cygnus-flume-ng agent", options, true);
            return;
        } // if

        int apiPort = DEF_MGMT_IF_PORT;

        if (commandLine.hasOption('p')) {
            apiPort = new Integer(commandLine.getOptionValue('p'));
        } // if

        int guiPort = DEF_GUI_PORT;

        if (commandLine.hasOption('g')) {
            guiPort = new Integer(commandLine.getOptionValue('g'));
        } else {
            guiPort = 0; // this disables the GUI for the time being
        } // if else

        int pollingInterval = DEF_POLLING_INTERVAL;

        if (commandLine.hasOption('t')) {
            pollingInterval = new Integer(commandLine.getOptionValue('t'));
        } // if

        // the following is to ensure that by default the agent will fail on startup if the file does not exist
        if (!configurationFile.exists()) {
            // if command line invocation, then need to fail fast
            if (System.getProperty(Constants.SYSPROP_CALLED_FROM_SERVICE) == null) {
                String path = configurationFile.getPath();

                try {
                    path = configurationFile.getCanonicalPath();
                } catch (IOException e) {
                    LOGGER.error(
                            "Failed to read canonical path for file: " + path + ". Details=" + e.getMessage());
                } // try catch

                throw new ParseException("The specified configuration file does not exist: " + path);
            } // if
        } // if

        List<LifecycleAware> components = Lists.newArrayList();
        CygnusApplication application;

        if (reload) {
            LOGGER.debug(
                    "no-reload-conf was not set, thus the configuration file will be polled each 30 seconds");
            EventBus eventBus = new EventBus(agentName + "-event-bus");
            PollingPropertiesFileConfigurationProvider configurationProvider = new PollingPropertiesFileConfigurationProvider(
                    agentName, configurationFile, eventBus, pollingInterval);
            components.add(configurationProvider);
            application = new CygnusApplication(components);
            eventBus.register(application);
        } else {
            LOGGER.debug("no-reload-conf was set, thus the configuration file will only be read this time");
            PropertiesFileConfigurationProvider configurationProvider = new PropertiesFileConfigurationProvider(
                    agentName, configurationFile);
            application = new CygnusApplication();
            application.handleConfigurationEvent(configurationProvider.getConfiguration());
        } // if else

        // use the agent name as component name in the logs through log4j Mapped Diagnostic Context (MDC)
        MDC.put(CommonConstants.LOG4J_COMP, commandLine.getOptionValue('n'));

        // start the Cygnus application
        application.start();

        // wait until the references to Flume components are not null
        try {
            while (sourcesRef == null || channelsRef == null || sinksRef == null) {
                LOGGER.info("Waiting for valid Flume components references...");
                Thread.sleep(1000);
            } // while
        } catch (InterruptedException e) {
            LOGGER.error("There was an error while waiting for Flume components references. Details: "
                    + e.getMessage());
        } // try catch

        // start the Management Interface, passing references to Flume components
        LOGGER.info("Starting a Jetty server listening on port " + apiPort + " (Management Interface)");
        mgmtIfServer = new JettyServer(apiPort, guiPort, new ManagementInterface(configurationFile, sourcesRef,
                channelsRef, sinksRef, apiPort, guiPort));
        mgmtIfServer.start();

        // create a hook "listening" for shutdown interrupts (runtime.exit(int), crtl+c, etc)
        Runtime.getRuntime().addShutdownHook(new AgentShutdownHook("agent-shutdown-hook", supervisorRef));

        // start YAFS
        YAFS yafs = new YAFS();
        yafs.start();
    } catch (IllegalArgumentException e) {
        LOGGER.error("A fatal error occurred while running. Exception follows. Details=" + e.getMessage());
    } catch (ParseException e) {
        LOGGER.error("A fatal error occurred while running. Exception follows. Details=" + e.getMessage());
    } // try catch // try catch
}

From source file:edu.harvard.med.screensaver.io.libraries.LibraryCopyPlateListParser.java

public static List<LibraryCopyPlateListParserResult> parsePlateCopiesSublists(String plateCopyLists) {
    List<LibraryCopyPlateListParserResult> results = Lists.newArrayList();
    for (String plateCopyList : plateCopyLists.split("\\n")) {
        results.add(parsePlateCopies(plateCopyList));
    }/*www . java 2  s. c om*/
    if (log.isDebugEnabled())
        log.debug("results: " + results);
    return results;
}

From source file:models.datatable.LicenseFeatureDataTable.java

public static List<FeatureInfo> features(License license, StorageStatsWrapper stats) {
    List<FeatureInfo> features = Lists.newArrayList();
    for (LicenseFeature lf : license.getLicenseFeatures()) {
        features.add(new FeatureInfo(lf, stats));
    }// ww  w .j ava  2s.  c  om
    return features;
}

From source file:cc.sion.core.persistence.DynamicSpecifications.java

public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters,
        final Class<T> entityClazz) {
    return new Specification<T>() {
        @Override//from w  w w . j ava 2  s .  co m
        public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
            if (Collections3.isNotEmpty(filters)) {

                List<Predicate> predicates = Lists.newArrayList();
                for (SearchFilter filter : filters) {
                    // nested path translate, Task??"user.name"filedName, ?Task.user.name
                    String[] names = StringUtils.split(filter.fieldName, ".");
                    Path expression = root.get(names[0]);
                    for (int i = 1; i < names.length; i++) {
                        expression = expression.get(names[i]);
                    }
                    //                  if(log.isDebugEnabled()){
                    //                     log.debug("   {}-{}-{}",names[0],filter.operator,filter.value);
                    //                  }
                    // logic operator
                    switch (filter.operator) {
                    case EQ:
                        predicates.add(builder.equal(expression, filter.value));
                        break;
                    case NE:
                        predicates.add(builder.notEqual(expression, filter.value));
                        break;
                    case LIKE:
                        predicates.add(builder.like(expression, "%" + filter.value + "%"));
                        break;
                    case GT:
                        predicates.add(builder.greaterThan(expression, (Comparable) filter.value));
                        break;
                    case LT:
                        predicates.add(builder.lessThan(expression, (Comparable) filter.value));
                        break;
                    case GTE:
                        predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value));
                        break;
                    case LTE:
                        predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value));
                        break;
                    }
                }

                // ? and ???
                if (!predicates.isEmpty()) {
                    return builder.and(predicates.toArray(new Predicate[predicates.size()]));
                }
            }

            return builder.conjunction();
        }
    };
}

From source file:com.kegare.friendlymobs.client.config.FriendlyConfigGui.java

private static List<IConfigElement> getConfigElements() {
    List<IConfigElement> list = Lists.newArrayList();

    list.addAll(new ConfigElement(FriendlyMobsAPI.getConfig().getCategory(Configuration.CATEGORY_GENERAL))
            .getChildElements());//from www.  j  av  a2 s  . c o m

    return list;
}