Example usage for java.util ArrayList get

List of usage examples for java.util ArrayList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.yalin.fidoclient.op.ASMMessageHandler.java

public static boolean checkFacetId(String facetId, ArrayList<FacetIdList> facetIdList) {
    if (facetIdList != null && facetIdList.size() > 0) {
        FacetIdList facetIdList1 = facetIdList.get(0);
        if (facetIdList1.ids != null) {
            for (String id : facetIdList1.ids) {
                if (id.equals(facetId)) {
                    return true;
                }/* w  w w. ja  v a 2s  .  c om*/
            }
        }
    }
    return false;
}

From source file:Main.java

public static void getTop(ArrayList<Double> array, ArrayList<Integer> rankList, int i) {
    int index = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    Double max = Double.MIN_VALUE;
    for (int m = 0; m < i && m < array.size(); m++) {
        max = Double.MIN_VALUE;// w ww .  jav  a 2  s.  c  o m
        for (int no = 0; no < array.size(); no++) {
            if (!scanned.contains(no)) {
                if (array.get(no) > max) {
                    index = no;
                    max = array.get(no);
                } else if (array.get(no).equals(max) && Math.random() > 0.5) {
                    index = no;
                    max = array.get(no);
                }
            }
        }
        if (!scanned.contains(index)) {
            scanned.add(index);
            rankList.add(index);
        }
        //System.out.println(m + "\t" + index);
    }
}

From source file:Main.java

/**
 * Maps a coorindate in a descendant view into the parent.
 *///from ww  w  . j a va2s .co m
public static float mapCoordInDescendentToSelf(View descendant, View root, float[] coord,
        boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }

        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:problematica.Graficos.java

/**
 * /*from w  w w  .ja v a  2  s. c  o m*/
 * @param cantCigarros
 */

public static void createGrafico(ArrayList<ArrayList<String>> datos, String nombreArchivo) {

    XYSeries series = new XYSeries("Linea de consumo");
    //como su nombre lo indica el primer valor sera asignado al eje X
    //y el segundo al eje Y

    series.add(0, 0);

    for (int i = 0; i < datos.size(); i++) {

        series.add((i + 1), Integer.parseInt(datos.get(i).get(0)));

    }

    //se crea un objeto XYDataset requerido mas adelante por el metodo que grafica
    XYDataset juegoDatos = new XYSeriesCollection(series);

    /*aqui se hace la instancia de la nueva grafica invocando al metodo de ChartFactory
    que nos dibujara una grafica de lineas este metodo como casi todos los demas
    recibe los siguientes argumentos:
            
    tipo              valor
    String            nombre de la grafica , aparecera en la parte superior centro
    String            tutulo del eje X
    String            titulo del eje Y
    XYDataset         el conjunto de datos X y Y del tipo XYDataset (aqui cambian el parametro
                      dependiendo del tipo de grafica que se quiere pueden ver todos los parametros
                      en la documentacion aqui <a href="http://www.jfree.org/jfreechart/api/javadoc/index.html
    " title="http://www.jfree.org/jfreechart/api/javadoc/index.html
    ">http://www.jfree.org/jfreechart/api/javadoc/index.html
    </a>                              iremos notando los cambios mas adelante..
     PlotOrientation  la orientacion del grafico puede ser PlotOrientation.VERTICAL o PlotOrientation.HORIZONTAL
     boolean                  muestra u oculta leyendas     
     boolean                  muestra u oculta tooltips
     boolean                  muestra u oculta urls (esta opcion aun no la entiendo del todo)
            
    generalmente solo necesitaremos cambiar los primeros 3 parametros lo demas puede quedarse asi
            
    */
    JFreeChart chart = ChartFactory.createXYLineChart("Grafico de consumo", "dias", "cantidad cigarrillos",
            juegoDatos, PlotOrientation.VERTICAL, true, false, true // Show legend
    );
    //donde guardaremos la imagen?? pues en un bufer jeje
    BufferedImage image = chart.createBufferedImage(500, 500);

    try {
        ImageIO.write(image, "jpg", new File("c:/users/public/nms/grafico/" + nombreArchivo + ".jpg"));
    } catch (IOException e) {
        System.out.println("Error de escritura");
    }

}

From source file:ch.unil.genescore.vegas.LinkageDisequilibrium.java

/** loads genotype form List into a DenseMatrix object. it also normalizes the data  and mean imputes*/
static public DenseMatrix loadGenotypeIntoDenseMatrix(ArrayList<Snp> geneSnps) {
    int numberOfSnps = geneSnps.size();
    int lengthOfGenotype = Snp.getGenotypeLength();
    double[][] dataArray = new double[lengthOfGenotype][numberOfSnps];
    double genotype;
    for (int j = 0; j < numberOfSnps; ++j) {
        Snp currentSnp = geneSnps.get(j);
        byte[] currentGenotype = currentSnp.getGenotypes();
        if (currentGenotype == null)
            throw new RuntimeException();
        for (int i = 0; i < lengthOfGenotype; ++i) {

            if (currentGenotype[i] == -9)
                genotype = currentSnp.getAlleleMean();
            else/*from  w  w  w.  j a v  a2s  . c  om*/
                genotype = currentGenotype[i];
            dataArray[i][j] = (genotype - currentSnp.getAlleleMean()) / currentSnp.getAlleleSd();
        }
    }
    return new DenseMatrix(dataArray);
}

From source file:Main.java

/**
 * Method that merges 2 data structures into 1
 * //  w w  w  . j  a  v  a  2 s. c  o  m
 * @param featureSet:
 *            the structure containing all features
 * @param featureSet2:
 *            the structure containing Pairwise Correlation features
 * @return the concatenated data structure
 */
public static HashMap<Integer, ArrayList<HashMap<String, Double>>> mergeStructures(
        HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet,
        ArrayList<ArrayList<HashMap<String, Double>>> featureSet2) {

    HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet_final = new HashMap<Integer, ArrayList<HashMap<String, Double>>>();

    for (int i = 0; i < featureSet.size(); i++) {
        ArrayList<HashMap<String, Double>> featuresPerChann = featureSet.get(i);
        ArrayList<HashMap<String, Double>> featuresPerChann2 = featureSet2.get(i);
        if (featuresPerChann2 == null)
            continue;

        ArrayList<HashMap<String, Double>> featuresPerChann_final = new ArrayList<HashMap<String, Double>>();

        for (int ii = 0; ii < featuresPerChann.size(); ii++) {
            HashMap<String, Double> h1 = new HashMap<String, Double>();
            HashMap<String, Double> h2 = new HashMap<String, Double>();
            // System.out.println("s:: "+String.format("%03d", ii));
            h1 = featuresPerChann.get(ii);
            for (int j = 0; j < featuresPerChann2.size(); j++) {
                h2 = featuresPerChann2.get(j);
                // System.out.println("h2:"+h2);
                String s = h2.keySet().toString();

                if (s.contains("s" + String.format("%04d", ii))) {
                    // System.out.println("sss"+s.substring(1,14));
                    String new_s = s.substring(1, 17);
                    if (h2.get(new_s) != null) {
                        double v = h2.get(new_s);
                        HashMap<String, Double> h = new HashMap<String, Double>();
                        h.put(new_s.substring(0, 11), v);
                        h1.putAll(h);
                    }
                }
            }
            featuresPerChann_final.add(h1);

        }
        featureSet_final.put(i, featuresPerChann_final);
    }

    return featureSet_final;
}

From source file:Main.java

public static byte[] encodeData(byte[] data) {
    // use arraylists because byte[] is annoying.
    ArrayList<Byte> inData = fromBytes(data);
    ArrayList<Byte> outData = new ArrayList<>();

    final byte[] codes = new byte[] { 21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28 };
    int acc = 0;//from w w  w  . jav a 2 s .  c om
    int bitcount = 0;
    int i;
    for (i = 0; i < inData.size(); i++) {
        acc <<= 6;
        acc |= codes[(inData.get(i) >> 4) & 0x0f];
        bitcount += 6;

        acc <<= 6;
        acc |= codes[inData.get(i) & 0x0f];
        bitcount += 6;

        while (bitcount >= 8) {
            byte outByte = (byte) (acc >> (bitcount - 8) & 0xff);
            outData.add(outByte);
            bitcount -= 8;
            acc &= (0xffff >> (16 - bitcount));
        }
    }
    if (bitcount > 0) {
        acc <<= (8 - bitcount);
        byte outByte = (byte) (acc & 0xff);
        outData.add(outByte);
    }

    // convert back to byte[]
    byte[] rval = toBytes(outData);

    Log.e(TAG, "encodeData: (length " + data.length + ") input is " + toHexString(data));
    Log.e(TAG, "encodeData: (length " + rval.length + ") output is " + toHexString(rval));
    return rval;

}

From source file:Main.java

/**
 * Maps a coordinate in a descendant view into the parent.
 *///w  ww. java 2  s. c o m
public static float mapCoordInDescendentToSelf(View descendant, View root, float[] coord,
        boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }

        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:eu.smartfp7.terrier.sensor.ParserUtility.java

public static EdgeNodeSnapShot parseHashMap(HashMap hashMap) throws Exception {

    /*// www  . j  av a 2 s .c  o m
     * ((HashMap)((java.util.HashMap)v.getValue()).get("crowd")).get("time");
            
    (java.lang.String) 2012-07-26T06:29:51.947Z
    (java.lang.String) #lab_visits    (java.util.ArrayList<E>) [07:00, 08:00]
            
            
    (java.util.HashMap<K,V>) {motion_spread=-1.000000, time=2012-07-26T06:29:51.947Z, motion_horizontal=-1, density=0.000000, motion_vertical=-1}
    (java.util.HashMap<K,V>) {isActive=false, temporalHint=[07:00, 08:00], name=#lab_visits, date=26-07-2012}
    (java.util.HashMap<K,V>) {motion_spread=-1.000000, time=2012-07-26T06:29:51.947Z, motion_horizontal=-1, density=0.000000, motion_vertical=-1}
    Evaluation failed. Reason(s):
    ClassCastException: Cannot cast java.util.HashMap (id=185) to java.util.Hashtable
     * */

    HashMap crowdHashMap = (HashMap) hashMap.get("crowd");
    double density = (Double) crowdHashMap.get("density");

    String time = (String) crowdHashMap.get("time");

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    Calendar c = Calendar.getInstance();
    ;
    c.setTime(df.parse(time));

    double[] colors = null;

    if (crowdHashMap.containsKey("color")) {
        ArrayList colorList = (ArrayList) crowdHashMap.get("color");
        colors = new double[colorList.size()];
        for (int i = 0; i < colorList.size(); i++) {
            colors[i] = (Double) colorList.get(i);
        }
    }

    CrowdReport crowdReport = new CrowdReport(null, new Double(density), 0.0, colors);
    EdgeNodeSnapShot snapShot = new EdgeNodeSnapShot(null, null, c, crowdReport);

    return snapShot;
}

From source file:Model.Picture.java

public static ArrayList<Picture> getNeighbors(String fileName) {
    ArrayList<Picture> neighbors = new ArrayList<Picture>();
    ArrayList<Picture> uploaded = (ArrayList) getUploadedPictures();

    for (int i = 0; i < uploaded.size() && neighbors.isEmpty(); i++) {
        if (uploaded.get(i).getName().equals(fileName)) {
            neighbors.addAll(Tools.getNeighbors(uploaded, i, Tools.NOT_CIRCULAR));
        }//  ww w  . ja  va 2s.c  om
    }

    return neighbors;
}