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.zoterodroid.client.ZoteroApi.java

/**
 * Fetches users bookmarks/*from  w w  w .  j a v a 2 s . c o m*/
 * 
 * @param account The account being synced.
 * @param authtoken The authtoken stored in the AccountManager for the
 *        account
 * @return list The list of bookmarks received from the server.
 * @throws AuthenticationException 
 */
public static ArrayList<Citation> getBookmark(ArrayList<String> hashes, Account account, Context context)
        throws IOException, AuthenticationException {

    ArrayList<Citation> bookmarkList = new ArrayList<Citation>();
    TreeMap<String, String> params = new TreeMap<String, String>();
    String hashString = "";
    String response = null;
    String url = FETCH_BOOKMARK_URI;

    for (String h : hashes) {
        if (hashes.get(0) != h) {
            hashString += "+";
        }
        hashString += h;
    }
    params.put("meta", "yes");
    params.put("hashes", hashString);

    response = ZoteroApiCall(url, params, account, context);

    if (response.contains("<?xml")) {
        bookmarkList = Citation.valueOf(response);
    } else {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }
    return bookmarkList;
}

From source file:net.sf.tweety.cli.plugins.CliMain.java

/**
 * This method is meant to load the tweety plugin pathes on startup
 * // ww  w .  ja  v a 2  s  .c  om
 * @return an object with one or more pluginpathes
 * @throws ConfigurationException
 */
public static Map<String, String> configCLI() throws ConfigurationException, FileNotFoundException {

    System.out.println("Initialize CLI...");

    // TODO : exception handling for empty/erroneous configuration
    Map<String, String> loadablePlugins = new HashMap<String, String>();

    XMLConfiguration tweetyXmlConfig = new XMLConfiguration();
    File in = new File(TWEETY_CLI_DEFAULT_CONFIG);
    try {
        System.out.print("Loading Configuration...");
        String inPath = in.getAbsolutePath();
        tweetyXmlConfig
                .setBasePath(inPath.substring(0, inPath.length() - TWEETY_CLI_DEFAULT_CONFIG.length() - 1));
        tweetyXmlConfig.load(in);
        System.out.print("success.\n");
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    // map ueber "plugins.plugin" mit keys ()
    // TODO: Verhalten bei leeren Feldern pruefen
    // TODO: Verhalten bei einem einzelnen Eintrag prfen
    Iterator<String> it = tweetyXmlConfig.getKeys("plugin");

    // // TODO fix the casts!
    // if (it.hasNext()) {
    //
    // String pluginPath = (String) tweetyXmlConfig.getProperty(it.next()
    // .toString());
    //
    // String pluginName = (String) tweetyXmlConfig.getProperty(it.next()
    // .toString());
    //
    // // for (int i = 0; i < pluginPath.size(); i++) {
    // // System.out.println(pluginName.get(i) + pluginPath.get(i));
    // loadablePlugins.put(pluginName, pluginPath);
    // }
    // }
    System.out.print("Getting Plugins...");
    // TODO fix the casts!
    if (it.hasNext()) {
        @SuppressWarnings("unchecked")
        ArrayList<String> pluginPath = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next());
        @SuppressWarnings("unchecked")
        ArrayList<String> pluginName = (ArrayList<String>) tweetyXmlConfig.getProperty(it.next());

        for (int i = 0; i < pluginPath.size(); i++) {
            // System.out.println(pluginName.get(i) + pluginPath.get(i));
            loadablePlugins.put(pluginName.get(i), pluginPath.get(i));
        }
    }
    System.out.print("done.\n");
    System.out.println("CLI initialized");
    return loadablePlugins;
}

From source file:net.opentsdb.tree.Leaf.java

/**
 * Attempts to fetch the requested leaf from storage.
 * <b>Note:</b> This method will not load the UID names from a TSDB. This is
 * only used to fetch a particular leaf from storage for collision detection
 * @param tsdb The TSDB to use for storage access
 * @param branch_id ID of the branch this leaf belongs to
 * @param display_name Name of the leaf//  w  w  w  .jav a2 s . c om
 * @return A valid leaf if found, null if the leaf did not exist
 * @throws HBaseException if there was an issue
 * @throws JSONException if the object could not be serialized
 */
private static Deferred<Leaf> getFromStorage(final TSDB tsdb, final byte[] branch_id,
        final String display_name) {

    final Leaf leaf = new Leaf();
    leaf.setDisplayName(display_name);

    final GetRequest get = new GetRequest(tsdb.treeTable(), branch_id);
    get.family(Tree.TREE_FAMILY());
    get.qualifier(leaf.columnQualifier());

    /**
     * Called with the results of the fetch from storage
     */
    final class GetCB implements Callback<Deferred<Leaf>, ArrayList<KeyValue>> {

        /**
         * @return null if the row was empty, a valid Leaf if parsing was 
         * successful
         */
        @Override
        public Deferred<Leaf> call(ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            final Leaf leaf = JSON.parseToObject(row.get(0).value(), Leaf.class);
            return Deferred.fromResult(leaf);
        }

    }

    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

private static boolean findEmptyCell(Context context, ArrayList<ItemInfo> items, int[] xy, int screen) {
    final int xCount = LauncherModel.getCellCountX();
    final int yCount = LauncherModel.getCellCountY();
    boolean[][] occupied = new boolean[xCount][yCount];

    ItemInfo item = null;/*from  w  w  w. j a v  a 2 s  .  c  om*/
    int cellX, cellY, spanX, spanY;
    for (int i = 0; i < items.size(); ++i) {
        item = items.get(i);
        if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
            if (item.screen == screen) {
                cellX = item.cellX;
                cellY = item.cellY;
                spanX = item.spanX;
                spanY = item.spanY;
                for (int x = cellX; 0 <= x && x < cellX + spanX && x < xCount; x++) {
                    for (int y = cellY; 0 <= y && y < cellY + spanY && y < yCount; y++) {
                        occupied[x][y] = true;
                    }
                }
            }
        }
    }

    return CellLayout.findVacantCell(xy, 1, 1, xCount, yCount, occupied);
}

From source file:mlflex.helper.MathUtilities.java

/** Identifies the maximum numeric value in a list.
 *
 * @param values Numeric values to test/*from  w  w  w .j av a  2  s  . c om*/
 * @return Maximum value
 * @throws Exception
 */
public static double Max(ArrayList<Double> values) throws Exception {
    ArrayList<Double> values2 = new ArrayList<Double>();
    for (Double value : values)
        if (!value.equals(Double.NaN))
            values2.add(value);

    if (values2.size() == 0)
        throw new Exception("The list was empty, so Max could not be determined.");

    int indexOfMax = 0;

    for (int i = 1; i < values2.size(); i++) {
        Double value = values2.get(i);

        if (value > values2.get(indexOfMax))
            indexOfMax = i;
    }

    return values2.get(indexOfMax);
}

From source file:Main.java

/**
 * Maps a coordinate in the root to a descendent.
 *///from   w  w w. j a v a  2s  . co  m
public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord,
        Matrix tmpInverseMatrix) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

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

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

    float scale = 1.0f;
    int count = ancestorChain.size();
    tmpInverseMatrix.set(IDENTITY_MATRIX);
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(tmpInverseMatrix);
            tmpInverseMatrix.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

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

From source file:edu.oregonstate.eecs.mcplan.util.Csv.java

public static Map<String, String> readKeyValue(final File f, final boolean headers) {
    try {/*from  www .j a va  2  s. c  o m*/
        final BufferedReader r = new BufferedReader(new FileReader(f));
        String line;
        final ArrayList<String[]> rows = new ArrayList<String[]>();
        while (true) {
            line = r.readLine();
            if (line == null) {
                break;
            }
            rows.add(line.split(","));
        }

        final Map<String, String> m = new HashMap<String, String>();
        for (int i = (headers ? 1 : 0); i < rows.size(); ++i) {
            final String[] row = rows.get(i);
            m.put(row[0], row[1]);
        }

        return m;
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.fuelworld.FuelWorldState.java

/**
 * This creates a problem with similar topology to the IPC-4 TireWorld
 * domain. The only difference is that the fuel stations in the three
 * loops on the "conservative" path (top path) are moved one space
 * further along. This is because if they were left in the same positions,
 * under the probability model we've adopted, reaching the first one
 * would be almost certain.//from  w w  w.j ava2s .co m
 * @param rng
 * @return
 */
public static FuelWorldState createDefault(final RandomGenerator rng) {
    int counter = 0;
    final ArrayList<TIntList> adjacency = new ArrayList<TIntList>();
    final int start = counter++;
    adjacency.add(new TIntArrayList());
    final int goal = counter++;
    adjacency.add(new TIntArrayList());

    final TIntList fuel_depots = new TIntArrayList();

    // Bottom path
    final int nuisance_begin = counter + 5;
    final int nuisance_end = counter + 7;
    adjacency.get(start).add(counter++);
    adjacency.add(new TIntArrayList());
    for (int i = 0; i < 7; ++i) {
        adjacency.get(counter - 1).add(counter++);
        adjacency.add(new TIntArrayList());
    }
    adjacency.get(counter - 1).add(goal);

    // Nuisance loop on bottom path
    adjacency.get(nuisance_begin).add(counter++);
    adjacency.add(new TIntArrayList());
    for (int i = 0; i < 3; ++i) {
        adjacency.get(counter - 1).add(counter++);
        adjacency.add(new TIntArrayList());
    }
    fuel_depots.add(counter);
    adjacency.get(counter - 1).add(counter++);
    adjacency.add(new TIntArrayList());
    adjacency.get(counter - 1).add(nuisance_end);

    // Top main-line path
    adjacency.get(start).add(counter++);
    adjacency.add(new TIntArrayList());
    for (int i = 0; i < 9; ++i) {
        if (i == 8) {
            fuel_depots.add(counter - 1);
        }
        adjacency.get(counter - 1).add(counter++);
        adjacency.add(new TIntArrayList());
    }
    adjacency.get(counter - 1).add(goal);

    // Fuel depot loops
    int loop_begin = adjacency.get(adjacency.get(start).get(1)).get(0);
    for (int loop = 0; loop < 3; ++loop) {
        adjacency.get(loop_begin).add(counter++);
        adjacency.add(new TIntArrayList());
        adjacency.get(counter - 1).add(counter++);
        adjacency.add(new TIntArrayList());
        fuel_depots.add(counter - 1);
        adjacency.get(counter - 1).add(loop_begin + 1);
        loop_begin += 2;
    }

    //      for( int i = 0; i < adjacency.size(); ++i ) {
    //         final TIntList list = adjacency.get( i );
    //         System.out.println( "V" + i + ": " + list );
    //      }
    //      System.out.println( "Fuel: " + fuel_depots );

    return new FuelWorldState(rng, adjacency, goal, new TIntHashSet(fuel_depots));
}

From source file:gr.iit.demokritos.cru.cps.ai.MachineLearningComponents.java

public static Vec CalculateUserProfile(double[] LastN, double[] LastS, double[] LastR, double[] LastE,
        double[] w, int D, double visionary, double constructive, ArrayList<User> group) {
    double OldCreativityX = visionary; //!!!!!!!!!!!!!!get old user's X,Y 
    double OldCreativityY = constructive;

    try {//  ww w  . j av a 2s  . c  o  m
        Vec UserVec = UserCreativity(LastN, LastS, LastR, LastE, w, D);
        Vec AverageGroupVec = new Vec(0, 0);
        int NumberOfGroups = group.size();
        for (int i = 0; i < NumberOfGroups; i++) {
            //!!!!!!!!!!!!!!!get last metrics of each group
            double x = (Double) group.get(i).getUps().get(0).getProperty_value();
            double y = (Double) group.get(i).getUps().get(1).getProperty_value();

            AverageGroupVec.x += x / NumberOfGroups;
            AverageGroupVec.y += y / NumberOfGroups;
        }
        double x = UserVec.x;
        double y = UserVec.y;
        //if the group's metrics are greater, change the UserVector to include the group's achievments
        if (UserVec.x < AverageGroupVec.x) {
            double k = 1 / 2 + 1 / 2 + Math.tanh(2 * ((AverageGroupVec.x - UserVec.x) - 1));
            x = UserVec.x + k * (AverageGroupVec.x - UserVec.x);
        }
        if (UserVec.y < AverageGroupVec.y) {
            double k = 1 / 2 + 1 / 2 + Math.tanh(2 * ((AverageGroupVec.x - UserVec.x) - 1));
            y = UserVec.y + k * (AverageGroupVec.y - UserVec.y);
        }
        UserVec = new Vec(x, y);
        Vec Creativity = new Vec(UserVec.x / D + (D - 1) * OldCreativityX / D,
                UserVec.y / D + (D - 1) * OldCreativityY / D);
        return Creativity;
    } catch (MWException ex) {
        Logger.getLogger(MachineLearningComponents.class.getName()).log(Level.SEVERE, null, ex);
        return new Vec(0, 0);
    }
}

From source file:net.mindengine.blogix.BlogixMain.java

private static String getLastEntryInFolder(String entryFolder) {
    File folder = new File("db" + File.separator + entryFolder);
    File[] files = folder.listFiles();

    ArrayList<File> entryFiles = new ArrayList<File>();
    for (File file : files) {
        if (file.getName().endsWith(_BLOGIX_SUFFIX)) {
            entryFiles.add(file);/* w w  w.  java2  s  .c  o m*/
        }
    }
    Collections.sort(entryFiles, byLastModified());
    if (entryFiles.size() > 0) {
        return trimBlogixSuffixFromEntryFileName(entryFiles.get(0).getName());
    }
    error("There are no entries in '" + entryFolder + "'");
    return null;
}