Package elemental.util

Examples of elemental.util.ArrayOfString


    }
    return array;
  }

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


  /**
   * Tests for {@link ArrayOfString}.
   */
  public void testArraysOfStrings() {
    // This is our test subject.
    final ArrayOfString array = Collections.arrayOfString();

    // These are items to put in him.
    final String[] items = new String[] {"zero goats", "one goat", "two goats"};

    // 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 String[] newItems = new String[] {"three goats", "four goats", "SQUIRREL!"};

    // 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("three goats$four goats$SQUIRREL!", array.join("$"));

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

    final String imposter = "Pajamas?";
    assertEquals(-1, array.indexOf(imposter));
    assertFalse(array.contains(imposter));

    final String[] itemsA = new String[] {"atlanta", "eagle"};
    final String[] itemsB = new String[] {"chaps", "profit"};
    final ArrayOfString a = arrayFrom(itemsA);
    final ArrayOfString b = arrayFrom(itemsB);
    assertSamelitude(new String[] {itemsA[0], itemsA[1], itemsB[0], itemsB[1]}, a.concat(b));
    assertSamelitude(itemsA, a);
    assertSamelitude(itemsB, b);
  }
View Full Code Here

  /**
   * Tests {@link ArrayOfString#insert(int, String)}.
   */
  public void testInsertingIntoArraysOfStrings() {
    final ArrayOfString array = Collections.arrayOfString();

    array.insert(0, "beer");
    assertSamelitude(new String[] {"beer"}, array);

    array.insert(0, "cigars");
    assertSamelitude(new String[] {"cigars", "beer"}, array);

    array.insert(100, "porn");
    assertSamelitude(new String[] {"cigars", "beer", "porn"}, array);

    array.insert(-1, "profit");
    assertSamelitude(new String[] {"cigars", "beer", "profit", "porn"}, array);
  }
View Full Code Here

   * Tests {@link ArrayOfString#sort()} and
   * {@link ArrayOfString#sort(CanCompareString)}.
   */
  public void testSortingOfArraysOfStrings() {
    final String[] items = new String[] {"aaa", "aab", "baa", "bab"};
    final ArrayOfString array = Collections.arrayOfString();
    array.push(items[2]);
    array.push(items[1]);
    array.push(items[3]);
    array.push(items[0]);

    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 CanCompareString() {
      @Override
      public int compare(String a, String b) {
        return b.compareTo(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

   */
  public void testSplicingOfArraysOfStrings() {
    final String[] items =
        new String[] {"One Gerbil", "Two Gerbil", "Three Gerbil", "Four Gerbil", "Five Gerbil"};

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

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

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

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

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

  }

  private void checkMapContents(MapFromStringToBoolean map, String[] keys, boolean[] values) {
    keys = Arrays.copyOf(keys, keys.length);
    Arrays.sort(keys);
    ArrayOfString mapKeys = map.keys();
    mapKeys.sort();
    assertSamelitude(keys, mapKeys);

    // We can't sort boolean array so we just compare true values count.
    ArrayOfBoolean mapValues = map.values();
    assertEquals(values.length, mapValues.length());
View Full Code Here

  }

  private void checkMapContents(MapFromStringToNumber map, String[] keys, double[] values) {
    keys = Arrays.copyOf(keys, keys.length);
    Arrays.sort(keys);
    ArrayOfString mapKeys = map.keys();
    mapKeys.sort();
    assertSamelitude(keys, mapKeys);

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

  }

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

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

  }

  private void checkMapContents(MapFromStringTo<TestItem> map, String[] keys, TestItem[] values) {
    keys = Arrays.copyOf(keys, keys.length);
    Arrays.sort(keys);
    ArrayOfString 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

TOP

Related Classes of elemental.util.ArrayOfString

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.