Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

In this page you can find the example usage for java.util ArrayList contains.

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:edu.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewPieChartPanel.java

/**
 * @return the data of the number of requirements a user has assigned to
 *         them//from w  w  w.  ja  v  a 2 s . c o  m
 */
private static PieDataset setDataAssignTo() {
    DefaultPieDataset dataSet = new DefaultPieDataset();
    ArrayList<String> userNames = new ArrayList<String>();

    List<Requirement> requirements = RequirementModel.getInstance().getRequirements();// list of requirements
    for (int i = 0; i < requirements.size(); i++) {
        List<String> users = requirements.get(i).getAssignedTo();// list of
                                                                 // users
                                                                 // for
                                                                 // specific
                                                                 // requirement
        for (int j = 0; j < users.size(); j++) {
            if (!userNames.contains(users.get(j))) {
                userNames.add(users.get(j));// populate a list of all users
            }
        }

    }
    int[] numReqAssigned = new int[userNames.size()];
    for (int i = 0; i < requirements.size(); i++) {
        List<String> users = requirements.get(i).getAssignedTo();
        for (int j = 0; j < userNames.size(); j++) {
            if (users.contains(userNames.get(j))) {
                numReqAssigned[j]++;// count the number of requirements a
                                    // user has assigned to them
            }
        }
    }
    for (int k = 0; k < userNames.size(); k++) {
        dataSet.setValue(userNames.get(k), numReqAssigned[k]);// populate
                                                              // pie chart
                                                              // data
    }
    return dataSet;
}

From source file:fr.fg.server.core.TerritoryManager.java

private static BufferedImage createTerritoryMap(int idSector) {
    List<Area> areas = new ArrayList<Area>(DataAccess.getAreasBySector(idSector));

    float[][] points = new float[areas.size()][2];
    int[] dominatingAllies = new int[areas.size()];
    int i = 0;/*  w  w w  .j a  v a 2s  . c  om*/
    for (Area area : areas) {
        points[i][0] = area.getX() * MAP_SCALE;
        points[i][1] = area.getY() * MAP_SCALE;
        dominatingAllies[i] = area.getIdDominatingAlly();
        i++;
    }

    Hull hull = new Hull(points);
    MPolygon hullPolygon = hull.getRegion();
    float[][] newPoints = new float[points.length + hullPolygon.count()][2];
    System.arraycopy(points, 0, newPoints, 0, points.length);

    float[][] hullCoords = hullPolygon.getCoords();

    for (i = 0; i < hullPolygon.count(); i++) {
        double angle = Math.atan2(hullCoords[i][1], hullCoords[i][0]);
        double length = Math.sqrt(hullCoords[i][0] * hullCoords[i][0] + hullCoords[i][1] * hullCoords[i][1]);

        newPoints[i + points.length][0] = (float) (Math.cos(angle) * (length + 8 * MAP_SCALE));
        newPoints[i + points.length][1] = (float) (Math.sin(angle) * (length + 8 * MAP_SCALE));
    }

    points = newPoints;

    Voronoi voronoi = new Voronoi(points);
    Delaunay delaunay = new Delaunay(points);

    // Dcoupage en rgions
    MPolygon[] regions = voronoi.getRegions();

    // Calcule le rayon de la galaxie
    int radius = 0;

    for (Area area : areas) {
        radius = Math.max(radius, area.getX() * area.getX() + area.getY() * area.getY());
    }

    radius = (int) Math.floor(Math.sqrt(radius) * MAP_SCALE) + 10 * MAP_SCALE;
    int diameter = 2 * radius + 1;

    // Construit l'image avec les quadrants
    BufferedImage territoriesImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) territoriesImage.getGraphics();

    // Affecte une couleur  chaque alliance
    HashMap<Integer, Color> alliesColors = new HashMap<Integer, Color>();

    for (Area area : areas) {
        int idDominatingAlly = area.getIdDominatingAlly();
        if (idDominatingAlly != 0)
            alliesColors.put(idDominatingAlly,
                    Ally.TERRITORY_COLORS[DataAccess.getAllyById(idDominatingAlly).getColor()]);
    }

    Polygon[] polygons = new Polygon[regions.length];
    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] != 0) {
            polygons[i] = createPolygon(regions[i].getCoords(), radius + 1, 3);
        }
    }

    // Dessine tous les secteurs
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        Polygon p = polygons[i];

        // Dessine le polygone
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.fill(p);

        // Rempli les espaces entre les polygones adjacents qui
        // correspondent au territoire d'une mme alliance
        int[] linkedRegions = delaunay.getLinked(i);
        for (int j = 0; j < linkedRegions.length; j++) {
            int linkedRegion = linkedRegions[j];

            if (linkedRegion >= areas.size())
                continue;

            if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                if (linkedRegion <= i)
                    continue;

                float[][] coords1 = regions[i].getCoords();
                float[][] coords2 = regions[linkedRegion].getCoords();

                int junctionIndex = 0;
                int[][] junctions = new int[2][2];

                search: for (int k = 0; k < coords1.length; k++) {
                    for (int l = 0; l < coords2.length; l++) {
                        if (coords1[k][0] == coords2[l][0] && coords1[k][1] == coords2[l][1]) {
                            junctions[junctionIndex][0] = k;
                            junctions[junctionIndex][1] = l;

                            junctionIndex++;

                            if (junctionIndex == 2) {
                                int[] xpts = new int[] { polygons[i].xpoints[junctions[0][0]],
                                        polygons[linkedRegion].xpoints[junctions[0][1]],
                                        polygons[linkedRegion].xpoints[junctions[1][1]],
                                        polygons[i].xpoints[junctions[1][0]], };
                                int[] ypts = new int[] { polygons[i].ypoints[junctions[0][0]],
                                        polygons[linkedRegion].ypoints[junctions[0][1]],
                                        polygons[linkedRegion].ypoints[junctions[1][1]],
                                        polygons[i].ypoints[junctions[1][0]], };

                                Polygon border = new Polygon(xpts, ypts, 4);
                                g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
                                g.fill(border);
                                g.draw(border);
                                break search;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    // Dessine des lignes de contours des territoires
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        g.setStroke(new BasicStroke(1.5f));
        g.setColor(alliesColors.get(dominatingAllies[i]).brighter().brighter());

        float[][] coords1 = regions[i].getCoords();

        lines: for (int j = 0; j < coords1.length; j++) {
            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]
                                && ((coords1[(j + 1) % coords1.length][0] == coords2[(m + 1)
                                        % coords2.length][0]
                                        && coords1[(j + 1) % coords1.length][1] == coords2[(m + 1)
                                                % coords2.length][1])
                                        || (coords1[(j + 1)
                                                % coords1.length][0] == coords2[(m - 1 + coords2.length)
                                                        % coords2.length][0]
                                                && coords1[(j + 1)
                                                        % coords1.length][1] == coords2[(m - 1 + coords2.length)
                                                                % coords2.length][1]))) {
                            continue lines;
                        }
                    }
                }
            }

            g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                    Math.round(polygons[i].xpoints[(j + 1) % coords1.length]),
                    Math.round(polygons[i].ypoints[(j + 1) % coords1.length]));
        }

        for (int j = 0; j < coords1.length; j++) {
            int neighbours = 0;
            int lastNeighbourRegion = -1;
            int neighbourCoordsIndex = -1;

            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]) {
                            neighbours++;
                            lastNeighbourRegion = linkedRegion;
                            neighbourCoordsIndex = m;
                            break;
                        }
                    }
                }
            }

            if (neighbours == 1) {
                g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                        Math.round(polygons[lastNeighbourRegion].xpoints[neighbourCoordsIndex]),
                        Math.round(polygons[lastNeighbourRegion].ypoints[neighbourCoordsIndex]));
            }
        }
    }

    BufferedImage finalImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    g = (Graphics2D) finalImage.getGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .15f));
    g.drawImage(territoriesImage, 0, 0, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .5f));

    // Charge la police pour afficher le nom des alliances
    try {
        Font textFont = Font.createFont(Font.TRUETYPE_FONT,
                Action.class.getClassLoader().getResourceAsStream("fr/fg/server/resources/TinDog.ttf"));
        textFont = textFont.deriveFont(12f).deriveFont(Font.BOLD);
        g.setFont(textFont);
    } catch (Exception e) {
        LoggingSystem.getServerLogger().warn("Could not load quadrant map font.", e);
    }
    FontMetrics fm = g.getFontMetrics();

    ArrayList<Integer> closedRegions = new ArrayList<Integer>();

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0 || closedRegions.contains(i))
            continue;

        ArrayList<Integer> allyRegions = new ArrayList<Integer>();
        ArrayList<Integer> openRegions = new ArrayList<Integer>();

        openRegions.add(i);

        while (openRegions.size() > 0) {
            int currentRegion = openRegions.remove(0);
            allyRegions.add(currentRegion);
            closedRegions.add(currentRegion);

            int[] linkedRegions = delaunay.getLinked(currentRegion);

            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size() || openRegions.contains(linkedRegion)
                        || allyRegions.contains(linkedRegion))
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion])
                    openRegions.add(linkedRegion);
            }
        }

        Area area = areas.get(i);
        long xsum = 0;
        long ysum = 0;

        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);
            area = areas.get(allyRegion);

            xsum += area.getX();
            ysum += area.getY();
        }

        int x = (int) (xsum / allyRegions.size()) * MAP_SCALE + radius + 1;
        int y = (int) (-ysum / allyRegions.size()) * MAP_SCALE + radius + 1;
        ;

        Point point = new Point(x, y);
        boolean validLocation = false;
        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);

            if (polygons[allyRegion].contains(point)) {
                validLocation = true;
                break;
            }
        }

        if (validLocation) {
            if (allyRegions.size() == 1)
                y -= 14;
        } else {
            int xmid = (int) (xsum / allyRegions.size());
            int ymid = (int) (ysum / allyRegions.size());

            area = areas.get(i);
            int dx = area.getX() - xmid;
            int dy = area.getY() - ymid;
            int distance = dx * dx + dy * dy;

            int nearestAreaIndex = i;
            int nearestDistance = distance;

            for (int k = 0; k < allyRegions.size(); k++) {
                int allyRegion = allyRegions.get(k);

                area = areas.get(allyRegion);
                dx = area.getX() - xmid;
                dy = area.getY() - ymid;
                distance = dx * dx + dy * dy;

                if (distance < nearestDistance) {
                    nearestAreaIndex = allyRegion;
                    nearestDistance = distance;
                }
            }

            area = areas.get(nearestAreaIndex);
            x = area.getX() * MAP_SCALE + radius + 1;
            y = -area.getY() * MAP_SCALE + radius - 13;
        }

        // Dessine le tag de l'alliance
        String allyTag = "[ " + DataAccess.getAllyById(dominatingAllies[i]).getTag() + " ]";
        g.setColor(Color.BLACK);
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2 + 1, y);
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2, y);
    }

    return finalImage;
}

From source file:edu.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewBarChartPanel.java

/**
 * @return the data of the number of requirements a user has assigned to
 *         them/*from w ww.j  a v  a  2s.  com*/
 */
private static CategoryDataset setDataAssignTo() {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    ArrayList<String> userNames = new ArrayList<String>();

    List<Requirement> requirements = RequirementModel.getInstance().getRequirements();// list of requirements
    for (int i = 0; i < requirements.size(); i++) {
        List<String> users = requirements.get(i).getAssignedTo();// list of
                                                                 // users
                                                                 // for
                                                                 // specific
                                                                 // requirement
        for (int j = 0; j < users.size(); j++) {
            if (!userNames.contains(users.get(j))) {
                userNames.add(users.get(j));// populate a list of all users
            }
        }

    }
    int[] numReqAssigned = new int[userNames.size()];
    for (int i = 0; i < requirements.size(); i++) {
        List<String> users = requirements.get(i).getAssignedTo();
        for (int j = 0; j < userNames.size(); j++) {
            if (users.contains(userNames.get(j))) {
                numReqAssigned[j]++;// count the number of requirements a
                                    // user has assigned to them
            }
        }
    }
    for (int k = 0; k < userNames.size(); k++) {
        dataSet.setValue(numReqAssigned[k], userNames.get(k), "Assigned To");// populate
        // bar chart
        // data
    }
    return dataSet;
}

From source file:com.ikon.module.jcr.stuff.JCRUtils.java

/**
 * Convert a Value array to String array and add a user id.
 */// w  w w  .ja  va2s  .  c  om
public static String[] usrValue2String(Value[] values, String usrId)
        throws ValueFormatException, IllegalStateException, javax.jcr.RepositoryException {
    ArrayList<String> list = new ArrayList<String>();

    for (int i = 0; i < values.length; i++) {
        // Admin and System user is not propagated across the child nodes
        if (!values[i].getString().equals(Config.SYSTEM_USER)
                && !values[i].getString().equals(Config.ADMIN_USER)) {
            list.add(values[i].getString());
        }
    }

    if (Config.USER_ASSIGN_DOCUMENT_CREATION) {
        // No add an user twice
        if (!list.contains(usrId)) {
            list.add(usrId);
        }
    }

    return (String[]) list.toArray(new String[list.size()]);
}

From source file:com.occamlab.te.parsers.ImageParser.java

/**
 * Gets the supported image types in the ImageIO class (gives a
 * comma-seperated list)/*from  w  w  w .  java 2  s .  c  om*/
 */
public static String getSupportedImageTypes() {
    String[] readers = ImageIO.getReaderFormatNames();
    ArrayList<String> imageArray = new ArrayList<String>();
    String str = "";
    for (int i = 0; i < readers.length; i++) {
        String current = readers[i].toLowerCase();
        if (!imageArray.contains(current)) {
            imageArray.add(current);
            str += current + ",";
        }
    }
    return str.substring(0, str.lastIndexOf(","));
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Makes the given file name valid for a Windows operating system.
 *
 * @param filename the file name to be cleansed
 * @return the cleansed file name//from  w  w  w .j av  a 2  s.  c  o  m
 */
public static String cleanseFileName(String filename) {
    filename = filename.trim();
    filename = filename.replaceAll("[<>:\"/\\\\|?*]", "");
    filename = filename.trim();
    if (!filename.isEmpty() && filename.charAt(filename.length() - 1) == '.')
        filename = filename.substring(0, filename.length() - 1);
    filename = filename.trim();
    ArrayList<String> arr = new ArrayList<>(Arrays.asList(
            new String[] { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
                    "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" }));
    if (filename.isEmpty() || arr.contains(filename))
        filename = "newfile";
    filename = filename.trim();
    return filename;
}

From source file:Debug.java

public static boolean compare(String prefix, Map a, Map b, ArrayList ignore, StringBuffer buffer) {
    if ((a == null) && (b == null)) {
        log(buffer, prefix + " both maps null");
        return true;
    }/*from www.j av  a2 s .co m*/
    if (a == null) {
        log(buffer, prefix + " map a: null, map b: map");
        return false;
    }
    if (b == null) {
        log(buffer, prefix + " map a: map, map b: null");
        return false;
    }

    ArrayList keys_a = new ArrayList(a.keySet());
    ArrayList keys_b = new ArrayList(b.keySet());

    if (ignore != null) {
        keys_a.removeAll(ignore);
        keys_b.removeAll(ignore);
    }

    boolean result = true;

    for (int i = 0; i < keys_a.size(); i++) {
        Object key = keys_a.get(i);
        if (!keys_b.contains(key)) {
            log(buffer, prefix + "b is missing key '" + key + "' from a");
            result = false;
        } else {
            keys_b.remove(key);
            Object value_a = a.get(key);
            Object value_b = b.get(key);
            if (!value_a.equals(value_b)) {
                log(buffer, prefix + "key(" + key + ") value a: " + value_a + ") !=  b: " + value_b + ")");
                result = false;
            }
        }
    }
    for (int i = 0; i < keys_b.size(); i++) {
        Object key = keys_b.get(i);

        log(buffer, prefix + "a is missing key '" + key + "' from b");
        result = false;
    }

    if (result)
        log(buffer, prefix + "a is the same as  b");

    return result;
}

From source file:eionet.acl.PersistenceDB.java

/**
 * Merges one CSV permissions String with the other avoiding duplicates.
 * Example: Result of merging "a,b,c,d" and "a,x,c,y" is "a,b,c,d,x,y"
 * @param existingPermissions existing permissions
 * @param newPermissions new permissions String
 * @return merged string/*from   w w w . j a  v a  2 s  .c  o m*/
 */
private static String mergePermissions(String existingPermissions, String newPermissions) {
    StringTokenizer oldPerms = new StringTokenizer(existingPermissions, ",");
    StringTokenizer newPerms = new StringTokenizer(newPermissions, ",");

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

    while (oldPerms.hasMoreTokens()) {
        allPerms.add(oldPerms.nextToken());
    }

    while (newPerms.hasMoreTokens()) {
        String p = newPerms.nextToken();
        if (!allPerms.contains(p)) {
            allPerms.add(p);
        }
    }
    return StringUtils.join(allPerms, ",");

}

From source file:com.yamin.kk.vlc.Util.java

public static String[] getStorageDirectories() {
    String[] dirs = null;/*from   ww  w  .j av  a 2 s .c  o m*/
    BufferedReader bufReader = null;
    try {
        bufReader = new BufferedReader(new FileReader("/proc/mounts"));
        ArrayList<String> list = new ArrayList<String>();
        list.add(Environment.getExternalStorageDirectory().getPath());
        String line;
        while ((line = bufReader.readLine()) != null) {
            if (line.contains("vfat") || line.contains("exfat") || line.contains("/mnt")
                    || line.contains("/Removable")) {
                StringTokenizer tokens = new StringTokenizer(line, " ");
                String s = tokens.nextToken();
                s = tokens.nextToken(); // Take the second token, i.e. mount point

                if (list.contains(s))
                    continue;

                if (line.contains("/dev/block/vold")) {
                    if (!line.startsWith("tmpfs") && !line.startsWith("/dev/mapper")
                            && !s.startsWith("/mnt/secure") && !s.startsWith("/mnt/shell")
                            && !s.startsWith("/mnt/asec") && !s.startsWith("/mnt/obb")) {
                        list.add(s);
                    }
                }
            }
        }

        dirs = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            dirs[i] = list.get(i);
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } finally {
        if (bufReader != null) {
            try {
                bufReader.close();
            } catch (IOException e) {
            }
        }
    }
    return dirs;
}

From source file:ca.sfu.federation.utils.IContextUtils.java

public static ArrayList<INamed> getElementsInTopologicalOrder(Map<String, INamed> ElementMap)
        throws GraphCycleException {
    ArrayList<INamed> sorted = new ArrayList<INamed>();
    Iterator iter = ElementMap.values().iterator();
    while (iter.hasNext()) {
        INamed named = (INamed) iter.next();
        if (named instanceof IGraphable) {
            IGraphable graphobject = (IGraphable) named;
            // get dependancies for the node
            LinkedHashMap deps = (LinkedHashMap) graphobject.getDependancies();
            // for each dependancy, do a topological sort on its subgraph
            Iterator it = deps.values().iterator();
            while (it.hasNext()) {
                INamed namedDep = (INamed) it.next();
                getElementsInTopologicalOrder(namedDep, sorted);
            }//from  w  w w.  j ava2  s  .c om
            // insert self into list
            if (!sorted.contains(named)) {
                sorted.add(named);
            }
        } else {
            // what should we do with an object that does not have dependancies?
        }
    }
    // return result
    return sorted;
}