Example usage for java.util LinkedList size

List of usage examples for java.util LinkedList size

Introduction

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

Prototype

int size

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

Click Source Link

Usage

From source file:Main.java

public static int[] parseIntList(String list) {
    if (list == null)
        return null;

    intMatch.reset(list);/*ww w  . j av  a 2s . c om*/

    LinkedList<Integer> intList = new LinkedList<Integer>();
    while (intMatch.find()) {
        String val = intMatch.group();
        intList.add(Integer.valueOf(val));
    }

    int[] retArr = new int[intList.size()];
    Iterator<Integer> it = intList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Integer) it.next()).intValue();
    }

    return retArr;
}

From source file:Main.java

public synchronized static float[] parseFloatList(String list) {
    if (list == null)
        return null;

    fpMatch.reset(list);/* ww  w.j  ava2 s. c om*/

    LinkedList<Float> floatList = new LinkedList<Float>();
    while (fpMatch.find()) {
        String val = fpMatch.group(1);
        floatList.add(Float.valueOf(val));
    }

    float[] retArr = new float[floatList.size()];
    Iterator<Float> it = floatList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Float) it.next()).floatValue();
    }

    return retArr;
}

From source file:Main.java

/**
 * Scans an input string for double values.  For each value found, places
 * in a list.  This method regards any characters not part of a floating
 * point value to be seperators.  Thus this will parse whitespace seperated,
 * comma seperated, and many other separation schemes correctly.
 */// w w w .  j  av a2 s . c om
public synchronized static double[] parseDoubleList(String list) {
    if (list == null)
        return null;

    fpMatch.reset(list);

    LinkedList<Double> doubList = new LinkedList<Double>();
    while (fpMatch.find()) {
        String val = fpMatch.group(1);
        doubList.add(Double.valueOf(val));
    }

    double[] retArr = new double[doubList.size()];
    Iterator<Double> it = doubList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Double) it.next()).doubleValue();
    }

    return retArr;
}

From source file:br.edu.ufcg.supervisor.engine.Simulation.java

public static void executeModel(JSONObject r, Automaton model, HashMap<String, Float> map1,
        HashMap<Integer, Float> map2, String currentState, String recommendation, String logString)
        throws Exception {
    ArrayList<String> names = LoadedModel.getNomesVariaveisMonitoradas();
    ArrayList<String> arrayMensagens = new ArrayList<String>();
    for (int i = 0; i < map1.size(); i++) {
        currentState = currentState + "- " + names.get(i) + ": " + map1.get(names.get(i)) + ".<br>";
    }/*from  w w w. j  a  v  a2  s .  c o  m*/

    logString = logString + currentState + " - ";
    r.put("cur", currentState);

    State estado = model.buscaEstadoCorrespondente(map2);
    if (!(estado.getClassificacao() == State.INT_CL_ACEITACAO)) {
        Search alg = new Search(model);
        alg.execute(estado);
        for (State estadoAceito : model.getArrayEstadosAceitos()) {
            LinkedList<State> caminho = alg.getPath(estadoAceito);
            if (caminho != null) {
                for (int j = 0; j < caminho.size() - 1; j++)
                    recommendation += "." + model.getMensagemDasTransicoesEntreDoisEstadosQuaisquer(
                            caminho.get(j), caminho.get(j + 1));//elthon
                arrayMensagens.add(recommendation);
            }
        }
        recommendation = getShortestPath(arrayMensagens);
        recommendation = eliminateReplicatedRecommendations(recommendation);
        if (recommendation.equals("."))
            recommendation = "Some variable has not been measured!";
        logString = logString + recommendation + "\n";
    } else {
        recommendation = "Keep going!";
        logString = logString + "(" + recommendation + ")\n";
    }
    r.put("rec", recommendation);
}

From source file:fi.smaa.libror.MaximalVectorComputation.java

/**
 * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007.
 * /*from  w  w w .j av  a2  s.  co  m*/
 * Returns indices of the rows from the original matrix.
 * 
 * @param mat The matrix of values (each row = 1 vector of input)
 * 
 * @return Matrix containing rows from the input s.t. none are dominated
 */
public static int[] computeBESTindices(RealMatrix mat) {
    LinkedList<Integer> list = matrixToListOfIndices(mat);
    LinkedList<Integer> results = new LinkedList<Integer>();

    while (list.size() > 0) {
        Iterator<Integer> iter = list.iterator();
        Integer b = iter.next(); // Get the first
        iter.remove();
        while (iter.hasNext()) { // Find a max
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            } else if (dominates(mat.getRowVector(t), mat.getRowVector(b))) {
                iter.remove();
                b = t;
            }
        }
        results.add(b);
        iter = list.iterator();
        while (iter.hasNext()) { // Clean up
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            }
        }
    }

    return listOfIntegersToIntArray(results);
}

From source file:fi.smaa.libror.MaximalVectorComputation.java

/**
 * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007.
 * /*  w w  w . j ava  2  s .c o m*/
 * @param mat The matrix of values (each row = 1 vector of input)
 * 
 * @return Matrix containing rows from the input s.t. none are dominated
 */
public static RealMatrix computeBEST(RealMatrix mat) {
    LinkedList<RealVector> list = matrixToListOfRows(mat);
    LinkedList<RealVector> results = new LinkedList<RealVector>();

    while (list.size() > 0) {
        Iterator<RealVector> iter = list.iterator();
        RealVector b = iter.next(); // Get the first
        iter.remove();
        while (iter.hasNext()) { // Find a max
            RealVector t = iter.next();
            if (dominates(b, t)) {
                iter.remove();
            } else if (dominates(t, b)) {
                iter.remove();
                b = t;
            }
        }
        results.add(b);
        iter = list.iterator();
        while (iter.hasNext()) { // Clean up
            RealVector t = iter.next();
            if (dominates(b, t)) {
                iter.remove();
            }
        }
    }

    return listOfRowsToMatrix(results);
}

From source file:Main.java

public static Element[] getChildrenByName(Element e, String name) {
    NodeList nl = e.getChildNodes();
    int max = nl.getLength();
    LinkedList<Node> list = new LinkedList<Node>();
    for (int i = 0; i < max; i++) {
        Node n = nl.item(i);/*from  w ww . jav  a 2  s .c om*/
        if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
            list.add(n);
        }
    }
    return list.toArray(new Element[list.size()]);
}

From source file:Main.java

public static Element[] getChildrenByName(Element parentElement, String childrenName) {
    NodeList nl = parentElement.getChildNodes();
    int max = nl.getLength();
    LinkedList<Node> list = new LinkedList<Node>();
    for (int i = 0; i < max; i++) {
        Node n = nl.item(i);/*w  w w .j ava  2  s. co m*/
        if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(childrenName)) {
            list.add(n);
        }
    }
    return list.toArray(new Element[list.size()]);
}

From source file:net.portalblock.untamedchat.bungee.UCConfig.java

private static String[] makeCommandArray(JSONArray array, String... defs) {
    if (array == null)
        return defs;
    LinkedList<String> val = new LinkedList<String>();
    for (int i = 0; i < array.length(); i++) {
        val.add(array.getString(i));
    }//from  w w  w .  ja  v  a 2s .co  m
    return val.toArray(new String[val.size()]);
}

From source file:org.samjoey.graphing.GraphUtility.java

public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (int j = 0; j < games.size(); j++) {
        Game game = games.get(j);// w  w  w  .  j ava2  s.  c o  m
        if (game == null) {
            continue;
        }
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }
    HashMap<String, ChartPanel> chartPanels = new HashMap<>();
    for (String key : datasets.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanels.put(key, chartPanel);
    }
    return chartPanels;
}