Exemplo n.º 1
0
 public int rollback() {
   currentTable.clear();
   currentTable.putAll(committedTable);
   int countOfChanges = changedKeys;
   changedKeys = 0;
   return countOfChanges;
 }
Exemplo n.º 2
0
 public int commit() {
   try {
     currentTable.write();
   } catch (MyException e) {
     throw new RuntimeException();
   }
   committedTable.clear();
   committedTable.putAll(currentTable);
   int countOfChanges = changedKeys;
   changedKeys = 0;
   return countOfChanges;
 }
Exemplo n.º 3
0
 public List<String> list() {
   List<String> result = new LinkedList<>();
   for (String key : currentTable.keySet()) {
     result.add(key);
   }
   return result;
 }
 @Override
 public final boolean exec(State fileMap, final String[] command) {
   if (command.length != 1) {
     System.err.println("exit: Usage - exit");
     return false;
   }
   try {
     ((FileMap) fileMap).saveFileMap();
   } catch (IOException e) {
     System.err.println(e.getMessage());
   }
   System.exit(0);
   return true;
 }
Exemplo n.º 5
0
  public void execute(String[] args, FileMap fileMap) throws MyException {
    if (args.length > 1) {
      throw new MyException("list: too many arguments");
    }

    int i = 0;
    for (String string : fileMap.keySet()) {
      if (i != 0) {
        System.out.print(", ");
      }
      System.out.print(string);
      ++i;
    }
    System.out.println();
  }
Exemplo n.º 6
0
 public int size() {
   return currentTable.size();
 }
Exemplo n.º 7
0
 public String get(String key) {
   if (key == null) {
     throw new IllegalArgumentException();
   }
   return currentTable.get(key);
 }
Exemplo n.º 8
0
 protected MyTable(FileMap passedTable) {
   currentTable = passedTable;
   committedTable = new FileMap();
   committedTable.putAll(passedTable);
   changedKeys = 0;
 }