public static <A> void addSideEffect(final TraversalStrategies traversalStrategies, final String key, final A value, final BinaryOperator<A> reducer) { SideEffectStrategy strategy = (SideEffectStrategy) traversalStrategies.toList().stream().filter(s -> s instanceof SideEffectStrategy).findAny().orElse(null); if (null == strategy) { strategy = new SideEffectStrategy(); traversalStrategies.addStrategies(strategy); } else { final SideEffectStrategy cloneStrategy = new SideEffectStrategy(); cloneStrategy.sideEffects.addAll(strategy.sideEffects); strategy = cloneStrategy; traversalStrategies.addStrategies(strategy); } strategy.sideEffects.add(new Triplet<>(key, null == value ? null : value instanceof Supplier ? (Supplier) value : new ConstantSupplier<>(value), reducer)); } }
/** * Asserts that two graphs are the "same" in way of structure. It assumes that the graphs both have vertices * with an "oid" property that is an Integer value. It iterates each vertex in graph 1, using the "oid" to * lookup vertices in graph 2. For each one found it checks both IN and OUT vertices to ensure that they * attach to the same IN/OUT vertices given their "oid" properties. */ protected boolean same(final Graph g1, final Graph g2) { return IteratorUtils.stream(g1.vertices()) .map(v -> Triplet.<Integer, List<Vertex>, List<Vertex>>with(v.value("oid"), IteratorUtils.list(v.vertices(Direction.IN)), IteratorUtils.list(v.vertices(Direction.OUT)))) .allMatch(p -> { final Vertex v = IteratorUtils.filter(g2.vertices(), vx -> vx.value("oid").equals(p.getValue0())).next(); return sameInVertices(v, p.getValue1()) && sameOutVertices(v, p.getValue2()); }); }
nullChecks.add(new Triplet<>(inputFilePath, R.string.fieldMissingError, "inputFilePath")); nullChecks.add(new Triplet<>(destinationFilePath, R.string.fieldMissingError, "outputFilePath")); nullChecks.add(new Triplet<>(container, R.string.fieldMissingOrInvalidError, "mediaContainer")); if(container != null && container.supportedVideoCodecs.size() > 0) nullChecks.add(new Triplet<>(videoCodec, R.string.fieldMissingOrInvalidError, "videoCodec")); nullChecks.add(new Triplet<>(videoBitrateK, R.string.fieldMissingError, "videoBitrateK missing")); nullChecks.add(new Triplet<>(resolution, R.string.fieldMissingError, "resolution")); nullChecks.add(new Triplet<>(fps, R.string.fieldMissingError, "fps")); nullChecks.add(new Triplet<>(audioCodec, R.string.fieldMissingOrInvalidError, "audioCodec")); nullChecks.add(new Triplet<>(audioSampleRate, R.string.fieldMissingError, "audioSampleRate")); nullChecks.add(new Triplet<>(audioChannel, R.string.fieldMissingError, "audioChannel")); nullChecks.add(new Triplet<>(audioBitrateK, R.string.fieldMissingError, "audioBitrateK")); if(check.getValue0() == null) String submsg = String.format(getString(check.getValue1()), check.getValue2()); String message = String.format(getString(R.string.cannotEncodeFile), submsg); Log.i(TAG, message);
@Override public <I extends InputShim> Triplet read(final KryoShim<I, ?> kryo, final I input, final Class<Triplet> tripletClass) { return Triplet.with(kryo.readClassAndObject(input), kryo.readClassAndObject(input), kryo.readClassAndObject(input)); } }
perMetricSamples.put(metric, new Triplet<>(highSamples, lowSamples, latestAvg)); } else { Triplet<Integer, Integer, Double> newHighLow = new Triplet<>( previousHighLow.getValue0() + highSamples, previousHighLow.getValue1() + lowSamples, (previousHighLow.getValue2() + latestAvg) / 2); perMetricSamples.put(metric, newHighLow); if (perMetricSamples.get(StreamMetric.Bytes).getValue2() >= perMetricSamples.get(StreamMetric.Records) .getValue2()) { higherUtilisationMetric = StreamMetric.Bytes; higherUtilisationPct = perMetricSamples.get(StreamMetric.Bytes).getValue2(); } else { higherUtilisationMetric = StreamMetric.Records; higherUtilisationPct = perMetricSamples.get(StreamMetric.Records).getValue2(); entry.getKey(), higherUtilisationMetric, higherUtilisationPct * 100)); if (perMetricSamples.get(higherUtilisationMetric).getValue0() >= config.getScaleUp().getScaleAfterMins()) { scaleVotes.put(entry.getKey(), ScaleDirection.UP); } else if (perMetricSamples.get(higherUtilisationMetric).getValue1() >= config.getScaleDown() .getScaleAfterMins()) { scaleVotes.put(entry.getKey(), ScaleDirection.DOWN);
private void processEdges(final Vertex vertex, final Path currentPath, final Number currentDistance, final Messenger<Triplet<Path, Edge, Number>> messenger) { final Traversal.Admin<Vertex, Edge> edgeTraversal = this.edgeTraversal.getPure(); edgeTraversal.addStart(edgeTraversal.getTraverserGenerator().generate(vertex, edgeTraversal.getStartStep(), 1)); while (edgeTraversal.hasNext()) { final Edge edge = edgeTraversal.next(); final Number distance = getDistance(edge); Vertex otherV = edge.inVertex(); if (otherV.equals(vertex)) otherV = edge.outVertex(); // only send message if the adjacent vertex is not yet part of the current path if (!currentPath.objects().contains(otherV)) { messenger.sendMessage(MessageScope.Global.of(otherV), Triplet.with(currentPath, this.includeEdges ? edge : null, NumberHelper.add(currentDistance, distance))); } } }
tests.add(new Triplet<>(0L, 0L, 1)); tests.add(new Triplet<>(1L, 1L, 1)); tests.add(new Triplet<>(2L, 2L, 1)); tests.add(new Triplet<>(3L, 3L, 0)); tests.add(new Triplet<>(0L, 10000L, 3)); tests.add(new Triplet<>(1L, 10000L, 2)); for(Triplet<Long, Long, Integer> test : tests) Long startTimeMs = test.getValue0(); Long endTimeMs = test.getValue1(); int expectedEntries = test.getValue2();
/** * Asserts that two graphs are the "same" in way of structure. It assumes that the graphs both have vertices * with an "oid" property that is an Integer value. It iterates each vertex in graph 1, using the "oid" to * lookup vertices in graph 2. For each one found it checks both IN and OUT vertices to ensure that they * attach to the same IN/OUT vertices given their "oid" properties. */ protected boolean same(final Graph g1, final Graph g2) { return IteratorUtils.stream(g1.vertices()) .map(v -> Triplet.<Integer, List<Vertex>, List<Vertex>>with(v.value("oid"), IteratorUtils.list(v.vertices(Direction.IN)), IteratorUtils.list(v.vertices(Direction.OUT)))) .allMatch(p -> { final Vertex v = IteratorUtils.filter(g2.vertices(), vx -> vx.value("oid").equals(p.getValue0())).next(); return sameInVertices(v, p.getValue1()) && sameOutVertices(v, p.getValue2()); }); }
public <X> Triplet<A,X,C> setAt1(final X value) { return new Triplet<A,X,C>( this.val0, value, this.val2); }
/** * {@inheritDoc} */ @Override public Builder addCustom(final Class clazz, final Function<Kryo, Serializer> serializer) { serializationList.add(Triplet.with(clazz, serializer, currentSerializationId.getAndIncrement())); return this; }
final Path sourcePath = triplet.getValue0(); final Number distance = triplet.getValue2(); final Vertex sourceVertex = sourcePath.get(0); newPath = extendPath(sourcePath, triplet.getValue1(), vertex); if (cmp < 0) { pathSet.add(newPath = extendPath(sourcePath, triplet.getValue1(), vertex)); paths.put(sourceVertex, Pair.with(distance, pathSet));
public Triplet<A,B,C> removeFrom3() { return new Triplet<A,B,C>( this.val0, this.val1, this.val2); }
/** * {@inheritDoc} */ @Override public Builder addCustom(final Class clazz, final Serializer serializer) { serializationList.add(Triplet.with(clazz, kryo -> serializer, currentSerializationId.getAndIncrement())); return this; }