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:dm_p2.DBSCAN.java

public static double kdist(gene g1, gene g2) {
    ArrayList<Double> gene1 = g1.getexp();
    ArrayList<Double> gene2 = g2.getexp();
    double distance = 0.0;
    for (int k = 0; k < gene1.size(); k++) {
        distance += Math.pow((gene1.get(k) - gene2.get(k)), 2);
    }//from  ww  w.  j a v  a2s . c o  m
    return Math.sqrt(distance);
}

From source file:Main.java

public static long[] getLongArrayfromString(final String string, final char token) {
    if (string == null)
        return new long[0];
    final String[] items_string_array = string.split(String.valueOf(token));
    final ArrayList<Long> items_list = new ArrayList<Long>();
    for (final String id_string : items_string_array) {
        try {// www  .ja  va2  s .c o m
            items_list.add(Long.parseLong(id_string));
        } catch (final NumberFormatException e) {
            // Ignore.
        }
    }
    final int list_size = items_list.size();
    final long[] array = new long[list_size];
    for (int i = 0; i < list_size; i++) {
        array[i] = items_list.get(i);
    }
    return array;
}

From source file:com.bc.fiduceo.db.MongoDbDriver.java

@SuppressWarnings("unchecked")
static List<PolygonCoordinates> gePolygonCoordinates(MultiPolygon multiPolygon) {
    List<Polygon> s2PolygonList = (List<Polygon>) multiPolygon.getInner();
    List<PolygonCoordinates> polygonCoordinatesList = new ArrayList<>();
    for (Polygon s2Polygon : s2PolygonList) {
        ArrayList<Position> positions = extractPointsFromGeometry(s2Polygon.getCoordinates());

        if (!positions.get(0).equals(positions.get(positions.size() - 1))) {
            positions.add(positions.get(0));
        }//from  w ww. j  av  a2s . c  om
        polygonCoordinatesList.add(new PolygonCoordinates(positions));
    }
    return polygonCoordinatesList;
}

From source file:eu.eexcess.partnerdata.evaluation.enrichment.PartnerRecommenderEvaluationTestHelper.java

static public StringEntity createParamsForPartnerRecommender(int records, ArrayList<String> keywords) {
    StringEntity params = null;//from  w ww.  j av a  2  s.com
    try {
        String userprofile = "<eexcess-secure-user-profile numResults=\"" + records
                + "\" firstName=\"Hugo\" lastName=\"Boss\" birthDate=\"2013-10-14T05:06:44.550+02:00\">   <contextKeywords>      ";
        for (int i = 0; i < keywords.size(); i++) {
            userprofile += "<contextKeywords><text>" + keywords.get(i) + "</text></contextKeywords>";
        }
        userprofile += " </contextKeywords></eexcess-secure-user-profile>";
        params = new StringEntity(userprofile);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return params;
}

From source file:id.zelory.tanipedia.util.Utils.java

public static ArrayList<Berita> getRandomBerita(Context context, String alamat) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayList<Berita> beritaArrayList = null;
    try {//from   w  w w. j  a  v  a 2s. com
        beritaArrayList = mapper.readValue(PrefUtils.ambilString(context, "berita"),
                mapper.getTypeFactory().constructCollectionType(ArrayList.class, Berita.class));
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < 5; i++) {
        int x = randInt(0, beritaArrayList.size() - 1);
        if (beritaArrayList.get(x).getAlamat().equals(alamat)) {
            beritaArrayList.remove(x);
            i--;
        } else {
            beritaArrayList.set(i, beritaArrayList.get(x));
            beritaArrayList.remove(x);
        }
    }

    for (int i = 5; i < beritaArrayList.size(); i++)
        beritaArrayList.remove(i);

    return beritaArrayList;
}

From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java

/**
 * Creates a <code>Graph</code> which is a vertex-folded version of <code>h</code>, whose
 * vertices are the input's hyperedges and whose edges are induced by adjacent hyperedges
 * in the input.//from w  ww. j a v  a  2 s. c  om
 * 
 * <p>The vertices of the new graph are the same objects as the hyperedges of 
 * <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding edges
 * in <code>h</code> have a vertex in common.  Thus, each vertex incident to  
 * <i>k</i> edges in <code>h</code> induces a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>The edges of the new graph are created by the specified factory.</p>
 * 
 * @param <V> vertex type
 * @param <E> input edge type
 * @param <F> output edge type
 * @param h hypergraph to be folded
 * @param graph_factory factory used to generate the output graph
 * @param edge_factory factory used to generate the output edges
 * @return a transformation of the input graph whose vertices correspond to the input's hyperedges 
 * and edges are induced by hyperedges sharing vertices in the input
 */
public static <V, E, F> Graph<E, F> foldHypergraphVertices(Hypergraph<V, E> h,
        Factory<Graph<E, F>> graph_factory, Factory<F> edge_factory) {
    Graph<E, F> target = graph_factory.create();

    for (E e : h.getEdges())
        target.addVertex(e);

    for (V v : h.getVertices()) {
        ArrayList<E> incident = new ArrayList<E>(h.getIncidentEdges(v));
        for (int i = 0; i < incident.size(); i++)
            for (int j = i + 1; j < incident.size(); j++)
                target.addEdge(edge_factory.create(), incident.get(i), incident.get(j));
    }

    return target;
}

From source file:com.ibm.rtc.automation.examples.client.RTCUserUtil.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void listUsers(ITeamRepository repo) throws TeamRepositoryException {
    IContributorManager icm = repo.contributorManager();
    List allContribs = icm.fetchAllContributors(null);
    //System.out.println(allContribs.size());
    ArrayList clone = new ArrayList();
    clone.addAll(allContribs);/*from www . jav a  2  s  .  c  om*/
    Collections.sort(clone, new UserComparator());

    int allContribSize = clone.size();
    for (int i = 0; i < allContribSize; i++) {
        IContributor user = (IContributor) clone.get(i);

        System.out.println(user.getName());
    }
    System.out.println("There are " + allContribSize + " total users in the repository");
}

From source file:Main.java

/**
 * Inverse of {@link #getDescendantCoordRelativeToSelf(View, int[])}.
 *//*from  w  ww. j ava 2  s  .c o  m*/
public static float mapCoordInSelfToDescendent(View descendant, View root, int[] coord) {
    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;
    Matrix inverse = new Matrix();
    int count = ancestorChain.size();
    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(inverse);
            inverse.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}

From source file:com.ibm.rtc.automation.examples.client.RTCUserUtil.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void listUsersEmail(ITeamRepository repo) throws TeamRepositoryException {
    IContributorManager icm = repo.contributorManager();
    List allContribs = icm.fetchAllContributors(null);
    //System.out.println(allContribs.size());
    ArrayList clone = new ArrayList();
    clone.addAll(allContribs);/*from  w  w w.j ava2s .co m*/
    Collections.sort(clone, new UserComparator());

    int allContribSize = clone.size();
    for (int i = 0; i < allContribSize; i++) {
        IContributor user = (IContributor) clone.get(i);
        if (!user.isArchived()) {
            System.out.println(user.getUserId() + " ," + user.getEmailAddress());
        }
    }
    System.out.println("There are " + allContribSize + " total users in the repository");
}

From source file:edu.uci.ics.jung.algorithms.transformation.FoldingTransformer.java

/**
 * Creates a <code>Graph</code> which is an edge-folded version of <code>h</code>, where
 * hyperedges are replaced by k-cliques in the output graph.
 * /*from   w  w w.ja  v  a2  s.  c  om*/
 * <p>The vertices of the new graph are the same objects as the vertices of 
 * <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding vertices
 * in <code>h</code> are connected by a hyperedge.  Thus, each hyperedge with 
 * <i>k</i> vertices in <code>h</code> induces a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>The edges of the new graph are generated by the specified edge factory.</p>
 * 
 * @param <V> vertex type
 * @param <E> input edge type
 * @param h hypergraph to be folded
 * @param graph_factory factory used to generate the output graph
 * @param edge_factory factory used to create the new edges 
 * @return a copy of the input graph where hyperedges are replaced by cliques
 */
public static <V, E> Graph<V, E> foldHypergraphEdges(Hypergraph<V, E> h, Factory<Graph<V, E>> graph_factory,
        Factory<E> edge_factory) {
    Graph<V, E> target = graph_factory.create();

    for (V v : h.getVertices())
        target.addVertex(v);

    for (E e : h.getEdges()) {
        ArrayList<V> incident = new ArrayList<V>(h.getIncidentVertices(e));
        for (int i = 0; i < incident.size(); i++)
            for (int j = i + 1; j < incident.size(); j++)
                target.addEdge(edge_factory.create(), incident.get(i), incident.get(j));
    }
    return target;
}