separate RelationTypeFactory from RelationType

This commit is contained in:
Eyck Jentzsch 2021-01-04 17:32:32 +01:00
parent 841b5fe2b2
commit 351a246238
10 changed files with 35 additions and 27 deletions

View File

@ -8,5 +8,4 @@
<version>2.0.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath> <relativePath>../..</relativePath>
</parent> </parent>
<version>2.0.0-SNAPSHOT</version>
</project> </project>

View File

@ -24,8 +24,8 @@ import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.HierNode; import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent; import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory;
import com.minres.scviewer.database.WaveformType; import com.minres.scviewer.database.WaveformType;
import com.minres.scviewer.database.sqlite.db.IDatabase; import com.minres.scviewer.database.sqlite.db.IDatabase;
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler; import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
@ -165,7 +165,7 @@ public class TxStream extends HierNode implements IWaveform {
} }
public RelationType getRelationType(String name) { public RelationType getRelationType(String name) {
RelationType relType=RelationType.create(name); RelationType relType=RelationTypeFactory.create(name);
if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType); if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType);
return relType; return relType;
} }

View File

@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Control;
import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory;
public interface IWaveformView extends PropertyChangeListener, ISelectionProvider{ public interface IWaveformView extends PropertyChangeListener, ISelectionProvider{
@ -29,7 +30,7 @@ public interface IWaveformView extends PropertyChangeListener, ISelectionProvide
String MARKER_PROPERTY = "marker_time"; String MARKER_PROPERTY = "marker_time";
public static final RelationType NEXT_PREV_IN_STREAM = RelationType.create("Prev/Next in stream"); public static final RelationType NEXT_PREV_IN_STREAM = RelationTypeFactory.create("Prev/Next in stream");
public void addSelectionChangedListener(ISelectionChangedListener listener); public void addSelectionChangedListener(ISelectionChangedListener listener);

View File

@ -8,5 +8,4 @@
<relativePath>../..</relativePath> <relativePath>../..</relativePath>
</parent> </parent>
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
<version>2.0.0-SNAPSHOT</version>
</project> </project>

View File

@ -11,31 +11,16 @@
package com.minres.scviewer.database; package com.minres.scviewer.database;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
public class RelationType implements Serializable { public class RelationType implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 6394859077558971735L; private static final long serialVersionUID = 6394859077558971735L;
private static HashMap<String, RelationType> registry = new HashMap<>();
private String name; private String name;
public static RelationType create(String name){ RelationType(String name) {
if(registry.containsKey(name)){
return registry.get(name);
}else{
RelationType relType = new RelationType(name);
registry.put(name, relType);
return relType;
}
}
private RelationType(String name) {
super(); super();
this.name = name; this.name = name;
} }
@ -59,6 +44,9 @@ public class RelationType implements Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return name.equals(obj); if(obj instanceof RelationType)
return name.equals(((RelationType)obj).name);
else
return false;
} }
} }

View File

@ -0,0 +1,22 @@
package com.minres.scviewer.database;
import java.util.HashMap;
public class RelationTypeFactory {
public static RelationType create(String name){
if(registry.containsKey(name)){
return registry.get(name);
}else{
RelationType relType = new RelationType(name);
registry.put(name, relType);
return relType;
}
}
private RelationTypeFactory() {}
private static HashMap<String, RelationType> registry = new HashMap<>();
}

View File

@ -11,7 +11,6 @@
package com.minres.scviewer.database.internal; package com.minres.scviewer.database.internal;
import java.io.File; import java.io.File;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -10,8 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.tx; package com.minres.scviewer.database.tx;
import java.io.Serializable;
import com.minres.scviewer.database.AssociationType; import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.DataType;

View File

@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory;
import com.minres.scviewer.database.tx.ITx; import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.e4.application.Messages; import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.parts.PartListener; import com.minres.scviewer.e4.application.parts.PartListener;
@ -50,7 +51,7 @@ public class RelationTypeToolControl extends PartListener implements ISelectionC
WaveformViewer waveformViewerPart; WaveformViewer waveformViewerPart;
/** The dummy. */ /** The dummy. */
RelationType dummy = RelationType.create(Messages.RelationTypeToolControl_0); RelationType dummy = RelationTypeFactory.create(Messages.RelationTypeToolControl_0);
/** /**
* Instantiates a new relation type tool control. * Instantiates a new relation type tool control.

View File

@ -87,6 +87,7 @@ import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb; import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory; import com.minres.scviewer.database.IWaveformDbFactory;
import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory;
import com.minres.scviewer.database.tx.ITx; import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.ITxAttribute; import com.minres.scviewer.database.tx.ITxAttribute;
import com.minres.scviewer.database.tx.ITxEvent; import com.minres.scviewer.database.tx.ITxEvent;
@ -1237,7 +1238,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* @param relationName the new navigation relation type * @param relationName the new navigation relation type
*/ */
public void setNavigationRelationType(String relationName) { public void setNavigationRelationType(String relationName) {
setNavigationRelationType(RelationType.create(relationName)); setNavigationRelationType(RelationTypeFactory.create(relationName));
} }
/** /**