Java Code Examples for java.util.AbstractMap#SimpleImmutableEntry

The following examples show how to use java.util.AbstractMap#SimpleImmutableEntry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSDirMkdirOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * For a given absolute path, create all ancestors as directories along the
 * path. All ancestors inherit their parent's permission plus an implicit
 * u+wx permission. This is used by create() and addSymlink() for
 * implicitly creating all directories along the path.
 *
 * For example, path="/foo/bar/spam", "/foo" is an existing directory,
 * "/foo/bar" is not existing yet, the function will create directory bar.
 *
 * @return a tuple which contains both the new INodesInPath (with all the
 * existing and newly created directories) and the last component in the
 * relative path. Or return null if there are errors.
 */
static Map.Entry<INodesInPath, String> createAncestorDirectories(
    FSDirectory fsd, INodesInPath iip, PermissionStatus permission)
    throws IOException {
  final String last = new String(iip.getLastLocalName(), Charsets.UTF_8);
  INodesInPath existing = iip.getExistingINodes();
  List<String> children = iip.getPath(existing.length(),
      iip.length() - existing.length());
  int size = children.size();
  if (size > 1) { // otherwise all ancestors have been created
    List<String> directories = children.subList(0, size - 1);
    INode parentINode = existing.getLastINode();
    // Ensure that the user can traversal the path by adding implicit
    // u+wx permission to all ancestor directories
    existing = createChildrenDirectories(fsd, existing, directories,
        addImplicitUwx(parentINode.getPermissionStatus(), permission));
    if (existing == null) {
      return null;
    }
  }
  return new AbstractMap.SimpleImmutableEntry<>(existing, last);
}
 
Example 2
Source File: ConcurrentSkipListMap.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Submap version of ConcurrentSkipListMap.getNearEntry
 */
Map.Entry<K,V> getNearEntry(K key, int rel) {
    Comparator<? super K> cmp = m.comparator;
    if (isDescending) { // adjust relation for direction
        if ((rel & LT) == 0)
            rel |= LT;
        else
            rel &= ~LT;
    }
    if (tooLow(key, cmp))
        return ((rel & LT) != 0) ? null : lowestEntry();
    if (tooHigh(key, cmp))
        return ((rel & LT) != 0) ? highestEntry() : null;
    for (;;) {
        Node<K,V> n = m.findNear(key, rel, cmp);
        if (n == null || !inBounds(n.key, cmp))
            return null;
        K k = n.key;
        V v = n.getValidValue();
        if (v != null)
            return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
    }
}
 
Example 3
Source File: ConcurrentSkipListMap.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Submap version of ConcurrentSkipListMap.getNearEntry
 */
Map.Entry<K,V> getNearEntry(K key, int rel) {
    Comparator<? super K> cmp = m.comparator;
    if (isDescending) { // adjust relation for direction
        if ((rel & LT) == 0)
            rel |= LT;
        else
            rel &= ~LT;
    }
    if (tooLow(key, cmp))
        return ((rel & LT) != 0) ? null : lowestEntry();
    if (tooHigh(key, cmp))
        return ((rel & LT) != 0) ? highestEntry() : null;
    for (;;) {
        Node<K,V> n = m.findNear(key, rel, cmp);
        if (n == null || !inBounds(n.key, cmp))
            return null;
        K k = n.key;
        V v = n.getValidValue();
        if (v != null)
            return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
    }
}
 
Example 4
Source File: ConcurrentSkipListMap.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method for EntrySet.removeIf.
 */
boolean removeEntryIf(Predicate<? super Entry<K,V>> function) {
    if (function == null) throw new NullPointerException();
    boolean removed = false;
    for (Node<K,V> n = findFirst(); n != null; n = n.next) {
        V v;
        if ((v = n.getValidValue()) != null) {
            K k = n.key;
            Map.Entry<K,V> e = new AbstractMap.SimpleImmutableEntry<>(k, v);
            if (function.test(e) && remove(k, v))
                removed = true;
        }
    }
    return removed;
}
 
Example 5
Source File: ConcurrentSkipListMap.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and returns a new SimpleImmutableEntry holding current
 * mapping if this node holds a valid value, else null.
 * @return new entry or null
 */
AbstractMap.SimpleImmutableEntry<K,V> createSnapshot() {
    Object v = value;
    if (v == null || v == this || v == BASE_HEADER)
        return null;
    @SuppressWarnings("unchecked") V vv = (V)v;
    return new AbstractMap.SimpleImmutableEntry<K,V>(key, vv);
}
 
Example 6
Source File: ChunkSpawnerModel.java    From factions-top with MIT License 5 votes vote down vote up
public void addBatch(int chunkId, int spawnerId, int count) throws SQLException {
    Integer relationId = identityCache.getChunkSpawnerId(chunkId, spawnerId);
    Map.Entry<Integer, Integer> insertionKey = new AbstractMap.SimpleImmutableEntry<>(chunkId, spawnerId);

    if (relationId == null) {
        if (!insertionQueue.contains(insertionKey)) {
            insertCounter(chunkId, spawnerId, count);
            insertionQueue.add(insertionKey);
        }
    } else {
        updateCounter(count, relationId);
    }
}
 
Example 7
Source File: TestUtils.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
public static Map.Entry<SchemaTableName, KinesisStreamDescription> createSimpleJsonStreamDescription(String streamName, SchemaTableName schemaTableName)
{
    // Format: {"id" : 1324, "name" : "some string"}
    ArrayList<KinesisStreamFieldDescription> fieldList = new ArrayList<KinesisStreamFieldDescription>();
    fieldList.add(new KinesisStreamFieldDescription("id", BigintType.BIGINT, "id", "comment", null, null, false));
    fieldList.add(new KinesisStreamFieldDescription("name", VarcharType.VARCHAR, "name", "comment", null, null, false));
    KinesisStreamFieldGroup grp = new KinesisStreamFieldGroup("json", fieldList);

    KinesisStreamDescription desc = new KinesisStreamDescription(schemaTableName.getTableName(), schemaTableName.getSchemaName(), streamName, grp);
    return new AbstractMap.SimpleImmutableEntry<>(schemaTableName, desc);
}
 
Example 8
Source File: ConcurrentSkipListMap.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a new SimpleImmutableEntry holding current
 * mapping if this node holds a valid value, else null.
 * @return new entry or null
 */
AbstractMap.SimpleImmutableEntry<K,V> createSnapshot() {
    Object v = value;
    if (v == null || v == this || v == BASE_HEADER)
        return null;
    @SuppressWarnings("unchecked") V vv = (V)v;
    return new AbstractMap.SimpleImmutableEntry<K,V>(key, vv);
}
 
Example 9
Source File: ConcurrentSkipListMap.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns SimpleImmutableEntry for results of findNear.
 * @param key the key
 * @param rel the relation -- OR'ed combination of EQ, LT, GT
 * @return Entry fitting relation, or null if no such
 */
final AbstractMap.SimpleImmutableEntry<K,V> getNear(K key, int rel) {
    Comparator<? super K> cmp = comparator;
    for (;;) {
        Node<K,V> n = findNear(key, rel, cmp);
        if (n == null)
            return null;
        AbstractMap.SimpleImmutableEntry<K,V> e = n.createSnapshot();
        if (e != null)
            return e;
    }
}
 
Example 10
Source File: ConcurrentSkipListMap.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
Map.Entry<K,V> removeLowest() {
    Comparator<? super K> cmp = m.comparator;
    for (;;) {
        Node<K,V> n = loNode(cmp);
        if (n == null)
            return null;
        K k = n.key;
        if (!inBounds(k, cmp))
            return null;
        V v = m.doRemove(k, null);
        if (v != null)
            return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
    }
}
 
Example 11
Source File: ConcurrentSkipListMap.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
Map.Entry<K,V> removeLowest() {
    Comparator<? super K> cmp = m.comparator;
    for (;;) {
        Node<K,V> n = loNode(cmp);
        if (n == null)
            return null;
        K k = n.key;
        if (!inBounds(k, cmp))
            return null;
        V v = m.doRemove(k, null);
        if (v != null)
            return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
    }
}
 
Example 12
Source File: ConcurrentSkipListMap.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Variant of findNear returning SimpleImmutableEntry
 * @param key the key
 * @param rel the relation -- OR'ed combination of EQ, LT, GT
 * @return Entry fitting relation, or null if no such
 */
final AbstractMap.SimpleImmutableEntry<K,V> findNearEntry(K key, int rel,
                                                          Comparator<? super K> cmp) {
    for (;;) {
        Node<K,V> n; V v;
        if ((n = findNear(key, rel, cmp)) == null)
            return null;
        if ((v = n.val) != null)
            return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, v);
    }
}
 
Example 13
Source File: NADCON.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the grid of the given name. This method returns the cached instance if it still exists,
 * or load the grid otherwise.
 *
 * @param latitudeShifts   name of the grid file for latitude shifts.
 * @param longitudeShifts  name of the grid file for longitude shifts.
 */
@SuppressWarnings("null")
static DatumShiftGridFile<Angle,Angle> getOrLoad(final Path latitudeShifts, final Path longitudeShifts)
        throws FactoryException
{
    final Path rlat = DataDirectory.DATUM_CHANGES.resolve(latitudeShifts).toAbsolutePath();
    final Path rlon = DataDirectory.DATUM_CHANGES.resolve(longitudeShifts).toAbsolutePath();
    final Object key = new AbstractMap.SimpleImmutableEntry<>(rlat, rlon);
    DatumShiftGridFile<?,?> grid = DatumShiftGridFile.CACHE.peek(key);
    if (grid == null) {
        final Cache.Handler<DatumShiftGridFile<?,?>> handler = DatumShiftGridFile.CACHE.lock(key);
        try {
            grid = handler.peek();
            if (grid == null) {
                final Loader loader;
                Path file = latitudeShifts;
                try {
                    // Note: buffer size must be divisible by the size of 'float' data type.
                    final ByteBuffer buffer = ByteBuffer.allocate(4096).order(ByteOrder.LITTLE_ENDIAN);
                    final FloatBuffer fb = buffer.asFloatBuffer();
                    try (ReadableByteChannel in = Files.newByteChannel(rlat)) {
                        DatumShiftGridLoader.startLoading(NADCON.class, CharSequences.commonPrefix(
                                latitudeShifts.toString(), longitudeShifts.toString()).toString() + '…');
                        loader = new Loader(in, buffer, file);
                        loader.readGrid(fb, null, longitudeShifts);
                    }
                    buffer.clear();
                    file = longitudeShifts;
                    try (ReadableByteChannel in = Files.newByteChannel(rlon)) {
                        new Loader(in, buffer, file).readGrid(fb, loader, null);
                    }
                } catch (IOException | NoninvertibleTransformException | RuntimeException e) {
                    throw DatumShiftGridLoader.canNotLoad("NADCON", file, e);
                }
                grid = DatumShiftGridCompressed.compress(loader.grid, null, loader.grid.accuracy);
                grid = grid.useSharedData();
            }
        } finally {
            handler.putAndUnlock(grid);
        }
    }
    return grid.castTo(Angle.class, Angle.class);
}
 
Example 14
Source File: ConcurrentSkipListMap.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Map.Entry<K,V> next() {
    Node<K,V> n = next;
    V v = nextValue;
    advance();
    return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, v);
}
 
Example 15
Source File: ConcurrentSkipListMap.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public Map.Entry<K,V> next() {
    Node<K,V> n = next;
    V v = nextValue;
    advance();
    return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, v);
}
 
Example 16
Source File: ConcurrentSkipListMap.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
public Map.Entry<K,V> next() {
    Node<K,V> n = next;
    V v = nextValue;
    advance();
    return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, v);
}
 
Example 17
Source File: JsonDocument.java    From ojai with Apache License 2.0 4 votes vote down vote up
@Override
public Entry<String, Value> next() {
  String key = keyIter.next();
  JsonValue kv = getRootMap().get(key);
  return new AbstractMap.SimpleImmutableEntry<String, Value>(key, kv);
}
 
Example 18
Source File: ConcurrentSkipListMap.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Removes last entry; returns its snapshot.
 * Specialized variant of doRemove.
 * @return null if empty, else snapshot of last entry
 */
private Map.Entry<K,V> doRemoveLastEntry() {
    outer: for (;;) {
        Index<K,V> q; Node<K,V> b;
        VarHandle.acquireFence();
        if ((q = head) == null)
            break;
        for (;;) {
            Index<K,V> d, r; Node<K,V> p;
            while ((r = q.right) != null) {
                if ((p = r.node) == null || p.val == null)
                    RIGHT.compareAndSet(q, r, r.right);
                else if (p.next != null)
                    q = r;  // continue only if a successor
                else
                    break;
            }
            if ((d = q.down) != null)
                q = d;
            else {
                b = q.node;
                break;
            }
        }
        if (b != null) {
            for (;;) {
                Node<K,V> n; K k; V v;
                if ((n = b.next) == null) {
                    if (b.key == null) // empty
                        break outer;
                    else
                        break; // retry
                }
                else if ((k = n.key) == null)
                    break;
                else if ((v = n.val) == null)
                    unlinkNode(b, n);
                else if (n.next != null)
                    b = n;
                else if (VAL.compareAndSet(n, v, null)) {
                    unlinkNode(b, n);
                    tryReduceLevel();
                    findPredecessor(k, comparator); // clean index
                    addCount(-1L);
                    return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
                }
            }
        }
    }
    return null;
}
 
Example 19
Source File: CitationsFileReader.java    From occurrence with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms tab-separated-line into a DatasetOccurrenceDownloadUsage instance.
 */
private static Map.Entry<UUID,Long> toDatasetOccurrenceDownloadUsage(String tsvLine) {
  Iterator<String> tsvLineIterator = TAB_SPLITTER.split(tsvLine).iterator();
  return new AbstractMap.SimpleImmutableEntry<>(UUID.fromString(tsvLineIterator.next()), Long.parseLong(tsvLineIterator.next()));
}
 
Example 20
Source File: ConcurrentSkipListMap.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Map.Entry<K,V> next() {
    Node<K,V> n = next;
    V v = nextValue;
    advance();
    return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, v);
}