All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xapi.collect.impl.InitMapDefault Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.collect.impl;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import xapi.util.api.ConvertsValue;
import xapi.util.api.ReceivesValue;

public class InitMapDefault  extends AbstractInitMap{

  protected final ConvertsValue valueProvider;

  private final ConcurrentHashMap map = new ConcurrentHashMap();

  public InitMapDefault(ConvertsValue keyProvider, ConvertsValue valueProvider) {
    super(keyProvider);
    assert valueProvider != null : "Cannot use null value provider for init map.";
    this.valueProvider = valueProvider;
  }


  public static  InitMapDefault createInitMap(
    ConvertsValue keyProvider, ConvertsValue valueProvider) {
    return new InitMapDefault(keyProvider, valueProvider);
  }

  @Override
  public boolean hasKey(String key) {
    return map.containsKey(key);
  }

  @Override
  public Value getValue(String key) {
    return map.get(key);
  }

  @Override
  public Value setValue(String key, Value value) {
    return map.put(key, value);
  }

  @Override
  public Value removeValue(String key) {
    return map.remove(key);
  }

  @Override
  public void clearValues() {
    map.clear();
  }

  @Override
  public Value initialize(Key k) {
    return valueProvider.convert(k);
  }

  @Override
  public void forKeys(ReceivesValue receiver) {
     for (String key : map.keySet())
       receiver.set(key);
  }
  
  public Iterable keys() {
    return map.keySet();
  }
  
  @Override
  public Iterator> iterator() {
    return map.entrySet().iterator();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy