1 19 20 package org.netbeans.modules.languages; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 30 public class Selector { 31 32 public static Selector create (String selector) { 33 List <String > path = new ArrayList <String > (); 34 int s = 0, e = selector.indexOf ('.'); 35 while (e >= 0) { 36 path.add (selector.substring (s, e)); 37 s = e + 1; 38 e = selector.indexOf ('.', s); 39 } 40 path.add (selector.substring (s)); 41 return new Selector (path); 42 } 43 44 private List <String > path; 45 46 private Selector (List <String > path) { 47 this.path = path; 48 } 49 50 List <String > getPath () { 51 return path; 52 } 53 54 private String asText; 55 56 public String getAsString () { 57 if (asText == null) { 58 Iterator <String > it = path.iterator (); 59 StringBuilder sb = new StringBuilder (); 60 if (it.hasNext ()) 61 sb.append (it.next ()); 62 while (it.hasNext ()) 63 sb.append ('.').append (it.next ()); 64 asText = sb.toString (); 65 } 66 return asText; 67 } 68 69 public String toString () { 70 return getAsString (); 71 } 72 } 73 | Popular Tags |