Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:eu.mihosoft.vrl.v3d.Edge.java

public static List<Polygon> boundaryPathsWithHoles(List<Polygon> boundaryPaths) {

    List<Polygon> result = boundaryPaths.stream().map(p -> p.clone()).collect(Collectors.toList());

    List<List<Integer>> parents = new ArrayList<>();
    boolean[] isHole = new boolean[result.size()];

    for (int i = 0; i < result.size(); i++) {
        Polygon p1 = result.get(i);
        List<Integer> parentsOfI = new ArrayList<>();
        parents.add(parentsOfI);// ww  w.j ava 2s  .c  om
        for (int j = 0; j < result.size(); j++) {
            Polygon p2 = result.get(j);
            if (i != j) {
                if (p2.contains(p1)) {
                    parentsOfI.add(j);
                }
            }
        }
        isHole[i] = parentsOfI.size() % 2 != 0;
    }

    int[] parent = new int[result.size()];

    for (int i = 0; i < parent.length; i++) {
        parent[i] = -1;
    }

    for (int i = 0; i < parents.size(); i++) {
        List<Integer> par = parents.get(i);

        int max = 0;
        int maxIndex = 0;
        for (int pIndex : par) {

            int pSize = parents.get(pIndex).size();

            if (max < pSize) {
                max = pSize;
                maxIndex = pIndex;
            }
        }

        parent[i] = maxIndex;

        if (!isHole[maxIndex] && isHole[i]) {

            List<Polygon> holes;

            Optional<List<Polygon>> holesOpt = result.get(maxIndex).getStorage().getValue(KEY_POLYGON_HOLES);

            if (holesOpt.isPresent()) {
                holes = holesOpt.get();
            } else {
                holes = new ArrayList<>();
                result.get(maxIndex).getStorage().set(KEY_POLYGON_HOLES, holes);
            }

            holes.add(result.get(i));
        }
    }

    return result;
}

From source file:ambroafb.general.StagesContainer.java

/**
 * The function removes only children stages of given stage from bidirectional map if they exists.
 * @param stage which children must be remove.
 *//*from ww w .jav a2s .  c  o  m*/
public static void removeOnlySubstagesFor(Stage stage) {
    String path = (String) bidmap.getKey(stage);
    List<String> pathes = (ArrayList<String>) bidmap.keySet().stream().filter(new Predicate() {
        @Override
        public boolean test(Object key) {
            return ((String) key).startsWith(path) && !((String) key).equals(path);
        }
    }).collect(Collectors.toList());
    //        bidmap.keySet().stream().forEach((key) -> {
    //            if (((String) key).startsWith(path) && !((String) key).equals(path)) {
    //                pathes.add((String) key);
    //            }
    //        });
    pathes.stream().forEach((currPath) -> {
        bidmap.remove((String) currPath);
    });
}

From source file:edu.ehu.galan.wiki2wordnet.wikipedia2wordnet.Mapper.java

private static void disambiguateUKB(HashMap<String, List<Wiki2WordnetMapping>> pUkbList,
        List<String> pDesambContext, String pFile, IDictionary pWordnet, HashMap<String, Integer> pMappings,
        String pUkbBinDir) {/*from  w ww.  jav a2  s. c o m*/
    logger.debug("Desambiguating Wornet synsets via UKB method");
    HashMap<String, List<String>> toDisam = new HashMap<>();
    logger.debug("Finding gold topics for disambiguation...");
    Function<String, String> contextSynsets = (String t) -> pWordnet
            .getSynset(new SynsetID(pMappings.get(t), POS.NOUN)).getWords().get(0).getLemma();
    List<String> context = pDesambContext.stream().map(contextSynsets).collect(toList());
    for (String topics21 : pUkbList.keySet()) {
        toDisam.put(pWordnet.getSynset(new SynsetID(pMappings.get(topics21), POS.NOUN)).getWords().get(0)
                .getLemma().toLowerCase(), context);
    }
    UKBUtils.prepareInput(toDisam, pFile);
    HashMap<String, Integer> synsets = UKBUtils.processUKB(pUkbBinDir, pFile);
    if (toDisam.size() == synsets.size()) {
        for (String topics21 : pUkbList.keySet()) {
            Integer inte = synsets.get(pWordnet.getSynset(new SynsetID(pMappings.get(topics21), POS.NOUN))
                    .getWords().get(0).getLemma().toLowerCase());
            pMappings.put(topics21, inte);
        }
        logger.debug("UKB disambiguation using WordNet finished");
    } else {
        logger.error("The number of topics to disambiguate via ukb must be the same than the ouput size");
    }

}

From source file:alfio.model.modification.EventModification.java

public static EventModification fromEvent(Event event, List<TicketCategory> ticketCategories,
        Optional<String> mapsApiKey) {
    final ZoneId zoneId = event.getZoneId();
    return new EventModification(event.getId(), event.getWebsiteUrl(), event.getTermsAndConditionsUrl(),
            event.getImageUrl(), event.getShortName(), event.getOrganizationId(), event.getLocation(),
            event.getDescription(), DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), event.getAvailableSeats(), event.getVat(), event.isVatIncluded(),
            event.getAllowedPaymentProxies(),
            ticketCategories.stream().map(tc -> TicketCategoryModification.fromTicketCategory(tc, zoneId))
                    .collect(toList()),/*from www.ja v  a2  s  .c om*/
            event.isFreeOfCharge(), fromGeoData(Pair.of(event.getLatitude(), event.getLongitude()),
                    TimeZone.getTimeZone(zoneId), mapsApiKey));
}

From source file:org.lambdamatic.internal.elasticsearch.codec.DocumentCodec.java

/**
 * Analyze the given domain type and returns the name of its field to use as the document id, if
 * available.//from   w  w  w .ja  v a 2 s.  c om
 * 
 * @param domainType the domain type to analyze
 * @return the <strong>single</strong> Java field annotated with {@link DocumentIdField}. If no field
 *         matches the criteria or more than one field is matches these criteria, a
 *         {@link MappingException} is thrown.
 */
public static Field getIdField(final Class<?> domainType) {
    final List<Pair<Field, DocumentIdField>> candidateFields = Stream.of(domainType.getDeclaredFields())
            .map(field -> new Pair<>(field, field.getAnnotation(DocumentIdField.class)))
            .filter(pair -> pair.getRight() != null).collect(Collectors.toList());
    if (candidateFields.isEmpty()) {
        throw new MappingException("No field is annotated with @{} in type {}", DocumentIdField.class.getName(),
                domainType);
    } else if (candidateFields.size() > 1) {
        final String fieldNames = candidateFields.stream().map(pair -> pair.getLeft().getName())
                .collect(Collectors.joining(", "));
        throw new MappingException("More than one field is annotated with @{} in type {}: {}",
                DocumentIdField.class.getName(), domainType, fieldNames);
    }
    return candidateFields.get(0).getLeft();
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil.java

/**
 * Groups the properties by their {@see NifiProperty#getIdKey}
 * @param properties the properties to inspect
 * @return a map with the property idKey (the processgroup+processorId+propertyKey, property)
 *//*from w  w w  . ja  v a2 s .com*/
public static Map<String, NifiProperty> groupPropertiesByIdKey(List<NifiProperty> properties) {
    Map<String, NifiProperty> map = new HashMap();
    if (properties != null) {
        map = properties.stream().collect(Collectors.toMap(p -> p.getIdKey(), p -> p));
    }
    return map;
}

From source file:com.ikanow.aleph2.shared.crud.mongodb.services.MongoDbCrudService.java

/** Low level util to get the set of fields to collect for retrieval
 * @param field_list//from w  w  w.ja v a  2 s. c  om
 * @param include
 * @return
 */
private static BasicDBObject getFields(List<String> field_list, boolean include) {
    final BasicDBObject fields = new BasicDBObject(
            field_list.stream().collect(Collectors.toMap(f -> f, f -> include ? 1 : 0)));
    if (include && !fields.containsField(_ID))
        fields.put(_ID, 0); // (mongodb adds this by default)
    return fields;
}

From source file:com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil.java

public static <T extends PolicyActionType> List<T> filterActions(List<PolicyActionType> actions,
        Class<T> clazz) {//from  www  . j a  v  a2 s . c o  m
    //noinspection unchecked
    return actions.stream().filter(a -> clazz.isAssignableFrom(a.getClass())).map(a -> (T) a)
            .collect(Collectors.toList());
}

From source file:controllers.nwbib.Lobid.java

/**
 * @param types The type uris associated with a resource
 * @param configKey The key from the config file (icons or labels)
 * @return The most specific of the passed types
 *///  ww  w.  j  a va2s. co  m
public static String selectType(List<String> types, String configKey) {
    if (configKey.isEmpty())
        return types.get(0);
    Logger.trace("Types: " + types);
    @SuppressWarnings("unchecked")
    List<Pair<String, Integer>> selected = types.stream().map(t -> {
        List<Object> vals = ((List<Object>) Application.CONFIG.getObject(configKey).unwrapped().get(t));
        if (vals == null)
            return Pair.of(t, 0);
        Integer specificity = (Integer) vals.get(2);
        return ((String) vals.get(0)).isEmpty() || ((String) vals.get(1)).isEmpty() //
                ? Pair.of("", specificity)
                : Pair.of(t, specificity);
    }).filter(t -> {
        return !t.getLeft().isEmpty();
    }).collect(Collectors.toList());
    Collections.sort(selected, (a, b) -> b.getRight().compareTo(a.getRight()));
    Logger.trace("Selected: " + selected);
    return selected.isEmpty() ? ""
            : selected.get(0).getLeft().contains("Miscellaneous") && selected.size() > 1
                    ? selected.get(1).getLeft()
                    : selected.get(0).getLeft();
}