Example usage for java.util List add

List of usage examples for java.util List add

Introduction

In this page you can find the example usage for java.util List add.

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:ch.devmine.javaparser.Main.java

/**
 * Main function//from ww  w.j a va 2  s.c  o  m
 * @param args
 *      the path of the repository to parse
 */
public static void main(String[] args) {

    // parse one repository
    if (args.length != 1) {
        System.err.println(
                "usage : javaparser <path>\n" + "path : the path to the folder or the tar archive to parse");
        return;
    }

    Project project = new Project();
    Language language = defineJavaLang();
    List<Language> languages = new ArrayList<>();
    languages.add(language);
    project.setLanguages(languages);

    HashMap<String, Package> packs = new HashMap<>();

    if (new File(args[0]).isDirectory()) {
        parseAsDirectory(project, packs, languages, language, args[0]);
    } else {
        parseAsTarArchive(project, packs, languages, language, args[0]);
    }

    List<Package> packages = new ArrayList<>(packs.values());
    int projLoc = 0;
    for (Package pack : packages) {
        int packLoc = 0;
        for (SourceFile file : pack.getSourceFiles()) {
            packLoc += file.getLoc();
        }
        pack.setLoc(packLoc);
        projLoc += packLoc;
    }
    project.setPackages(packages);
    project.setLoc(projLoc);
    Gson gson = GsonFactory.build();
    String jsonProject = gson.toJson(project);

    // the result is written in the system output in order to be
    // used in chain with the source analyzer
    // see https://github.com/devmine/scranlzr
    System.out.println(jsonProject);
}

From source file:drpc.KMeansDrpcQuery.java

public static void main(final String[] args)
        throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;//from   ww w  .  j  a  v  a  2 s.  c  o  m
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 10) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            i++;

            Double[] features = map.get("chi2").toArray(new Double[0]);
            Double[] moreFeatures = map.get("chi1").toArray(new Double[0]);
            Double[] rmsd = map.get("rmsd").toArray(new Double[0]);
            Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));

            String centroidsSerialized = runQuery(args[1], parameters, client);

            Gson gson = new Gson();
            Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class);

            for (Object obj : deserialized) {
                // result we get is of the form List<result>
                List l = ((List) obj);
                centroidsSerialized = (String) l.get(0);

                String[] centroidSerializedArrays = centroidsSerialized
                        .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM);
                List<double[]> centroids = new ArrayList<double[]>();
                for (String centroid : centroidSerializedArrays) {
                    centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid));
                }

                double[] rmsdPrimitive = ArrayUtils.toPrimitive(both);
                double[] rmsdKmeans = new double[centroids.size()];

                for (int k = 0; k < centroids.size(); k++) {
                    System.out.println("centroid        -- " + Arrays.toString(centroids.get(k)));
                    double[] centroid = centroids.get(k);
                    rmsdKmeans[k] = computeRootMeanSquare(centroid);
                }

                System.out.println("1 rmsd original -- " + Arrays.toString(rmsd));
                System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans));
                System.out.println();
            }

        }
    }
    client.close();
}

From source file:com.samtech.piv.ChinaNameTool.java

public static void main(String[] args) {
    ChinaNameTool tool = ChinaNameTool.getInstance();
    System.out.println(tool.containSurName(""));
    List ls = new ArrayList();
    ls.add("1  12344  11111");
    ls.add("2vds");
    ls.add("3vds");
    ls.add("41111");
    ls.add("5sdfs");
    ls.add("6-");
    ls.add("7,");
    ls.add("8*");
    ls.add("9");/*from  w w  w  .  jav a  2s .  com*/
    ls.add("10!");

    ls.add("test");
    ls.add("");
    ls.add("??");
    ls.add("??");
    ls.add("????123456789");
    ls.add("????123456789");
    ls.add("YZ??,7842423921250");
    ls.add("????7842423461567??");
    ls.add("YZ?");
    ls.add("YZC0906090012009");

    for (int i = 0; i < ls.size(); i++) {
        String input = (String) ls.get(i);
        System.out.println(input + "=====" + tool.findChinaName(input));
    }
    System.out.println("*************************");
    for (int i = 0; i < ls.size(); i++) {
        String input = (String) ls.get(i);
        String[] names = tool.findChinaNames(input);
        if (names != null && names.length > 0) {
            String r = input + "=====";
            for (int j = 0; j < names.length; j++) {
                r = r + "," + names[j];
            }
            System.out.println(r);
        } else {
            System.out.println(input + "=====null");
        }

    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final List<String> list = new ArrayList<String>();
    ParserDelegator parserDelegator = new ParserDelegator();
    ParserCallback parserCallback = new ParserCallback() {
        public void handleText(final char[] data, final int pos) {
            list.add(new String(data));
        }// w  w  w  .  j a v  a2  s  .c  o m

        public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) {
        }

        public void handleEndTag(Tag t, final int pos) {
        }

        public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) {
        }

        public void handleComment(final char[] data, final int pos) {
        }

        public void handleError(final java.lang.String errMsg, final int pos) {
        }
    };
    parserDelegator.parse(new FileReader("a.html"), parserCallback, true);
    System.out.println(list);
}

From source file:br.com.asisprojetos.mailreport.Main.java

public static void main(String args[]) {

    logger.debug("Testando debug");

    if (args.length < 2) {
        logger.error("Erro : Numero de parametros errados.");
        System.exit(1);//from   w  w  w  . j  av a2 s  .co m
    }

    String dataIniProc = String.format("%s 00:00:00", args[0]);
    String dataFimProc = String.format("%s 23:59:59", args[1]);

    logger.debug("Data Inicial: {} , Data Final: {}", dataIniProc, dataFimProc);

    String mes = String.format("%s/%s", args[0].substring(5, 7), args[0].substring(0, 4));

    ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Datasource.xml");

    TBRelatorioEmailDAO tbRelatorioEmailDAO = (TBRelatorioEmailDAO) context.getBean("TBRelatorioEmailDAO");

    List<TBRelatorioEmail> listaRelatorioEmail = tbRelatorioEmailDAO.getAll();

    for (TBRelatorioEmail tbRelatorioEmail : listaRelatorioEmail) {

        logger.debug(" CodContrato: {}, CodProduto: {}", tbRelatorioEmail.getCodContrato(),
                tbRelatorioEmail.getCodProduto());

        List<String> listaEmails = tbRelatorioEmailDAO.getListaEmails(tbRelatorioEmail.getCodContrato());

        if (!listaEmails.isEmpty()) {

            logger.debug("Lista de Emails obtida : [{}] ", listaEmails);

            //List<String> listaCodProduto = Arrays.asList( StringUtils.split(tbRelatorioEmail.getCodProduto(), ';') ) ;
            List<String> listaCodProduto = new ArrayList<String>();
            listaCodProduto.add("1");//Sped Fiscal

            logger.debug("Gerando Relatorio Geral de Consumo por Produto...");

            List<String> fileNames = new ArrayList<String>();
            String fileName;

            BarChartDemo barChartDemo = (BarChartDemo) context.getBean("BarChartDemo");
            //fileName = barChartDemo.generateBarChartGraph(tbRelatorioEmail.getCodContrato());
            //fileNames.add(fileName);
            fileNames = barChartDemo.generateBarChartGraph2(tbRelatorioEmail.getCodContrato());

            String templateFile = null;

            for (String codProduto : listaCodProduto) {

                if (codProduto.equals(Produto.SPED_FISCAL.getCodProduto())) {

                    logger.debug("Produto Codigo : {} ", codProduto);
                    templateFile = "index6.html";

                    //grafico de diagnostico
                    fileName = barChartDemo.generateDiagnosticGraph(tbRelatorioEmail.getCodContrato(),
                            dataIniProc, dataFimProc);
                    fileNames.add(fileName);

                    //grafico de auditoria recorrente
                    fileName = barChartDemo.generateRecurrentGraph(tbRelatorioEmail.getCodContrato(),
                            dataIniProc, dataFimProc);
                    fileNames.add(fileName);

                } else {
                    logger.debug("Produto Codigo : {} no aceito para gerar grafico ", codProduto);
                }

                logger.debug("Enviando Email.............Produto Codigo : {}", codProduto);

                SendEmail sendEmail = (SendEmail) context.getBean("SendEmail");
                sendEmail.enviar(listaEmails.toArray(new String[listaEmails.size()]),
                        "Relatrio Mensal de Riscos Fiscais", templateFile, fileNames, mes,
                        tbRelatorioEmail.getCodContrato());

                //sendEmail.enviar( new String[]{"leandro.prates@asisprojetos.com.br","leandro.prates@gmail.com"}  , 
                //        "Relatrio Mensal de Riscos Fiscais", templateFile, fileNames, mes, tbRelatorioEmail.getCodContrato() );

            }

            //Remover todos os arquivos png gerado para o cliente

            Config config = (Config) context.getBean("Config");

            for (String f : fileNames) {

                try {
                    File file = new File(String.format("%s/%s", config.getOutDirectory(), f));
                    if (file.delete()) {
                        logger.debug("Arquivo: [{}/{}] deletado com sucesso.", config.getOutDirectory(), f);
                    } else {
                        logger.error("Erro ao deletar o arquivo: [{}/{}]", config.getOutDirectory(), f);
                    }

                } catch (Exception ex) {
                    logger.error("Erro ao deletar o arquivo: [{}/{}] . Message {}", config.getOutDirectory(), f,
                            ex);
                }

            }

        }

    }

}

From source file:edu.cwru.jpdg.JPDG.java

public static void main(String[] argv) throws pDG_Builder.Error {
    final Option helpOpt = new Option("h", "help", false, "print this message");
    final Option outputOpt = new Option("o", "output", true, "output file location");
    final Option baseOpt = new Option("b", "base-dir", true, "base directory to analyze");
    final Option excludeOpt = new Option("e", "exclude", true, "exclude these directories");
    final Option classOpt = new Option("c", "classpath", true, "classpath for soot");
    final Option labelOpt = new Option("l", "label-type", true,
            "label type, valid choices are: expr-tree, inst");
    final org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();

    options.addOption(helpOpt);//  w w  w.  j  av  a  2 s  .  c o m
    options.addOption(outputOpt);
    options.addOption(baseOpt);
    options.addOption(classOpt);
    options.addOption(labelOpt);
    options.addOption(excludeOpt);

    String cp = null;
    String base_dir = null;
    String label_type = "expr-tree";
    String output_file = null;
    List<String> excluded = new ArrayList<String>();

    try {
        GnuParser parser = new GnuParser();
        CommandLine line = parser.parse(options, argv);

        if (line.hasOption(helpOpt.getLongOpt())) {
            Usage(options);
        }

        cp = line.getOptionValue(classOpt.getLongOpt());
        base_dir = line.getOptionValue(baseOpt.getLongOpt());
        label_type = line.getOptionValue(labelOpt.getLongOpt());
        output_file = line.getOptionValue(outputOpt.getLongOpt());
        String[] ex = line.getOptionValues(excludeOpt.getLongOpt());
        if (ex != null) {
            excluded = Arrays.asList(ex);
        }
    } catch (final MissingOptionException e) {
        System.err.println(e.getMessage());
        Usage(options);
    } catch (final UnrecognizedOptionException e) {
        System.err.println(e.getMessage());
        Usage(options);
    } catch (final ParseException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    List<String> dirs = new ArrayList<String>();
    dirs.add(base_dir);

    soot.Scene S = runSoot(cp, dirs, excluded);
    writeGraph(build_PDG(S, excluded, label_type), output_file);
}

From source file:com.http.my.ClientFormLogin.java

public static void main(String[] args) throws Exception {

    ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

        public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
            int status = response.getStatusLine().getStatusCode();
            System.out.println(response.getStatusLine());
            if (status >= 200 && status < 303) {
                HttpEntity entity = response.getEntity();

                return entity != null ? EntityUtils.toString(entity) : null;
            } else {
                throw new ClientProtocolException("Unexpected response status: " + status);
            }/*from  w ww . j  a  va2  s.  c  om*/
        }

    };

    BasicCookieStore cookieStore = new BasicCookieStore();
    //        
    //        BasicClientCookie cookieJSESSIONID = new BasicClientCookie("JSESSIONID", "3FD927DC6911B719E4492E7473897FBA");
    //        cookieJSESSIONID.setVersion(0);
    //        cookieJSESSIONID.setDomain("218.75.79.230");
    //        cookieJSESSIONID.setPath("/");
    //        System.out.println("Initial set of cookies:");
    //        cookieStore.addCookie(cookieJSESSIONID);

    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    // HttpProtocolParams.setUserAgent(httpclient.getParams(), "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");

    try {

        // HttpPost httpost = new HttpPost("http://localhost:8081/cring/jsp/user/userLogin.do?method=login");
        HttpPost loginpost = new HttpPost("http://134.96.41.47/ecommunications_chs/start.swe");
        //HttpGet loginGet = new HttpGet("http://134.96.41.47/ecommunications_chs/start.swe");
        // HttpGet loginGet = new HttpGet("http://www.baidu.com");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("SWEUserName", "nili"));
        nvps.add(new BasicNameValuePair("SWEPassword", "nili7788"));
        nvps.add(new BasicNameValuePair("SWEFo", "SWEEntryForm"));
        nvps.add(new BasicNameValuePair("SWENeedContext", "false"));
        nvps.add(new BasicNameValuePair("SWECmd", "ExecuteLogin"));
        nvps.add(new BasicNameValuePair("W", "t"));
        nvps.add(new BasicNameValuePair("SWEC", "0"));
        nvps.add(new BasicNameValuePair("SWEBID", "-1"));
        nvps.add(new BasicNameValuePair("SWETS", "1385712482625"));

        /**
         *  SWEUserName:111111
        SWEPassword:222222
        SWEFo:SWEEntryForm
        SWENeedContext:false
        SWECmd:ExecuteLogin
        W:t
        SWESPNR:
        SWESPNH:
        SWEH:
        SWEC:0
        SWEW:
        SWEBID:-1
        SWETS:1385712482625
        SWEWN:
         */
        loginpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
        //            CloseableHttpResponse response =  httpclient.execute(loginpost);
        // HttpEntity httpEntity =  response.getEntity();
        CloseableHttpResponse responseGet = httpclient.execute(loginpost);
        HttpEntity httpEntityGet = responseGet.getEntity();
        System.out.println("statusLine: " + responseGet.getStatusLine());
        System.out.println("ContentType: " + httpEntityGet.getContentType());
        System.out.println("ContentLength: " + httpEntityGet.getContentLength());

        //  httpEntityGet.get
        System.out.println("loginGet: " + EntityUtils.toString(httpEntityGet));
        /* try {
                
        System.out.println("Post logon cookies:");
        List<Cookie> cookies = cookieStore.getCookies();
        if (cookies.isEmpty()) {
            System.out.println("None");
        } else {
            for (int i = 0; i < cookies.size(); i++) {
                System.out.println("- " + cookies.get(i).toString());
            }
        }
                
                
                
        HttpPost modifypost = new HttpPost("http://localhost:8081/cring/jsp/user/corpUserController.do?method=modifyPwd");
        List <NameValuePair> modifynvps = new ArrayList <NameValuePair>();
        modifynvps.add(new BasicNameValuePair("newPwd","111111"));
        modifypost.setEntity(new UrlEncodedFormEntity(modifynvps, Consts.UTF_8));
                    
        CloseableHttpResponse modifyresponse = httpclient.execute(modifypost);
            System.out.println("modifyresponse : "+modifyresponse.getStatusLine()); 
                
                
                
         } finally {
        //response2.close();
         }*/
    } finally {
        httpclient.close();
    }
}

From source file:com.cyclopsgroup.waterview.jelly.JellyRunner.java

/**
 * Main entry to run a script/*  w w  w  . j  a  va 2  s  . c o m*/
 * 
 * @param args Script paths
 * @throws Exception Throw it out
 */
public static final void main(String[] args) throws Exception {
    List scripts = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        String path = args[i];
        File file = new File(path);
        if (file.isFile()) {
            scripts.add(file.toURL());
        } else {
            Enumeration enu = JellyRunner.class.getClassLoader().getResources(path);
            CollectionUtils.addAll(scripts, enu);
        }
    }
    if (scripts.isEmpty()) {
        System.out.println("No script to run, return!");
        return;
    }

    String basedir = new File("").getAbsolutePath();
    Properties initProperties = new Properties(System.getProperties());
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);

    WaterviewPlexusContainer container = new WaterviewPlexusContainer();
    for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
        String initPropertyName = (String) j.next();
        container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
    }

    container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
    container.initialize();
    container.start();

    JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE);
    JellyContext jc = new JellyContext(je.getGlobalContext());

    for (Iterator i = scripts.iterator(); i.hasNext();) {
        URL script = (URL) i.next();
        System.out.print("Running script " + script);
        jc.runScript(script, XMLOutput.createDummyXMLOutput());
        System.out.println("... Done!");
    }
    container.dispose();
}

From source file:edu.asu.ca.kaushik.algorithms.randomized.lll.TwoStageSimpleMT.java

public static void main(String[] args) throws IOException {

    int t = 0, k1 = 0, k2 = 0, v = 0;

    if (args.length == 4) {
        t = Integer.parseInt(args[0]);
        v = Integer.parseInt(args[1]);
        k1 = Integer.parseInt(args[2]);
        k2 = Integer.parseInt(args[3]);
    } else {/*from w w  w.j av a  2 s  . co  m*/
        System.err.println("Need four arguments- t, v, kStart and kEnd");
        System.exit(1);
    }

    List<CAGenAlgo> algoList = new ArrayList<CAGenAlgo>();

    algoList.add(new TwoStageSimpleMT());

    OutputFormatter formatter = new TableOutputFormatter("data\\out\\tables\\two-stage", "two-stage-simple");

    Runner runner = new Runner(formatter);
    runner.setParam(t, v, k1, k2);
    runner.setAlgos(algoList);
    runner.run();

    /*CAWriter writer = new StandardCAWriter();
    CAGeneration c = new CAGeneration();
            
    int t = 6;
    int k = 54;
    int v = 3;
            
    //int N = 12123;
            
            
    if (args.length == 4) {
       t = Integer.parseInt(args[0]);
       k = Integer.parseInt(args[1]);
       v = Integer.parseInt(args[2]);
       N = Integer.parseInt(args[3]);
    } else {
       System.err.println("Need three arguments- t, k, v and N");
       System.exit(1);
    }
            
            
    System.out.println("TwoStageSimple");
            
    System.out.println(new Date());
    c.setCAGenAlgo(new TwoStageSimple());
    CA ca = c.generateCA(t, k, v);
    System.out.println(new Date());
            
    writer.writeCA(ca, "data\\out\\lll\\6-k-3\\" + t + "-" + k + "-" + v + "-LLLExtension.txt");
            
    System.out.println("TwoStageSimple Done");*/
}

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.Main.java

/**
 * @param args/*from  ww w.j  a v a 2 s . c  o  m*/
 */
public static void main(final String[] args) {
    System.out.println(args.toString());
    final String batch_name = args[0];
    final String[] instance_args = args[1].split(",");
    final String[] pi_args = args[2].split(",");
    final String[] phi_args = args[3].split(",");

    final File root_directory = createDirectory(args);
    final int Nplanets = Integer.parseInt(instance_args[0]);
    final int policy_epoch = Integer.parseInt(instance_args[1]);
    final int Nworlds = Integer.parseInt(instance_args[2]);
    final int max_time = Integer.parseInt(instance_args[3]);
    final int Nanytime = Integer.parseInt(instance_args[4]);

    // FIXME: This default_params thing is too error-prone! There's no
    // easy way to know whether you need to set a parameter in
    // 1) default_params
    // 2) an element of ps
    // 3) both places
    final VoyagerParameters default_params = new VoyagerParameters.Builder().Nplanets(Nplanets)
            .policy_epoch(policy_epoch).finish();
    final Environment default_environment = new Environment.Builder().root_directory(root_directory)
            .rng(new MersenneTwister(default_params.master_seed)).finish();

    final int[] anytime_times = new int[Nanytime];
    anytime_times[Nanytime - 1] = max_time;
    for (int i = Nanytime - 2; i >= 0; --i) {
        anytime_times[i] = anytime_times[i + 1] / 2;
    }

    final List<VoyagerParameters> ps = new ArrayList<VoyagerParameters>(Nanytime);
    for (final int t : anytime_times) {
        ps.add(new VoyagerParameters.Builder().max_time(t).Nplanets(Nplanets).policy_epoch(policy_epoch)
                .finish());
    }

    final List<VoyagerInstance> ws = new ArrayList<VoyagerInstance>(Nworlds);
    for (int i = 0; i < Nworlds; ++i) {
        // FIXME: Why default_params and not ps.get( i ) ?
        ws.add(new VoyagerInstance(default_params, default_environment.rng.nextInt()));
    }

    final MultipleInstanceMultipleWorldGenerator<VoyagerParameters, VoyagerInstance> experimental_setups = new MultipleInstanceMultipleWorldGenerator<VoyagerParameters, VoyagerInstance>(
            default_environment, ps, ws);

    final ArrayList<EpisodeListener<VoyagerState, VoyagerEvent>> extra_listeners = new ArrayList<EpisodeListener<VoyagerState, VoyagerEvent>>();

    if (default_params.use_monitor) {
        // TODO: Actually create the viewport!
        extra_listeners.add(new VisualizationUpdater());
    }

    final Experiment<VoyagerParameters, VoyagerInstance> experiment = new PolicyComparison<VoyagerState, VoyagerEvent, VoyagerParameters, VoyagerInstance>(
            createPolicy(pi_args), createPolicy(phi_args), extra_listeners);

    while (experimental_setups.hasNext()) {
        final ExperimentalSetup<VoyagerParameters, VoyagerInstance> setup = experimental_setups.next();
        experiment.setup(setup.environment, setup.parameters, setup.world);
        experiment.run();
        experiment.finish();
    }

    System.exit(0);
}