Example usage for com.google.gwt.core.client JsArrayNumber length

List of usage examples for com.google.gwt.core.client JsArrayNumber length

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayNumber length.

Prototype

public final native int length() ;

Source Link

Document

Gets the length of the array.

Usage

From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java

License:Apache License

/**
 * Implementation of SWFUpload Speed plug-in's moving average calculation based on the
 * set of data points available ported directly from the original 2.9 implementation
 *
 * @param history An array of values calculated so far
 * @return The moving average//from   w  ww .j a va  2  s.  c o  m
 */
private static double calculateMovingAverage(JsArrayNumber history) {
    double[] vals = new double[history.length()];
    long size = history.length();
    double sum = 0.0;
    double mSum = 0.0;
    long mCount = 0;

    // Check for sufficient data
    if (size >= 8) {
        // Clone the array and Calculate sum of the values
        for (int i = 0; i < size; i++) {
            vals[i] = history.get(i);
            sum += vals[i];
        }
        double mean = sum / size;

        // Calculate variance for the set
        double varianceTemp = 0.0;
        for (int i = 0; i < size; i++) {
            varianceTemp += Math.pow((vals[i] - mean), 2);
        }
        double variance = varianceTemp / size;
        double standardDev = Math.sqrt(variance);

        // Standardize the Data
        for (int i = 0; i < size; i++) {
            vals[i] = (vals[i] - mean) / standardDev;
        }

        // Calculate the average excluding outliers
        double deviationRange = 2.0;

        for (int i = 0; i < size; i++) {
            if (vals[i] <= deviationRange && vals[i] >= -deviationRange) {
                mCount++;
                mSum += history.get(i);
            }
        }

    } else {
        // Calculate the average (not enough data points to remove outliers)
        mCount = size;
        for (int i = 0; i < size; i++) {
            mSum += history.get(i);
        }
    }

    return mSum / mCount;
}

From source file:com.ait.toolkit.gmaps.client.overlays.MarkerShape.java

License:Open Source License

public double[] getCoords() {
    JsArrayNumber values = _getCoords();
    double[] coords = new double[values.length()];
    for (int i = 0; i < values.length(); i++) {
        coords[i] = values.get(i);/*  ww w .j  a  va2s .c o m*/
    }
    return coords;
}

From source file:com.badlogic.gdx.controllers.gwt.GwtControllers.java

License:Apache License

@Override
public void onGamepadUpdated(int index) {
    Gamepad gamepad = Gamepad.getGamepad(index);
    GwtController controller = controllerMap.get(index);
    if (gamepad != null && controller != null) {
        // Determine what changed
        JsArrayNumber axes = gamepad.getAxes();
        JsArrayNumber buttons = gamepad.getButtons();
        synchronized (eventQueue) {
            for (int i = 0, j = axes.length(); i < j; i++) {
                float oldAxis = controller.getAxis(i);
                float newAxis = (float) axes.get(i);
                if (oldAxis != newAxis) {
                    GwtControllerEvent event = eventPool.obtain();
                    event.type = GwtControllerEvent.AXIS;
                    event.controller = controller;
                    event.code = i;//from w  ww .  j  a va 2 s .  co  m
                    event.amount = newAxis;
                    eventQueue.add(event);
                }
            }
            for (int i = 0, j = buttons.length(); i < j; i++) {
                float oldButton = controller.getButtonAmount(i);
                float newButton = (float) buttons.get(i);
                if (oldButton != newButton) {
                    if ((oldButton < 0.5f && newButton < 0.5f) || (oldButton >= 0.5f && newButton >= 0.5f)) {
                        controller.buttons.put(i, newButton);
                        continue;
                    }

                    GwtControllerEvent event = eventPool.obtain();
                    event.type = newButton >= 0.5f ? GwtControllerEvent.BUTTON_DOWN
                            : GwtControllerEvent.BUTTON_UP;
                    event.controller = controller;
                    event.code = i;
                    event.amount = newButton;
                    eventQueue.add(event);
                }
            }
        }
    }
}

From source file:com.brazoft.foundation.gwt.client.ui.Slider.java

License:Apache License

public Double[] getValues() {
    JsArrayNumber number = this.getValuesJS(this.slider.getId());
    Double[] values = new Double[number.length()];

    for (int i = 0; i < number.length(); i++) {
        values[i] = number.get(i);// ww  w .ja  va2s  .  co  m
    }

    return values;
}

From source file:com.brazoft.foundation.gwt.client.ui.Slider.java

License:Apache License

public static Double getValue(Event<JsArrayNumber> event) {
    JsArrayNumber values = Slider.getValues(event);

    if (values.length() == 0) {
        return -1d;
    }//from  w w  w . j av a  2 s .  c  om

    return values.get(0);
}

From source file:com.codenvy.ide.ext.java.jdt.core.util.JsUtil.java

License:Open Source License

public static long[] toLongArray(JsArrayNumber numberArray) {
    long[] result = new long[numberArray.length()];
    for (int i = 0; i < numberArray.length(); i++) {
        result[i] = (long) numberArray.get(i);
    }//from w ww . j a v  a2s.  c  o m
    return result;
}

From source file:com.github.gwtcannonjs.demo.client.impl.BunnyDemo.java

License:Open Source License

@Override
public void run() {
    ScriptInjector.fromString(BunnyResource.INSTANCE.source().getText()).inject();

    final Demo demo = CANNON.newDemo();

    demo.addScene("Bunny", new AddSceneCallback() {
        @Override//  w  w  w.  j  av a 2  s .  c om
        public void execute() {
            World world = demo.getWorld();

            world.getGravity().set(0, 0, -20);
            world.setBroadphase(CANNON.newNaiveBroadphase());
            ((GSSolver) world.getSolver().cast()).setIterations(20);
            world.getDefaultContactMaterial().setContactEquationStiffness(1e10);
            world.getDefaultContactMaterial().setContactEquationRelaxation(10);

            JsArray<CustomPolyhedron> bunny = getBunny();

            Body bunnyBody = CANNON.newBody(CANNON.newBodyOptions().withMass(1));
            for (int i = 0; i < bunny.length(); i++) {

                JsArrayNumber rawVerts = bunny.get(i).getVertices();
                JsArrayNumber rawFaces = bunny.get(i).getFaces();
                JsArrayNumber rawOffset = bunny.get(i).getOffset();

                JsArray<Vec3> verts = JsArray.createArray().cast();
                JsArray<JsArrayInteger> faces = JsArray.createArray().cast();
                Vec3 offset;

                // Get vertices
                for (int j = 0; j < rawVerts.length(); j += 3) {
                    verts.push(CANNON.newVec3(rawVerts.get(j), rawVerts.get(j + 1), rawVerts.get(j + 2)));
                }

                // Get faces
                for (int j = 0; j < rawFaces.length(); j += 3) {
                    JsArrayInteger face = JsArray.createArray().cast();
                    face.push((int) rawFaces.get(j));
                    face.push((int) rawFaces.get(j + 1));
                    face.push((int) rawFaces.get(j + 2));
                    faces.push(face);
                }

                // Get offset
                offset = CANNON.newVec3(rawOffset.get(0), rawOffset.get(1), rawOffset.get(2));

                // Construct polyhedron
                Shape bunnyPart = CANNON.newConvexPolyhedron(verts, faces);

                // Add to compound
                bunnyBody.addShape(bunnyPart, offset);
            }

            // Create body
            bunnyBody.getQuaternion().setFromAxisAngle(CANNON.newVec3(1, 0, 0), -Math.PI / 2);
            Quaternion z180 = CANNON.newQuaternion();
            z180.setFromAxisAngle(CANNON.newVec3(0, 0, 1), Math.PI);
            bunnyBody.setQuaternion(z180.mult(bunnyBody.getQuaternion(), null));
            world.addBody(bunnyBody);
            demo.addVisual(bunnyBody);

            // ground plane
            Shape groundShape = CANNON.newPlane();
            Body groundBody = CANNON.newBody(CANNON.newBodyOptions().withMass(0));
            groundBody.addShape(groundShape);
            groundBody.getPosition().set(0, 0, -5);
            world.addBody(groundBody);
            demo.addVisual(groundBody);
        }
    });

    demo.start();
}

From source file:com.github.nmorel.gwtjackson.client.deser.array.cast.PrimitiveDoubleArrayJsonDeserializer.java

License:Apache License

@Override
public double[] doDeserializeArray(JsonReader reader, JsonDeserializationContext ctx,
        JsonDeserializerParameters params) {
    JsArrayNumber jsArray = JsArrayNumber.createArray().cast();
    reader.beginArray();//from   w ww.j  a  v a 2 s .  c  o m
    while (JsonToken.END_ARRAY != reader.peek()) {
        if (JsonToken.NULL == reader.peek()) {
            reader.skipValue();
            jsArray.push(DEFAULT);
        } else {
            jsArray.push(reader.nextDouble());
        }
    }
    reader.endArray();

    if (GWT.isScript()) {
        return reinterpretCast(jsArray);
    } else {
        int length = jsArray.length();
        double[] ret = new double[length];
        for (int i = 0; i < length; i++) {
            ret[i] = jsArray.get(i);
        }
        return ret;
    }
}

From source file:com.googlecode.gflot.client.options.AbstractAxisOptions.java

License:Open Source License

/**
 * Sets the property of ZoomRange, the interval in which zooming can happen, receives as a parameter an array or a
 * null value//  w  w w  .  ja va  2 s  .co m
 */
public final T setZoomRange(JsArrayNumber range) {
    assert range.length() == 2 : "Array length must be 2";
    put(ZOOM_RANGE_KEY, range);
    return (T) this;
}

From source file:com.googlecode.gflot.client.options.AbstractAxisOptions.java

License:Open Source License

/**
 * Sets the property PanRange, confines the panning to stay within a range, receives as a parameter an array or a
 * null value/*from ww w . j  av  a 2 s.co  m*/
 */
public final T setPanRange(JsArrayNumber range) {
    assert range.length() == 2 : "Array length must be 2";
    put(PAN_RANGE_KEY, range);
    return (T) this;
}