public ClientMessageBusImpl() { setBusToInitializableState(); managementConsole = new ManagementConsole(this); clientId = String.valueOf(com.google.gwt.user.client.Random.nextInt(99999)) + "-" + (System.currentTimeMillis() % (com.google.gwt.user.client.Random.nextInt(99999) + 1)); IN_SERVICE_ENTRY_POINT = "in." + getClientId() + ".erraiBus"; OUT_SERVICE_ENTRY_POINT = "out." + getClientId() + ".erraiBus"; // when the window is closing, we want to stop the bus without causing any // errors (unless the server is unavailable of course) (see ERRAI-225) Window.addCloseHandler(new CloseHandler<Window>() { @Override public void onClose(final CloseEvent<Window> event) { if (state != BusState.LOCAL_ONLY) { stop(true); } } }); }
@Override double randomDouble() { return Random.nextDouble(); }
@Override boolean randomBoolean() { return Random.nextBoolean(); }
public static final void shuffle(final char[] input) { // --- Shuffle by exchanging each element randomly for (int i = 0; i < input.length; i++) { int randomPosition = Random.nextInt(input.length); char temp = input[i]; input[i] = input[randomPosition]; input[randomPosition] = temp; } }
@UiHandler("markersBtn") public void onMarkersBtnClicked(ClickEvent event) { for (int i = 0; i < 20; i++) { double userX = Random.nextDouble() * 40000000 - 20000000; double userY = Random.nextDouble() * 40000000 - 20000000; Marker1 marker1 = new Marker1(resources.marker1(), userX, userY, 16, 32); container.add(marker1); } }
public static final void shuffle(final int[] input) { // --- Shuffle by exchanging each element randomly for (int i = 0; i < input.length; i++) { int randomPosition = Random.nextInt(input.length); int temp = input[i]; input[i] = input[randomPosition]; input[randomPosition] = temp; } }
private Bbox getNextBounds() { if (zoomOut) { layer.setEnabled(false); zoomOut = false; return new Bbox(-5000000, -5000000, 10000000, 10000000); } else { layer.setEnabled(true); double x = (Random.nextDouble() - 0.5) * 5000000; double y = (Random.nextDouble() - 0.5) * 5000000; double width = 5000; double height = 5000; zoomOut = true; return new Bbox(x, y, width, height); } }
public static final void shuffle(final char[] input) { // --- Shuffle by exchanging each element randomly for (int i = 0; i < input.length; i++) { int randomPosition = Random.nextInt(input.length); char temp = input[i]; input[i] = input[randomPosition]; input[randomPosition] = temp; } }
@UiHandler("rectBtn") public void onRectangleBtnClicked(ClickEvent event) { if (rectangleContainer != null) { rectangleContainer.clear(); List<CanvasShape> shapes = new ArrayList<CanvasShape>(); double factor = Math.pow(count, -0.5); for (int i = 0; i < count; i++) { double x = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor); double y = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor); double width = Random.nextDouble() * SHAPE_SIZE * factor; double height = Random.nextDouble() * SHAPE_SIZE * factor; CanvasRect rect = new CanvasRect(new Bbox(x - width / 2, y - height / 2, width, height)); rect.setFillStyle(getRandomRGB(0.5)); rect.setStrokeStyle(getRandomRGB(1)); shapes.add(rect); } rectangleContainer.addAll(shapes); rectangleContainer.repaint(); } }
@UiHandler("polyBtn") public void onPolyBtnClicked(ClickEvent event) { if (polygonContainer != null) { polygonContainer.clear(); List<CanvasShape> shapes = new ArrayList<CanvasShape>(); double factor = Math.pow(count, -0.5); for (int i = 0; i < count; i++) { double x1 = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor); double y1 = (Random.nextDouble() - 0.5) * (TOTAL_SIZE - SHAPE_SIZE * factor); double x2 = x1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor; double y2 = y1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor; double x3 = x1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor; double y3 = y1 + (Random.nextDouble() - 0.5) * SHAPE_SIZE * factor; Coordinate[] coords = new Coordinate[] { new Coordinate(x1, y1), new Coordinate(x2, y2), new Coordinate(x3, y3), new Coordinate(x1, y1) }; Geometry ring = new Geometry(Geometry.LINEAR_RING, 0, 5); ring.setCoordinates(coords); Geometry poly = new Geometry(Geometry.POLYGON, 0, 5); poly.setGeometries(new Geometry[] { ring }); CanvasPath path = new CanvasPath(poly); path.setFillStyle(getRandomRGB(0.5)); path.setStrokeStyle(getRandomRGB(1)); shapes.add(path); } polygonContainer.addAll(shapes); polygonContainer.repaint(); } }
public static final void shuffle(final int[] input) { // --- Shuffle by exchanging each element randomly for (int i = 0; i < input.length; i++) { int randomPosition = Random.nextInt(input.length); int temp = input[i]; input[i] = input[randomPosition]; input[randomPosition] = temp; } }
@Override int randomInt(int limit) { return Random.nextInt(limit); }
@Override int randomInt() { return Random.nextInt(); }
/** * TODO window.crypto.getRandomValues. */ @Override byte[] newUID_() { byte[] bytes = new byte[UID.LENGTH]; int n = 0; for (int i = 0; i < 4; i++) { int value = Random.nextInt(); bytes[n++] = (byte) (value >>> 0); bytes[n++] = (byte) (value >>> 8); bytes[n++] = (byte) (value >>> 16); bytes[n++] = (byte) (value >>> 24); } return bytes; }
private static String getNextFormattedRandomNumber() { String randomHex = Integer.toHexString(Random.nextInt(256)); if (randomHex.length() == 1) { // ensure two digits randomHex = "0" + randomHex; } return randomHex; }
public static String getBase62RandomInt() { int randomValue = Random.nextInt(); ByteBuffer byteBuffer = ByteBuffer.allocate(4); byteBuffer.putInt(randomValue); BigInteger bi = new BigInteger(byteBuffer.array()); return convertToBase62String(bi); }
/** * Randomly shuffle the list of objects provided. * <p> * <i>Note: {@link Collections#shuffle(List)} is not GWT compatible</i> * * @param objects * the list to shuffle */ public static final void shuffle(final List<?> objects) { for (int i = objects.size(); i > 1; i--) { swap(objects, i - 1, Random.nextInt(i)); } }
public static void runAsync(final RunAsyncCallback callback) { final int delay = Random.nextInt(50) + 1; final Throwable _trace = new Throwable(); new Timer() { @Override public void run() { trace = _trace; callback.onSuccess(); } }.schedule(delay); logger.info("simulating async load with " + delay + "ms delay."); } }
/** * Randomly shuffle the list of objects provided. * <p> * <i>Note: {@link Collections#shuffle(List)} is not GWT compatible</i> * * @param objects * the list to shuffle */ public static final void shuffle(final List<?> objects) { for (int i = objects.size(); i > 1; i--) { swap(objects, i - 1, Random.nextInt(i)); } }