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.nubits.nubot.trading.TradeUtils.java

public static boolean takeDownOrders(String type, CurrencyPair pair) {
    boolean completed = true;
    //Get active orders
    ApiResponse activeOrdersResponse = Global.exchange.getTrade().getActiveOrders(Global.options.getPair());
    if (activeOrdersResponse.isPositive()) {
        ArrayList<Order> orderList = (ArrayList<Order>) activeOrdersResponse.getResponseObject();

        for (int i = 0; i < orderList.size(); i++) {
            Order tempOrder = orderList.get(i);
            if (tempOrder.getType().equalsIgnoreCase(type)) {
                boolean tempDeleted = takeDownAndWait(tempOrder.getId(), 120 * 1000, pair);
                if (!tempDeleted) {
                    completed = false;/*from   www  . j  av  a 2  s . c  om*/
                }
            }
        }
    } else {
        LOG.severe(activeOrdersResponse.getError().toString());
        return false;
    }
    return completed;
}

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java

private static HashMap sortByValuesArray(HashMap map) {
    List list = new LinkedList(map.entrySet());
    // Defined Custom Comparator here
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            ArrayList<Integer> a1 = (ArrayList<Integer>) ((Map.Entry) (o1)).getValue();
            ArrayList<Integer> a2 = (ArrayList<Integer>) ((Map.Entry) (o2)).getValue();
            return ((Comparable) a1.get(0)).compareTo(a2.get(0));
        }//from ww  w .j ava2 s  .c om
    });

    // Here I am copying the sorted list in HashMap
    // using LinkedHashMap to preserve the insertion order
    HashMap sortedHashMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedHashMap.put(entry.getKey(), entry.getValue());
    }
    return sortedHashMap;
}

From source file:EndmemberExtraction.java

public static ArrayList<Integer> ORASIS(double[][] data, int nData, int nDim, double threshold,
        int[] exemplarLabel) {
    ArrayRealVector vec;//  www  .  ja v  a 2 s  .  co  m
    ArrayList<ArrayRealVector> X = new ArrayList<>();
    ArrayList<ArrayRealVector> E = new ArrayList<>();
    ArrayList<Integer> exemplarIndex = new ArrayList<>();

    for (int i = 0; i < nData; i++) {
        vec = new ArrayRealVector(data[i]);
        vec.unitize();
        X.add(vec);
    }

    E.add(X.get(0));
    exemplarIndex.add(0);
    double t = Math.sqrt(2 * (1 - threshold));

    //Add first element of test spectra to set of exemplar spectra
    exemplarLabel[0] = 0;

    boolean flag;
    double maxCos, sigmaMin, sigmaMax, dotXR, dotER, cosTheta;

    double[] vecR = new double[nDim];
    for (int i = 0; i < nDim; i++) {
        vecR[i] = 1 / Math.sqrt(nDim);
    }
    ArrayRealVector R = new ArrayRealVector(vecR);

    ArrayRealVector exemplarSpec, testSpec;

    for (int i = 0; i < X.size(); i++) {
        if (i == 0 || exemplarLabel[i] == -1) {
            continue;
        }

        flag = false;
        maxCos = 0;
        testSpec = X.get(i);
        dotXR = testSpec.dotProduct(R);
        sigmaMin = dotXR - t;
        sigmaMax = dotXR + t;

        for (int j = 0; j < E.size(); j++) {
            exemplarSpec = E.get(j);
            dotER = exemplarSpec.dotProduct(R);

            if (dotER < sigmaMax && dotER > sigmaMin) {
                cosTheta = testSpec.dotProduct(exemplarSpec);

                if (cosTheta > threshold) {
                    //Test spectra is similar to one of the exemplar spectra
                    if (cosTheta > maxCos) {
                        maxCos = cosTheta;
                        exemplarLabel[i] = j;
                        //System.out.println("Count: "+i+"\texemplarLabel: "+exemplarLabel[i]);
                        flag = true;
                    }
                }
            }
        }

        if (!flag) {
            //Test spectra is unique, add it to set of exemplars
            E.add(testSpec);
            exemplarIndex.add(i);
            exemplarLabel[i] = E.size() - 1;
            //System.out.println("Count: "+i+"\texemplarLabel: "+exemplarLabel[i]);
        }

    }
    return exemplarIndex;
}

From source file:Anaphora_Resolution.ParseAllXMLDocuments.java

public static Tree HobbsResolve(Tree pronoun, ArrayList<Tree> forest) {
    Tree wholetree = forest.get(forest.size() - 1); // The last one is the one I am going to start from
    ArrayList<Tree> candidates = new ArrayList<Tree>();
    List<Tree> path = wholetree.pathNodeToNode(wholetree, pronoun);
    System.out.println(path);/*from w  w  w.j av a2 s.  c  o  m*/
    // Step 1
    Tree ancestor = pronoun.parent(wholetree); // This one locates the NP the pronoun is in, therefore we need one more "parenting" !
    // Step 2
    ancestor = ancestor.parent(wholetree);
    //System.out.println("LABEL: "+pronoun.label().value() + "\n\tVALUE: "+pronoun.firstChild());
    while (!ancestor.label().value().equals("NP") && !ancestor.label().value().equals("S"))
        ancestor = ancestor.parent(wholetree);
    Tree X = ancestor;
    path = X.pathNodeToNode(wholetree, pronoun);
    System.out.println(path);
    // Step 3
    for (Tree relative : X.children()) {
        for (Tree candidate : relative) {
            if (candidate.contains(pronoun))
                break; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path
            //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild());
            if ((candidate.parent(wholetree) != X) && (candidate.parent(wholetree).label().value().equals("NP")
                    || candidate.parent(wholetree).label().value().equals("S")))
                if (candidate.label().value().equals("NP")) // "Propose as the antecedent any NP node that is encountered which has an NP or S node between it and X"
                    candidates.add(candidate);
        }
    }
    // Step 9 is a GOTO step 4, hence I will envelope steps 4 to 8 inside a while statement.
    while (true) { // It is NOT an infinite loop. 
        // Step 4
        if (X.parent(wholetree) == wholetree) {
            for (int q = 1; q < MAXPREVSENTENCES; ++q) {// I am looking for the prev sentence (hence we start with 1)
                if (forest.size() - 1 < q)
                    break; // If I don't have it, break
                Tree prevTree = forest.get(forest.size() - 1 - q); // go to previous tree
                // Now we look for each S subtree, in order of recency (hence right-to-left, hence opposite order of that of .children() ).
                ArrayList<Tree> backlist = new ArrayList<Tree>();
                for (Tree child : prevTree.children()) {
                    for (Tree subtree : child) {
                        if (subtree.label().value().equals("S")) {
                            backlist.add(child);
                            break;
                        }
                    }
                }
                for (int i = backlist.size() - 1; i >= 0; --i) {
                    Tree Treetovisit = backlist.get(i);
                    for (Tree relative : Treetovisit.children()) {
                        for (Tree candidate : relative) {
                            if (candidate.contains(pronoun))
                                continue; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path
                            //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild());
                            if (candidate.label().value().equals("NP")) { // "Propose as the antecedent any NP node that you find"
                                if (!candidates.contains(candidate))
                                    candidates.add(candidate);
                            }
                        }
                    }
                }
            }
            break; // It will always come here eventually
        }
        // Step 5
        ancestor = X.parent(wholetree);
        //System.out.println("LABEL: "+pronoun.label().value() + "\n\tVALUE: "+pronoun.firstChild());
        while (!ancestor.label().value().equals("NP") && !ancestor.label().value().equals("S"))
            ancestor = ancestor.parent(wholetree);
        X = ancestor;
        // Step 6
        if (X.label().value().equals("NP")) { // If X is an NP
            for (Tree child : X.children()) { // Find the nominal nodes that X directly dominates
                if (child.label().value().equals("NN") || child.label().value().equals("NNS")
                        || child.label().value().equals("NNP") || child.label().value().equals("NNPS"))
                    if (!child.contains(pronoun))
                        candidates.add(X); // If one of them is not in the path between X and the pronoun, add X to the antecedents
            }
        }
        // Step SETTE
        for (Tree relative : X.children()) {
            for (Tree candidate : relative) {
                if (candidate.contains(pronoun))
                    continue; // I am looking to all the nodes to the LEFT (i.e. coming before) the path leading to X. contain <-> in the path
                //System.out.println("LABEL: "+relative.label().value() + "\n\tVALUE: "+relative.firstChild());
                if (candidate.label().value().equals("NP")) { // "Propose as the antecedent any NP node that you find"
                    boolean contains = false;
                    for (Tree oldercandidate : candidates) {
                        if (oldercandidate.contains(candidate)) {
                            contains = true;
                            break;
                        }
                    }
                    if (!contains)
                        candidates.add(candidate);
                }
            }
        }
        // Step 8
        if (X.label().value().equals("S")) {
            boolean right = false;
            // Now we want all branches to the RIGHT of the path pronoun -> X.
            for (Tree relative : X.children()) {
                if (relative.contains(pronoun)) {
                    right = true;
                    continue;
                }
                if (!right)
                    continue;
                for (Tree child : relative) { // Go in but do not go below any NP or S node. Go below the rest
                    if (child.label().value().equals("NP")) {
                        candidates.add(child);
                        break; // not sure if this means avoid going below NP but continuing with the rest of non-NP children. Should be since its DFS.
                    }
                    if (child.label().value().equals("S"))
                        break; // Same
                }
            }
        }
    }

    // Step 9 is a GOTO, so we use a while.

    System.out.println(pronoun + ": CHAIN IS " + candidates.toString());
    ArrayList<Integer> scores = new ArrayList<Integer>();

    for (int j = 0; j < candidates.size(); ++j) {
        Tree candidate = candidates.get(j);
        Tree parent = null;
        int parent_index = 0;
        for (Tree tree : forest) {
            if (tree.contains(candidate)) {
                parent = tree;
                break;
            }
            ++parent_index;
        }
        scores.add(0);
        if (parent_index == 0)
            scores.set(j, scores.get(j) + 100); // If in the last sentence, +100 points
        scores.set(j, scores.get(j) + syntacticScore(candidate, parent));

        if (existentialEmphasis(candidate)) // Example: "There was a dog standing outside"
            scores.set(j, scores.get(j) + 70);
        if (!adverbialEmphasis(candidate, parent))
            scores.set(j, scores.get(j) + 50);
        if (headNounEmphasis(candidate, parent))
            scores.set(j, scores.get(j) + 80);

        int sz = forest.size() - 1;
        //          System.out.println("pronoun in sentence " + sz + "(sz). Candidate in sentence "+parent_index+" (parent_index)");
        int dividend = 1;
        for (int u = 0; u < sz - parent_index; ++u)
            dividend *= 2;
        //System.out.println("\t"+dividend);
        scores.set(j, scores.get(j) / dividend);
        System.out.println(candidate + " -> " + scores.get(j));
    }
    int max = -1;
    int max_index = -1;
    for (int i = 0; i < scores.size(); ++i) {
        if (scores.get(i) > max) {
            max_index = i;
            max = scores.get(i);
        }
    }
    Tree final_candidate = candidates.get(max_index);
    System.out.println("My decision for " + pronoun + " is: " + final_candidate);
    // Decide what candidate, with both gender resolution and Lappin and Leass ranking.

    Tree pronounparent = pronoun.parent(wholetree).parent(wholetree); // 1 parent gives me the NP of the pronoun
    int pos = 0;
    for (Tree sibling : pronounparent.children()) {
        System.out.println("Sibling " + pos + ": " + sibling);
        if (sibling.contains(pronoun))
            break;
        ++pos;
    }
    System.out.println("Before setchild: " + pronounparent);
    @SuppressWarnings("unused")
    Tree returnval = pronounparent.setChild(pos, final_candidate);
    System.out.println("After setchild: " + pronounparent);

    return wholetree; // wholetree is already modified, since it contains pronounparent
}

From source file:edu.usc.squash.Main.java

private static HashMap<String, Module> parseQASMHF(Library library) {
    HFQParser hfqParser = null;//from w  ww. j  av  a2 s  .  co m
    /*
     * Pass 1: Getting module info
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> moduleMap = hfqParser.parse(library, true, null);

    /* 
     * In order traversal of modules
     */

    ArrayList<CalledModule> modulesList = new ArrayList<CalledModule>();
    modulesList.add(new CalledModule(moduleMap.get("main"), new ArrayList<String>()));
    while (!modulesList.isEmpty()) {
        Module module = modulesList.get(0).getModule();

        if (!module.isVisited()) {
            module.setVisited();

            ArrayList<CalledModule> calledModules = module.getChildModules();
            modulesList.addAll(calledModules);
            for (CalledModule calledModule : calledModules) {
                Module childModule = calledModule.getModule();
                for (int i = 0; i < calledModule.getOps().size(); i++) {
                    Operand operand = childModule.getOperand(i);
                    if (operand.isArray() && operand.getLength() == -1) {
                        operand.setLength(module.getOperandLength(calledModule.getOps().get(i)));
                    }
                }
            }
        }
        modulesList.remove(0);
    }

    /*
     * Pass 2: Making hierarchical QMDG
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> modules = hfqParser.parse(library, false, moduleMap);

    return modules;
}

From source file:com.mapviewer.business.UserRequestManager.java

/**
 * Generate links for the default entry layers
 *
 * @param layers ArrayList<Layer> contains the layers
 * @return String[] array with kml link of layers
 */// www. ja v  a2s  . c o m
public static String[] getCheckboxKmlLinks(ArrayList<Layer> layers) {
    String[] kmlLinks = new String[layers.size()];//this array will have the links of the kml of each layer requested. 

    String layerName = null;
    String serverLayer = null;
    for (int i = 0; i < kmlLinks.length; i++) {
        kmlLinks[i] = UserRequestManager.buildKmlLink(layers.get(i), layers.get(i).getPalette());
    }
    return kmlLinks;
}

From source file:net.oauth.provider.core.SampleOAuthProvider.java

public static synchronized void loadConsumers(ServletConfig config) throws IOException {
    Connection conn = DBConnector.getconecttion(); //??
    try {/*  w  ww .j av a  2  s.  co  m*/
        ArrayList applist = Xt_appCtl.list(conn,
                "SELECT * FROM XT_APP WHERE app_key IS NOT NULL AND app_key<>'' AND app_secret IS NOT NULL AND app_secret<>''",
                new Xt_app());
        for (int i = 0; i < applist.size(); i++) {
            Xt_app app = (Xt_app) applist.get(i);
            String consumer_key = app.getAppKey();
            String consumer_secret = app.getAppSecret();
            String consumer_description = StringUtil.null2String(app.getDescription());
            String consumer_callback_url = StringUtil.null2String(app.getCallbackurl());
            OAuthConsumer consumer = new OAuthConsumer(consumer_callback_url, consumer_key, consumer_secret,
                    null);
            consumer.setProperty("name", consumer_key);
            consumer.setProperty("description", consumer_description);
            ALL_CONSUMERS.put(consumer_key, consumer);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DBConnector.freecon(conn); //?
    }

    //       
    //       
    //       
    //        Properties p = consumerProperties;
    //        if (p == null) {
    //            p = new Properties();
    //            String resourceName = "/"
    //                    + SampleOAuthProvider.class.getPackage().getName().replace(
    //                    ".", "/") + "/provider.properties";
    //            URL resource = SampleOAuthProvider.class.getClassLoader()
    //            .getResource(resourceName);
    //            if (resource == null) {
    //                throw new IOException("resource not found: " + resourceName);
    //            }
    //            InputStream stream = resource.openStream();
    //            try {
    //                p.load(stream);
    //            } finally {
    //                stream.close();
    //            }
    //        }
    //        consumerProperties = p;
    //        
    //        // for each entry in the properties file create a OAuthConsumer
    //        for(Map.Entry prop : p.entrySet()) {
    //            String consumer_key = (String) prop.getKey();
    //            // make sure it's key not additional properties
    //            if(!consumer_key.contains(".")){
    //                String consumer_secret = (String) prop.getValue();
    //                if(consumer_secret != null){
    //                    String consumer_description = (String) p.getProperty(consumer_key + ".description");
    //                    String consumer_callback_url =  (String) p.getProperty(consumer_key + ".callbackURL");
    //                    // Create OAuthConsumer w/ key and secret
    //                    OAuthConsumer consumer = new OAuthConsumer(
    //                            consumer_callback_url, 
    //                            consumer_key, 
    //                            consumer_secret, 
    //                            null);
    //                    consumer.setProperty("name", consumer_key);
    //                    consumer.setProperty("description", consumer_description);
    //                    ALL_CONSUMERS.put(consumer_key, consumer);
    //                }
    //            }
    //        }

}

From source file:Main.java

/**
 * Returns the relative path beginning after the getAppFolder(appName) directory.
 * The relative path does not start or end with a '/'
 *
 * @param appName/*from  www.ja va  2 s.  c o  m*/
 * @param fileUnderAppName
 * @return
 */
public static String asRelativePath(String appName, File fileUnderAppName) {
    // convert fileUnderAppName to a relative path such that if
    // we just append it to the AppFolder, we have a full path.
    File parentDir = new File(getAppFolder(appName));

    ArrayList<String> pathElements = new ArrayList<String>();

    File f = fileUnderAppName;
    while (f != null && !f.equals(parentDir)) {
        pathElements.add(f.getName());
        f = f.getParentFile();
    }

    if (f == null) {
        throw new IllegalArgumentException("file is not located under this appName (" + appName + ")!");
    }

    StringBuilder b = new StringBuilder();
    for (int i = pathElements.size() - 1; i >= 0; --i) {
        String element = pathElements.get(i);
        b.append(element);
        if (i != 0) {
            b.append(File.separator);
        }
    }
    return b.toString();

}

From source file:com.wst.cls.HTTPBaseIO.java

public static ArrayList paramToArray(String param) throws UnsupportedEncodingException {
    ArrayList arr = null;/*www.jav a2 s  .c  o  m*/
    if (param != null) {
        String[] p = param.split("&");
        if (param.toLowerCase().contains("&")) {
            ArrayList p2 = new ArrayList();
            int j = 0;
            for (String p1 : p) {
                if (p1.toLowerCase().startsWith("amp;")) {
                    p2.set(j - 1, p2.get(j - 1) + "&" + p1.substring(4));
                    j--;
                }
                p2.add(p1);
                j++;
            }
            p2.toArray(p);
        }

        for (String p1 : p) {
            String[] item = p1.split("=");
            if (item.length == 2) {
                if (arr == null) {
                    arr = new ArrayList();
                }
                // item[0]=URLDecoder.decode(item[0],charset);
                // item[1]=URLDecoder.decode(item[1],charset);  
                arr.add(item);
            }
        }
    }
    return arr;
}

From source file:com.good.example.contributor.jhawkins.pathstore.PathStore.java

public static Object createFromICC(Object from) {
    // Eliminate the simplest case
    if (from == null)
        return from;

    String from_type = from.getClass().toString();
    if (from_type.endsWith("Map")) {
        PathStore ret = new PathStore(new JSONObject());
        Map<String, Object> from_map = (Map<String, Object>) from;
        Iterator<String> iterator = from_map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            ret.pathSet(createFromICC(from_map.get(key)), key);
        }/*from  ww  w.  jav  a  2 s .  c  om*/
        return ret;
    } else if (from_type.endsWith(".ArrayList")) {
        PathStore ret = new PathStore(new JSONArray());
        ArrayList<Object> from_list = (ArrayList<Object>) from;
        for (int i = 0; i < from_list.size(); i++) {
            ret.pathSet(createFromICC(from_list.get(i)), i);
        }
        return ret;
    } else {
        return from;
    }
}