Formatting, annotations, and other pedantry from Dave Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2707 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -140,6 +140,7 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
protected class EntrySet extends AbstractSet<Map.Entry<K, Integer>>
|
protected class EntrySet extends AbstractSet<Map.Entry<K, Integer>>
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public Iterator<Map.Entry<K, Integer>> iterator ()
|
public Iterator<Map.Entry<K, Integer>> iterator ()
|
||||||
{
|
{
|
||||||
// fuck if I know why I gotta jump through this hoop
|
// fuck if I know why I gotta jump through this hoop
|
||||||
@@ -149,7 +150,7 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains (Object o) {
|
public boolean contains (Object o) {
|
||||||
if (!(o instanceof Map.Entry)) {
|
if (!(o instanceof Map.Entry<?, ?>)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Map.Entry<?, ?> oentry = (Map.Entry<?, ?>) o;
|
Map.Entry<?, ?> oentry = (Map.Entry<?, ?>) o;
|
||||||
@@ -157,6 +158,7 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
return (entry != null) && entry.getValue().equals(oentry.getValue());
|
return (entry != null) && entry.getValue().equals(oentry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean remove (Object o) {
|
public boolean remove (Object o) {
|
||||||
if (contains(o)) {
|
if (contains(o)) {
|
||||||
CountMap.this.remove(((Map.Entry<?, ?>) o).getKey());
|
CountMap.this.remove(((Map.Entry<?, ?>) o).getKey());
|
||||||
@@ -165,10 +167,12 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int size () {
|
public int size () {
|
||||||
return CountMap.this.size();
|
return CountMap.this.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clear () {
|
public void clear () {
|
||||||
CountMap.this.clear();
|
CountMap.this.clear();
|
||||||
}
|
}
|
||||||
@@ -208,17 +212,19 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
return oldVal;
|
return oldVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int hashCode ()
|
public int hashCode ()
|
||||||
{
|
{
|
||||||
return ((key == null) ? 0 : key.hashCode()) ^ count;
|
return ((key == null) ? 0 : key.hashCode()) ^ count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals (Object o)
|
public boolean equals (Object o)
|
||||||
{
|
{
|
||||||
if (o == this) {
|
if (o == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(o instanceof Map.Entry)) {
|
if (!(o instanceof Map.Entry<?, ?>)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
|
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
|
||||||
@@ -227,6 +233,7 @@ public class CountMap<K> extends AbstractMap<K, Integer>
|
|||||||
getValue().equals(e.getValue());
|
getValue().equals(e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
return key + "=" + count;
|
return key + "=" + count;
|
||||||
|
|||||||
@@ -185,20 +185,16 @@ public class IntSets
|
|||||||
// the following are overridden so that they don't appear to work if given empty collections
|
// the following are overridden so that they don't appear to work if given empty collections
|
||||||
// or an improper Object key
|
// or an improper Object key
|
||||||
@Override public boolean remove (Object o) { throw new UnsupportedOperationException(); }
|
@Override public boolean remove (Object o) { throw new UnsupportedOperationException(); }
|
||||||
@Override public boolean addAll (Collection<? extends Integer> c)
|
@Override public boolean addAll (Collection<? extends Integer> c) {
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@Override public boolean removeAll (Collection<?> c)
|
@Override public boolean removeAll (Collection<?> c) {
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@Override public boolean retainAll (Collection<?> c)
|
@Override public boolean retainAll (Collection<?> c) {
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@Override public void clear ()
|
@Override public void clear () {
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
} // end: class AbstractImmutableIntSet
|
} // end: class AbstractImmutableIntSet
|
||||||
@@ -212,16 +208,14 @@ public class IntSets
|
|||||||
@Override public int size () { return 0; }
|
@Override public int size () { return 0; }
|
||||||
@Override public boolean isEmpty () { return true; }
|
@Override public boolean isEmpty () { return true; }
|
||||||
|
|
||||||
public Interator interator ()
|
public Interator interator () {
|
||||||
{
|
|
||||||
return EMPTY_INTERATOR;
|
return EMPTY_INTERATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Interator EMPTY_INTERATOR =
|
protected static Interator EMPTY_INTERATOR = new AbstractInterator() {
|
||||||
new AbstractInterator() {
|
public boolean hasNext () { return false; }
|
||||||
public boolean hasNext () { return false; }
|
public int nextInt () { throw new NoSuchElementException(); }
|
||||||
public int nextInt () { throw new NoSuchElementException(); }
|
};
|
||||||
};
|
|
||||||
} // end: class EmptyIntSet
|
} // end: class EmptyIntSet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,8 +223,7 @@ public class IntSets
|
|||||||
*/
|
*/
|
||||||
protected static class UnmodifiableIntSetView extends AbstractImmutableIntSet
|
protected static class UnmodifiableIntSetView extends AbstractImmutableIntSet
|
||||||
{
|
{
|
||||||
public UnmodifiableIntSetView (IntSet s)
|
public UnmodifiableIntSetView (IntSet s) {
|
||||||
{
|
|
||||||
_s = s;
|
_s = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +231,7 @@ public class IntSets
|
|||||||
@Override public int size () { return _s.size(); }
|
@Override public int size () { return _s.size(); }
|
||||||
@Override public boolean isEmpty () { return _s.isEmpty(); }
|
@Override public boolean isEmpty () { return _s.isEmpty(); }
|
||||||
|
|
||||||
public Interator interator ()
|
public Interator interator () {
|
||||||
{
|
|
||||||
return new AbstractInterator() {
|
return new AbstractInterator() {
|
||||||
public boolean hasNext () { return _i.hasNext(); }
|
public boolean hasNext () { return _i.hasNext(); }
|
||||||
public int nextInt () { return _i.nextInt(); }
|
public int nextInt () { return _i.nextInt(); }
|
||||||
@@ -257,13 +249,11 @@ public class IntSets
|
|||||||
*/
|
*/
|
||||||
protected static abstract class FindingInterator extends AbstractInterator
|
protected static abstract class FindingInterator extends AbstractInterator
|
||||||
{
|
{
|
||||||
public boolean hasNext ()
|
public boolean hasNext () {
|
||||||
{
|
|
||||||
return _hasNext || (_hasNext = findNext());
|
return _hasNext || (_hasNext = findNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int nextInt ()
|
public int nextInt () {
|
||||||
{
|
|
||||||
if (_hasNext) {
|
if (_hasNext) {
|
||||||
_hasNext = false;
|
_hasNext = false;
|
||||||
} else if (!findNext()) { // support calling nextInt() without using hasNext() (tsk tsk)
|
} else if (!findNext()) { // support calling nextInt() without using hasNext() (tsk tsk)
|
||||||
@@ -290,8 +280,7 @@ public class IntSets
|
|||||||
*/
|
*/
|
||||||
protected static class AndIntSetView extends AbstractImmutableIntSet
|
protected static class AndIntSetView extends AbstractImmutableIntSet
|
||||||
{
|
{
|
||||||
public AndIntSetView (IntSet... sources)
|
public AndIntSetView (IntSet... sources) {
|
||||||
{
|
|
||||||
if (sources.length == 0) {
|
if (sources.length == 0) {
|
||||||
_sources = new IntSet[] { IntSets.emptyIntSet() };
|
_sources = new IntSet[] { IntSets.emptyIntSet() };
|
||||||
|
|
||||||
@@ -303,8 +292,7 @@ public class IntSets
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains (int value)
|
public boolean contains (int value) {
|
||||||
{
|
|
||||||
for (IntSet src : _sources) {
|
for (IntSet src : _sources) {
|
||||||
if (!src.contains(value)) {
|
if (!src.contains(value)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -315,11 +303,9 @@ public class IntSets
|
|||||||
|
|
||||||
// TODO: smarter size() (Right now we're using inherited, which counts interated)
|
// TODO: smarter size() (Right now we're using inherited, which counts interated)
|
||||||
|
|
||||||
public Interator interator ()
|
public Interator interator () {
|
||||||
{
|
|
||||||
return new FindingInterator() {
|
return new FindingInterator() {
|
||||||
@Override protected boolean findNext ()
|
@Override protected boolean findNext () {
|
||||||
{
|
|
||||||
OUTER:
|
OUTER:
|
||||||
while (_i.hasNext()) {
|
while (_i.hasNext()) {
|
||||||
_next = _i.nextInt();
|
_next = _i.nextInt();
|
||||||
@@ -344,18 +330,15 @@ public class IntSets
|
|||||||
/**
|
/**
|
||||||
* An "or" view of the specified sources.
|
* An "or" view of the specified sources.
|
||||||
*/
|
*/
|
||||||
protected static class OrIntSetView extends AbstractImmutableIntSet
|
protected static class OrIntSetView extends AbstractImmutableIntSet {
|
||||||
{
|
public OrIntSetView (IntSet... sources) {
|
||||||
public OrIntSetView (IntSet... sources)
|
|
||||||
{
|
|
||||||
_sources = sources;
|
_sources = sources;
|
||||||
// TODO: sort sources by size (largest first), to optimize general checks?
|
// TODO: sort sources by size (largest first), to optimize general checks?
|
||||||
// TODO: copy array to prevent befuckery?
|
// TODO: copy array to prevent befuckery?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains (int value)
|
public boolean contains (int value) {
|
||||||
{
|
|
||||||
for (IntSet src : _sources) {
|
for (IntSet src : _sources) {
|
||||||
if (src.contains(value)) {
|
if (src.contains(value)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -364,13 +347,12 @@ public class IntSets
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: smarter size() (right now we're using inherited, which
|
// TODO: smarter size() (right now we're using inherited, which
|
||||||
|
|
||||||
public Interator interator ()
|
public Interator interator () {
|
||||||
{
|
|
||||||
return new FindingInterator() {
|
return new FindingInterator() {
|
||||||
protected boolean findNext ()
|
@Override
|
||||||
{
|
protected boolean findNext () {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (_i == null) {
|
if (_i == null) {
|
||||||
if (_srcIdx >= _sources.length - 1) {
|
if (_srcIdx >= _sources.length - 1) {
|
||||||
@@ -408,14 +390,12 @@ public class IntSets
|
|||||||
/**
|
/**
|
||||||
* Construct a ComplementIntSet with the specified view source.
|
* Construct a ComplementIntSet with the specified view source.
|
||||||
*/
|
*/
|
||||||
public NotIntSetView (IntSet source)
|
public NotIntSetView (IntSet source) {
|
||||||
{
|
|
||||||
_source = source;
|
_source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size ()
|
public int size () {
|
||||||
{
|
|
||||||
// Even if our source was an ArrayIntSet with exactly MAX_VALUE elements,
|
// Even if our source was an ArrayIntSet with exactly MAX_VALUE elements,
|
||||||
// there are still over MAX_VALUE ints in the complement!
|
// there are still over MAX_VALUE ints in the complement!
|
||||||
if (_source.size() < Integer.MAX_VALUE) {
|
if (_source.size() < Integer.MAX_VALUE) {
|
||||||
@@ -426,8 +406,7 @@ public class IntSets
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from IntSet
|
@Override // from IntSet
|
||||||
public boolean contains (int value)
|
public boolean contains (int value) {
|
||||||
{
|
|
||||||
return !_source.contains(value);
|
return !_source.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,42 +414,40 @@ public class IntSets
|
|||||||
* Returns the positive integers first, starting with 0.
|
* Returns the positive integers first, starting with 0.
|
||||||
*/
|
*/
|
||||||
// from IntSet
|
// from IntSet
|
||||||
public Interator interator ()
|
public Interator interator () {
|
||||||
{
|
|
||||||
return new FindingInterator() {
|
return new FindingInterator() {
|
||||||
protected boolean findNext ()
|
@Override
|
||||||
{
|
protected boolean findNext () {
|
||||||
if (_positive) {
|
if (_positive) {
|
||||||
// first go from 0 to MAX_VALUE
|
// first go from 0 to MAX_VALUE
|
||||||
while (_next != Integer.MAX_VALUE) {
|
while (_next != Integer.MAX_VALUE) {
|
||||||
if (contains(++_next)) {
|
if (contains(++_next)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// prepare to go negative.. (preparing to go negative, sir!)
|
// prepare to go negative.. (preparing to go negative, sir!)
|
||||||
_positive = false;
|
_positive = false;
|
||||||
_next = 0;
|
_next = 0;
|
||||||
}
|
}
|
||||||
// now go down from -1 to MIN_VALUE
|
// now go down from -1 to MIN_VALUE
|
||||||
while (_next != Integer.MIN_VALUE) {
|
while (_next != Integer.MIN_VALUE) {
|
||||||
if (contains(--_next)) {
|
if (contains(--_next)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // initializer
|
{ // initializer
|
||||||
_next = -1;
|
_next = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean _positive = true;
|
protected boolean _positive = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from IntSet
|
@Override // from IntSet
|
||||||
public int[] toIntArray ()
|
public int[] toIntArray () {
|
||||||
{
|
|
||||||
Interator it = interator();
|
Interator it = interator();
|
||||||
if (!it.hasNext()) {
|
if (!it.hasNext()) {
|
||||||
return new int[0];
|
return new int[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user