Changeset 2429

Show
Ignore:
Timestamp:
08/25/08 21:24:22 (3 months ago)
Author:
kelleyt
Message:

Fixed some errors with the conversion in regards to Ticket 200

Files:

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  
    22 
    33import java.util.ArrayList; 
     4import java.util.HashMap; 
    45import java.util.Iterator; 
    56import java.util.LinkedHashMap; 
     7import java.util.LinkedList; 
    68import java.util.List; 
    79import java.util.Map; 
    8 import java.util.Queue; 
    9 import java.util.concurrent.ConcurrentHashMap; 
    10 import java.util.concurrent.ConcurrentLinkedQueue; 
     10 
    1111 
    1212public class MATArcs { 
     
    2222        private boolean valid = false; 
    2323        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();        
    2626        } 
    2727 
    2828        public MATArcs(String s) throws Exception{ 
    2929                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(); 
    3232                this.valid = testArcsnEdges(properties); 
    3333        } 
     
    3535        public boolean testArcsnEdges(String[] strings) throws Exception{ 
    3636                boolean value = false; 
    37                 Queue stringQueue = new ConcurrentLinkedQueue(); 
     37                LinkedList stringQueue = new LinkedList(); 
    3838                for(int ii = 0; ii < strings.length; ii++){ 
    3939                        String s = strings[ii]; 
    4040                        stringQueue.add(s); 
    4141                } 
    42                 if(((String)stringQueue.peek()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 
     42                if(((String)stringQueue.getFirst()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 
    4343                        comment = ""; 
    4444                        for(int ii = 0; ii < strings.length; ii++){ 
     
    6363        } 
    6464 
    65         public boolean testSourceTargetWeight(Queue qs) throws Exception{ 
     65        public boolean testSourceTargetWeight(LinkedList qs) throws Exception{ 
    6666                boolean value = false; 
    6767                int i = 0; 
     
    7171                                        switch (i){ 
    7272                                        case 0: 
    73                                                 this.setSource((String) qs.poll()); 
     73                                                this.setSource((String) qs.removeFirst()); 
    7474                                                break; 
    7575                                        case 1: 
    76                                                 this.setTarget((String) qs.poll()); 
     76                                                this.setTarget((String) qs.removeFirst()); 
    7777                                                break; 
    7878                                        case 2: 
    79                                                 this.setWeight((String) qs.poll()); 
     79                                                this.setWeight((String) qs.removeFirst()); 
    8080                                                break; 
    8181                                        default: 
  • trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATFileFunctions.java

    r2040 r2429  
    1616                        if(!append){ 
    1717                                if(!st.startsWith("\"")){ 
    18                                         st = st.replace("\"", ""); 
     18                                        //st.replaceFirst("\"", ""); 
    1919                                        sl.add(st); 
    2020                                } 
    2121                                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)); 
    2425                                } 
    2526                                else { 
    2627                                        append = true; 
     28                                        st.replaceFirst("\"", ""); 
    2729                                        bf.append(st); 
    2830                                } 
     
    3436                                } 
    3537                                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()); 
    3841                                        bf = new StringBuffer(); 
    3942                                        append=false; 
     
    8891                } 
    8992 
    90                 //      System.out.println(); 
    91  
    9293                return tokens; 
    9394 
     
    109110 
    110111        protected static boolean isAString(String input, String attr) throws Exception { 
    111                 /*if (!input.startsWith("\"") || !input.endsWith("\"")) { 
    112                          
    113                 }   */   
    114112                if(input.getClass().toString().endsWith("String")) 
    115113                return true; 
  • trunk/plugins/converter/edu.iu.nwb.converter.pajekmat/src/edu/iu/nwb/converter/pajekmat/common/MATVertex.java

    r2040 r2429  
    22 
    33import java.util.ArrayList; 
     4import java.util.HashMap; 
    45import java.util.Iterator; 
    56import java.util.LinkedHashMap; 
     7import java.util.LinkedList; 
    68import java.util.List; 
    79import java.util.Map; 
    8 import java.util.Queue; 
    9 import java.util.concurrent.ConcurrentHashMap; 
    10 import java.util.concurrent.ConcurrentLinkedQueue; 
    1110 
    1211public class MATVertex { 
     
    2322 
    2423        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(); 
    2726        } 
    2827 
    2928        public MATVertex(String s) throws Exception { 
    3029                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(); 
    3332                this.valid = testVertices(properties); 
    3433 
     
    3736        public boolean testVertices(String[] strings) throws Exception{ 
    3837                boolean value = false; 
    39                 Queue stringQueue = new ConcurrentLinkedQueue(); 
     38                LinkedList stringQueue = new LinkedList(); 
    4039                for(int ii = 0; ii < strings.length; ii++){ 
    4140                        String s = strings[ii]; 
    4241                        stringQueue.add(s); 
    4342                } 
    44                 if(((String) stringQueue.peek()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 
     43                if(((String) stringQueue.getFirst()).startsWith(MATFileProperty.PREFIX_COMMENTS)){ 
    4544                        comment = ""; 
    4645                        for(int ii = 0; ii < strings.length; ii++){ 
     
    5049                        return true; 
    5150                } 
    52                  
     51 
    5352                try{ 
    54                          
    55                 this.testVertexID(stringQueue); 
    56                  
    57                 if(!stringQueue.isEmpty()){ 
    58                          
     53 
     54                       this.testVertexID(stringQueue); 
     55 
     56                       if(!stringQueue.isEmpty()){ 
     57 
    5958                                this.testVertexPosition(stringQueue);    
    60                                 if(! setVertexShape((String) stringQueue.peek())){ 
     59                                if(! setVertexShape((String) stringQueue.getFirst())){ 
    6160                                        testParameters(stringQueue); 
    6261                                } 
    6362                                else { 
    64                                         stringQueue.poll(); 
     63                                        stringQueue.removeFirst(); 
    6564                                        testParameters(stringQueue); 
    6665                                } 
    6766                        } 
    68                          
     67 
    6968                }catch(Exception ex){ 
    7069                        throw ex; 
     
    7473        } 
    7574 
    76         public boolean testVertexID(Queue qs) throws Exception{ 
     75        public boolean testVertexID(LinkedList qs) throws Exception{ 
    7776                try 
    7877                { 
     
    8079                                throw new MATFileFormatException("Vertices must have both ID and Label"); 
    8180                        } 
    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 
    8887                        return true; 
    8988                } 
     
    9392        } 
    9493 
    95         public boolean testVertexPosition(Queue qs) throws Exception{ 
     94        public boolean testVertexPosition(LinkedList qs) throws Exception{ 
    9695 
    9796                boolean value = true; 
     
    103102                                        return false;  //no positional data 
    104103                                } 
    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                       
    123122                } 
    124123                catch(NumberFormatException ex){ 
     
    126125                } 
    127126 
    128          
     127 
    129128        } 
    130129 
     
    133132        public boolean setVertexShape(String st) throws Exception{ 
    134133                try { 
    135                          
    136                                        this.setShape(st); 
    137                                        return true; 
    138                                  
    139                          
    140                          
     134 
     135                        this.setShape(st); 
     136                        return true; 
     137 
     138 
     139 
    141140                } 
    142141                catch(Exception ex){ 
     
    146145 
    147146 
    148         public boolean testParameters(Queue qs) throws Exception{ 
     147        public boolean testParameters(LinkedList qs) throws Exception{ 
    149148                boolean value = false; 
    150149 
    151150                while(!qs.isEmpty()){ 
    152                         String s1 = (String) qs.poll(); 
     151                        String s1 = (String) qs.removeFirst(); 
    153152 
    154153                        if(MATFileFunctions.isInList(s1,MATFileShape.ATTRIBUTE_SHAPE_LIST)){ 
     
    156155                                continue; 
    157156                        } 
    158                          
    159                         String s2 = (String) qs.peek(); 
     157 
     158                        String s2 = (String) qs.getFirst(); 
    160159 
    161160 
    162161                        if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_X_FACT)){ 
    163162                                this.setXScaleFactor(s2); 
    164                                 qs.poll(); 
     163                                qs.removeFirst(); 
    165164                        } 
    166165                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_Y_FACT)){ 
    167166                                this.setYScaleFactor(s2); 
    168                                 qs.poll(); 
     167                                qs.removeFirst(); 
    169168                        } 
    170169                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_SIZE)){ 
    171170                                this.setSize(s2); 
    172                                 qs.poll(); 
     171                                qs.removeFirst(); 
    173172                        } 
    174173                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_PHI)){ 
    175174                                this.setPhi(s2); 
    176                                 qs.poll(); 
     175                                qs.removeFirst(); 
    177176                        } 
    178177                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_R)){ 
    179178                                this.setCornerRadius(s2); 
    180                                 qs.poll(); 
     179                                qs.removeFirst(); 
    181180                        } 
    182181                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_Q)){ 
    183182                                this.setDiamondRatio(s2); 
    184                                 qs.poll(); 
     183                                qs.removeFirst(); 
    185184                        } 
    186185                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_IC) || s1.equalsIgnoreCase(MATFileParameter.PARAMETER_COLOR)){ 
    187186                                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(); 
    191190                                        this.setInternalColor(s); 
    192191                                } 
    193192                                else{ 
    194193                                        this.setInternalColor(s2); 
    195                                         qs.poll(); 
     194                                        qs.removeFirst(); 
    196195                                } 
    197196                        } 
    198197                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_BC)){ 
    199198                                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(); 
    203202                                        this.setBorderColor(s); 
    204203                                } 
    205204                                else{ 
    206205                                        this.setBorderColor(s2); 
    207                                         qs.poll(); 
     206                                        qs.removeFirst(); 
    208207                                } 
    209208                        } 
    210209                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_BW)){ 
    211210                                this.setBorderWidth(s2); 
    212                                 qs.poll(); 
     211                                qs.removeFirst(); 
    213212                        } 
    214213                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LC)){ 
    215214                                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(); 
    219218                                        this.setLabelColor(s); 
    220219                                } 
    221220                                else{ 
    222221                                        this.setLabelColor(s2); 
    223                                         qs.poll(); 
     222                                        qs.removeFirst(); 
    224223                                } 
    225224                        } 
    226225                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LA)){ 
    227226                                this.setLabelAngle(s2); 
    228                                 qs.poll(); 
     227                                qs.removeFirst(); 
    229228                        } 
    230229                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_FONT)){ 
    231230                                this.setFont(s2); 
    232                                 qs.poll(); 
     231                                qs.removeFirst(); 
    233232                        } 
    234233                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LPHI)){ 
    235234                                this.setLabelPhi(s2); 
    236                                 qs.poll(); 
     235                                qs.removeFirst(); 
    237236                        } 
    238237                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_FOS)){ 
    239238                                this.setFontSize(s2); 
    240                                 qs.poll(); 
     239                                qs.removeFirst(); 
    241240                        } 
    242241                        else if(s1.equalsIgnoreCase(MATFileParameter.PARAMETER_LR)){ 
    243242                                this.setLabelRadius(s2); 
    244                                 qs.poll(); 
    245                         } 
    246  
    247                          
     243                                qs.removeFirst(); 
     244                        } 
     245 
     246 
    248247                        else if(s1.startsWith(MATFileProperty.PREFIX_COMMENTS)){ 
    249248                                qs.clear(); 
     
    252251                        else if(s1.startsWith(MATFileParameter.PARAMETER_SHAPE)){ 
    253252                                this.setVertexShape(s2); 
    254                                 qs.poll(); 
     253                                qs.removeFirst(); 
    255254                        } 
    256255 
     
    263262 
    264263        } 
    265          
     264 
    266265        public static void clearAttributes(){ 
    267266                MATVertex.Attributes.clear(); 
     
    303302                        throw new MATFileFormatException("Vertices must have both ID and Label"); 
    304303                MATVertex.Attributes.put(MATFileProperty.ATTRIBUTE_LABEL, MATFileProperty.TYPE_STRING); 
    305                  
     304 
    306305                this.label = s; 
    307306 
     
    346345                        this.setZpos(f); 
    347346                        break; 
    348                        default : 
    349                                throw new MATFileFormatException("Unknown positional data"); 
     347                default : 
     348                        throw new MATFileFormatException("Unknown positional data"); 
    350349                } 
    351350        } 
     
    360359        public void setShape(String s) throws MATFileFormatException{ 
    361360                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); 
    364363                } 
    365364        } 
     
    382381        public void setPhi(String s) throws Exception{ 
    383382                float f = MATFileFunctions.asAFloat(s); 
    384                        this.setPhi(f); 
     383                this.setPhi(f); 
    385384 
    386385        } 
     
    401400        public void setSize(String s){ 
    402401                float f = MATFileFunctions.asAFloat(s); 
    403                        this.setSize(f); 
     402                this.setSize(f); 
    404403 
    405404        } 
     
    414413         * written by: Tim Kelley 
    415414         */ 
    416          
     415 
    417416        public void setFont(String s) throws MATFileFormatException{ 
    418417                if(s!=null) 
    419                 MATVertex.Attributes.put(MATFileParameter.PARAMETER_FONT, "string"); 
     418                       MATVertex.Attributes.put(MATFileParameter.PARAMETER_FONT, "string"); 
    420419                this.String_Parameters.put(MATFileParameter.PARAMETER_FONT, s); 
    421420        } 
     
    431430        public void setBorderColor(String s) throws MATFileFormatException{ 
    432431                if(s!= null){ 
    433                         String[] number = s.split(" "); 
     432                        String[] number = s.split("\\s+"); 
    434433                        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               
    444443        } 
    445444 
     
    471470        private void setInternalColor(String s) throws MATFileFormatException{ 
    472471                if(s != null){ 
    473                         String[] number = s.split(" "); 
     472                        String[] number = s.split("\\s+"); 
    474473                        if(MATFileFunctions.isAFloat(number[0], "float") || MATFileFunctions.isAnInteger(number[0], "int")){ 
    475474                                MATVertex.Attributes.put(MATFileParameter.PARAMETER_IC, "float"); 
     
    480479                                this.String_Parameters.put(MATFileParameter.PARAMETER_IC, s); 
    481480                        } 
    482                        
     481               
    483482        } 
    484483 
     
    496495        public void setFontSize(String s) throws Exception { 
    497496                float f = MATFileFunctions.asAFloat(s); 
    498                        this.setFontSize(f); 
     497                this.setFontSize(f); 
    499498 
    500499        } 
     
    513512        private void setLabelAngle(String s){ 
    514513                float f = MATFileFunctions.asAFloat(s); 
    515                        this.setLabelAngle(f); 
     514                this.setLabelAngle(f); 
    516515 
    517516        } 
     
    527526        private void setLabelPhi(String s){ 
    528527                float f = MATFileFunctions.asAFloat(s); 
    529                        this.setLabelPhi(f); 
     528                this.setLabelPhi(f); 
    530529 
    531530        } 
     
    563562                                this.String_Parameters.put(MATFileParameter.PARAMETER_LC, s); 
    564563                        } 
    565                        
     564               
    566565 
    567566        } 
     
    588587        public void setYScaleFactor(String s) {  
    589588                float f = MATFileFunctions.asAFloat(s); 
    590                        this.setYScaleFactor(f);        
     589                this.setYScaleFactor(f);       
    591590        } 
    592591 
     
    606605        } 
    607606        private void setCornerRadius(String s) throws MATFileFormatException{ 
    608                  
     607 
    609608                try { 
    610609                        float f = MATFileFunctions.asAFloat(s); 
    611                          
     610 
    612611                        this.setCornerRadius(f); 
    613612                } 
     
    632631        } 
    633632        public void setDiamondRatio(String s) throws MATFileFormatException{ 
    634                  
     633 
    635634                try { 
    636635                        float f = MATFileFunctions.asAFloat(s); 
     
    642641 
    643642        } 
    644          
     643 
    645644        private void setUnknownAttribute(String s){ 
    646645                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++; 
    651650                } 
    652651        } 
     
    726725                return false; 
    727726        } 
    728          
     727 
    729728        private boolean finalCheck() throws MATFileFormatException{ 
    730          
     729 
    731730                if((this.getAttribute(MATFileParameter.PARAMETER_LPHI) == null) && (this.getAttribute(MATFileParameter.PARAMETER_LR) == null)) 
    732731                        return true; 
     
    735734                else 
    736735                        throw new MATFileFormatException("Only one of two polar coordinates has been set"); 
    737                  
     736 
    738737        } 
    739738 
  • trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/OSGI-INF/pajeknettopajekmat.properties

    r2028 r2429  
    44remoteable=true 
    55type=converter 
    6 conversion=lossless 
     6conversion=lossy 
  • trunk/plugins/converter/edu.iu.nwb.converter.pajekmatpajeknet/src/edu/iu/nwb/converter/pajekmatpajeknet/PajekmatToPajeknet.java

    r2028 r2429  
    125125                                                } 
    126126                                                else{ 
    127                                                         s += attr + " " + mv.getAttribute(attr) + "\" "; 
     127                                                        s += attr + " \"" + mv.getAttribute(attr) + "\" "; 
    128128                                                } 
    129129                                }