java - String manipulation for VML Path 2 -



java - String manipulation for VML Path 2 -

i trying parse vml path value (this post not same string manipulation vml path). has more complicated path value handle. have string value

m@0,l@0@0,0@0,0@2@0@2@0,21600@1,21600@1@2,21600@2,21600@0@1@0@1,250,350,450,@5,xe

i have 4 commands here m, l, x, , e. next sums goal.

m@0, l @0 @0 0 @0 0 @2 @0 @2 @0,21600 @1,21600 @1@2 21600@2 21600@0 @1@0 @1,250 350,450 @5, x e

in code, think next representation.

string command_type = "m" list<string, string> parameters = add("@0", "0") // because y parameter not specified need forcefulness 0 string command_type = "l" list<string, string> parameters = add("@0", "@0") add("0", "@0") add("0", "@2") add("@0", "@2") add("@0", "216000") add("@1", "216000") add("@1", "@2") add("21600", "@2") add("21600", "@0") add("@1", "@0") add("@1", "250") add("350", "450") add("@5", "0") //because y parameter not specified need forcefulness 0 string command_type = "x" (can have no parameter ) string command_type = "e" (can have no parameter )

here things noticed vml.

commands not preceded comma , (true vml commands except m first command.

parameters come in pairs (x , y pairs)

i saw link java string.split() regex , maybe possible utilize regular expressions in retreiving parameters.

update function/method each command (like m, l, , other vml commands). if want retreive parameters commands please implement own method iterates through vml command vml parameter.

this solution question. plenty needs. if have more suggestions or improve algorithms please share. :-)

private list<list<string>> createstructuredparameterarray(string vmlparameter){ int totalparametercount = 0; string currentxoryparameter = ""; list<string> listofparameters = new arraylist<string>(); boolean previousiscomma = false; boolean firstrun = true; for(int = 0; < vmlparameter.length(); i++){ if (i != 0) firstrun = false; char nextchar = vmlparameter.charat(i); if (nextchar == '@'){ /** * check currentxoryparameter if valid format already, * <br> if true - proceed handling next parameter * <br> ex. handling x parameter y parameter * <br> ex. handling y parameter x parameter */ if (checkifvalidsingleparameter(currentxoryparameter)){ totalparametercount++; listofparameters.add(currentxoryparameter); currentxoryparameter = ""; currentxoryparameter= currentxoryparameter+nextchar; }else{ currentxoryparameter= currentxoryparameter+nextchar; } previousiscomma = false; }else if (nextchar != '@' && nextchar != ','){ //numeric character currentxoryparameter= currentxoryparameter+nextchar; previousiscomma = false; }else if (nextchar == ','){ if (checkifvalidsingleparameter(currentxoryparameter)){ totalparametercount++; listofparameters.add(currentxoryparameter); currentxoryparameter = ""; }else{ if (firstrun){ totalparametercount++; currentxoryparameter = "0"; listofparameters.add(currentxoryparameter); currentxoryparameter = ""; firstrun = false; } } if (previousiscomma){ totalparametercount++; currentxoryparameter = "0"; listofparameters.add(currentxoryparameter); currentxoryparameter = ""; } previousiscomma = true; } if ((i+1)==vmlparameter.length()){ if (checkifvalidsingleparameter(currentxoryparameter)){ totalparametercount++; listofparameters.add(currentxoryparameter); currentxoryparameter = ""; /** * check if parametercounter odd or even, * <br> if odd - add together additional "0" create * <br> if - nil */ if ((totalparametercount % 2)==1){ listofparameters.add("0"); } } } } if ((listofparameters.size()%2)==1){ listofparameters.add("0"); } /** * grouping parameters 2 in list<string> object * <br>list<string> object * <br> object.add("\<value here\>"); => x coordinate * <br> object.add("\<value here\>"); => y coordinate * * <br>then create list of list<string> object created above * <br> uncomment below if desired result homecoming value described above */ list<list<string>> result = new arraylist<list<string>>(); list<string> temp = new arraylist<string>(); if(listofparameters.size()>1){ int counter = 1; (int = 0; i<listofparameters.size(); i++){ string xycoordinate = listofparameters.get(i); if ((counter%2)==1){ //x coordinate temp.add(xycoordinate); }else if ((counter%2)==0){ //y coordinate temp.add(xycoordinate); result.add(temp); //temp.clear(); temp = new arraylist<string>(); } counter++; } } homecoming result; }

java string string-matching stringtokenizer vml

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -