From: Gary P. <gpa...@gm...> - 2009-09-08 13:25:07
|
I like the refactor. Patch currently in testing. On Tuesday 08 September 2009 14:36:40 Andrich van Wyk wrote: > The Visitor abstract class only implemented a single method (isDone) and > had an empty default constructor (it maintained no instance fields). It > has therefore been changed to an interface and the responisibility of > isDone delegated to the implementing class. Updated extensions > accordingly. > --- > .../cilib/container/visitor/PrePostVisitor.java | 11 ++++++++++- > .../cilib/container/visitor/Visitor.java | 14 +++----------- > .../cilib/entity/visitor/ClosestEntityVisitor.java | 8 ++++++++ > .../cilib/entity/visitor/DiameterVisitor.java | 8 ++++++++ > .../cilib/entity/visitor/RadiusVisitor.java | 8 ++++++++ > .../cilib/entity/visitor/SpatialRadiusVisitor.java | 8 ++++++++ > .../cilib/entity/visitor/TopologyVisitor.java | 2 +- > .../foundation/NeuralNetworkRetrievalVisitor.java | 5 +++++ > .../sourceforge/cilib/problem/ProblemVisitor.java | 3 ++- > .../cilib/pso/particle/ParticleVisitor.java | 3 ++- > .../net/sourceforge/cilib/type/types/Types.java | 2 +- > 11 files changed, 56 insertions(+), 16 deletions(-) > > diff --git > a/src/main/java/net/sourceforge/cilib/container/visitor/PrePostVisitor.jav > a > b/src/main/java/net/sourceforge/cilib/container/visitor/PrePostVisitor.jav > a index 63ca955..207ba86 100644 > --- > a/src/main/java/net/sourceforge/cilib/container/visitor/PrePostVisitor.jav > a +++ > b/src/main/java/net/sourceforge/cilib/container/visitor/PrePostVisitor.jav > a @@ -31,7 +31,7 @@ package net.sourceforge.cilib.container.visitor; * > @author Gary Pampara > * @param <E> The element type. > */ > -public class PrePostVisitor<E> extends Visitor<E> { > +public class PrePostVisitor<E> implements Visitor<E> { > > /** > * Create a new instance of {@linkplain PrePostVisitor}. > @@ -48,6 +48,7 @@ public class PrePostVisitor<E> extends Visitor<E> { > /** > * {@inheritDoc} > */ > + @Override > public void visit(E o) {}; > > /** > @@ -55,4 +56,12 @@ public class PrePostVisitor<E> extends Visitor<E> { > * @param o The element to post visit. > */ > public void postVisit(E o) {}; > + > + /** > + * {@inheritDoc} > + */ > + @Override > + public boolean isDone() { > + return false; > + } > } > diff --git > a/src/main/java/net/sourceforge/cilib/container/visitor/Visitor.java > b/src/main/java/net/sourceforge/cilib/container/visitor/Visitor.java index > db5d38a..e0c9220 100644 > --- a/src/main/java/net/sourceforge/cilib/container/visitor/Visitor.java > +++ b/src/main/java/net/sourceforge/cilib/container/visitor/Visitor.java > @@ -24,16 +24,10 @@ package net.sourceforge.cilib.container.visitor; > /** > * Abstract class defining the general structure of a <tt>Visitor</tt>. > * > - * @author Gary Pampara > + * @author Gary Pampara, andrich > * @param <E> The type object. > */ > -public abstract class Visitor<E> { > - > - /** > - * Create the {@linkplain Visitor} instance. > - */ > - protected Visitor() { > - } > +public interface Visitor<E> { > > /** > * Visit the provided object. > @@ -46,7 +40,5 @@ public abstract class Visitor<E> { > * @return <code>true</code> if the visit operation is complete, > * <code>false</code> otherwise. > */ > - public boolean isDone() { > - return false; > - } > + public boolean isDone(); > } > diff --git > a/src/main/java/net/sourceforge/cilib/entity/visitor/ClosestEntityVisitor. > java > b/src/main/java/net/sourceforge/cilib/entity/visitor/ClosestEntityVisitor. > java index 6aa4580..97d229b 100644 > --- > a/src/main/java/net/sourceforge/cilib/entity/visitor/ClosestEntityVisitor. > java +++ > b/src/main/java/net/sourceforge/cilib/entity/visitor/ClosestEntityVisitor. > java @@ -35,6 +35,7 @@ public class ClosestEntityVisitor extends > TopologyVisitor { private Entity closestEntity; > private Entity targetEntity; > private double closest = Double.MAX_VALUE; > + private boolean done; > > /** > * Perform the search for the closest entity. > @@ -42,6 +43,7 @@ public class ClosestEntityVisitor extends TopologyVisitor > { */ > @Override > public void visit(Topology<? extends Entity> topology) { > + done = false; > closestEntity = null; > > for (Entity entity : topology) { > @@ -54,6 +56,7 @@ public class ClosestEntityVisitor extends TopologyVisitor > { this.closest = distance; > } > } > + done = true; > } > > /** > @@ -82,4 +85,9 @@ public class ClosestEntityVisitor extends TopologyVisitor > { this.targetEntity = targetEntity; > } > > + @Override > + public boolean isDone() { > + return done; > + } > + > } > diff --git > a/src/main/java/net/sourceforge/cilib/entity/visitor/DiameterVisitor.java > b/src/main/java/net/sourceforge/cilib/entity/visitor/DiameterVisitor.java > index 8c182a7..a7324c4 100644 > --- > a/src/main/java/net/sourceforge/cilib/entity/visitor/DiameterVisitor.java > +++ > b/src/main/java/net/sourceforge/cilib/entity/visitor/DiameterVisitor.java > @@ -34,12 +34,14 @@ import > net.sourceforge.cilib.type.types.container.Vector; public class > DiameterVisitor extends TopologyVisitor { > > private double distance = -Double.MAX_VALUE; > + private boolean done; > > public DiameterVisitor() { > } > > @Override > public void visit(Topology<? extends Entity> topology) { > + done = false; > double maxDistance = 0.0; > > Iterator<? extends Entity> k1 = topology.iterator(); > @@ -59,6 +61,7 @@ public class DiameterVisitor extends TopologyVisitor { > } > > distance = maxDistance; > + done = true; > } > > @Override > @@ -66,4 +69,9 @@ public class DiameterVisitor extends TopologyVisitor { > return this.distance; > } > > + @Override > + public boolean isDone() { > + return done; > + } > + > } > diff --git > a/src/main/java/net/sourceforge/cilib/entity/visitor/RadiusVisitor.java > b/src/main/java/net/sourceforge/cilib/entity/visitor/RadiusVisitor.java > index cebfdf5..400bfcc 100644 > --- a/src/main/java/net/sourceforge/cilib/entity/visitor/RadiusVisitor.java > +++ b/src/main/java/net/sourceforge/cilib/entity/visitor/RadiusVisitor.java > @@ -33,6 +33,7 @@ import net.sourceforge.cilib.type.types.container.Vector; > public class RadiusVisitor extends TopologyVisitor { > > private double radius = -Double.MAX_VALUE; > + private boolean done; > > /** > * {@inheritDoc} > @@ -41,6 +42,7 @@ public class RadiusVisitor extends TopologyVisitor { > */ > @Override > public void visit(Topology<? extends Entity> topology) { > + done = false; > double maxDistance = 0.0; > > Vector swarmBestParticlePosition = (Vector) > this.currentAlgorithm.getBestSolution().getPosition(); @@ -57,6 +59,7 @@ > public class RadiusVisitor extends TopologyVisitor { } > > radius = maxDistance; > + done = true; > } > > @Override > @@ -64,4 +67,9 @@ public class RadiusVisitor extends TopologyVisitor { > return this.radius; > } > > + @Override > + public boolean isDone() { > + return done; > + } > + > } > diff --git > a/src/main/java/net/sourceforge/cilib/entity/visitor/SpatialRadiusVisitor. > java > b/src/main/java/net/sourceforge/cilib/entity/visitor/SpatialRadiusVisitor. > java index 1bb02d0..37c2182 100644 > --- > a/src/main/java/net/sourceforge/cilib/entity/visitor/SpatialRadiusVisitor. > java +++ > b/src/main/java/net/sourceforge/cilib/entity/visitor/SpatialRadiusVisitor. > java @@ -34,12 +34,14 @@ import > net.sourceforge.cilib.type.types.container.Vector; public class > SpatialRadiusVisitor extends TopologyVisitor { > > private double radius = -Double.MAX_VALUE; > + private boolean done; > > /** > * {@inheritDoc} > */ > @Override > public void visit(Topology<? extends Entity> topology) { > + done = false; > // set radius value to be returned to zero > double maxDistance = 0.0; > > @@ -78,6 +80,7 @@ public class SpatialRadiusVisitor extends TopologyVisitor > { } > > radius = maxDistance; > + done = true; > } > > @Override > @@ -85,4 +88,9 @@ public class SpatialRadiusVisitor extends TopologyVisitor > { return this.radius; > } > > + @Override > + public boolean isDone() { > + return done; > + } > + > } > diff --git > a/src/main/java/net/sourceforge/cilib/entity/visitor/TopologyVisitor.java > b/src/main/java/net/sourceforge/cilib/entity/visitor/TopologyVisitor.java > index 8c4f77b..1f1d011 100644 > --- > a/src/main/java/net/sourceforge/cilib/entity/visitor/TopologyVisitor.java > +++ > b/src/main/java/net/sourceforge/cilib/entity/visitor/TopologyVisitor.java > @@ -36,7 +36,7 @@ import > net.sourceforge.cilib.util.EuclideanDistanceMeasure; * > * @author gpampara > */ > -public abstract class TopologyVisitor extends Visitor<Topology<? extends > Entity>> { +public abstract class TopologyVisitor implements > Visitor<Topology<? extends Entity>> { > > protected Algorithm currentAlgorithm; > protected DistanceMeasure distanceMeasure; > diff --git > a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetwo > rkRetrievalVisitor.java > b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetwo > rkRetrievalVisitor.java index b8fa30b..1ca32c1 100644 > --- > a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetwo > rkRetrievalVisitor.java +++ > b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetwo > rkRetrievalVisitor.java @@ -43,4 +43,9 @@ public class > NeuralNetworkRetrievalVisitor extends ProblemVisitor { public > EvaluationMediator getMediator() { > return mediator; > } > + > + @Override > + public boolean isDone() { > + return false; > + } > } > diff --git > a/src/main/java/net/sourceforge/cilib/problem/ProblemVisitor.java > b/src/main/java/net/sourceforge/cilib/problem/ProblemVisitor.java index > 3d27452..42acb8d 100644 > --- a/src/main/java/net/sourceforge/cilib/problem/ProblemVisitor.java > +++ b/src/main/java/net/sourceforge/cilib/problem/ProblemVisitor.java > @@ -23,11 +23,12 @@ package net.sourceforge.cilib.problem; > > import net.sourceforge.cilib.container.visitor.Visitor; > > -public abstract class ProblemVisitor extends Visitor<Problem> { > +public abstract class ProblemVisitor implements Visitor<Problem> { > > /** > * {@inheritDoc} > */ > + @Override > public abstract void visit(Problem o); > > } > diff --git > a/src/main/java/net/sourceforge/cilib/pso/particle/ParticleVisitor.java > b/src/main/java/net/sourceforge/cilib/pso/particle/ParticleVisitor.java > index d822605..c463415 100644 > --- a/src/main/java/net/sourceforge/cilib/pso/particle/ParticleVisitor.java > +++ b/src/main/java/net/sourceforge/cilib/pso/particle/ParticleVisitor.java > @@ -28,11 +28,12 @@ import net.sourceforge.cilib.entity.Particle; > /** > * @author Edwin Peer > */ > -public abstract class ParticleVisitor extends Visitor<Particle> { > +public abstract class ParticleVisitor implements Visitor<Particle> { > > /** > * Visit the provided particle. > * @param entity The {@linkplain Particle} to apply the visitor to. > */ > + @Override > public abstract void visit(Particle entity); > } > diff --git a/src/main/java/net/sourceforge/cilib/type/types/Types.java > b/src/main/java/net/sourceforge/cilib/type/types/Types.java index > f6dc48c..963b06b 100644 > --- a/src/main/java/net/sourceforge/cilib/type/types/Types.java > +++ b/src/main/java/net/sourceforge/cilib/type/types/Types.java > @@ -57,7 +57,7 @@ public final class Types { > return false; > } > > - private static class BoundsVerificationVisitor extends Visitor<Type> { > + private static class BoundsVerificationVisitor implements > Visitor<Type> { private boolean valid = true; > private boolean isDone = false; > |