Esempio n. 1
0
 /** Parse a string of the form [x1,y1},[x2,y2},...,[xN,yN} into a list of Points ([int,int]) */
 public static List<Point> parseString(String str) throws NumberFormatException {
   if (StringUtil.isNullString(str)) {
     throw new IllegalArgumentException("Must supply non-empty string");
   }
   ArrayList<Point> res = new ArrayList<Point>();
   Perl5Matcher matcher = RegexpUtil.getMatcher();
   while (matcher.contains(str, ONE_POINT_PAT)) {
     MatchResult matchResult = matcher.getMatch();
     String xstr = matchResult.group(1);
     String ystr = matchResult.group(2);
     str = matchResult.group(3);
     try {
       int x = Integer.parseInt(xstr);
       int y = Integer.parseInt(ystr);
       res.add(new Point(x, y));
     } catch (NumberFormatException e) {
       throw new IllegalArgumentException("bad point [" + xstr + "," + ystr + "] in " + str);
     }
   }
   res.trimToSize();
   return res;
 }