Class List Method List File List

# Class: Concurrent::Collection::JavaNonConcurrentPriorityQueue

Inherits:
  Object
  - Object
  - Concurrent::Collection::JavaNonConcurrentPriorityQueue
  show all
Defined in:
  lib/concurrent/collection/java_non_concurrent_priority_queue.rb

## Class Method Summary (collapse)

- + (NonConcurrentPriorityQueue) from_list(list, opts = {})

  Create a new priority queue from the given list.

## Instance Method Summary (collapse)

- - (undocumented) clear
- - (undocumented) delete(item)
- - (Boolean) empty?
- - (Boolean) include?(item) (also: #has_priority?)
- - (JavaNonConcurrentPriorityQueue) initialize(opts = {}) constructor

  A new instance of JavaNonConcurrentPriorityQueue.

- - (undocumented) length (also: #size)
- - (undocumented) peek
- - (undocumented) pop (also: #deq, #shift)
- - (undocumented) push(item) (also: #<<, #enq)

## Constructor Details

### - (`JavaNonConcurrentPriorityQueue`) initialize(opts = {})

Returns a new instance of JavaNonConcurrentPriorityQueue

    14
    15
    16
    17
    18
    19
    20
    21

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 14

    def initialize(opts = {})
      order = opts.fetch(:order, :max)
      if [:min, :low].include?(order)
        @queue = java.util.PriorityQueue.new(11) # 11 is the default initial capacity
      else
        @queue = java.util.PriorityQueue.new(11, java.util.Collections.reverseOrder())
      end
    end

## Class Method Details

### + (`NonConcurrentPriorityQueue`) from_list(list, opts = {})

Create a new priority queue from the given list.

Parameters:

- list (`Enumerable`) —

  the list to build the queue from

- opts (`Hash`) (defaults to: `{}`) —

  the options for creating the queue

Returns:

- (`NonConcurrentPriorityQueue`) —

  the newly created and populated queue

    76
    77
    78
    79
    80

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 76

    def self.from_list(list, opts = {})
      queue = new(opts)
      list.each{|item| queue << item }
      queue
    end

## Instance Method Details

### - (`undocumented`) clear

    24
    25
    26
    27

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 24

    def clear
      @queue.clear
      true
    end

### - (`undocumented`) delete(item)

    30
    31
    32
    33
    34
    35
    36

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 30

    def delete(item)
      found = false
      while @queue.remove(item) do
        found = true
      end
      found
    end

### - (`Boolean`) empty?

Returns:

- (`Boolean`)

    39
    40
    41

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 39

    def empty?
      @queue.size == 0
    end

### - (`Boolean`) include?(item) Also known as: has_priority?

Returns:

- (`Boolean`)

    44
    45
    46

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 44

    def include?(item)
      @queue.contains(item)
    end

### - (`undocumented`) length Also known as: size

    50
    51
    52

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 50

    def length
      @queue.size
    end

### - (`undocumented`) peek

    56
    57
    58

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 56

    def peek
      @queue.peek
    end

### - (`undocumented`) pop Also known as: deq, shift

    61
    62
    63

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 61

    def pop
      @queue.poll
    end

### - (`undocumented`) push(item) Also known as: <<, enq

Raises:

- (`ArgumentError`)

    68
    69
    70
    71

    # File 'lib/concurrent/collection/java_non_concurrent_priority_queue.rb', line 68

    def push(item)
      raise ArgumentError.new('cannot enqueue nil') if item.nil?
      @queue.add(item)
    end