PageRenderTime 68ms CodeModel.GetById 62ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/branch-1.0/src/org/getopt/luke/Ranges.java

http://luke.googlecode.com/
Java | 35 lines | 31 code | 4 blank | 0 comment | 8 complexity | 5042c0b9740467f53e93cc2463e7fc4e MD5 | raw file
 1package org.getopt.luke;
 2
 3import org.apache.lucene.util.OpenBitSet;
 4
 5@SuppressWarnings("serial")
 6public class Ranges extends OpenBitSet {
 7  
 8  public static Ranges parse(String expr) throws Exception {
 9    Ranges res = new Ranges();
10    expr = expr.replaceAll("\\s+", "");
11    if (expr.length() == 0) {
12      return res;
13    }
14    String[] ranges = expr.split(",");
15    for (int i = 0; i < ranges.length; i++) {
16      String[] ft = ranges[i].split("-");
17      int from, to;
18      from = Integer.parseInt(ft[0]);
19      if (ft.length == 1) {
20        res.set(from);
21      } else {
22        to = Integer.parseInt(ft[1]);
23        res.set(from, to);
24      }
25    }
26    return res;
27  }
28  
29  public void set(int from, int to) {
30    if (from > to) return;
31    for (int i = from; i <= to; i++) {
32      set(i);
33    }
34  }
35}