Sha256: 69afdd21a44eb9547802b2b25302a45203e307dc1e2b3b87003249d64e1f6e98

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Pacer::Pipes
  class IsUniquePipe < RubyPipe
    import java.util.ArrayList
    import com.tinkerpop.pipes.sideeffect.SideEffectPipe
    import com.tinkerpop.pipes.util.ExpandableIterator
    import com.tinkerpop.pipes.filter.DuplicateFilterPipe

    include SideEffectPipe

    def initialize
      super()
      prepare_state
    end

    def processNextStart
      value = starts.next
      check_uniqueness value if @unique
      value
    rescue NativeException => e
      if e.cause.getClass == Pacer::NoSuchElementException.getClass
        raise e.cause
      else
        raise e
      end
    end

    def reset
      super()
      prepare_state
    end

    def unique?
      @unique
    end

    def getSideEffect
      @unique
    end

    protected

    def check_uniqueness(value)
      @expando.add value
      @unique_pipe.next
    rescue NativeException => e
      if e.cause.getClass == Pacer::NoSuchElementException.getClass
        @unique = false
      else
        raise e
      end
    end

    def prepare_state
      @unique = true
      @expando = ExpandableIterator.new ArrayList.new.iterator
      @unique_pipe = DuplicateFilterPipe.new
      @unique_pipe.setStarts @expando
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacer-0.9.1.1-java lib/pacer/pipe/is_unique_pipe.rb