01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package js;
21 
22 /**
23  * <p>An <b>opaque</b> interface helping to simulate JavaScript <tt>switch</tt> 
24  * statement in the Java language environment.</p>
25  * <p>This interface must be implemented in JS Simulation Libraries.</p>
26  *
27  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
28  * @see Js#cases()
29  * 
30  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
31  * generated into the target codes. Re-compilers must exit with error on the operations of 
32  * accessing that kind of class objects.
33  * Re-compilers shall convert Java <tt>switch</tt> statements like:
34  * <pre>switch (Js.cases().add(k0).add(k1).add(k2).indexOf(k)) {
35  *  case 0:
36  *    statement0;</p>
37  *  case 1:</p>
38  *    statement1;</p>
39  *  case 2:</p>
40  *    statement2;</p>
41  *  default:</p>
42  *    default_statement;</p>
43  *}</pre>
44  * into JavaScript <tt>switch</tt> statements as:
45  * <pre>switch (k) {
46  *  case k0:
47  *    statement0;</p>
48  *  case k1:</p>
49  *    statement1;</p>
50  *  case k2:</p>
51  *    statement2;</p>
52  *  default:</p>
53  *    default_statement;</p>
54  *}</pre>
55  */
56 
57 public interface Cases
58 {
59     /**
60      * <p>Adds a key to the current <tt>Cases</tt> cache.</p>
61      * @return The current <tt>Cases</tt> cache itself.
62      * @since 1.0
63      * @javascript Re-compilers must append the expression of <tt>key</tt> to the current 
64      * re-compile time <tt>Cases</tt> cache without generating any JavaScript statements 
65      * or expressions for the interface invocation of this method.
66      */
67     public Cases add(Object key);
68     /**
69      * <p>Returns the index of a key by searching its reference in the current <tt>Cases</tt> 
70      * cache.</p>
71      * @return The index of a key in the current <tt>Cases</tt> cache.
72      * @since 1.0
73      * @javascript Re-compilers must find the identifier of <tt>key </tt> by looking 
74      * into the current re-compile time <tt>Cases</tt> cache reporting error if it can 
75      * not and replace the interface invocation of this method with the key identifier it 
76      * has found.
77      */
78     public int indexOf(Object key);
79 }