KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > alphabet > Realms


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Raymond Audet <raymond.audet@gmail.com>
4  * Copyright 2007 Etienne M. Gagnon <egagnon@j-meg.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.sablecc.sablecc.alphabet;
20
21 import java.math.BigInteger JavaDoc;
22
23 public class Realms {
24
25     private static final AdjacencyRealm<Integer JavaDoc> integer = new AdjacencyRealm<Integer JavaDoc>() {
26
27         @Override JavaDoc
28         public boolean isAdjacent(
29                 Integer JavaDoc bound1,
30                 Integer JavaDoc bound2) {
31
32             return bound1 + 1 == bound2;
33         }
34
35         @Override JavaDoc
36         public Integer JavaDoc next(
37                 Integer JavaDoc bound) {
38
39             return bound + 1;
40         }
41
42         @Override JavaDoc
43         public Integer JavaDoc previous(
44                 Integer JavaDoc bound) {
45
46             return bound - 1;
47         }
48     };
49
50     private static final AdjacencyRealm<BigInteger JavaDoc> bigInteger = new AdjacencyRealm<BigInteger JavaDoc>() {
51
52         @Override JavaDoc
53         public boolean isAdjacent(
54                 BigInteger JavaDoc bound1,
55                 BigInteger JavaDoc bound2) {
56
57             return bound1.add(BigInteger.ONE).equals(bound2);
58         }
59
60         @Override JavaDoc
61         public BigInteger JavaDoc next(
62                 BigInteger JavaDoc bound) {
63
64             return bound.add(BigInteger.ONE);
65         }
66
67         @Override JavaDoc
68         public BigInteger JavaDoc previous(
69                 BigInteger JavaDoc bound) {
70
71             return bound.subtract(BigInteger.ONE);
72         }
73
74     };
75
76     private static final AdjacencyRealm<Character JavaDoc> character = new AdjacencyRealm<Character JavaDoc>() {
77
78         @Override JavaDoc
79         public boolean isAdjacent(
80                 Character JavaDoc bound1,
81                 Character JavaDoc bound2) {
82
83             return bound1 + 1 == bound2;
84         }
85
86         @Override JavaDoc
87         public Character JavaDoc next(
88                 Character JavaDoc bound) {
89
90             return (char) (bound + 1);
91         }
92
93         @Override JavaDoc
94         public Character JavaDoc previous(
95                 Character JavaDoc bound) {
96
97             return (char) (bound - 1);
98         }
99
100     };
101
102     public static AdjacencyRealm<BigInteger JavaDoc> getBigInteger() {
103
104         return bigInteger;
105     }
106
107     public static AdjacencyRealm<Integer JavaDoc> getInteger() {
108
109         return integer;
110     }
111
112     public static AdjacencyRealm<Character JavaDoc> getCharacter() {
113
114         return character;
115     }
116
117 }
118
Popular Tags