Skip to content

Commit

Permalink
ttools: make certain ShapeForm implementations effectively @Equality
Browse files Browse the repository at this point in the history
SizeForm and PairLinkForm are now singletons.  MarkForm overrides
equals and hashCode.  This is so that certain distinct but equivalent
ShapePlotters can be identified as the same, though neither MarkForm
nor Plotter is currently declared with the annotation @Equality.
This is used by MatchPlotter so that adding layers can be done by
inserting layer attributes into existing layers, so it makes it
tidier rather than being essential.  Maybe declare MarkForm as
@Equality at some point, it could be done.
  • Loading branch information
mbtaylor committed Dec 17, 2013
1 parent 020a901 commit 441756e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public Plotter[] getPlotters() {
List<Plotter> list = new ArrayList<Plotter>();
ShapeForm[] forms = new ShapeForm[] {
MarkForm.SINGLE,
new SizeForm(),
SizeForm.getInstance(),
MultiPointForm
.createVectorForm( new CartesianVectorCoordSet( axisNames_ ),
true ),
MultiPointForm
.createErrorForm( CartesianErrorCoordSet
.createAllAxesErrorCoordSet( axisNames_ ),
StyleKeys.ERROR_SHAPE_3D ),
new PairLinkForm(),
PairLinkForm.getInstance(),
MarkForm.PAIR,
};
Plotter[] shapePlotters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Plotter[] getPlotters() {
List<Plotter> list = new ArrayList<Plotter>();
ShapeForm[] forms = new ShapeForm[] {
MarkForm.SINGLE,
new SizeForm(),
SizeForm.getInstance(),
MultiPointForm
.createVectorForm( new CartesianVectorCoordSet( axisNames_ ), true ),
MultiPointForm
Expand All @@ -72,7 +72,7 @@ public Plotter[] getPlotters() {
StyleKeys.ERROR_SHAPE_2D ),
MultiPointForm
.createEllipseForm( new PlaneEllipseCoordSet(), true ),
new PairLinkForm(),
PairLinkForm.getInstance(),
MarkForm.PAIR,
};
Plotter[] shapePlotters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public Plotter[] getPlotters() {
List<Plotter> list = new ArrayList<Plotter>();
ShapeForm[] forms = new ShapeForm[] {
MarkForm.SINGLE,
new SizeForm(),
SizeForm.getInstance(),
MultiPointForm.createVectorForm( new SkyVectorCoordSet( true ),
true ),
MultiPointForm.createEllipseForm( new SkyEllipseCoordSet(), true ),
new PairLinkForm(),
PairLinkForm.getInstance(),
MarkForm.PAIR,
};
Plotter[] shapePlotters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public Plotter[] getPlotters() {
List<Plotter> list = new ArrayList<Plotter>();
ShapeForm[] forms = new ShapeForm[] {
MarkForm.SINGLE,
new SizeForm(),
new PairLinkForm(),
SizeForm.getInstance(),
PairLinkForm.getInstance(),
MarkForm.PAIR,
};
Plotter[] shapePlotters =
Expand Down
16 changes: 16 additions & 0 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/layer/MarkForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public Coord[] getExtraCoords() {
return new Coord[ 0 ];
}

@Override
public int hashCode() {
return npos_;
}

@Override
public boolean equals( Object o ) {
if ( o instanceof MarkForm ) {
MarkForm other = (MarkForm) o;
return this.npos_ == other.npos_;
}
else {
return false;
}
}

/**
* Factory method to create an instance of this class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@

/**
* Draws a line between two related positions.
* Singleton class.
*
* @author Mark Taylor
* @since 28 Nov 2013
*/
public class PairLinkForm implements ShapeForm {

private static final PairLinkForm instance_ = new PairLinkForm();

/**
* Private constructor prevents instantiation.
*/
private PairLinkForm() {
}

public String getFormName() {
return "Link";
}
Expand All @@ -56,6 +65,15 @@ public Outliner createOutliner( ConfigMap config ) {
return new LinkOutliner();
}

/**
* Returns the singleton instance of this class.
*
* @return sole instance
*/
public static PairLinkForm getInstance() {
return instance_;
}

/**
* Returns an uncoloured icon suitable for use in a legend.
*
Expand Down
18 changes: 18 additions & 0 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/layer/SizeForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* ShapeForm implementation that draws shaped markers of a size
* given by an additional data coordinate.
* Auto-scaling is provided.
* Singleton class.
*
* @author Mark Taylor
* @since 18 Feb 2013
Expand All @@ -50,6 +51,14 @@ public class SizeForm implements ShapeForm {
16, 2, 64, false );
private static final AuxScale SIZE_SCALE = new AuxScale( "globalsize" );

private static final SizeForm instance_ = new SizeForm();

/**
* Private constructor prevents instantiation.
*/
private SizeForm() {
}

public int getPositionCount() {
return 1;
}
Expand Down Expand Up @@ -90,6 +99,15 @@ public Outliner createOutliner( ConfigMap config ) {
return new SizeOutliner( shape, scale, autoscale );
}

/**
* Returns the sole instance of this class.
*
* @return singleton instance
*/
public static SizeForm getInstance() {
return instance_;
}

/**
* Returns the column index in a tuple sequenc at which the size
* coordinate will be found.
Expand Down

0 comments on commit 441756e

Please sign in to comment.