Example #1
0
  public static void testForEach() {
    class MyVisitor<T> implements Table.Visitor<T> {
      List<int[]> list = new ArrayList<int[]>(20);

      public boolean visit(long seqno, T element, int row, int column) {
        System.out.println("#" + seqno + ": " + element + ", row=" + row + ", column=" + column);
        list.add(new int[] {row, column});
        return true;
      }
    }
    MyVisitor<Integer> visitor = new MyVisitor<Integer>();

    Table<Integer> table = new Table<Integer>(3, 10, 0);
    for (int i = 1; i <= 20; i++) table.add(i, i);
    System.out.println("table = " + table);
    table.forEach(table.getLow() + 1, table.getHighestReceived() - 1, visitor);
    int count = 1;
    for (int[] pair : visitor.list) {
      int row = pair[0], column = pair[1];
      if (count < Util.getNextHigherPowerOfTwo(10)) {
        assert row == 0;
        assert column == count;
      } else {
        assert row == 1;
        assert column == count - Util.getNextHigherPowerOfTwo(10);
      }
      count++;
    }
  }
Example #2
0
  public void init() throws Exception {
    if (keyPassword == null && storePassword != null) {
      keyPassword = storePassword;
      log.debug("key_password used is same as store_password");
    }
    if (keyStoreName == null) {
      initSymKey();
      initKeyPair();
    } else initConfiguredKey();

    if (cipher_pool_size <= 0) {
      log.warn("cipher_pool_size of %d is invalid; setting it to 1", cipher_pool_size);
      cipher_pool_size = 1;
    }

    int tmp = Util.getNextHigherPowerOfTwo(cipher_pool_size);
    if (tmp != cipher_pool_size) {
      log.warn(
          "setting cipher_pool_size (%d) to %d (power of 2) for faster modulo operation",
          cipher_pool_size, tmp);
      cipher_pool_size = tmp;
    }

    encoding_ciphers = new Cipher[cipher_pool_size];
    encoding_locks = new Lock[cipher_pool_size];
    decoding_ciphers = new Cipher[cipher_pool_size];
    decoding_locks = new Lock[cipher_pool_size];

    initSymCiphers(symAlgorithm, getSecretKey());
  }
Example #3
0
  public void testGetNextHigher() {
    int[][] numbers = {
      {0, 1},
      {1, 1},
      {2, 2},
      {3, 4},
      {4, 4},
      {5, 8},
      {10, 16},
      {8000, 8192}
    };

    for (int[] pair : numbers) {
      int input = pair[0];
      int expected = pair[1];
      int actual = Util.getNextHigherPowerOfTwo(input);
      assert expected == actual
          : "expected " + expected + " but got " + actual + " (input=" + input + ")";
    }
  }
Example #4
0
 protected static void assertCapacity(int actual_capacity, int num_rows, int elements_per_row) {
   int actual_elements_per_row = Util.getNextHigherPowerOfTwo(elements_per_row);
   int expected_capacity = num_rows * actual_elements_per_row;
   assert actual_capacity == expected_capacity
       : "expected capacity of " + expected_capacity + " but got " + actual_capacity;
 }