PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/kilim/analysis/Range.java

http://github.com/kilim/kilim
Java | 37 lines | 21 code | 5 blank | 11 comment | 7 complexity | 97d2c8da6354a4cea6a3aefe4d9403d5 MD5 | raw file
 1/* Copyright (c) 2006, Sriram Srinivasan
 2 *
 3 * You may distribute this software under the terms of the license 
 4 * specified in the file "License"
 5 */
 6
 7package kilim.analysis;
 8
 9/**
10 * Used by catch handlers to handle overlapping ranges
11 *
12 */
13public class Range {
14    int from;
15    int to;
16
17    public Range(int aFrom, int aTo) {
18        from = aFrom;
19        to = aTo;
20    }
21    
22    static Range intersect(int a1, int e1, int a2, int e2) {
23        // a2 lies between a1 and e1 or a1 between a2 and e2
24        // all comparisons are inclusive of endpoints
25        assert a1 <= e1 && a2 <= e2;
26        int a;
27        if (a1 <= a2 && a2 <= e1) {
28            a = a2;
29        } else if (a2 <= a1 && a1 <= e2) {
30            a = a1; 
31        } else {
32            return null;
33        }
34        return new Range(a, e1 < e2 ? e1 : e2);
35    }
36
37}