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

/**
 * Returns a List of Lists: all combinations of the elements of the given
 * List.// w w w .  ja  v a2s  .co m
 *
 * @param maxCombinationSize combinations larger than this value are
 * discarded
 * @param mandatoryItem an item that all returned combinations must contain,
 * or null to leave unspecified
 */
public static List combinations(List original, int maxCombinationSize, Object mandatoryItem) {
    ArrayList combinations = new ArrayList();

    //Combinations are given by the bits of each binary number from 1 to 2^N
    for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) {
        ArrayList combination = new ArrayList();
        for (int j = 0; j < original.size(); j++) {
            if ((i & (int) Math.pow(2, j)) > 0) {
                combination.add(original.get(j));
            }
        }
        if (combination.size() > maxCombinationSize) {
            continue;
        }
        if ((mandatoryItem != null) && !combination.contains(mandatoryItem)) {
            continue;
        }
        combinations.add(combination);
    }

    return combinations;
}

From source file:com.clust4j.algo.preprocess.impute.NearestNeighborImputation.java

private static double[] exclude(double[] vec, ArrayList<Integer> exclude) {
    final double[] comp = new double[vec.length - exclude.size()];
    final int n = vec.length;

    int j = 0;//from w  w  w.j  a  v a2s . c o  m
    for (int i = 0; i < n; i++) {
        if (exclude.contains(i))
            continue;
        comp[j++] = vec[i];
    }

    return comp;
}

From source file:Main.java

private static ArrayList<PointF> colorPointsForModel(String model) {
    // LLC001, // LedStrip    // LWB001, // LivingWhite    
    if (model == null) { // if model is not known go for the default choice
        model = " ";
    }//from   w  w  w  .j  a v  a 2  s .c  om
    ArrayList<PointF> colorPoints = new ArrayList<PointF>();

    ArrayList<String> hueBulbs = new ArrayList<String>();
    hueBulbs.add("LCT001");

    ArrayList<String> livingColors = new ArrayList<String>();
    livingColors.add("LLC001");
    livingColors.add("LLC005");
    livingColors.add("LLC006");
    livingColors.add("LLC007");
    livingColors.add("LLC010");
    livingColors.add("LLC011");
    livingColors.add("LLC012");

    if (hueBulbs.contains(model)) {
        // Hue bulbs color gamut triangle
        colorPoints.add(new PointF(.674F, 0.322F)); // Red        
        colorPoints.add(new PointF(0.408F, 0.517F)); // Green        
        colorPoints.add(new PointF(0.168F, 0.041F)); // Blue            
    } else if (livingColors.contains(model)) {
        // LivingColors color gamut triangle
        colorPoints.add(new PointF(0.703F, 0.296F)); // Red        
        colorPoints.add(new PointF(0.214F, 0.709F)); // Green        
        colorPoints.add(new PointF(0.139F, 0.081F)); // Blue    
    } else {
        // Default construct triangle wich contains all values        
        colorPoints.add(new PointF(1.0F, 0.0F));// Red        
        colorPoints.add(new PointF(0.0F, 1.0F)); // Green       
        colorPoints.add(new PointF(0.0F, 0.0F));// Blue    
    }
    return colorPoints;
}

From source file:com.evolveum.midpoint.common.policy.ValuePolicyGenerator.java

private static int charIntersectionCounter(ArrayList<String> a, ArrayList<String> b) {
    int ret = 0;//from  w  w w .  j ava 2s  .co  m
    for (String s : b) {
        if (a.contains(s)) {
            ret++;
        }
    }
    return ret;
}

From source file:coolmap.utils.statistics.test.CTest.java

public static void ttest(CoolMapObject obj, Dimension direction, VNode leafNode1, VNode leafNode2) {
    try {//  ww w. j  av  a2  s  .  c o m
        ArrayList<VNode> leafNodes = new ArrayList<VNode>();
        if (direction == Dimension.ROW) {
            leafNodes.addAll(obj.getViewNodesRow());
        } else if (direction == Dimension.COLUMN) {
            leafNodes.addAll(obj.getViewNodesColumn());
        } else {
            return;
        }

        if (leafNodes.contains(leafNode1) && leafNodes.contains(leafNode2)) {

            double[] data1 = null;
            double[] data2 = null;

            if (direction == Dimension.ROW) {
                data1 = extractRow(obj, leafNode1);
                data2 = extractRow(obj, leafNode2);
            } else if (direction == Dimension.COLUMN) {
                data1 = extractColumn(obj, leafNode1);
                data2 = extractColumn(obj, leafNode2);
            }

            TTest test = new TTest();
            double pValue = test.pairedTTest(data1, data2);

            TestResult result = new TestResult("Student Paired T-Test",
                    "Two tailed paired t-test with alpha = 0.05.\nData: " + obj.getName() + "\nDirection: "
                            + direction + "\nGroups: " + leafNode1 + ", " + leafNode2,
                    pValue);
            CMConsole.log(result.toString());

        } else {
            CMConsole.logError(
                    "T-test error: group dimension mismatch, must both be row ontology group or column ontology groups.");
        }

    } catch (Exception e) {
        CMConsole.logError("T-test error: " + " Dataset:" + obj + " Direction:" + direction + " Group1:"
                + leafNode1 + " Group2:" + leafNode2);
    }
}

From source file:Main.java

/**
 * Puts the node attributes (if it has any) into HashMap<String,String> Retrieves only those
 * attributes that are in attr ArrayList Ignores other attributes values that are in node
 * //from   ww w . j a v  a 2  s  . c o m
 * @param node : XML node to look for its attributes
 * @param attrNames : attributes to fetch from node
 * @return Hashmap<String,String> of the node attributes
 */
public static HashMap<String, String> getAttributesByName(Node node, ArrayList<String> attrNames) {
    String attrName = null;
    String attrValue = null;
    HashMap<String, String> attributesMap = new HashMap<String, String>();
    NamedNodeMap attributes = node.getAttributes();
    for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
        attrName = attributes.item(attrIndex).getNodeName();
        attrValue = attributes.item(attrIndex).getNodeValue();
        if (attrNames.contains(attrName)) {
            attributesMap.put(attrName, attrValue);
        }
    }
    return attributesMap.size() == 0 ? null : attributesMap;
}

From source file:Main.java

public static String getSdCardPath(ContentResolver cr, Uri uri, String defaultPath) {
    ArrayList files = new ArrayList();
    if (uri != null) {
        Cursor mCursor = cr.query(uri, null, null, null, null);
        if (mCursor != null) {
            while (mCursor.moveToNext()) {
                String path = mCursor.getString(mCursor.getColumnIndexOrThrow("_data"));
                if (!path.contains(defaultPath)) {
                    String parentFolder = (new File(path)).getParent();
                    if (!files.contains(parentFolder)) {
                        files.add(parentFolder);
                    }//from w w w  .  j a va 2  s. com
                }
            }
        }
    }

    return getCommonSubStringFromList(files);
}

From source file:de._13ducks.cor.game.server.movement.SubSectorPathfinder.java

private static SubSectorEdge shortestCommonEdge(SubSectorNode from, SubSectorNode to) {
    ArrayList<SubSectorEdge> toEdges = to.getMyEdges();
    SubSectorEdge shortesCommon = null;// w w w. j  av  a2 s . c o m
    double minLength = Double.POSITIVE_INFINITY;
    for (SubSectorEdge edge : from.getMyEdges()) {
        if (toEdges.contains(edge)) {
            if (edge.getLength() < minLength) {
                shortesCommon = edge;
                minLength = edge.getLength();
            }
        }
    }
    return shortesCommon;
}

From source file:Main.java

public static void getTopNZ(float[] array, int[] counts, ArrayList<Integer> rankList,
        ArrayList<Float> rankProbs, int i, int threshold) {
    // clear//  w w w . j  av a  2  s  . c o  m
    rankList.clear();
    rankProbs.clear();
    //
    int index = 0;
    float max = Float.MIN_VALUE;
    for (int m = 0; m < i && m < array.length; m++) {
        boolean flag = false;
        max = Float.MIN_VALUE;
        for (int no = 0; no < array.length; no++) {
            if (counts[no] >= threshold) {
                if (array[no] >= max && !rankList.contains(no)) {
                    index = no;
                    max = array[no];
                    flag = true;
                }
            }
        }
        if (flag) { // found value
            rankList.add(index);
            //            rankProbs.add(array[index]);
            rankProbs.add(counts[index] + 0.0f);
        }
        //System.out.println(m + "\t" + index);
    }
}

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

/**
 * Get elements in topological order.// w  w  w . j a  v  a2  s . c  o  m
 * @param Named Named object.
 * @param Sorted List of elements in topological order.
 * @throws GraphCycleException Graph contains a cycle and can not be updated.
 */
private static void getElementsInTopologicalOrder(INamed Named, ArrayList Sorted) throws GraphCycleException {
    // if the NamedObject is already in the list, then we expect that its dependancies
    // are also already represented there and therefore we don't need to do anything
    if (Named instanceof IGraphable && !Sorted.contains(Named)) {
        IGraphable graphobject = (IGraphable) Named;
        // add nodes upon which the object is dependant first
        LinkedHashMap deps = (LinkedHashMap) graphobject.getDependancies();
        Iterator iter = deps.values().iterator();
        while (iter.hasNext()) {
            INamed namedDep = (INamed) iter.next();
            getElementsInTopologicalOrder(namedDep, Sorted);
        }
        // add myself
        if (!Sorted.contains(Named)) {
            Sorted.add(Named);
        } else {
            // graph has a cycle
            throw new GraphCycleException();
        }
    }
}