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

xapi.collect.impl.StringToAbstract 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.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import xapi.annotation.inject.InstanceDefault;
import xapi.collect.api.StringTo;
import xapi.platform.GwtDevPlatform;
import xapi.platform.JrePlatform;
import xapi.util.X_Runtime;

@JrePlatform
@GwtDevPlatform
@InstanceDefault(implFor=StringTo.class)
public class StringToAbstract  implements StringTo{

  private static final long serialVersionUID = 7743120861632536635L;
  private final java.util.Map map;

  public StringToAbstract() {
    if (isMultithreaded()) {
      map = new ConcurrentHashMap();
    } else {
      map = new HashMap();
    }
  }
  public StringToAbstract(final Map map) {
    this.map = map;
  }

  protected boolean isMultithreaded() {
    return X_Runtime.isMultithreaded();
  }

  @Override
  public boolean isEmpty() {
    return map.isEmpty();
  }

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

  @Override
  public boolean containsKey(final Object key) {
    return map.containsKey(key);
  }

  @Override
  public boolean containsValue(final Object key) {
    return map.containsValue(key);
  }

  @Override
  @SuppressWarnings({"unchecked","rawtypes"})
  public void putAll(final Iterable> items) {
    if (items instanceof java.util.Map) {
      map.putAll((java.util.Map)items);
    } else {
      for (final java.util.Map.Entry item : items) {
        map.put(item.getKey(), item.getValue());
      }
    }
  }

  @Override
  public void removeAll(final Iterable items) {
    for (final String item : items) {
      map.remove(item);
    }
  }

  @Override
  public Iterable keys() {
    return map.keySet();
  }

  @Override
  public String[] keyArray() {
    return map.keySet().toArray(new String[0]);
  }

  @Override
  public Iterable values() {
    return map.values();
  }

  @Override
  public Iterable> entries() {
    return map.entrySet();
  }

  @Override
  public V get(final String key) {
    return map.get(key);
  }

  @Override
  public V put(final String key, final V value) {
    if (value == null) {
      return map.remove(key);
    } else {
      return map.put(key, value);
    }
  }

  @Override
  public V remove(final String key) {
    return map.remove(key);
  }

  @Override
  public int size() {
    return map.size();
  }

  @Override
  public String toString() {
    return map.toString();
  }

  protected Collection valueSet() {
    return map.values();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy