Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

In this page you can find the example usage for java.util ArrayList size.

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:edu.lternet.pasta.datapackagemanager.ProvenanceBackfiller.java

/**
 * Main program to backfill the provenance table. 
 * It takes no command arguments. //from ww  w  . j a va2  s .  c o  m
 * Should be run in the DataPackageManager top-level directory.
 * 
 * @param args   Any arguments passed to the program are ignored.
 */
public static void main(String[] args) {
    int backfillCount = 0;
    int derivedDataPackageCount = 0;
    int recordsInserted = 0;
    final boolean evaluateMode = false;

    try {
        ConfigurationListener configurationListener = new ConfigurationListener();
        configurationListener.initialize(dirPath);
        DataPackageRegistry dpr = DataPackageManager.makeDataPackageRegistry();
        ProvenanceIndex provenanceIndex = new ProvenanceIndex(dpr);
        EmlPackageIdFormat epif = new EmlPackageIdFormat();

        List<EmlPackageId> emlPackageIds = getAllDataPackageRevisions(dpr);

        for (EmlPackageId emlPackageId : emlPackageIds) {
            DataPackageMetadata dataPackageMetadata = new DataPackageMetadata(emlPackageId);
            if (dataPackageMetadata != null) {
                File levelOneEMLFile = dataPackageMetadata.getMetadata(evaluateMode);
                String emlDocument = FileUtils.readFileToString(levelOneEMLFile);
                String packageId = epif.format(emlPackageId);
                System.err.println("  " + packageId);

                try {
                    ArrayList<String> sourceIds = provenanceIndex.insertProvenanceRecords(packageId,
                            emlDocument);
                    if ((sourceIds != null) && (sourceIds.size() > 0)) {
                        derivedDataPackageCount++;
                        recordsInserted += sourceIds.size();
                    }
                } catch (ProvenanceException e) {
                    logger.error(e.getMessage());
                }

                backfillCount++;
            }
        }
    } catch (Exception e) {
        logger.error(
                String.format("An error occurred during provenance backfill processing: %s", e.getMessage()));
        e.printStackTrace();
    }

    System.err.println(String.format(
            "Finished provenance backfill processing. Provenance generated and stored for %d resource(s).",
            backfillCount));
    System.err.println(
            String.format("Total number of derived data packages detected: %d.", derivedDataPackageCount));
    System.err.println(String.format("Total records inserted into provenance table: %d.", recordsInserted));
}

From source file:MainClass.java

public static void main(String[] args) {
    ArrayList list = new ArrayList();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i));
    }/*from  w w w  .  ja  v  a  2 s. c  o m*/
}

From source file:dk.dma.nogoservice.Application.java

public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
    ArrayList<String> profiles = Lists.newArrayList(ApiProfiles.PRODUCTION, ApiProfiles.SECURITY);
    if (Boolean.getBoolean("disableSecurity")) {
        profiles.remove(ApiProfiles.SECURITY);
    }/*  w w  w  .  ja  va 2 s . com*/
    builder.profiles(profiles.toArray(new String[profiles.size()])).headless(false).run(args);
}

From source file:eurecom.constrained.devices.ReadZipFile.java

public static void main(String[] args) {
    ZipFile zipfile;//from w ww .  j a v  a  2  s  . com
    String sensor_data = ReadFile.readContentFile(SENSOR_DATA_FILE);
    ConvertRaspberrySensorData converter = new ConvertRaspberrySensorData();
    Model model;
    try {
        model = converter.convertRaspberrySensorDataToRDF(sensor_data, M3_RULES_PATH);

        M2MAppGeneric m2mappli = new M2MAppGeneric(model);

        //LOAD ONTOLOGIES AND DATASETS
        //ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, "./WAR/M3IoTApplicationTemplate/transport");
        //   ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, "./WAR/M3IoTApplicationTemplate/weather");
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                "./WAR/M3IoTApplicationTemplate/transport-dataset");
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                "./WAR/M3IoTApplicationTemplate/weather-dataset");

        //EXECUTE SPARQL QUERY

        Model inf = m2mappli.reasonWithJenaRules("./WAR/M3IoTApplicationTemplate/LinkedOpenRules.txt");
        ExecuteSparqlGeneric reqSenml = new ExecuteSparqlGeneric(inf,
                "./WAR/M3IoTApplicationTemplate/weatherTransportSafetyDevice.sparql");

        ArrayList<ResultSensorDataReasoning> resultAfterReasoning = reqSenml.getSelectResultAnsParseIt(null);

        for (int i = 0; i < resultAfterReasoning.size(); i++) {
            System.out.println(resultAfterReasoning.get(i).toString());
        }

        //EXECUTE RULES

        //try {
        /*   zipfile = new ZipFile(ZIP_FILE_IOT_APPLI);
           File file = new File("./WAR/M3IoTApplicationTemplate");
           unzip(zipfile, file);*/

        for (int i = 0; i < FILE_TO_LOAD.size(); i++) {
            System.out.println(FILE_TO_LOAD.get(i));

            //if extension is sparql then execute sparql
            if (FILE_TO_LOAD.get(i).contains(".sparql")) {

            }

            // if extension is .txt then execute rules
            if (FILE_TO_LOAD.get(i).contains(".txt")) {

            }

            //otherwise load ontology and dataset
            else {
                ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                        "./WAR/M3IoTApplicationTemplate/transport-dataset");
                // + "\\" +FILE_TO_LOAD.get(i)
                m2mappli.model.write(System.out);
            }

        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    /*} catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

}

From source file:com.au.splashinc.JControl.MainCLI.java

public static void main(String[] args) throws AWTException, InterruptedException {
    MyControllers myControllers = new MyControllers();
    ArrayList<Controller> controllers = myControllers.GetControllers();
    myControllers = new MyControllers(true);
    ArrayList<Controller> controllers2 = myControllers.GetControllers();

    System.out.println("Let's do this");
    System.out.println("Length without all USB: " + controllers.size());
    System.out.println("Length with all USB: " + controllers2.size());
    AControllerLoader mjs = new DarkForcesJsonLoader("This is a test");
    mjs.LoadConfig();/*  www . j a v  a 2  s  . com*/
    //JSONObject obj = new JSONObject();
    //obj.put("Hello", "World");
    //System.out.println("JSON String: " + obj.toJSONString());
    if (controllers.size() > 0) {
        try {
            MyController controller = new MyController(controllers.get(0));
            AControllerAction buttonAction = new SimpleControllerAction(controller, mjs);
            while (true) {
                buttonAction.Execute();
                Thread.sleep(20);
            }
        } catch (AWTException ex) {
            System.out.println(ex.toString());
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> list = new ArrayList<>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");
    list.add("E");
    list.add("F");
    list.add("G");
    list.add("H");

    System.out.println(list);/*from   w w w .  j a  va2s  .  c o m*/

    while (!list.isEmpty()) {
        long index = Math.round(Math.floor(Math.random() * list.size()));
        System.out.println("Name " + list.get((int) index));
        list.remove((int) index);
    }

}

From source file:gamlss.algorithm.Gamlss.java

/**
 * Main method./*  w  w w. j  av  a  2 s  .  co m*/
 * @param args -  command-line arguments
 */
public static void main(final String[] args) {

    //String fileName = "Data/dataReduced.csv";
    String fileName = "Data/oil.csv";
    // String fileName = "Data/sp.csv";
    //String fileName = "Data/dataReduced.csv";
    CSVFileReader readData = new CSVFileReader(fileName);
    readData.readFile();
    ArrayList<String> data = readData.storeValues;

    ArrayRealVector y = new ArrayRealVector(data.size());
    BlockRealMatrix muX = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix sigmaX = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix nuX = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix tauX = new BlockRealMatrix(data.size(), 1);
    ArrayRealVector w = new ArrayRealVector(data.size());

    BlockRealMatrix muS = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix sigmaS = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix nuS = new BlockRealMatrix(data.size(), 1);
    BlockRealMatrix tauS = new BlockRealMatrix(data.size(), 1);

    for (int i = 0; i < data.size(); i++) {
        String[] line = data.get(i).split(",");
        y.setEntry(i, Double.parseDouble(line[0]));
        muX.setEntry(i, 0, Double.parseDouble(line[1]));
        muS.setEntry(i, 0, Double.parseDouble(line[1]));
        sigmaX.setEntry(i, 0, Double.parseDouble(line[1]));
        sigmaS.setEntry(i, 0, Double.parseDouble(line[1]));
        nuX.setEntry(i, 0, Double.parseDouble(line[1]));
        nuS.setEntry(i, 0, Double.parseDouble(line[1]));
        tauX.setEntry(i, 0, Double.parseDouble(line[1]));
        tauS.setEntry(i, 0, Double.parseDouble(line[1]));
    }

    Hashtable<Integer, BlockRealMatrix> designMatrices = new Hashtable<Integer, BlockRealMatrix>();
    designMatrices.put(DistributionSettings.MU, muX);
    designMatrices.put(DistributionSettings.SIGMA, sigmaX);
    designMatrices.put(DistributionSettings.NU, nuX);
    designMatrices.put(DistributionSettings.TAU, tauX);

    HashMap<Integer, BlockRealMatrix> smoothMatrices = new HashMap<Integer, BlockRealMatrix>();
    smoothMatrices.put(DistributionSettings.MU, muS);
    smoothMatrices.put(DistributionSettings.SIGMA, sigmaS);
    smoothMatrices.put(DistributionSettings.NU, nuS);
    smoothMatrices.put(DistributionSettings.TAU, tauS);

    //smoothMatrices.put(DistributionSettings.MU, null);
    //smoothMatrices.put(DistributionSettings.SIGMA, null);
    //smoothMatrices.put(DistributionSettings.NU, null);
    //smoothMatrices.put(DistributionSettings.TAU, null);

    DistributionSettings.DISTR = DistributionSettings.SST;
    Controls.GLOB_DEVIANCE_TOL = 5500;
    Controls.INTER = 50;//only for the PB smoother
    Controls.SMOOTHER = Controls.PB; //or PB
    Controls.IS_SVD = true;
    Controls.BIG_DATA = true;
    Controls.JAVA_OPTIMIZATION = false;
    Controls.GAMLSS_NUM_CYCLES = 50;
    //Gamlss gamlss = new Gamlss(y, designMatrices, null);
    Gamlss gamlss = new Gamlss(y, designMatrices, null);
    //Gamlss gamlss = new Gamlss(y, null, smoothMatrices);      
    gamlss.saveFittedDistributionParameters("Data/oilresults.csv");
}

From source file:at.tuwien.ifs.somtoolbox.doc.RunnablesReferenceCreator.java

public static void main(String[] args) {
    ArrayList<Class<? extends SOMToolboxApp>> runnables = SubClassFinder.findSubclassesOf(SOMToolboxApp.class,
            true);/*from w w w  .  ja  v a  2 s  . co  m*/
    Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR);

    StringBuilder sbIndex = new StringBuilder(runnables.size() * 50);
    StringBuilder sbDetails = new StringBuilder(runnables.size() * 200);

    sbIndex.append("\n<table border=\"0\">\n");

    Type lastType = null;

    for (Class<? extends SOMToolboxApp> c : runnables) {
        try {
            // Ignore abstract classes and interfaces
            if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) {
                continue;
            }

            Type type = Type.getType(c);
            if (type != lastType) {
                sbIndex.append("  <tr> <td colspan=\"2\"> <h5> " + type + " Applications </h5> </td> </tr>\n");
                sbDetails.append("<h2> " + type + " Applications </h2>\n");
                lastType = type;
            }
            String descr = "N/A";
            try {
                descr = (String) c.getDeclaredField("DESCRIPTION").get(null);
            } catch (Exception e) {
            }
            String longDescr = "descr";
            try {
                longDescr = (String) c.getDeclaredField("LONG_DESCRIPTION").get(null);
            } catch (Exception e) {
            }

            sbIndex.append("  <tr>\n");
            sbIndex.append("    <td> <a href=\"#").append(c.getSimpleName()).append("\">")
                    .append(c.getSimpleName()).append("</a> </td>\n");
            sbIndex.append("    <td> ").append(descr).append(" </td>\n");
            sbIndex.append("  </tr>\n");

            sbDetails.append("<h3 id=\"").append(c.getSimpleName()).append("\">").append(c.getSimpleName())
                    .append("</h3>\n");
            sbDetails.append("<p>").append(longDescr).append("</p>\n");

            try {
                Parameter[] options = (Parameter[]) c.getField("OPTIONS").get(null);
                JSAP jsap = AbstractOptionFactory.registerOptions(options);
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                PrintStream ps = new PrintStream(os);
                AbstractOptionFactory.printHelp(jsap, c.getName(), ps);
                sbDetails.append("<pre>").append(StringEscapeUtils.escapeHtml(os.toString())).append("</pre>");
            } catch (Exception e1) { // we didn't find the options => let the class be invoked ...
            }

        } catch (SecurityException e) {
            // Should not happen - no Security
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    sbIndex.append("</table>\n\n");
    System.out.println(sbIndex);
    System.out.println(sbDetails);
}

From source file:cooccurrence.emf.java

public static void main(String args[]) {
    String path = "";
    String writePath = "";
    BufferedReader br = null;//  ww w.  ja va  2  s .c  om
    ArrayList<String> files = new ArrayList<>();
    listFilesForFolder(new File(path), files);
    for (String filePath : files) {
        System.out.println(filePath);
        String fileName = new File(filePath).getName();

        //data structure to store the PPMI matrix in the file
        HashMap<String, HashMap<String, Double>> cooccur = new HashMap<>();
        readFileContents(filePath, cooccur); //reading the file and storing the content in the hashmap
        //Because Matrices are identified by row and col id, the following 
        //lists maps id to corresponding string. Note that matrix is symmetric. 
        ArrayList<String> rowStrings = new ArrayList<>(cooccur.keySet());
        ArrayList<String> colStrings = new ArrayList<>(cooccur.keySet());

        //creating matrix with given dimensions and initializing it to 0
        RealMatrix matrixR = MatrixUtils.createRealMatrix(rowStrings.size(), colStrings.size());
        //populating the matrices based on the co-occur hashmap
        populateMatrixR(matrixR, cooccur, rowStrings, colStrings);

    }
}

From source file:HannonHillSecret.HannonHillSecret.java

/**
 * @param args the command line arguments
 *//*from  w ww . jav  a  2 s.com*/
public static void main(String[] args) {
    // This is a placeholder for the provided value of N
    final int N = 55;
    int currentNum = 0;
    int x = 0;
    int sizePrimes;
    boolean isAdditive = true;
    ArrayList<Integer> primeNumbers = new ArrayList<>();

    currentNum = Primes.nextPrime(currentNum);

    //Add all prime numbers less than or equal to N
    while (currentNum <= N) {
        primeNumbers.add(currentNum);
        currentNum = Primes.nextPrime(currentNum++);
    }

    sizePrimes = primeNumbers.size();

    // If there are only two prime numbers in the arraylist, it means it is empty or there
    // is only one.
    if (sizePrimes < 2) {
        System.out.println("Cannot test if Secret is additive since there "
                + "are not two or more prime numbers less than N!");
    } else // Testing for additive property is possible
    {
        outerloop:
        // Assuming the additive test only requires pair combinations, go through
        // all possible pairs until all pass or one fails
        while (x < sizePrimes && isAdditive) {
            for (int y = x + 1; y <= sizePrimes; y++) {
                isAdditive = isSecretAdditive(primeNumbers.get(x), primeNumbers.get(x));

                //Failed additive test for a combination of prime numbers,
                // so break the while loop and return false
                if (!isAdditive) {
                    break outerloop;
                }
            }
            x++;
        }

        if (isAdditive) {
            System.out.println("Secret is additive!");
        } else {
            System.out.println("Secret is NOT additive!");
        }
    }
}