@@ -38,121 +38,69 @@ Development and Distribution License("CDDL") (collectively, the
3838Contributor(s):
3939
4040Portions Copyrighted 2011 Gephi Consortium.
41- */
41+ */
4242package org .gephi .io .importer .api ;
4343
4444import java .io .Serializable ;
45- import java .util .LinkedList ;
46- import java .util .List ;
45+ import java .util .HashMap ;
46+ import java .util .Map ;
4747
48- /**
49- *
50- * @author Mathieu Bastian
51- */
5248public final class PropertiesAssociations implements Serializable {
5349
5450 public enum NodeProperties {
55-
56- X , Y , Z , R , G , B , COLOR , SIZE , ID , LABEL , FIXED , START , END , START_OPEN , END_OPEN
51+ X , Y , Z , R , G , B , COLOR , SIZE , ID , LABEL , FIXED , START , END , START_OPEN , END_OPEN ;
5752 }
5853
5954 public enum EdgeProperties {
60-
61- R , G , B , COLOR , WEIGHT , ID , LABEL , ALPHA , SOURCE , TARGET , START , END , START_OPEN , END_OPEN
55+ R , G , B , COLOR , WEIGHT , ID , LABEL , ALPHA , SOURCE , TARGET , START , END , START_OPEN , END_OPEN ;
6256 }
63- //PropertiesAssociations association
64- private final List <PropertyAssociation <NodeProperties >> nodePropertyAssociations = new LinkedList <>();
65- private final List <PropertyAssociation <EdgeProperties >> edgePropertyAssociations = new LinkedList <>();
6657
67- public void addEdgePropertyAssociation (EdgeProperties property , String title ) {
68- PropertyAssociation <EdgeProperties > association = new PropertyAssociation <>(property , title );
69- /*if (edgePropertyAssociations.contains(association)) {
70- return;
71- }
72- //Avoid any double
73- for (Iterator<PropertyAssociation<EdgeProperties>> itr = edgePropertyAssociations.iterator(); itr.hasNext();) {
74- PropertyAssociation<EdgeProperties> p = itr.next();
75- if (p.getTitle().equalsIgnoreCase(association.getTitle())) {
76- itr.remove();
77- } else if (p.getProperty().equals(association.getProperty())) {
78- itr.remove();
79- }
80- }*/
81- edgePropertyAssociations .add (association );
82- }
58+ private final Map <String , NodeProperties > titleToNodeProperty = new HashMap <>();
59+ private final Map <String , EdgeProperties > titleToEdgeProperty = new HashMap <>();
8360
8461 public void addNodePropertyAssociation (NodeProperties property , String title ) {
85- PropertyAssociation <NodeProperties > association = new PropertyAssociation <>(property , title );
86- /*if (nodePropertyAssociations.contains(association)) {
87- return;
88- }
89- //Avoid any double
90- for (Iterator<PropertyAssociation<NodeProperties>> itr = nodePropertyAssociations.iterator(); itr.hasNext();) {
91- PropertyAssociation<NodeProperties> p = itr.next();
92- if (p.getTitle().equalsIgnoreCase(association.getTitle())) {
93- itr.remove();
94- } else if (p.getProperty().equals(association.getProperty())) {
95- itr.remove();
96- }
97- }*/
98- nodePropertyAssociations .add (association );
62+ titleToNodeProperty .put (title , property );
9963 }
10064
101- PropertyAssociation <EdgeProperties >[] getEdgePropertiesAssociation () {
102- return edgePropertyAssociations .toArray (new PropertyAssociation [0 ]);
103- }
104-
105- PropertyAssociation <NodeProperties >[] getNodePropertiesAssociation () {
106- return nodePropertyAssociations .toArray (new PropertyAssociation [0 ]);
65+ public void addEdgePropertyAssociation (EdgeProperties property , String title ) {
66+ titleToEdgeProperty .put (title , property );
10767 }
10868
10969 public NodeProperties getNodeProperty (String title ) {
110- for ( PropertyAssociation < NodeProperties > p : nodePropertyAssociations ) {
111- if ( p . getTitle (). equalsIgnoreCase ( title )) {
112- return p . getProperty ();
113- }
70+ if ( titleToNodeProperty . containsKey ( title ) ) {
71+ return titleToNodeProperty . get ( title );
72+ } else {
73+ return null ;
11474 }
115- return null ;
11675 }
11776
11877 public EdgeProperties getEdgeProperty (String title ) {
119- for (PropertyAssociation <EdgeProperties > p : edgePropertyAssociations ) {
120- if (p .getTitle ().equalsIgnoreCase (title )) {
121- return p .getProperty ();
122- }
123- }
124- return null ;
125- }
126-
127- public String getNodePropertyTitle (NodeProperties property ) {
128- for (PropertyAssociation <NodeProperties > p : nodePropertyAssociations ) {
129- if (p .getProperty ().equals (property )) {
130- return p .getTitle ();
131- }
132- }
133- return null ;
134- }
135-
136- public String getEdgePropertyTitle (EdgeProperties property ) {
137- for (PropertyAssociation <EdgeProperties > p : edgePropertyAssociations ) {
138- if (p .getProperty ().equals (property )) {
139- return p .getTitle ();
140- }
78+ if (titleToEdgeProperty .containsKey (title )) {
79+ return titleToEdgeProperty .get (title );
80+ } else {
81+ return null ;
14182 }
142- return null ;
14383 }
14484
14585 public String getInfos () {
146- String res = "***Node Properties Associations***\n " ;
147- for (PropertyAssociation <NodeProperties > p : nodePropertyAssociations ) {
148- res += "Property " + p .getProperty ().toString () + " = " + p .getTitle () + " Column\n " ;
86+ StringBuilder builder = new StringBuilder ("***Node Properties Associations***\n " );
87+ for (Map .Entry <String , NodeProperties > entry : titleToNodeProperty .entrySet ()) {
88+ builder .append ("Property " )
89+ .append (entry .getValue ().name ())
90+ .append (" = " )
91+ .append (entry .getKey ())
92+ .append (" Column\n " );
14993 }
150- res += "*********************************\n " ;
151- res = "***Edge Properties Associations***\n " ;
152- for (PropertyAssociation <EdgeProperties > p : edgePropertyAssociations ) {
153- res += "Property " + p .getProperty ().toString () + " = " + p .getTitle () + " Column\n " ;
94+ builder .append ("*********************************\n " );
95+ builder .append ("***Edge Properties Associations***\n " );
96+ for (Map .Entry <String , EdgeProperties > entry : titleToEdgeProperty .entrySet ()) {
97+ builder .append ("Property " )
98+ .append (entry .getValue ().name ())
99+ .append (" = " )
100+ .append (entry .getKey ())
101+ .append (" Column\n " );
154102 }
155- res += "*********************************\n " ;
156- return res ;
103+ builder . append ( "*********************************\n " ) ;
104+ return builder . toString () ;
157105 }
158106}
0 commit comments