Sha256: 80229527bdfeaf42ac0f67d0f0b79496ce282e00632dd0831a493beca53970a7
Contents?: true
Size: 1.71 KB
Versions: 10
Compression:
Stored size: 1.71 KB
Contents
package com.xnlogic.pacer.pipes; import java.util.Collection; import java.util.HashSet; import java.util.Set; import com.tinkerpop.blueprints.Contains; import com.tinkerpop.blueprints.Element; import com.tinkerpop.pipes.AbstractPipe; public class IdCollectionFilterPipe<E extends Element> extends AbstractPipe<E, E> { private Set<Object> ids; private boolean containsIn; // TODO: Consider making this a derived exception. Also, this constructor is the reverse of the Ruby one. Is this ok? // Also also, is an Object array the way to go? Can we nail down the type further? @SuppressWarnings("unchecked") public IdCollectionFilterPipe(final Collection<?> ids, final Contains comparison) throws RuntimeException { super(); if (ids instanceof Set) { this.ids = (Set<Object>)ids; } else if (ids == null) { this.ids = new HashSet<Object>(); } else { this.ids = new HashSet<Object>(); this.ids.addAll(ids); } if (comparison == Contains.IN) this.containsIn = true; else if (comparison == Contains.NOT_IN) this.containsIn = false; else throw new RuntimeException("Unknown comparison type for ID collection filter"); } protected E processNextStart() { if (this.containsIn) { while (true) { E e = this.starts.next(); if (e != null && this.ids.contains(e.getId())) return e; } } else { while (true) { E e = this.starts.next(); if (e != null && !this.ids.contains(e.getId())) return e; } } } }
Version data entries
10 entries across 10 versions & 1 rubygems