Java Collections.newSetFromMap Examples

Java Collections.newSetFromMap - 30 examples found. These are the top rated real world Java examples of java.util.Collections.newSetFromMap extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private boolean registerSmelted(SmeltedRecipe recipe) {
    boolean failed = false;
    Plugin plugin = recipe.getPlugin();
    if (plugin != null) {
      ConcurrentHashMap<Integer, Set<SmeltedRecipe>> recipesMap =
          (ConcurrentHashMap<Integer, Set<SmeltedRecipe>>) registeredSmeltedRecipes.get(plugin);
      if (recipesMap == null) {
        recipesMap = new ConcurrentHashMap<Integer, Set<SmeltedRecipe>>();
        registeredSmeltedRecipes.put(plugin, recipesMap);
      }
      if (recipesMap.get(recipe.getIngredients().size()) == null) {
        Set<SmeltedRecipe> recipes =
            Collections.newSetFromMap(new ConcurrentHashMap<SmeltedRecipe, Boolean>());
        registeredSmeltedRecipes.get(plugin).put(recipe.getIngredients().size(), recipes);
      }
      failed =
          !registeredSmeltedRecipes.get(plugin).get(recipe.getIngredients().size()).add(recipe)
              || failed;
    }

    if (allSmeltedRecipes.get(recipe.getIngredients().size()) == null) {
      Set<SmeltedRecipe> recipes =
          Collections.newSetFromMap(new ConcurrentHashMap<SmeltedRecipe, Boolean>());
      allSmeltedRecipes.put(recipe.getIngredients().size(), recipes);
    }
    failed = !allSmeltedRecipes.get(recipe.getIngredients().size()).add(recipe) || failed;
    return !failed;
  }
Example #2
0
  @Override
  public void subscribe(
      String orgDomain,
      String sessionId,
      int processId,
      String callback,
      Map<String, Object> options) {
    Set<String> sessions = orgSessionMap.get(orgDomain);
    if (sessions == null)
      orgSessionMap.putIfAbsent(
          orgDomain, Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()));

    Set<Binding> bindings = pushBindingsMap.get(sessionId);
    if (bindings == null)
      pushBindingsMap.putIfAbsent(
          callback, Collections.newSetFromMap(new ConcurrentHashMap<Binding, Boolean>()));

    sessions = orgSessionMap.get(orgDomain);
    sessions.add(sessionId);

    bindings = pushBindingsMap.get(callback);
    Binding binding = new Binding(sessionId, processId);
    bindings.add(binding);

    PushCondition condition =
        new PushCondition(orgDomain, binding.sessionId, binding.processId, callback, options);
    pushConditions.put(condition.getKey(), condition);

    logger.trace(
        "kraken msgbus: subscribe push, org [{}], session [{}], callback [{}]",
        new Object[] {orgDomain, sessionId, callback});
  }
  @Test
  public void testCheck() {
    Random rnd = random();
    Set<Object> jdk = Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>());
    RamUsageEstimator.IdentityHashSet<Object> us = new RamUsageEstimator.IdentityHashSet<Object>();

    int max = 100000;
    int threshold = 256;
    for (int i = 0; i < max; i++) {
      // some of these will be interned and some will not so there will be collisions.
      Integer v = rnd.nextInt(threshold);

      boolean e1 = jdk.contains(v);
      boolean e2 = us.contains(v);
      Assert.assertEquals(e1, e2);

      e1 = jdk.add(v);
      e2 = us.add(v);
      Assert.assertEquals(e1, e2);
    }

    Set<Object> collected = Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>());
    for (Object o : us) {
      collected.add(o);
    }

    Assert.assertEquals(collected, jdk);
  }
 private BlockPoolSliceStorage() {
   super(NodeType.DATA_NODE);
   storagesWithRollingUpgradeMarker =
       Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
   storagesWithoutRollingUpgradeMarker =
       Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
 }
Example #5
0
  /**
   * Constructs a new game.
   *
   * @param web <code>true</code> if this game is meant to be an applet (which can be played
   *     online), and <code>false</code> otherwise. Note: this doesn't work yet.
   */
  public Game() {
    Game.applet = false;
    canvas = new Canvas(this);
    solidShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>());
    allShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>());

    // TODO: sort out which data structures actually have to support concurrency
    layerContents = new ConcurrentHashMap<Integer, java.util.List<Shape>>();
    layers = new CopyOnWriteArrayList<Integer>();
    layerOf = new ConcurrentHashMap<Shape, Integer>();

    counters = new ArrayList<Counter>();

    Mouse mouse = new Mouse();
    if (applet) {
      addMouseMotionListener(mouse);
      addMouseListener(mouse);
      addKeyListener(new Keyboard());
    } else {
      frame = new JFrame();
      frame.addMouseMotionListener(mouse);
      frame.addMouseListener(mouse);
      frame.addKeyListener(new Keyboard());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    setDefaults();
  }
 BlockPoolSliceStorage(int namespaceID, String bpID, long cTime, String clusterId) {
   super(NodeType.DATA_NODE);
   this.namespaceID = namespaceID;
   this.blockpoolID = bpID;
   this.cTime = cTime;
   this.clusterID = clusterId;
   storagesWithRollingUpgradeMarker =
       Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
   storagesWithoutRollingUpgradeMarker =
       Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
 }