This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.io.storage.ram;
020
021import org.apache.reef.io.ExternalMap;
022import org.apache.reef.io.storage.util.GetAllIterable;
023
024import javax.inject.Inject;
025import java.util.Map;
026import java.util.Map.Entry;
027import java.util.Set;
028import java.util.concurrent.ConcurrentSkipListMap;
029
030/**
031 * Simple in-memory ExternalMap implementation.  This class does not require
032 * any codecs, and so is guaranteed to be instantiable.  Therefore, it is the
033 * default ExternalMap provided by StorageManagerRam.
034 */
035public class RamMap<T> implements ExternalMap<T> {
036
037  private final ConcurrentSkipListMap<CharSequence, T> map = new ConcurrentSkipListMap<>();
038
039  @Inject
040  public RamMap(final RamStorageService ramStore) {
041  }
042
043  @Override
044  public boolean containsKey(final CharSequence key) {
045    return map.containsKey(key);
046  }
047
048  @Override
049  public T get(final CharSequence key) {
050    return map.get(key);
051  }
052
053  @Override
054  public T put(final CharSequence key, final T value) {
055    return map.put(key, value);
056  }
057
058  @Override
059  public T remove(final CharSequence key) {
060    return map.remove(key);
061  }
062
063  @Override
064  public void putAll(final Map<? extends CharSequence, ? extends T> m) {
065    map.putAll(m);
066  }
067
068  @Override
069  public Iterable<Entry<CharSequence, T>> getAll(final Set<? extends CharSequence> keys) {
070    return new GetAllIterable<>(keys, this);
071  }
072}