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:edu.mit.genecircuits.GcUtils.java

/** Return true if the given array is an ordered list of positive integers, given in increasing order */
public static boolean posIntIncreasing(ArrayList<Integer> x) {

    if (x == null || x.size() == 0)
        return true;

    for (int i = 0; i < x.size(); i++) {
        if (x.get(i) < 1)
            return false;
        if (i > 0 && x.get(i) <= x.get(i - 1))
            return false;
    }/*from  w  ww .j av  a  2 s .  c  o  m*/
    return true;
}

From source file:Main.java

public static List<ByteBuffer> mergeAdjacentBuffers(List<ByteBuffer> paramList) {
    ArrayList localArrayList = new ArrayList(paramList.size());
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext()) {
        ByteBuffer localByteBuffer1 = (ByteBuffer) localIterator.next();
        int i = -1 + localArrayList.size();
        if ((i >= 0) && (localByteBuffer1.hasArray()) && (((ByteBuffer) localArrayList.get(i)).hasArray())
                && (localByteBuffer1.array() == ((ByteBuffer) localArrayList.get(i)).array())
                && (((ByteBuffer) localArrayList.get(i)).arrayOffset()
                        + ((ByteBuffer) localArrayList.get(i)).limit() == localByteBuffer1.arrayOffset())) {
            ByteBuffer localByteBuffer3 = (ByteBuffer) localArrayList.remove(i);
            localArrayList.add(ByteBuffer.wrap(localByteBuffer1.array(), localByteBuffer3.arrayOffset(),
                    localByteBuffer3.limit() + localByteBuffer1.limit()).slice());
        } else if ((i >= 0) && ((localByteBuffer1 instanceof MappedByteBuffer))
                && ((localArrayList.get(i) instanceof MappedByteBuffer))
                && (((ByteBuffer) localArrayList.get(i))
                        .limit() == ((ByteBuffer) localArrayList.get(i)).capacity()
                                - localByteBuffer1.capacity())) {
            ByteBuffer localByteBuffer2 = (ByteBuffer) localArrayList.get(i);
            localByteBuffer2.limit(localByteBuffer1.limit() + localByteBuffer2.limit());
        } else {/*from w  ww. j  ava  2  s .c om*/
            localByteBuffer1.reset();
            localArrayList.add(localByteBuffer1);
        }
    }
    return localArrayList;
}

From source file:FindHullWindowLogic.java

static public void fullfilTableWithConvexHull(JTable jTableDest, ArrayList<Point2D> convexHull) {
    DefaultTableModel jTableDestModel = (DefaultTableModel) jTableDest.getModel();
    jTableDestModel.setRowCount(0);//from  www .j a v a2s . c  o m

    int i = 1;
    for (Point2D onePoint : convexHull) {
        if (i != 1 && areTheSamePoints(onePoint, convexHull.get(0)))
            break;
        jTableDestModel.addRow(new Object[] { i + ".", onePoint.getX(), onePoint.getY() });
        i++;
    }

}

From source file:Estadistica.java

/**
 * Metodo  multiple// w ww  .j a  v  a  2 s . co  m
 * param  dos listas de valores (xArrayList,ArrayList)
 * @return
 */
public static double multiple(ArrayList<Double> xArrayList, ArrayList<Double> yArrayList) {
    double cal = 0;
    for (int i = 0; i < xArrayList.size(); i++) {
        cal += xArrayList.get(i) * yArrayList.get(i);
    }
    return cal;
}

From source file:Estadistica.java

/**
* Metodo  para obtener el promedio/*  ww  w .j  a  v a 2 s. c  o m*/
* param  lista de valores  a la que se le va a calcular el promedio
* @return el promedio
*/
public static double getAverage(ArrayList<Double> cal) {
    double sumFloat = 0;
    double averageFloat = 0;
    for (int i = 0; i < cal.size(); i++) {
        sumFloat += cal.get(i);
    }
    averageFloat = sumFloat / cal.size();
    return averageFloat;
}

From source file:com.house365.build.util.CsvUtil.java

/**
 * ?./*  ww  w.  j  av a 2 s . c o m*/
 *
 * @param csvContent
 * @throws IOException
 */
public static void printlnCsv(ArrayList<LinkedHashMap<String, String>> csvContent) throws IOException {
    TableBuilder tb = new TableBuilder();
    ArrayList<String> headerNames = new ArrayList<>();
    LinkedHashMap<String, String> linkedHashMap = csvContent.get(0);
    for (Map.Entry<String, String> entry : linkedHashMap.entrySet()) {
        headerNames.add(entry.getKey());
    }
    String[] names = new String[headerNames.size()];
    headerNames.toArray(names);
    tb.addRow(names);
    for (HashMap<String, String> mapRecord : csvContent) {
        names = new String[headerNames.size()];
        mapRecord.values().toArray(names);
        tb.addRow(names);
    }
    tb.toString();
    BufferedReader reader = new BufferedReader(new StringReader(tb.toString()));
    String line = reader.readLine();
    System.out.println(AnsiColor.ANSI_YELLOW + line + AnsiColor.ANSI_RESET);
    for (line = reader.readLine(); line != null; line = reader.readLine()) {
        System.out.println(AnsiColor.ANSI_GREEN + line + AnsiColor.ANSI_RESET);
    }
}

From source file:com.hanuor.sapphire.utils.Client.java

public static void updateJson(final ArrayList<String> tags, String docID) {

    storageService.findDocumentById(LibraryDatabase.DBNAME, LibraryDatabase.collectionName, docID,
            new App42CallBack() {
                public void onSuccess(Object response) {
                    String jsonD = null;
                    HashMap<String, String> hMap = new HashMap<String, String>();
                    ArrayList<String> arrayList = new ArrayList<String>();
                    Storage storage = (Storage) response;
                    System.out.println("dbName is " + storage.getDbName());
                    System.out.println("collection Name is " + storage.getCollectionName());
                    ArrayList<Storage.JSONDocument> jsonDocList = storage.getJsonDocList();
                    for (int i = 0; i < jsonDocList.size(); i++) {
                        jsonD = jsonDocList.get(i).getJsonDoc();
                    }/*from   w  ww  .  j  a v  a2  s. com*/
                    try {
                        if (jsonD != null) {
                            JSONObject jObj = new JSONObject(jsonD);
                            for (int i = 0; i < tags.size(); i++) {
                                String entityValue = null;
                                entityValue = jObj.getString(tags.get(i));
                                if (entityValue.length() != 0) {
                                    hMap.put(tags.get(i), entityValue);
                                } else {
                                    arrayList.add(tags.get(i));
                                }
                                //add to hashmap here
                                for (int j = 0; j < arrayList.size(); j++) {
                                    hMap.put(arrayList.get(j), "0.1");
                                }
                            }
                            updateJsonDoc(hMap);
                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

                public void onException(Exception ex) {
                    System.out.println("Exception Message" + ex.getMessage());
                }
            });

}

From source file:fr.bmartel.android.tictactoe.request.ResponseParser.java

public static MessageObject parseMessage(Intent intent) {

    ArrayList<String> actionsStr = intent.getStringArrayListExtra("");

    if (actionsStr.size() > 0) {
        try {// www  .  j  a  v  a  2 s .com
            JSONObject mainObject = new JSONObject(actionsStr.get(0));
            if (mainObject.has(RequestConstants.DEVICE_MESSAGE_TOPIC)) {

                GameMessageTopic topic = GameMessageTopic
                        .getTopic(mainObject.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC));

                switch (topic) {

                case CHALLENGED: {

                    if (mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                            && mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {
                        return new ChallengeMessage(topic,
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));
                    }
                    return null;
                }
                case ACCEPTED: {
                    if (mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                            && mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {
                        return new ChallengeResponse(topic, true,
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));
                    }
                    return null;
                }
                case DECLINED: {
                    if (mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                            && mainObject.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {
                        return new ChallengeResponse(topic, false,
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                                mainObject.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));
                    }
                    return null;
                }
                case GAME_STOPPED: {
                    break;
                }
                case PLAY: {
                    if (mainObject.has(RequestConstants.DEVICE_PLAY)) {
                        return new PlayRequest(topic, mainObject.getInt(RequestConstants.DEVICE_PLAY));
                    }
                    return null;
                }
                case CLIENT_CONNECTED: {

                    if (mainObject.has(RequestConstants.DEVICE_ID)
                            && mainObject.has(RequestConstants.DEVICE_NAME)) {
                        return new ClientConnectionEvent(topic,
                                mainObject.getString(RequestConstants.DEVICE_ID),
                                mainObject.getString(RequestConstants.DEVICE_NAME));
                    }
                    return null;
                }
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    return null;
}

From source file:lite.flow.util.ActivityInspector.java

static public String[] getOutputNames(Class<?> clazz) {

    ArrayList<Field> outputs = getOutputs(clazz);
    String[] outputNames = new String[outputs.size()];

    for (int i = 0; i < outputNames.length; i++) {
        outputNames[i] = outputs.get(i).getName();
    }//from w ww . java  2 s.  c o m
    return outputNames;
}

From source file:com.espertech.esper.pattern.EvalAndStateNode.java

/**
 * For each combination of MatchedEventMap instance in all collections, add an entry to the list.
 * Recursive method.//from w w  w  . j a  va2s.co m
 * @param eventList is an array of lists containing MatchedEventMap instances to combine
 * @param index is the current index into the array
 * @param result is the resulting list of MatchedEventMap
 * @param matchEvent is the start MatchedEventMap to generate from
 */
protected static void generateMatchEvents(ArrayList<List<MatchedEventMap>> eventList, int index,
        List<MatchedEventMap> result, MatchedEventMap matchEvent) {
    List<MatchedEventMap> events = eventList.get(index);

    for (MatchedEventMap theEvent : events) {
        MatchedEventMap current = matchEvent.shallowCopy();
        current.merge(theEvent);

        // If this is the very last list in the array of lists, add accumulated MatchedEventMap events to result
        if ((index + 1) == eventList.size()) {
            result.add(current);
        } else {
            // make a copy of the event collection and hand to next list of events
            generateMatchEvents(eventList, index + 1, result, current);
        }
    }
}