Example usage for java.util ArrayList stream

List of usage examples for java.util ArrayList stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:it.polimi.diceH2020.launcher.controller.LaunchAnalysis.java

/**
 * With multi provider different TXTs should be provided
 *//*from w  ww.  j ava  2 s.  co m*/
private boolean minNumTxt(List<String> providers, ArrayList<String> pathList) {
    for (String provider : providers) {
        if (pathList.stream().filter(s -> s.contains(provider)).count() < 2)
            return false;
    }
    return true;
}

From source file:qa.experiment.SRLToAligner.java

private ArrayList<RoleSpan> getRoleSpan(Sentence correspondingSent, Predicate pred, String roleType) {
    System.out.println("Getting rolespan for " + roleType + " , Predicate : " + pred.getForm());
    ArrayList<RoleSpan> spans = new ArrayList<RoleSpan>();
    ArrayList<Integer> roleIdx = pred.getRoleFillersIdxs(roleType);
    if (roleType.equalsIgnoreCase("T")) {
        spans.add(new RoleSpan(pred.getForm(), new double[] { 1.0, 0.0 }, roleType));
        return spans;
    }/*  ww w .  j  a va 2 s .c o m*/
    if (roleIdx.size() == 0) {
        return null;
    }

    Collections.sort(roleIdx);
    int prevIdx = roleIdx.get(0);
    ArrayList<Word> currentSpan = new ArrayList<Word>();
    currentSpan.add(correspondingSent.get(prevIdx));

    for (int i = 1; i < roleIdx.size(); i++) {
        if (roleIdx.get(i) == prevIdx + 1) {
            currentSpan.add(correspondingSent.get(roleIdx.get(i)));
            prevIdx = roleIdx.get(i);
        } else {
            StringBuilder textSpan = new StringBuilder();
            double[] scores = new double[3];
            Arrays.fill(scores, 1);

            for (int j = 0; j < currentSpan.size(); j++) {
                textSpan.append(currentSpan.get(j).getForm() + " ");
                int currentWordIdx = currentSpan.get(j).getIdx();
                ArrayList<WordProbsPair> wProbsArr = correspondingSent.labelProbs.get(roleType);
                WordProbsPair collect = wProbsArr.stream().filter(e -> e.getWord().getIdx() == currentWordIdx)
                        .collect(Collectors.toList()).get(0);
                for (int k = 0; k < scores.length; k++) {
                    scores[k] *= collect.getArgumentScore(k);
                }
            }
            spans.add(new RoleSpan(textSpan.toString().trim(), scores, roleType));
            currentSpan.clear();
            currentSpan.add(correspondingSent.get(roleIdx.get(i)));
            prevIdx = roleIdx.get(i);
        }
    }

    if (currentSpan.size() > 0) {
        StringBuilder textSpan = new StringBuilder();
        double[] scores = new double[3];
        Arrays.fill(scores, 1);
        for (int j = 0; j < currentSpan.size(); j++) {
            textSpan.append(currentSpan.get(j).getForm() + " ");
            int currentWordIdx = currentSpan.get(j).getIdx();
            ArrayList<WordProbsPair> wProbsArr = correspondingSent.labelProbs.get(roleType);
            WordProbsPair collect = wProbsArr.stream().filter(e -> e.getWord().getIdx() == currentWordIdx)
                    .collect(Collectors.toList()).get(0);
            for (int k = 0; k < scores.length; k++) {
                scores[k] *= collect.getArgumentScore(k);
            }
        }

        spans.add(new RoleSpan(textSpan.toString().trim(), scores, roleType));
        currentSpan.clear();

    }
    return spans;
}

From source file:io.druid.server.coordinator.cost.SegmentsCostCache.java

SegmentsCostCache(ArrayList<Bucket> sortedBuckets) {
    this.sortedBuckets = Preconditions.checkNotNull(sortedBuckets, "buckets should not be null");
    this.intervals = sortedBuckets.stream().map(Bucket::getInterval)
            .collect(Collectors.toCollection(ArrayList::new));
    Preconditions.checkArgument(BUCKET_ORDERING.isOrdered(sortedBuckets),
            "buckets must be ordered by interval");
}

From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java

private void drawDevices() {
    ArrayList<Device> devs = new ArrayList(DEVS.values());

    devs.stream().forEach((dev) -> {
        if (dev.getImgCurr() != null) {
            g2.drawImage(dev.getImgCurr(), dev.getX(), dev.getY(), this);
        }//  w w w  . j a  v a  2  s . co  m
    });

}

From source file:it.tizianofagni.sparkboost.DataUtils.java

/**
 * Load data file in LibSvm format. The documents IDs are assigned according to the row index in the original
 * file, i.e. useful at classification time. We are assuming that the feature IDs are the same as the training
 * file used to build the classification model.
 *
 * @param sc       The spark context.//from   w  w  w  .  ja  v  a  2  s .  c o  m
 * @param dataFile The data file.
 * @param fromID   The inclusive start document ID to read from.
 * @param toID     The noninclusive end document ID to read to.
 * @return An RDD containing the read points.
 */
public static JavaRDD<MultilabelPoint> loadLibSvmFileFormatDataAsList(JavaSparkContext sc, String dataFile,
        boolean labels0Based, boolean binaryProblem, long fromID, long toID, int numFeaturesInDataset) {
    if (sc == null)
        throw new NullPointerException("The Spark Context is 'null'");
    if (dataFile == null || dataFile.isEmpty())
        throw new IllegalArgumentException("The dataFile is 'null'");

    JavaRDD<String> lines = sc.textFile(dataFile).cache();
    int numFeatures = 0;
    if (numFeaturesInDataset == -1)
        numFeatures = computeNumFeatures(lines);
    else
        numFeatures = numFeaturesInDataset;

    ArrayList<MultilabelPoint> points = new ArrayList<>();
    try {
        Path pt = new Path(dataFile);
        FileSystem fs = FileSystem.get(pt.toUri(), new Configuration());
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));

        //BufferedReader br = new BufferedReader(new FileReader(dataFile));

        try {
            int docID = 0;
            String line = br.readLine();
            while (line != null) {
                if (docID >= toID)
                    break;
                if (docID < fromID || line.isEmpty()) {
                    line = br.readLine();
                    docID++;
                    continue;
                }

                String[] fields = line.split("\\s+");
                String[] t = fields[0].split(",");
                int[] labels = new int[0];
                if (!binaryProblem) {
                    labels = new int[t.length];
                    for (int i = 0; i < t.length; i++) {
                        String label = t[i];
                        if (labels0Based)
                            labels[i] = new Double(Double.parseDouble(label)).intValue();
                        else
                            labels[i] = new Double(Double.parseDouble(label)).intValue() - 1;
                        if (labels[i] < 0)
                            throw new IllegalArgumentException(
                                    "In current configuration I obtain a negative label ID value. Please check if this is a problem binary or multiclass "
                                            + "and if the labels IDs are in form 0-based or 1-based");
                    }
                } else {
                    if (t.length > 1)
                        throw new IllegalArgumentException(
                                "In binary problem you can only specify one label ID (+1 or -1) per document as valid label IDs");
                    int label = new Double(Double.parseDouble(t[0])).intValue();
                    if (label > 0) {
                        labels = new int[] { 0 };
                    }
                }
                ArrayList<Integer> indexes = new ArrayList<Integer>();
                ArrayList<Double> values = new ArrayList<Double>();
                for (int j = 1; j < fields.length; j++) {
                    String data = fields[j];
                    if (data.startsWith("#"))
                        // Beginning of a comment. Skip it.
                        break;
                    String[] featInfo = data.split(":");
                    // Transform feature ID value in 0-based.
                    int featID = Integer.parseInt(featInfo[0]) - 1;
                    double value = Double.parseDouble(featInfo[1]);
                    indexes.add(featID);
                    values.add(value);
                }

                SparseVector v = (SparseVector) Vectors.sparse(numFeatures,
                        indexes.stream().mapToInt(i -> i).toArray(),
                        values.stream().mapToDouble(i -> i).toArray());
                points.add(new MultilabelPoint(docID, v, labels));

                line = br.readLine();
                docID++;
            }
        } finally {
            br.close();
        }
    } catch (Exception e) {
        throw new RuntimeException("Reading input LibSVM data file", e);
    }

    return sc.parallelize(points);
}

From source file:qa.aligner.SRLToAligner.java

private ArrayList<RoleSpan> getRoleSpan(Sentence correspondingSent, Predicate pred, String roleType) {
    System.out.println("Getting rolespan for " + roleType + " , Predicate : " + pred.getForm());
    ArrayList<RoleSpan> spans = new ArrayList<RoleSpan>();
    ArrayList<Integer> roleIdx = pred.getRoleFillersIdxs(roleType);
    if (roleType.equalsIgnoreCase(GlobalV.T)) {
        spans.add(new RoleSpan(pred.getForm(), new double[] { pred.triggerScore, pred.noTriggerScore },
                roleType));//from   ww w .  ja  va2s .  co  m
        return spans;
    }
    if (roleIdx.size() == 0) {
        return null;
    }

    Collections.sort(roleIdx);
    int prevIdx = roleIdx.get(0);
    ArrayList<Word> currentSpan = new ArrayList<Word>();
    currentSpan.add(correspondingSent.get(prevIdx));

    for (int i = 1; i < roleIdx.size(); i++) {
        if (roleIdx.get(i) == prevIdx + 1) {
            currentSpan.add(correspondingSent.get(roleIdx.get(i)));
            prevIdx = roleIdx.get(i);
        } else {
            StringBuilder textSpan = new StringBuilder();
            double[] scores = new double[3];
            Arrays.fill(scores, 1);

            for (int j = 0; j < currentSpan.size(); j++) {
                textSpan.append(currentSpan.get(j).getForm() + " ");
                int currentWordIdx = currentSpan.get(j).getIdx();
                ArrayList<WordProbsPair> wProbsArr = correspondingSent.labelProbs.get(roleType);
                WordProbsPair collect = wProbsArr.stream().filter(e -> e.getWord().getIdx() == currentWordIdx)
                        .collect(Collectors.toList()).get(0);
                for (int k = 0; k < scores.length; k++) {
                    scores[k] *= collect.getArgumentScore(k);
                }
            }
            spans.add(new RoleSpan(textSpan.toString().trim(), scores, roleType));
            currentSpan.clear();
            currentSpan.add(correspondingSent.get(roleIdx.get(i)));
            prevIdx = roleIdx.get(i);
        }
    }

    if (currentSpan.size() > 0) {
        StringBuilder textSpan = new StringBuilder();
        double[] scores = new double[GlobalV.NB_ARG];
        Arrays.fill(scores, 1);
        for (int j = 0; j < currentSpan.size(); j++) {
            textSpan.append(currentSpan.get(j).getForm() + " ");
            int currentWordIdx = currentSpan.get(j).getIdx();
            ArrayList<WordProbsPair> wProbsArr = correspondingSent.labelProbs.get(roleType);
            WordProbsPair collect = wProbsArr.stream().filter(e -> e.getWord().getIdx() == currentWordIdx)
                    .collect(Collectors.toList()).get(0);
            for (int k = 0; k < scores.length; k++) {
                scores[k] *= collect.getArgumentScore(k);
            }
        }

        spans.add(new RoleSpan(textSpan.toString().trim(), scores, roleType));
        currentSpan.clear();

    }
    return spans;
}

From source file:com.eventsourcing.index.NavigableIndexTest.java

@Test
public void retrieveBetween() {
    IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
    SortedKeyStatisticsIndex<String, EntityHandle<Car>> PRICE_INDEX = onAttribute(Car.PRICE);
    PRICE_INDEX.clear(noQueryOptions());
    collection.addIndex(PRICE_INDEX);//from ww  w  .j av  a 2s .  co  m

    collection.addAll(CarFactory.createCollectionOfCars(10));

    try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(between(Car.PRICE, 8000.00, 9001.00))) {
        assertEquals(resultSet.size(), 2);
        ArrayList<EntityHandle<Car>> values = Lists.newArrayList(resultSet.iterator());
        assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("M6")));
        assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Prius")));
    }
}

From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java

private void drawSwitchRotary() {
    ArrayList<Device> sws = new ArrayList(DEVS.values());

    sws.stream().forEach((sw) -> {

        //Check type for some lamp use same picture.
        switch (sw.getType()) {
        case "Switch Rotary Black":
            if (sw.getImgCurr() == switchYesNoBlackOnImg && !mousePressed) {
                sw.setImgCurr(switchRotaryBlackIdleImg);
            } else if (sw.getImgCurr() == switchYesNoBlackOffImg && !mousePressed) {
                sw.setImgCurr(switchRotaryBlackIdleImg);
            }/* w w w .ja v  a 2s . co m*/
            break;

        case "Switch Rotary Yellow":
            if (sw.getImgCurr() == switchRotaryYellowOnImg && !mousePressed) {
                sw.setImgCurr(switchRotaryYellowIdleOnImg);
            } else if (sw.getImgCurr() == switchRotaryYellowOffImg && !mousePressed) {
                sw.setImgCurr(switchRotaryYellowIdleOffImg);
            }
            break;

        case "Switch PB Permit":
            if (!mousePressed & sw.getImgCurr() != switchPBPermitOffImg) {
                sw.setImgCurr(switchPBPermitOffImg);

                jsonObj = new JSONObject();
                JSONObject jsonDevs = new JSONObject();
                jsonDevs.put(sw.getId(), 0);
                jsonObj.put("ACAR", jsonDevs);
                App.OUT_QUEUE.add(jsonObj.toJSONString());
            }
            break;

        case "Switch PB Square Black":
            if (!mousePressed & sw.getImgCurr() != switchPBSquareBlackOffImg) {
                sw.setImgCurr(switchPBSquareBlackOffImg);

                jsonObj = new JSONObject();
                JSONObject jsonDevs = new JSONObject();
                jsonDevs.put(sw.getId(), 0);
                jsonObj.put("ACAR", jsonDevs);
                App.OUT_QUEUE.add(jsonObj.toJSONString());
            }
            break;
        }

        if (sw.getImgCurr() != null) {
            g2.drawImage(sw.getImgCurr(), sw.getX(), sw.getY(), this);
        }

    });
}

From source file:org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest.java

private void deleteCreatedComponents2(Map<String, ArrayList<Component>> convertCatalogResponseToJavaObject)
        throws IOException {
    final String userId = getUser().getUserId();
    ArrayList<Component> resourcesArrayList = convertCatalogResponseToJavaObject.get("resources");

    List<String> collect = resourcesArrayList.stream().filter(s -> s.getName().startsWith("ci"))
            .map(e -> e.getUniqueId()).collect(Collectors.toList());
    for (String uId : collect) {
        ResourceRestUtils.deleteResource(uId, userId);
    }/*w ww .  ja v a  2  s .c o  m*/

    resourcesArrayList = convertCatalogResponseToJavaObject.get("services");
    collect = resourcesArrayList.stream().filter(s -> s.getName().startsWith("ci")).map(e -> e.getUniqueId())
            .collect(Collectors.toList());
    for (String uId : collect) {
        ServiceRestUtils.deleteServiceById(uId, userId);
    }

    resourcesArrayList = convertCatalogResponseToJavaObject.get("products");
    collect = resourcesArrayList.stream().filter(s -> s.getName().startsWith("ci")).map(e -> e.getUniqueId())
            .collect(Collectors.toList());
    for (String uId : collect) {
        ProductRestUtils.deleteProduct(uId, userId);
    }

}

From source file:com.eventsourcing.index.NavigableIndexTest.java

@Test
public void retrieveLess() {
    IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
    SortedKeyStatisticsIndex<String, EntityHandle<Car>> PRICE_INDEX = onAttribute(Car.PRICE);
    PRICE_INDEX.clear(noQueryOptions());
    collection.addIndex(PRICE_INDEX);/*from   w w w.  j a  v a  2s.c om*/

    collection.addAll(CarFactory.createCollectionOfCars(10));

    try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(lessThan(Car.PRICE, 3999.99))) {
        assertEquals(resultSet.size(), 1);
        assertEquals(resultSet.uniqueResult().get().getModel(), "Accord");
    }

    try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(lessThanOrEqualTo(Car.PRICE, 3999.99))) {
        assertEquals(resultSet.size(), 2);
        ArrayList<EntityHandle<Car>> values = Lists.newArrayList(resultSet.iterator());
        assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Fusion")));
        assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Accord")));
    }

}