Package elemental.util

Examples of elemental.util.ArrayOfInt


    }
    return array;
  }

  private static ArrayOfInt arrayFrom(int... items) {
    final ArrayOfInt array = Collections.arrayOfInt();
    for (int i = 0, n = items.length; i < n; ++i) {
      array.push(items[i]);
    }
    return array;
  }
View Full Code Here


  /**
   * Tests {@link ArrayOfInt}.
   */
  public void testArraysOfInts() {
    // This is our test subject.
    final ArrayOfInt array = Collections.arrayOfInt();

    // These are items to put in him.
    final int[] items = new int[] {0, 1, 2};

    // Let's put the items in him.
    for (int i = 0, n = items.length; i < n; ++i) {
      array.push(items[i]);
    }

    // Are the items in the right places?
    assertEquals(items.length, array.length());
    for (int i = 0, n = items.length; i < n; ++i) {
      assertEquals(items[i], array.get(i));
    }

    // These are some more items to put in him.
    final int[] newItems = new int[] {3, 4, 5};

    // Put all these items in where the others were.
    for (int i = 0, n = items.length; i < n; ++i) {
      array.set(i, newItems[i]);
      assertEquals(newItems[i], array.get(i));
    }

    // Shift our test subject to squeeze out the first item.
    assertEquals(newItems[0], array.shift());
    assertEquals(newItems.length - 1, array.length());

    // Then Unshift.
    array.unshift(newItems[0]);
    assertEquals(newItems[0], array.get(0));
    assertEquals(newItems.length, array.length());

    // Now join them together in harmony.
    assertEquals("3$4$5", array.join("$"));

    for (int i = 0, n = items.length; i < n; ++i) {
      assertEquals(i, array.indexOf(newItems[i]));
      assertTrue(array.contains(newItems[i]));
    }

    final int imposter = 100;
    assertEquals(-1, array.indexOf(imposter));
    assertFalse(array.contains(imposter));

    final int[] itemsA = new int[] {11, 12};
    final int[] itemsB = new int[] {13, 14};
    final ArrayOfInt a = arrayFrom(itemsA);
    final ArrayOfInt b = arrayFrom(itemsB);
    assertSamelitude(new int[] {itemsA[0], itemsA[1], itemsB[0], itemsB[1]}, a.concat(b));
    assertSamelitude(itemsA, a);
    assertSamelitude(itemsB, b);
  }
View Full Code Here

  /**
   * Tests {@link ArrayOfInt#insert(int, int)}.
   */
  public void testInsertingIntoArraysOfInts() {
    final ArrayOfInt array = Collections.arrayOfInt();

    array.insert(0, 0);
    assertSamelitude(new int[] {0}, array);

    array.insert(0, 1);
    assertSamelitude(new int[] {1, 0}, array);

    array.insert(100, 2);
    assertSamelitude(new int[] {1, 0, 2}, array);

    array.insert(-1, 3);
    assertSamelitude(new int[] {1, 0, 3, 2}, array);
  }
View Full Code Here

   * Tests {@link ArrayOfInt#sort()} and
   * {@link ArrayOfInt#sort(CanCompareInt)}.
   */
  public void testSortingOfArraysOfInts() {
    final int[] items = new int[] {0, 1, 2, 3};
    final ArrayOfInt array = Collections.arrayOfInt();
    array.push(items[2]);
    array.push(items[1]);
    array.push(items[0]);
    array.push(items[3]);

    array.sort();
    assertEquals(items.length, array.length());
    for (int i = 0, n = array.length(); i < n; ++i) {
      assertEquals(items[i], array.get(i));
    }

    array.sort(new CanCompareInt() {
      @Override
      public int compare(int a, int b) {
        return b - a;
      }
    });
    assertEquals(items.length, array.length());
    for (int i = 0, n = array.length(); i < n; ++i) {
      assertEquals(items[n - 1 - i], array.get(i));
    }
  }
View Full Code Here

   * Tests {@link ArrayOfInt#splice(int, int)}.
   */
  public void testSplicingOfArraysOfInts() {
    final int[] items = new int[] {0, 1, 2, 3, 4};

    final ArrayOfInt a = arrayFrom(items);
    assertSamelitude(items, a.splice(0, items.length));
    assertSamelitude(new int[] {}, a);

    final ArrayOfInt b = arrayFrom(items);
    assertSamelitude(new int[] {}, b.splice(0, 0));
    assertSamelitude(items, b);

    final ArrayOfInt c = arrayFrom(items);
    assertSamelitude(new int[] {items[0], items[1]}, c.splice(0, 2));
    assertSamelitude(new int[] {items[2], items[3], items[4]}, c);
  }
View Full Code Here

  }

  private void checkMapContents(MapFromIntTo<TestItem> map, int[] keys, TestItem[] values) {
    keys = Arrays.copyOf(keys, keys.length);
    Arrays.sort(keys);
    ArrayOfInt mapKeys = map.keys();
    mapKeys.sort();
    assertSamelitude(keys, mapKeys);

    values = Arrays.copyOf(values, values.length);
    Arrays.sort(values);
    ArrayOf<TestItem> mapValues = map.values();
View Full Code Here

  }

  private void checkMapContents(MapFromIntToString map, int[] keys, String[] values) {
    keys = Arrays.copyOf(keys, keys.length);
    Arrays.sort(keys);
    ArrayOfInt mapKeys = map.keys();
    mapKeys.sort();
    assertSamelitude(keys, mapKeys);

    values = Arrays.copyOf(values, values.length);
    Arrays.sort(values);
    ArrayOfString mapValues = map.values();
View Full Code Here

    mapKeys.sort();
    assertSamelitude(keys, mapKeys);

    values = Arrays.copyOf(values, values.length);
    Arrays.sort(values);
    ArrayOfInt mapValues = map.values();
    mapValues.sort();
    assertSamelitude(values, mapValues);
  }
View Full Code Here

  /**
   * Indicates that all data has been loaded into the model.
   */
  @Override
  public void modelDidFinishLoading(Model model) {
    final ArrayOfInt histogram = model.histogram();
    assert histogram.length() > 0 : "histogram is empty.";

    xAxisScale = (double) css.rootWidth() / (double) histogram.length();

    // Build the histogram graph.
    render();

    // Create the marker.
View Full Code Here

  /**
   * Renders the bar graph.
   */
  private void render() {
    final ArrayOfInt histogram = model.histogram();

    final int padding = 2;
    final int topPadding = 50;

    final double dx = xAxisScale;
    final double dy = (double) css.rootHeight() / histogram.get(histogram.length() - 1);
    final double halfDx = dx / 2.0;

    // Render all bars.
    for (int i = 0, n = histogram.length(); i < n; ++i) {
      final int value = histogram.get(i);
      if (value == 0) continue;

      final int x = (int) (dx * i) + padding;
      final int h = (int) (dy * value) - topPadding;
      final int w = (int) dx - padding * 2;

      // Create the vertical bar.
      final Element bar = div(css.bar());
      final CSSStyleDeclaration barStyle = bar.getStyle();
      barStyle.setLeft(x, Unit.PX);
      barStyle.setBottom("0");
      barStyle.setHeight(h, Unit.PX);
      barStyle.setWidth(w, Unit.PX);

      // Add a count at the top.
      final Element count = div(css.count());
      count.setTextContent("" + value);

      bar.appendChild(count);
      root.appendChild(bar);
    }

    // Render labels
    for (int i = 0, n = histogram.length(); i <= n; ++i) {
      final int x = (int) (dx * i);
      final int w = (int) dx;

      final String time = secondsToTime(i * Model.SECONDS_PER_HISTOGRAM_BUCKET, false);

View Full Code Here

TOP

Related Classes of elemental.util.ArrayOfInt

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.