Beispiel #1
0
 private <T> T removeObject(
     SchedulingContext ctxt,
     Pair<String, String> key,
     Map<Pair<String, String>, T> objectsByKey,
     Map<String, Map<String, T>> objHierarchy) {
   T removed = objectsByKey.remove(key);
   if (removed != null) {
     Map<String, T> objsByName = objHierarchy.get(key.getFirst());
     if (objsByName != null) {
       objsByName.remove(key.getSecond());
     }
     return removed;
   } else {
     return null;
   }
 }
Beispiel #2
0
  private <T> void storeObject(
      SchedulingContext ctxt,
      Pair<String, String> key,
      T t,
      boolean replaceExisting,
      Map<Pair<String, String>, T> objectsByKey,
      Map<String, Map<String, T>> objHierarchy)
      throws ObjectAlreadyExistsException {
    if ((!replaceExisting) && (objectsByKey.containsKey(key))) {
      throw new ObjectAlreadyExistsException("Object " + key + " already exists.");
    }

    objectsByKey.put(key, t);

    Map<String, T> objsByName = objHierarchy.get(key.getFirst());
    if (objsByName == null) {
      objsByName = new HashMap<String, T>(29);
      objHierarchy.put(key.getFirst(), objsByName);
    }
    objsByName.put(key.getSecond(), t);
  }