/** * Adds a new scope and returns its ID. * * @param scp scope to add * @return the scope's ID */ private int add(final Scope scp) { final int id = scopes.size(); if (id == MAP_THRESHOLD) { ids = new IdentityHashMap<>(); for (final Scope s : scopes) ids.put(s, ids.size()); } scopes.add(scp); adjacent.add(null); if (ids != null) ids.put(scp, id); return id; }
/** * Gets the ID of the given scope. * * @param scp scope * @return id if existing, {@code null} otherwise */ private int id(final Scope scp) { if (ids != null) { final Integer id = ids.get(scp); return id == null ? -1 : id; } final int ss = scopes.size(); for (int s = 0; s < ss; s++) if (scopes.get(s) == scp) return s; return -1; }