コード例 #1
0
ファイル: XLBufferedReader.java プロジェクト: clayschemer/OMD
 // TODO Change Object to something appropriate
 public void load(Map<Address, Slot> map) {
   SlotFactory factory = new SlotFactory(storage);
   try {
     if (ready()) {
       System.out.println("ajam redi");
     } else {
       System.out.println("ajam nut redi");
     }
     while (ready()) {
       String string = readLine();
       System.out.println(string);
       int i = string.indexOf('=');
       storage.add(string.substring(0, i - 1), string.substring(0, i + 1));
       map.put(
           new Address(string.substring(0, i - 1)),
           factory.slotBuilder(string.substring(0, i + 1)));
     }
   } catch (Exception e) {
     throw new XLException(e.getMessage());
   }
 }
コード例 #2
0
ファイル: StorageTest.java プロジェクト: riengcs/utils
  /**
   * Tests {@link Storage} by creating a new Storage, {@link Storage#add(Storable) adding data},
   * adding more data, {@link Storage#remove(long) removing data}, and {@link Storage#compact()
   * compacting the directory}, checking the {@link Storage#size() number of stored objects} and the
   * {@link Storage#getDirectorySize() number of directory entries} after every action.
   *
   * @throws StorageException
   */
  @SuppressWarnings("synthetic-access")
  public void testSimpleStorage() throws StorageException {
    Storage<Data> storage;
    Data data;

    storage = new Storage<Data>(new DataFactory(), directory, "data");
    data = new Data(0x12345678);
    try {
      storage.add(data);
      fail("exception expected");
    } catch (IllegalStateException ise1) {
      /* okay. */
    }

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.add(data);
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    data = storage.load(0x12345678);
    assertNotNull(data);
    storage.close();

    data = new Data(0x23456789);
    storage.open();
    assertEquals(1, storage.size());
    assertEquals(1, storage.getDirectorySize());
    storage.add(data);
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(2, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x12345678);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x01234567);
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(1, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.remove(0x23456789);
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.open();
    assertEquals(0, storage.size());
    assertEquals(2, storage.getDirectorySize());
    storage.close();

    storage.compact();
    storage.open();
    assertEquals(0, storage.size());
    assertEquals(0, storage.getDirectorySize());
    storage.close();
  }