Changeset 2429
- Timestamp:
- 08/25/08 21:24:22 (3 months ago)
- Files:
-
- trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATArcs.java (modified) (5 diffs)
- trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATFileFunctions.java (modified) (4 diffs)
- trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATVertex.java (modified) (33 diffs)
- trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/OSGI-INF/pajeknettopajekmat.properties (modified) (1 diff)
- trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/src/edu/iu/nwb/converter/pajekmatpajeknet/PajekmatToPajeknet.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATArcs.java
r1332 r2429 2 2 3 3 import java.util.ArrayList; 4 import java.util.HashMap; 4 5 import java.util.Iterator; 5 6 import java.util.LinkedHashMap; 7 import java.util.LinkedList; 6 8 import java.util.List; 7 9 import java.util.Map; 8 import java.util.Queue; 9 import java.util.concurrent.ConcurrentHashMap; 10 import java.util.concurrent.ConcurrentLinkedQueue; 10 11 11 12 12 public class MATArcs { … … 22 22 private boolean valid = false; 23 23 public MATArcs(){ 24 this.Numeric_Parameters = new ConcurrentHashMap();25 this.String_Parameters = new ConcurrentHashMap();24 this.Numeric_Parameters = new HashMap(); 25 this.String_Parameters = new HashMap(); 26 26 } 27 27 28 28 public MATArcs(String s) throws Exception{ 29 29 String[] properties = MATFileFunctions.processTokens(s); 30 this.Numeric_Parameters = new ConcurrentHashMap();31 this.String_Parameters = new ConcurrentHashMap();30 this.Numeric_Parameters = new HashMap(); 31 this.String_Parameters = new HashMap(); 32 32 this.valid = testArcsnEdges(properties); 33 33 } … … 35 35 public boolean testArcsnEdges(String[] strings) throws Exception{ 36 36 boolean value = false; 37 Queue stringQueue = new ConcurrentLinkedQueue();37 LinkedList stringQueue = new LinkedList(); 38 38 for(int ii = 0; ii < strings.length; ii++){ 39 39 String s = strings[ii]; 40 40 stringQueue.add(s); 41 41 } 42 if(((String)stringQueue. peek()).startsWith(MATFileProperty.PREFIX_COMMENTS)){42 if(((String)stringQueue.getFirst()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 43 43 comment = ""; 44 44 for(int ii = 0; ii < strings.length; ii++){ … … 63 63 } 64 64 65 public boolean testSourceTargetWeight( Queueqs) throws Exception{65 public boolean testSourceTargetWeight(LinkedList qs) throws Exception{ 66 66 boolean value = false; 67 67 int i = 0; … … 71 71 switch (i){ 72 72 case 0: 73 this.setSource((String) qs. poll());73 this.setSource((String) qs.removeFirst()); 74 74 break; 75 75 case 1: 76 this.setTarget((String) qs. poll());76 this.setTarget((String) qs.removeFirst()); 77 77 break; 78 78 case 2: 79 this.setWeight((String) qs. poll());79 this.setWeight((String) qs.removeFirst()); 80 80 break; 81 81 default: trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATFileFunctions.java
r2040 r2429 16 16 if(!append){ 17 17 if(!st.startsWith("\"")){ 18 st = st.replace("\"", "");18 //st.replaceFirst("\"", ""); 19 19 sl.add(st); 20 20 } 21 21 else if (st.startsWith("\"") && st.endsWith("\"")){ 22 st = st.replace("\"", ""); 23 sl.add(st); 22 st = st.replaceFirst("\"", ""); 23 int lastIndex = st.lastIndexOf("\""); 24 sl.add(st.substring(0,lastIndex)); 24 25 } 25 26 else { 26 27 append = true; 28 st.replaceFirst("\"", ""); 27 29 bf.append(st); 28 30 } … … 34 36 } 35 37 else if (st.endsWith("\"")){ 36 bf.append(" "+st); 37 sl.add(bf.toString().replace("\"", "")); 38 int lastIndex = st.lastIndexOf("\""); 39 bf.append(" "+st.substring(0,lastIndex)); 40 sl.add(bf.toString()); 38 41 bf = new StringBuffer(); 39 42 append=false; … … 88 91 } 89 92 90 // System.out.println();91 92 93 return tokens; 93 94 … … 109 110 110 111 protected static boolean isAString(String input, String attr) throws Exception { 111 /*if (!input.startsWith("\"") || !input.endsWith("\"")) {112 113 } */114 112 if(input.getClass().toString().endsWith("String")) 115 113 return true; trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATVertex.java
r2040 r2429 2 2 3 3 import java.util.ArrayList; 4 import java.util.HashMap; 4 5 import java.util.Iterator; 5 6 import java.util.LinkedHashMap; 7 import java.util.LinkedList; 6 8 import java.util.List; 7 9 import java.util.Map; 8 import java.util.Queue;9 import java.util.concurrent.ConcurrentHashMap;10 import java.util.concurrent.ConcurrentLinkedQueue;11 10 12 11 public class MATVertex { … … 23 22 24 23 public MATVertex(){ 25 this.Numeric_Parameters = new ConcurrentHashMap();26 this.String_Parameters = new ConcurrentHashMap();24 this.Numeric_Parameters = new HashMap(); 25 this.String_Parameters = new HashMap(); 27 26 } 28 27 29 28 public MATVertex(String s) throws Exception { 30 29 String[] properties = MATFileFunctions.processTokens(s); 31 this.Numeric_Parameters = new ConcurrentHashMap();32 this.String_Parameters = new ConcurrentHashMap();30 this.Numeric_Parameters = new HashMap(); 31 this.String_Parameters = new HashMap(); 33 32 this.valid = testVertices(properties); 34 33 … … 37 36 public boolean testVertices(String[] strings) throws Exception{ 38 37 boolean value = false; 39 Queue stringQueue = new ConcurrentLinkedQueue();38 LinkedList stringQueue = new LinkedList(); 40 39 for(int ii = 0; ii < strings.length; ii++){ 41 40 String s = strings[ii]; 42 41 stringQueue.add(s); 43 42 } 44 if(((String) stringQueue. peek()).startsWith(MATFileProperty.PREFIX_COMMENTS)){43 if(((String) stringQueue.getFirst()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 45 44 comment = ""; 46 45 for(int ii = 0; ii < strings.length; ii++){ … … 50 49 return true; 51 50 } 52 51 53 52 try{ 54 55 this.testVertexID(stringQueue);56 57 if(!stringQueue.isEmpty()){58 53 54 this.testVertexID(stringQueue); 55 56 if(!stringQueue.isEmpty()){ 57 59 58 this.testVertexPosition(stringQueue); 60 if(! setVertexShape((String) stringQueue. peek())){59 if(! setVertexShape((String) stringQueue.getFirst())){ 61 60 testParameters(stringQueue); 62 61 } 63 62 else { 64 stringQueue. poll();63 stringQueue.removeFirst(); 65 64 testParameters(stringQueue); 66 65 } 67 66 } 68 67 69 68 }catch(Exception ex){ 70 69 throw ex; … … 74 73 } 75 74 76 public boolean testVertexID( Queueqs) throws Exception{75 public boolean testVertexID(LinkedList qs) throws Exception{ 77 76 try 78 77 { … … 80 79 throw new MATFileFormatException("Vertices must have both ID and Label"); 81 80 } 82 String s = (String) qs.poll();83 84 this.setID(s);85 s = (String)qs.poll();86 this.setLabel(s);87 81 String s = (String) qs.removeFirst(); 82 83 this.setID(s); 84 s = (String)qs.removeFirst(); 85 this.setLabel(s); 86 88 87 return true; 89 88 } … … 93 92 } 94 93 95 public boolean testVertexPosition( Queueqs) throws Exception{94 public boolean testVertexPosition(LinkedList qs) throws Exception{ 96 95 97 96 boolean value = true; … … 103 102 return false; //no positional data 104 103 } 105 106 f = new Float((String)qs. poll()).floatValue();107 108 value = true;109 switch (i){110 case 0:111 this.setPos("Xpos", f);112 break;113 case 1:114 this.setPos("Ypos", f);115 break;116 case 2:117 this.setPos("Zpos", f);118 break;119 }120 i++;121 qs.poll();122 }104 105 f = new Float((String)qs.getFirst()).floatValue(); 106 107 value = true; 108 switch (i){ 109 case 0: 110 this.setPos("Xpos", f); 111 break; 112 case 1: 113 this.setPos("Ypos", f); 114 break; 115 case 2: 116 this.setPos("Zpos", f); 117 break; 118 } 119 i++; 120 qs.removeFirst(); 121 } 123 122 } 124 123 catch(NumberFormatException ex){ … … 126 125 } 127 126 128 127 129 128 } 130 129 … … 133 132 public boolean setVertexShape(String st) throws Exception{ 134 133 try { 135 136 this.setShape(st);137 return true;138 139 140 134 135 this.setShape(st); 136 return true; 137 138 139 141 140 } 142 141 catch(Exception ex){ … … 146 145 147 146 148 public boolean testParameters( Queueqs) throws Exception{147 public boolean testParameters(LinkedList qs) throws Exception{ 149 148 boolean value = false; 150 149 151 150 while(!qs.isEmpty()){ 152 String s1 = (String) qs. poll();151 String s1 = (String) qs.removeFirst(); 153 152 154 153 if(MATFileFunctions.isInList(s1,MATFileShape.ATTRIBUTE_SHAPE_LIST)){ … … 156 155 continue; 157 156 } 158 159 String s2 = (String) qs. peek();157 158 String s2 = (String) qs.getFirst(); 160 159 161 160 162 161 if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_X_FACT)){ 163 162 this.setXScaleFactor(s2); 164 qs. poll();163 qs.removeFirst(); 165 164 } 166 165 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_Y_FACT)){ 167 166 this.setYScaleFactor(s2); 168 qs. poll();167 qs.removeFirst(); 169 168 } 170 169 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_SIZE)){ 171 170 this.setSize(s2); 172 qs. poll();171 qs.removeFirst(); 173 172 } 174 173 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_PHI)){ 175 174 this.setPhi(s2); 176 qs. poll();175 qs.removeFirst(); 177 176 } 178 177 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_R)){ 179 178 this.setCornerRadius(s2); 180 qs. poll();179 qs.removeFirst(); 181 180 } 182 181 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_Q)){ 183 182 this.setDiamondRatio(s2); 184 qs. poll();183 qs.removeFirst(); 185 184 } 186 185 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_IC) || s1.equalsIgnoreCase(MATFileParameter.PARAMETER_COLOR)){ 187 186 if(MATFileFunctions.isAFloat(s2, "float") || MATFileFunctions.isAnInteger(s2, "int")){ 188 String s = (String)qs. poll();189 s += " " + qs. poll() + " ";190 s += " " + qs. poll();187 String s = (String)qs.removeFirst(); 188 s += " " + qs.removeFirst() + " "; 189 s += " " + qs.removeFirst(); 191 190 this.setInternalColor(s); 192 191 } 193 192 else{ 194 193 this.setInternalColor(s2); 195 qs. poll();194 qs.removeFirst(); 196 195 } 197 196 } 198 197 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_BC)){ 199 198 if(MATFileFunctions.isAFloat(s2, "float") || MATFileFunctions.isAnInteger(s2, "int")){ 200 String s = (String)qs. poll();201 s += " " + qs. poll() + " ";202 s += " " + qs. poll();199 String s = (String)qs.removeFirst(); 200 s += " " + qs.removeFirst() + " "; 201 s += " " + qs.removeFirst(); 203 202 this.setBorderColor(s); 204 203 } 205 204 else{ 206 205 this.setBorderColor(s2); 207 qs. poll();206 qs.removeFirst(); 208 207 } 209 208 } 210 209 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_BW)){ 211 210 this.setBorderWidth(s2); 212 qs. poll();211 qs.removeFirst(); 213 212 } 214 213 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LC)){ 215 214 if(MATFileFunctions.isAFloat(s2, "float") || MATFileFunctions.isAnInteger(s2, "int")){ 216 String s = (String)qs. poll();217 s += " " + qs. poll() + " ";218 s += " " + qs. poll();215 String s = (String)qs.removeFirst(); 216 s += " " + qs.removeFirst() + " "; 217 s += " " + qs.removeFirst(); 219 218 this.setLabelColor(s); 220 219 } 221 220 else{ 222 221 this.setLabelColor(s2); 223 qs. poll();222 qs.removeFirst(); 224 223 } 225 224 } 226 225 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LA)){ 227 226 this.setLabelAngle(s2); 228 qs. poll();227 qs.removeFirst(); 229 228 } 230 229 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_FONT)){ 231 230 this.setFont(s2); 232 qs. poll();231 qs.removeFirst(); 233 232 } 234 233 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LPHI)){ 235 234 this.setLabelPhi(s2); 236 qs. poll();235 qs.removeFirst(); 237 236 } 238 237 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_FOS)){ 239 238 this.setFontSize(s2); 240 qs. poll();239 qs.removeFirst(); 241 240 } 242 241 else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LR)){ 243 242 this.setLabelRadius(s2); 244 qs. poll();245 } 246 247 243 qs.removeFirst(); 244 } 245 246 248 247 else if(s1.startsWith(MATFileProperty.PREFIX_COMMENTS)){ 249 248 qs.clear(); … … 252 251 else if(s1.startsWith(MATFileParameter.PARAMETER_SHAPE)){ 253 252 this.setVertexShape(s2); 254 qs. poll();253 qs.removeFirst(); 255 254 } 256 255 … … 263 262 264 263 } 265 264 266 265 public static void clearAttributes(){ 267 266 MATVertex.Attributes.clear(); … … 303 302 throw new MATFileFormatException("Vertices must have both ID and Label"); 304 303 MATVertex.Attributes.put(MATFileProperty.ATTRIBUTE_LABEL, MATFileProperty.TYPE_STRING); 305 304 306 305 this.label = s; 307 306 … … 346 345 this.setZpos(f); 347 346 break; 348 default :349 throw new MATFileFormatException("Unknown positional data");347 default : 348 throw new MATFileFormatException("Unknown positional data"); 350 349 } 351 350 } … … 360 359 public void setShape(String s) throws MATFileFormatException{ 361 360 if(s != null){ 362 MATVertex.Attributes.put("shape", "string");363 this.String_Parameters.put("shape", s);361 MATVertex.Attributes.put("shape", "string"); 362 this.String_Parameters.put("shape", s); 364 363 } 365 364 } … … 382 381 public void setPhi(String s) throws Exception{ 383 382 float f = MATFileFunctions.asAFloat(s); 384 this.setPhi(f);383 this.setPhi(f); 385 384 386 385 } … … 401 400 public void setSize(String s){ 402 401 float f = MATFileFunctions.asAFloat(s); 403 this.setSize(f);402 this.setSize(f); 404 403 405 404 } … … 414 413 * written by: Tim Kelley 415 414 */ 416 415 417 416 public void setFont(String s) throws MATFileFormatException{ 418 417 if(s!=null) 419 MATVertex.Attributes.put(MATFileParameter.PARAMETER_FONT, "string");418 MATVertex.Attributes.put(MATFileParameter.PARAMETER_FONT, "string"); 420 419 this.String_Parameters.put(MATFileParameter.PARAMETER_FONT, s); 421 420 } … … 431 430 public void setBorderColor(String s) throws MATFileFormatException{ 432 431 if(s!= null){ 433 String[] number = s.split(" ");432 String[] number = s.split("\\s+"); 434 433 if(MATFileFunctions.isAFloat(number[0], "float") || MATFileFunctions.isAnInteger(number[0], "int")){ 435 MATVertex.Attributes.put(MATFileParameter.PARAMETER_BC, "float");436 this.Numeric_Parameters.put(MATFileParameter.PARAMETER_BC, s);437 }438 else{439 MATVertex.Attributes.put(MATFileParameter.PARAMETER_BC, "string");440 this.String_Parameters.put(MATFileParameter.PARAMETER_BC, s);441 }442 443 }434 MATVertex.Attributes.put(MATFileParameter.PARAMETER_BC, "float"); 435 this.Numeric_Parameters.put(MATFileParameter.PARAMETER_BC, s); 436 } 437 else{ 438 MATVertex.Attributes.put(MATFileParameter.PARAMETER_BC, "string"); 439 this.String_Parameters.put(MATFileParameter.PARAMETER_BC, s); 440 } 441 442 } 444 443 } 445 444 … … 471 470 private void setInternalColor(String s) throws MATFileFormatException{ 472 471 if(s != null){ 473 String[] number = s.split(" ");472 String[] number = s.split("\\s+"); 474 473 if(MATFileFunctions.isAFloat(number[0], "float") || MATFileFunctions.isAnInteger(number[0], "int")){ 475 474 MATVertex.Attributes.put(MATFileParameter.PARAMETER_IC, "float"); … … 480 479 this.String_Parameters.put(MATFileParameter.PARAMETER_IC, s); 481 480 } 482 }481 } 483 482 } 484 483 … … 496 495 public void setFontSize(String s) throws Exception { 497 496 float f = MATFileFunctions.asAFloat(s); 498 this.setFontSize(f);497 this.setFontSize(f); 499 498 500 499 } … … 513 512 private void setLabelAngle(String s){ 514 513 float f = MATFileFunctions.asAFloat(s); 515 this.setLabelAngle(f);514 this.setLabelAngle(f); 516 515 517 516 } … … 527 526 private void setLabelPhi(String s){ 528 527 float f = MATFileFunctions.asAFloat(s); 529 this.setLabelPhi(f);528 this.setLabelPhi(f); 530 529 531 530 } … … 563 562 this.String_Parameters.put(MATFileParameter.PARAMETER_LC, s); 564 563 } 565 }564 } 566 565 567 566 } … … 588 587 public void setYScaleFactor(String s) { 589 588 float f = MATFileFunctions.asAFloat(s); 590 this.setYScaleFactor(f);589 this.setYScaleFactor(f); 591 590 } 592 591 … … 606 605 } 607 606 private void setCornerRadius(String s) throws MATFileFormatException{ 608 607 609 608 try { 610 609 float f = MATFileFunctions.asAFloat(s); 611 610 612 611 this.setCornerRadius(f); 613 612 } … … 632 631 } 633 632 public void setDiamondRatio(String s) throws MATFileFormatException{ 634 633 635 634 try { 636 635 float f = MATFileFunctions.asAFloat(s); … … 642 641 643 642 } 644 643 645 644 private void setUnknownAttribute(String s){ 646 645 if(s != null){ 647 String name = "unknown" + this.unknowns;648 MATVertex.Attributes.put(name, MATFileProperty.TYPE_STRING);649 this.String_Parameters.put(name, s);650 this.unknowns++;646 String name = "unknown" + this.unknowns; 647 MATVertex.Attributes.put(name, MATFileProperty.TYPE_STRING); 648 this.String_Parameters.put(name, s); 649 this.unknowns++; 651 650 } 652 651 } … … 726 725 return false; 727 726 } 728 727 729 728 private boolean finalCheck() throws MATFileFormatException{ 730 729 731 730 if((this.getAttribute(MATFileParameter.PARAMETER_LPHI) == null) && (this.getAttribute(MATFileParameter.PARAMETER_LR) == null)) 732 731 return true; … … 735 734 else 736 735 throw new MATFileFormatException("Only one of two polar coordinates has been set"); 737 736 738 737 } 739 738 trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/OSGI-INF/pajeknettopajekmat.properties
r2028 r2429 4 4 remoteable=true 5 5 type=converter 6 conversion=loss less6 conversion=lossy trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/src/edu/iu/nwb/converter/pajekmatpajeknet/PajekmatToPajeknet.java
r2028 r2429 125 125 } 126 126 else{ 127 s += attr + " " + mv.getAttribute(attr) + "\" ";127 s += attr + " \"" + mv.getAttribute(attr) + "\" "; 128 128 } 129 129 }
