Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.energy;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -26,12 +27,141 @@ import appeng.api.networking.energy.IEnergyWatcher;
|
||||
import appeng.api.networking.energy.IEnergyWatcherHost;
|
||||
import appeng.me.cache.EnergyGridCache;
|
||||
|
||||
|
||||
/**
|
||||
* Maintain my interests, and a global watch list, they should always be fully synchronized.
|
||||
*/
|
||||
public class EnergyWatcher implements IEnergyWatcher
|
||||
{
|
||||
|
||||
final EnergyGridCache gsc;
|
||||
final IEnergyWatcherHost myObject;
|
||||
final HashSet<EnergyThreshold> myInterests = new HashSet<EnergyThreshold>();
|
||||
|
||||
public EnergyWatcher( EnergyGridCache cache, IEnergyWatcherHost host )
|
||||
{
|
||||
this.gsc = cache;
|
||||
this.myObject = host;
|
||||
}
|
||||
|
||||
public void post( EnergyGridCache energyGridCache )
|
||||
{
|
||||
this.myObject.onThresholdPass( energyGridCache );
|
||||
}
|
||||
|
||||
public IEnergyWatcherHost getHost()
|
||||
{
|
||||
return this.myObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains( Object o )
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Double> iterator()
|
||||
{
|
||||
return new EnergyWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray( T[] a )
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add( Double e )
|
||||
{
|
||||
if( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
EnergyThreshold eh = new EnergyThreshold( e, this );
|
||||
return this.gsc.interests.add( eh ) && this.myInterests.add( eh );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove( Object o )
|
||||
{
|
||||
EnergyThreshold eh = new EnergyThreshold( (Double) o, this );
|
||||
return this.myInterests.remove( eh ) && this.gsc.interests.remove( eh );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll( Collection<?> c )
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll( Collection<? extends Double> c )
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for( Double o : c )
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for( Object o : c )
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll( Collection<?> c )
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<Double> i = this.iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
if( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<EnergyThreshold> i = this.myInterests.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
this.gsc.interests.remove( i.next() );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
class EnergyWatcherIterator implements Iterator<Double>
|
||||
{
|
||||
|
||||
@@ -39,7 +169,8 @@ public class EnergyWatcher implements IEnergyWatcher
|
||||
final Iterator<EnergyThreshold> interestIterator;
|
||||
EnergyThreshold myLast;
|
||||
|
||||
public EnergyWatcherIterator(EnergyWatcher parent, Iterator<EnergyThreshold> i) {
|
||||
public EnergyWatcherIterator( EnergyWatcher parent, Iterator<EnergyThreshold> i )
|
||||
{
|
||||
this.watcher = parent;
|
||||
this.interestIterator = i;
|
||||
}
|
||||
@@ -63,134 +194,5 @@ public class EnergyWatcher implements IEnergyWatcher
|
||||
EnergyWatcher.this.gsc.interests.remove( this.myLast );
|
||||
this.interestIterator.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final EnergyGridCache gsc;
|
||||
final IEnergyWatcherHost myObject;
|
||||
final HashSet<EnergyThreshold> myInterests = new HashSet<EnergyThreshold>();
|
||||
|
||||
public void post(EnergyGridCache energyGridCache)
|
||||
{
|
||||
this.myObject.onThresholdPass( energyGridCache );
|
||||
}
|
||||
|
||||
public EnergyWatcher(EnergyGridCache cache, IEnergyWatcherHost host) {
|
||||
this.gsc = cache;
|
||||
this.myObject = host;
|
||||
}
|
||||
|
||||
public IEnergyWatcherHost getHost()
|
||||
{
|
||||
return this.myObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Double e)
|
||||
{
|
||||
if ( this.myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
EnergyThreshold eh = new EnergyThreshold( e, this );
|
||||
return this.gsc.interests.add( eh ) && this.myInterests.add( eh );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Double> c)
|
||||
{
|
||||
boolean didChange = false;
|
||||
|
||||
for (Double o : c)
|
||||
didChange = this.add( o ) || didChange;
|
||||
|
||||
return didChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
Iterator<EnergyThreshold> i = this.myInterests.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
this.gsc.interests.remove( i.next() );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o)
|
||||
{
|
||||
return this.myInterests.contains( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c)
|
||||
{
|
||||
return this.myInterests.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.myInterests.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Double> iterator()
|
||||
{
|
||||
return new EnergyWatcherIterator( this, this.myInterests.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o)
|
||||
{
|
||||
EnergyThreshold eh = new EnergyThreshold( (Double) o, this );
|
||||
return this.myInterests.remove( eh ) && this.gsc.interests.remove( eh );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c)
|
||||
{
|
||||
boolean didSomething = false;
|
||||
for (Object o : c)
|
||||
didSomething = this.remove( o ) || didSomething;
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c)
|
||||
{
|
||||
boolean changed = false;
|
||||
Iterator<Double> i = this.iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
if ( !c.contains( i.next() ) )
|
||||
{
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.myInterests.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray()
|
||||
{
|
||||
return this.myInterests.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a)
|
||||
{
|
||||
return this.myInterests.toArray( a );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user