List of usage examples for java.util List stream
default Stream<E> stream()
From source file:org.labkey.graphql.GraphQLController.java
public static List<GraphQLFieldDefinition> createFields(List<ColumnInfo> columns, Set<GraphQLType> types) { return columns.stream().map(col -> GraphQLController.createField(col, types)).collect(Collectors.toList()); }
From source file:de.bund.bfr.jung.JungUtils.java
static Line2D getLineInMiddle(Shape edgeShape) { GeneralPath path = new GeneralPath(edgeShape); float[] seg = new float[6]; List<Point2D> points = new ArrayList<>(); for (PathIterator i = path.getPathIterator(null, 1); !i.isDone(); i.next()) { i.currentSegment(seg);//from w w w. j a va 2 s. c o m points.add(new Point2D.Float(seg[0], seg[1])); } Point2D first = points.get(0); Point2D last = points.get(points.size() - 1); if (first.equals(last)) { Point2D minP = points.stream().min((p1, p2) -> Double.compare(p1.getY(), p2.getY())).get(); return new Line2D.Float(minP, new Point2D.Float((float) (minP.getX() + 1.0), (float) minP.getY())); } else { for (int i = 0; i < points.size() - 1; i++) { Point2D p1 = points.get(i); Point2D p2 = points.get(i + 1); if (p2.distance(last) < p2.distance(first)) { Line2D ortho = getOrthogonal(new Line2D.Float(first, last)); Point2D pp1 = getIntersection(new Line2D.Float(p1, p2), ortho); Point2D pp2 = new Point2D.Float((float) (pp1.getX() + last.getX() - first.getX()), (float) (pp1.getY() + last.getY() - first.getY())); return new Line2D.Float(pp1, pp2); } } return null; } }
From source file:com.vmware.photon.controller.api.frontend.utils.SecurityGroupUtils.java
/** * Merge the 'self' security groups to existing security groups. * * @param existingSecurityGroups Existing security groups including both inherited and self ones. * @param selfSecurityGroups 'self' security groups to be merged. * @return The merging result and security groups not being merged. *//*from w ww . j a v a 2s .co m*/ public static Pair<List<SecurityGroup>, List<String>> mergeSelfSecurityGroups( List<SecurityGroup> existingSecurityGroups, List<String> selfSecurityGroups) { checkNotNull(existingSecurityGroups, "Provided value for existingSecurityGroups is unacceptably null"); checkNotNull(selfSecurityGroups, "Provided value for selfSecurityGroups is unacceptably null"); List<SecurityGroup> mergedSecurityGroups = new ArrayList<>(); List<String> securityGroupsNotMerged = new ArrayList<>(); Set<String> inheritedSecurityGroupNames = new HashSet<>(); existingSecurityGroups.stream().filter(g -> g.isInherited()).forEach(g -> { mergedSecurityGroups.add(g); inheritedSecurityGroupNames.add(g.getName()); }); selfSecurityGroups.forEach(g -> { if (!inheritedSecurityGroupNames.contains(g)) { mergedSecurityGroups.add(new SecurityGroup(g, false)); } else { securityGroupsNotMerged.add(g); } }); return Pair.of(mergedSecurityGroups, securityGroupsNotMerged); }
From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.OrcaRunner.java
private static String formatId(String id) { if (id.length() == 0) { return id; }/*from w w w . ja v a2s. c o m*/ id = capitalize(id); List<Integer> breaks = new ArrayList<>(); char[] arr = id.toCharArray(); for (int i = 0; i < arr.length; i++) { char c = arr[i]; if (Character.isUpperCase(c)) { breaks.add(i); } } breaks.add(id.length()); if (breaks.size() == 1) { return id; } List<String> words = new ArrayList<>(); int last = breaks.remove(0); while (breaks.size() > 0) { int curr = breaks.remove(0); String word = id.substring(last, curr); if (last != 0) { word = unCapitalize(word); } words.add(word); last = curr; } return words.stream().reduce("", (a, b) -> a + " " + b).trim(); }
From source file:net.hamnaberg.json.Collection.java
public static Collection create(Optional<URI> href, List<Link> links, List<Item> items, List<Query> queries, Optional<Template> template, Optional<Error> error) { ObjectNode obj = JsonNodeFactory.instance.objectNode(); obj.put("version", Version.ONE.getIdentifier()); href.ifPresent(value -> obj.put("href", value.toString())); if (!links.isEmpty()) { obj.set("links", links.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); }//from w w w . j a v a 2 s.c o m if (!items.isEmpty()) { obj.set("items", items.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); } if (!queries.isEmpty()) { obj.set("queries", queries.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); } template.ifPresent(value -> obj.set("template", value.asJson())); error.ifPresent(value -> obj.set("error", value.asJson())); Collection coll = new Collection(obj); coll.validate(); return coll; }
From source file:cn.com.sunjiesh.wechat.handler.WechatMaterialHandler.java
/** * ??// w w w .j ava 2s. c o m * * @param materialNewsList ?? * @param accessToken AccessToken * @return * @throws ServiceException ServiceException */ public static WechatAddMaterialNewsResponse addMaterialNews(List<MaterialNewsRequest> materialNewsList, String accessToken) throws ServiceException { //url and params String url = getRequestUrl(WechatUrlConstants.MATERIAL_ADD_NEWS, accessToken); JSONArray articleJsonArr = new JSONArray(); materialNewsList.stream().map((media) -> materiaNewsToJsonObj(media)).forEach((articleJson) -> { articleJsonArr.add(articleJson); }); JSONObject requestJson = new JSONObject(); requestJson.put("articles", articleJsonArr); JSONObject responseJson = getWxJSONObjectResponseFromHttpPostMethod(url, requestJson); String mediaId = responseJson.getString("media_id"); WechatAddMaterialNewsResponse response = new WechatAddMaterialNewsResponse(); response.setMediaId(mediaId); return response; }
From source file:io.pravega.controller.store.stream.tables.TableHelper.java
/** * Find segments from the candidate set that have overlapping key ranges with current segment. * * @param current current segment number * @param candidates candidates//from w ww . j av a 2 s .c om * @return */ public static List<Integer> getOverlaps(final Segment current, final List<Segment> candidates) { return candidates.stream().filter(x -> x.overlaps(current)).map(x -> x.getNumber()) .collect(Collectors.toList()); }
From source file:cn.com.sunjiesh.wechat.handler.WechatMaterialHandler.java
/** * ??/*ww w . j a v a 2s . com*/ * * @param mediaId mediaId * @param mediaList mediaList * @param index index * @param accessToken AccessToken * @throws ServiceException ServiceException */ public static void updateMaterialNews(String mediaId, List<MaterialNewsRequest> mediaList, Integer index, String accessToken) throws ServiceException { //url and params String url = getRequestUrl(WechatUrlConstants.MATERIAL_UPDATE_NEWS, accessToken); JSONArray articleJsonArr = new JSONArray(); mediaList.stream().map((media) -> materiaNewsToJsonObj(media)).forEach((articleJson) -> { articleJsonArr.add(articleJson); }); JSONObject requestJson = new JSONObject(); requestJson.put("articles", articleJsonArr); requestJson.put("media_id", mediaId); requestJson.put("index", index); getWxJSONObjectResponseFromHttpPostMethod(url, requestJson); }
From source file:io.pravega.controller.store.stream.tables.TableHelper.java
private static List<Integer> diff(List<Integer> list1, List<Integer> list2) { return list1.stream().filter(z -> !list2.contains(z)).collect(Collectors.toList()); }
From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java
/** * Reduce./*from w w w.ja va 2 s . c om*/ * * @param network the network * @param functions the functions * @param parallelLossFunctions the parallel loss functions */ public static void reduce(final PipelineNetwork network, final List<Tuple2<Double, DAGNode>> functions, final boolean parallelLossFunctions) { functions.stream().filter(x -> x._1 != 0).reduce((a, b) -> { return new Tuple2<>(1.0, network.wrap(new BinarySumLayer(a._1, b._1), a._2, b._2).setParallel(parallelLossFunctions)); }).get(); }