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:Main.java

static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) {
    ArrayList<String> basePath = getPathComponents(canonicalBaseFile);
    ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize);

    //if the roots aren't the same (i.e. different drives on a windows machine), we can't construct a relative
    //path from one to the other, so just return the canonical file
    if (!basePath.get(0).equals(pathToRelativize.get(0))) {
        return canonicalFileToRelativize.getPath();
    }/*from w  w  w . j  av  a2s  .  c  o  m*/

    int commonDirs;
    StringBuilder sb = new StringBuilder();

    for (commonDirs = 1; commonDirs < basePath.size() && commonDirs < pathToRelativize.size(); commonDirs++) {
        if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) {
            break;
        }
    }

    boolean first = true;
    for (int i = commonDirs; i < basePath.size(); i++) {
        if (!first) {
            sb.append(File.separatorChar);
        } else {
            first = false;
        }

        sb.append("..");
    }

    first = true;
    for (int i = commonDirs; i < pathToRelativize.size(); i++) {
        if (first) {
            if (sb.length() != 0) {
                sb.append(File.separatorChar);
            }
            first = false;
        } else {
            sb.append(File.separatorChar);
        }

        sb.append(pathToRelativize.get(i));
    }

    if (sb.length() == 0) {
        return ".";
    }

    return sb.toString();
}

From source file:com.gst.integrationtests.common.CenterHelper.java

public static int[] associateGroups(final int id, final int[] groupMembers,
        final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
    final String ASSOCIATE_GROUP_CENTER_URL = CENTERS_URL + "/" + id + "?command=associateGroups&"
            + Utils.TENANT_IDENTIFIER;/*w w  w .j av a  2 s.c o  m*/
    HashMap groupMemberHashMap = new HashMap();
    groupMemberHashMap.put("groupMembers", groupMembers);
    System.out.println("---------------------------------ASSOCIATING GROUPS AT " + id
            + "--------------------------------------------");
    HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL,
            new Gson().toJson(groupMemberHashMap), "changes");
    System.out.println(hash);
    ArrayList<String> arr = (ArrayList<String>) hash.get("groupMembers");
    int[] ret = new int[arr.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = Integer.parseInt(arr.get(i));
    }
    return ret;
}

From source file:Main.java

/**
 * Given a coordinate relative to the descendant, find the coordinate in a parent view's
 * coordinates.//  w w  w  . ja  va 2 s .co m
 *
 * @param descendant The descendant to which the passed coordinate is relative.
 * @param root The root view to make the coordinates relative to.
 * @param coord The coordinate that we want mapped.
 * @param includeRootScroll Whether or not to account for the scroll of the descendant:
 *          sometimes this is relevant as in a child's coordinates within the descendant.
 * @return The factor by which this descendant is scaled relative to this DragLayer. Caution
 *         this scale factor is assumed to be equal in X and Y, and so if at any point this
 *         assumption fails, we will need to return a pair of scale factors.
 */
public static float getDescendantCoordRelativeToParent(View descendant, View root, int[] 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] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}

From source file:edu.cmu.cs.lti.util.general.BasicConvenience.java

public static int[] ArrayOfIntegers2intArray(ArrayList<Integer> in) {
    int[] result = new int[in.size()];
    for (int i = 0; i < in.size(); i++) {
        result[i] = in.get(i);
    }//from   w  w w.  jav  a2s. c o m
    return result;
}

From source file:Main.java

public static void showOnSameScreenAsMouseCenter(Container frame) {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();

    GraphicsDevice device;//  ww  w. jav  a2  s . co  m

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();

    ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length);

    for (GraphicsDevice gd : lstGDs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screenBounds = gc.getBounds();

        if (screenBounds.contains(mouseLocation)) {
            lstDevices.add(gd);
        }
    }

    if (lstDevices.size() > 0) {
        device = lstDevices.get(0);
    } else {
        device = ge.getDefaultScreenDevice();
    }

    Rectangle bounds = device.getDefaultConfiguration().getBounds();
    frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2,
            bounds.y + bounds.height / 2 - frame.getHeight() / 2);
}

From source file:DBClust.java

public static void Ident(double[] eps, int[] minPts, int[] pixelSize, boolean[] doCluster) {
    ArrayList<Particle> InpParticle = TableIO.Load(); // Get current table data.

    ij.measure.ResultsTable tab = Analyzer.getResultsTable();
    double width = tab.getValue("width", 0);
    double height = tab.getValue("height", 0);
    tab.reset();/*from   www . ja v  a  2s .  com*/
    //      tab.incrementCounter();

    for (int Ch = 1; Ch <= InpParticle.get(InpParticle.size() - 1).channel; Ch++) {
        if (doCluster[Ch - 1]) {
            List<DoublePoint> points = new ArrayList<DoublePoint>();

            for (int i = 0; i < InpParticle.size(); i++) {
                double[] p = new double[2];
                if (InpParticle.get(i).include == 1 && InpParticle.get(i).channel == Ch) {
                    p[0] = InpParticle.get(i).x;
                    p[1] = InpParticle.get(i).y;
                    points.add(new DoublePoint(p));
                }
            }
            DBSCANClusterer<DoublePoint> DB = new DBSCANClusterer<DoublePoint>(eps[Ch - 1], minPts[Ch - 1]);
            List<Cluster<DoublePoint>> cluster = DB.cluster(points);
            int ClustIdx = 1;
            int[] IndexList = new int[InpParticle.size()];
            for (Cluster<DoublePoint> c : cluster) {
                for (int j = 0; j < c.getPoints().size(); j++) {
                    DoublePoint p = c.getPoints().get(j);
                    double[] Coord = p.getPoint();
                    for (int i = 0; i < InpParticle.size(); i++) {
                        Particle tempParticle = InpParticle.get(i);
                        if (tempParticle.x == Coord[0] && tempParticle.y == Coord[1]) {
                            IndexList[i] = ClustIdx;
                        }
                    }
                }
                ClustIdx++;
            }
            boolean first = true;
            for (int i = 0; i < InpParticle.size(); i++) {

                if (InpParticle.get(i).channel == Ch) {
                    tab.incrementCounter();
                    tab.addValue("Cluster", IndexList[i]);
                    tab.addValue("x0", InpParticle.get(i).x);
                    tab.addValue("y0", InpParticle.get(i).y);
                    tab.addValue("z0", InpParticle.get(i).z);
                    tab.addValue("frame", InpParticle.get(i).frame);
                    tab.addValue("channel", InpParticle.get(i).channel);
                    tab.addValue("sigma_x", InpParticle.get(i).sigma_x);
                    tab.addValue("sigma_y", InpParticle.get(i).sigma_y);
                    tab.addValue("precision_x", InpParticle.get(i).precision_x);
                    tab.addValue("precision_y", InpParticle.get(i).precision_y);
                    tab.addValue("precision_z", InpParticle.get(i).precision_z);
                    tab.addValue("r_square", InpParticle.get(i).r_square);
                    tab.addValue("photons", InpParticle.get(i).photons);
                    if (IndexList[i] > 0)
                        tab.addValue("include", 1);
                    else
                        tab.addValue("include", 0);
                    if (first) {
                        first = false;
                        tab.addValue("width", width);
                        tab.addValue("height", height);
                    }
                }
            }
        }
    } // Channel loop.
    tab.show("Results");

    RenderIm.run(doCluster, pixelSize, false);

}

From source file:com.facebook.tsdb.tsdash.server.model.Metric.java

private static boolean arrayIsSorted(ArrayList<DataPoint> array) {
    for (int i = 0; i < array.size() - 1; i++) {
        if (array.get(i).compareTo(array.get(i + 1)) > 0) {
            return false;
        }/*from w w w.ja v a  2 s .c o m*/
    }
    return true;
}

From source file:Main.java

public static long[] fromString(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 {//from w ww. ja v  a2s .  com
            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.remobile.file.Filesystem.java

/**
 * Removes multiple repeated //s, and collapses processes ../s.
 *//*from   ww  w .j av a 2s.com*/
protected static String normalizePath(String rawPath) {
    // If this is an absolute path, trim the leading "/" and replace it later
    boolean isAbsolutePath = rawPath.startsWith("/");
    if (isAbsolutePath) {
        rawPath = rawPath.replaceFirst("/+", "");
    }
    ArrayList<String> components = new ArrayList<String>(Arrays.asList(rawPath.split("/+")));
    for (int index = 0; index < components.size(); ++index) {
        if (components.get(index).equals("..")) {
            components.remove(index);
            if (index > 0) {
                components.remove(index - 1);
                --index;
            }
        }
    }
    StringBuilder normalizedPath = new StringBuilder();
    for (String component : components) {
        normalizedPath.append("/");
        normalizedPath.append(component);
    }
    if (isAbsolutePath) {
        return normalizedPath.toString();
    } else {
        return normalizedPath.toString().substring(1);
    }
}

From source file:Main.java

public static long[] parseLongArray(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 {/*from w w  w  .j av a 2  s .  c om*/
            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;
}