Top Description Inners Fields Constructors Methods
com.thoughtworks.xstream.core.util

public Class PrioritizedList

extends Object
Class Inheritance
Imports
java.util.Iterator, .Set, .TreeSet

List that allows items to be added with a priority that will affect the order in which they are later iterated over. Objects with a high priority will appear before objects with a low priority in the list. If two objects of the same priority are added to the list, the most recently added one will be iterated over first. Implementation uses a TreeSet, which has a guaranteed add time of O(log(n)).
Authors
Joe Walnes, Guilherme Silveira

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private int
private int
private final Set<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(Object item, int priority)

public Iterator<E>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lastIdback to summary
private int lastId
lowestPriorityback to summary
private int lowestPriority
setback to summary
private final Set<E> set

Constructor Detail

PrioritizedListback to summary
public PrioritizedList()

Method Detail

addback to summary
public void add(Object item, int priority)
iteratorback to summary
public Iterator<E> iterator()
com.thoughtworks.xstream.core.util back to summary

private Class PrioritizedList.PrioritizedItem

extends Object
implements Comparable
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.xstream.core.util.PrioritizedList.PrioritizedItem
All Implemented Interfaces
java.lang.Comparable

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
pack-priv final Object

Constructor Summary

AccessConstructor and Description
public
PrioritizedItem(Object value, int priority, int id)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

idback to summary
pack-priv final int id
priorityback to summary
pack-priv final int priority
valueback to summary
pack-priv final Object value

Constructor Detail

PrioritizedItemback to summary
public PrioritizedItem(Object value, int priority, int id)

Method Detail

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Object

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

com.thoughtworks.xstream.core.util back to summary

private Class PrioritizedList.PrioritizedItemIterator

extends Object
implements Iterator
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.xstream.core.util.PrioritizedList.PrioritizedItemIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private Iterator<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Object
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private Iterator<E> iterator

Constructor Detail

PrioritizedItemIteratorback to summary
public PrioritizedItemIterator(Iterator<E> iterator)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Object next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Object

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.