View Javadoc
1   /*
2    * Copyright 2010 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package com.googlecode.mgwt.collection.client;
17  
18  import com.google.gwt.core.client.JavaScriptObject;
19  import com.googlecode.mgwt.collection.shared.LightArrayBoolean;
20  
21  /**
22   * An implementation of {@link LightArrayBoolean} that uses native javascript arrays
23   * 
24   * @author Daniel Kurka
25   * 
26   */
27  public class JsLightArrayBoolean implements LightArrayBoolean {
28  
29  	private JavaScriptObject array;
30  
31    /**
32     * Construct a {@link JsLightArrayBoolean}
33     */
34  	public JsLightArrayBoolean() {
35  		this(JavaScriptObject.createArray());
36  	}
37  
38    /**
39     * Construct a {@link JsLightArrayBoolean} with a given javascript array
40     * 
41     * @param array the javascript array to use
42     */
43  	public JsLightArrayBoolean(JavaScriptObject array) {
44  		this.array = array;
45  	}
46  
47  	@Override
48  	public native void push(boolean value)/*-{
49  		this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array[this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array.length] = value;
50    }-*/;
51  
52  	@Override
53  	public native boolean shift() /*-{
54  		return this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array
55  				.shift();
56    }-*/;
57  
58  	@Override
59  	public native boolean get(int index) /*-{
60  		return this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array[index];
61    }-*/;
62  
63  	@Override
64  	public native void set(int index, boolean value) /*-{
65  		this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array[index] = value;
66    }-*/;
67  
68  	@Override
69  	public native int length()/*-{
70  		return this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array.length;
71    }-*/;
72  
73  	@Override
74  	public native void unshift(boolean value)/*-{
75  		this.@com.googlecode.mgwt.collection.client.JsLightArrayBoolean::array
76  				.unshift(value);
77    }-*/;
78  
79    /**
80     * get the underlying javascript array
81     * 
82     * @return the javascript array
83     */
84  	public JavaScriptObject getArray() {
85  		return array;
86  	}
87  
88  }