## org.klomp.snark
Class Piece

    java.lang.Object
      org.klomp.snark.Piece

All Implemented Interfaces:
  Comparable

     class Piece

extends Object
implements Comparable

This class is used solely by PeerCoordinator. Caller must synchronize on many of these methods.

Constructor Summary
`Piece(int id)`

Method Summary
`boolean` `addPeer(Peer peer)` caller must synchronize
`int` `compareTo(Object o)` Highest priority first, then rarest first
`boolean` `equals(Object o)`
`int` `getId()`
`int` `getPriority()`
`int` `getRequestCount()` How many peers are requesting this piece? Caller must synchronize
`int` `hashCode()`
`boolean` `isDisabled()`
`boolean` `isRequested()` caller must synchronize
`boolean` `isRequestedBy(Peer peer)` Is peer requesting this piece? Caller must synchronize
`boolean` `removePeer(Peer peer)` caller must synchronize
`void` `setDisabled()`
`void` `setPriority(int p)`
`void` `setRequested(Peer peer, boolean requested)` Since 0.8.3, keep track of who is requesting here, to avoid deadlocks from querying each peer.
`String` `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Piece

    public Piece(int id)

Method Detail

### compareTo

    public int compareTo(Object o)
                  throws ClassCastException

  Highest priority first, then rarest first

  Specified by:
    `compareTo` in interface `Comparable`
  Throws:
    `ClassCastException`

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### getId

    public int getId()

### addPeer

    public boolean addPeer(Peer peer)

  caller must synchronize

### removePeer

    public boolean removePeer(Peer peer)

  caller must synchronize

### isRequested

    public boolean isRequested()

  caller must synchronize

### setRequested

    public void setRequested(Peer peer,
                             boolean requested)

  Since 0.8.3, keep track of who is requesting here, to avoid deadlocks from querying each peer. Caller must synchronize

### isRequestedBy

    public boolean isRequestedBy(Peer peer)

  Is peer requesting this piece? Caller must synchronize

  Since:
    0.8.3

### getRequestCount

    public int getRequestCount()

  How many peers are requesting this piece? Caller must synchronize

  Since:
    0.8.3

### getPriority

    public int getPriority()

  Returns:
    default 0 @since 0.8.1

### setPriority

    public void setPriority(int p)

  Since:
    0.8.1

### isDisabled

    public boolean isDisabled()

  Since:
    0.8.1

### setDisabled

    public void setDisabled()

  Since:
    0.8.1

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`