void applyDedupBijectionStrategy(final Traversal traversal) { final TraversalStrategies strategies = new DefaultTraversalStrategies(); strategies.addStrategies( FilterRankingStrategy.instance(), IdentityRemovalStrategy.instance()); traversal.asAdmin().setStrategies(strategies); traversal.asAdmin().setEngine(this.traversalEngine); traversal.asAdmin().applyStrategies(); }
@Override @SuppressWarnings({"unchecked", "varargs"}) public TraversalStrategies addStrategies(final TraversalStrategy<?>... strategies) { final Class<? extends TraversalStrategy>[] classes = new Class[strategies.length]; for (int i = 0; i < strategies.length; i++) { classes[i] = strategies[i].getClass(); } this.removeStrategies(classes); // todo: do a remove with no sort Collections.addAll(this.traversalStrategies, strategies); this.traversalStrategies = TraversalStrategies.sortStrategies(this.traversalStrategies); return this; }
@Override public TraversalStrategies addStrategies(final TraversalStrategy<?>... strategies) { boolean added = false; for (final TraversalStrategy strategy : strategies) { if (!this.traversalStrategies.contains(strategy)) { this.traversalStrategies.add(strategy); added = true; } } if (added) this.traversalStrategies = TraversalStrategies.sortStrategies(this.traversalStrategies); return this; }
@SuppressWarnings("unchecked") @Override public TraversalStrategies removeStrategies( final Class<? extends TraversalStrategy>... strategyClasses) { boolean removed = false; for (final Class<? extends TraversalStrategy> strategyClass : strategyClasses) { final Optional<TraversalStrategy<?>> strategy = this.traversalStrategies .stream() .filter(s -> s.getClass().equals(strategyClass)) .findAny(); if (strategy.isPresent()) { this.traversalStrategies.remove(strategy.get()); removed = true; } } if (removed) this.traversalStrategies = TraversalStrategies.sortStrategies(this.traversalStrategies); return this; }