Js Array Util : Utility « GWT « Java






Js Array Util

     
package com.googlecode.gwtgl.util;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayBoolean;
import com.google.gwt.core.client.JsArrayInteger;
import com.google.gwt.core.client.JsArrayNumber;
import com.google.gwt.core.client.JsArrayString;

/**
 * @author Steffen Schfer
 *
 */
public final class JsArrayUtil {

  private JsArrayUtil() {
  }

  /**
   * Wraps a Java String Array to a JsArrayString for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayString wrapArray(String[] srcArray) {
    JsArrayString result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }
  
  /**
   * Converts a JsArrayString to a String[].
   * 
   * @param jsArrayString the array to unwrap.
   * @return the created String[].
   */
  public static String[] unwrapArray(JsArrayString jsArrayString) {
    String[] result = new String[jsArrayString.length()];
    for(int i=0; i<jsArrayString.length();i++) {
      result[i]=jsArrayString.get(i);
    }
    return result;
  }
  
  /**
   * Wraps a Java float Array to a JsArrayNumber for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayNumber wrapArray(float[] srcArray) {
    JsArrayNumber result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }
  
  /**
   * Wraps a Java double Array to a JsArrayNumber for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayNumber wrapArray(double[] srcArray) {
    JsArrayNumber result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }
  
  /**
   * Wraps a Java int Array to a JsArrayInteger for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayInteger wrapArray(int[] srcArray) {
    JsArrayInteger result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }
  
  /**
   * Wraps a Java byte Array to a JsArrayInteger for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayInteger wrapArray(byte[] srcArray) {
    JsArrayInteger result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }
  
  /**
   * Wraps a Java boolean Array to a JsArrayBoolean for dev mode.
   * 
   * @param srcArray the array to wrap
   * @return the wrapped array
   */
  public static JsArrayBoolean wrapArray(boolean[] srcArray) {
    JsArrayBoolean result = JavaScriptObject.createArray().cast();
    for (int i = 0; i < srcArray.length; i++) {
      result.set(i, srcArray[i]);
    }
    return result;
  }

}

   
    
    
    
    
  








Related examples in the same category

1.Use reflection to generate the async interface from the Service interface as per GWT standard
2.Array Utils for client side GWT
3.A simple number formatting/ parsing class
4.GWT window utility
5.Implement java.util.regex.Pattern with Javascript RegExp object
6.GWT color class
7.DOM related helper methods (Smart GWT)
8.Formatting functions for GWT client side (Ext GWT)
9.Helper class to decode and encode objects to and from Json (Ext GWT)
10.String util for GWT client side (Smart GWT)
11.GWT DOM util
12.Replace string for GWT
13.GWT style util
14.gwt DateTimeFormat
15.A utility class that provides utility methods to work with arrays for GWT.
16.Date compare util for GWT
17.GWT DOM utility functions for use when programmatically constructing a UI.
18.Generate a faster string comparison than String.equals() for web mode code.