Sha256: fe28e91fd772cea4e1fc6bced42cf42c117a13803c9212559560ddc5d934c6e7

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

package com.xnlogic.pacer.pipes;

import java.util.LinkedHashSet;
import java.util.Set;

import com.tinkerpop.pipes.AbstractPipe;

public class IsUniquePipe<T> extends AbstractPipe<T, T> {
    private boolean unique;
    private Set<T> historySet;
  
    public IsUniquePipe() {
        super();
        this.prepareState();
    }

    protected T processNextStart() {
        T value = this.starts.next();
        if (this.unique)
            this.checkUniqueness(value);
        return value;
    }

    public void reset() {
        super.reset();
        this.prepareState();
    }
    
    public boolean isUnique() {
        return this.unique;
    }

    public boolean getSideEffect() {
        return this.unique;
    }
    
    protected void checkUniqueness(T value) {
        if (!this.historySet.add(value)) {
            this.unique = false;
            this.historySet = null;
        }
    }

    protected void prepareState() {
        this.historySet = new LinkedHashSet<T>();
        this.unique = true;
    }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pacer-2.0.24-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.22-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.20-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.19-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.18-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.17-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.16-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.15-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.14-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java
pacer-2.0.13-java ext/src/main/java/com/xnlogic/pacer/pipes/IsUniquePipe.java