Java Code Examples for java.util.AbstractMap

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project adbcj, under directory /api/src/main/java/org/adbcj/support/.

Source file: DefaultRow.java

  19 
vote

@Override public Set<java.util.Map.Entry<Object,Value>> entrySet(){
  if (entrySet == null) {
    Set<java.util.Map.Entry<Object,Value>> set=new HashSet<Entry<Object,Value>>();
    for (    Value value : values) {
      set.add(new AbstractMap.SimpleEntry<Object,Value>(value.getField(),value));
    }
    entrySet=Collections.unmodifiableSet(set);
  }
  return entrySet;
}
 

Example 2

From project android_external_guava, under directory /src/com/google/common/collect/.

Source file: LinkedListMultimap.java

  19 
vote

public Map<K,Collection<V>> asMap(){
  Map<K,Collection<V>> result=map;
  if (result == null) {
    map=result=new AbstractMap<K,Collection<V>>(){
      Set<Entry<K,Collection<V>>> entrySet;
      @Override public Set<Entry<K,Collection<V>>> entrySet(){
        Set<Entry<K,Collection<V>>> result=entrySet;
        if (result == null) {
          entrySet=result=new AsMapEntries();
        }
        return result;
      }
      @Override public boolean containsKey(      @Nullable Object key){
        return LinkedListMultimap.this.containsKey(key);
      }
      @SuppressWarnings("unchecked") @Override public Collection<V> get(      @Nullable Object key){
        Collection<V> collection=LinkedListMultimap.this.get((K)key);
        return collection.isEmpty() ? null : collection;
      }
      @Override public Collection<V> remove(      @Nullable Object key){
        Collection<V> collection=removeAll(key);
        return collection.isEmpty() ? null : collection;
      }
    }
;
  }
  return result;
}
 

Example 3

From project conversation, under directory /candi/src/main/java/org/jboss/seam/conversation/plugins/candi/.

Source file: HackExternalContext.java

  19 
vote

public Map<String,Object> getSessionMap(){
  return new AbstractMap<String,Object>(){
    public Set<Entry<String,Object>> entrySet(){
      return Collections.emptySet();
    }
    public Object get(    Object key){
      return session.getAttribute(key.toString());
    }
    public Object put(    String key,    Object value){
      Object previous=get(key);
      session.setAttribute(key,value);
      return previous;
    }
  }
;
}
 

Example 4

From project factored-customer, under directory /src/main/java/org/powertac/factoredcustomer/.

Source file: AdaptiveCapacityOriginator.java

  19 
vote

private CapacityProfile selectBestProfileInRecommendation(ProfileRecommendation rec){
  double bestUtility=Double.MIN_VALUE;
  CapacityProfile bestProfile=null;
  for (  AbstractMap.Entry<CapacityProfile,Double> entry : rec.getUtilities().entrySet()) {
    if (entry.getValue() > bestUtility) {
      bestUtility=entry.getValue();
      bestProfile=entry.getKey();
    }
  }
  if (bestProfile == null)   throw new Error("Best profile in recommendation is null!");
  return bestProfile;
}
 

Example 5

From project Gemini-Blueprint, under directory /core/src/test/java/org/eclipse/gemini/blueprint/service/exporter/support/.

Source file: OsgiServiceFactoryBeanTest.java

  19 
vote

public void testAutoDetectClassesForPublishingClassHierarchy() throws Exception {
  exporter.setInterfaceDetector(DefaultInterfaceDetector.CLASS_HIERARCHY);
  Class<?>[] clazz=DefaultInterfaceDetector.CLASS_HIERARCHY.detect(HashMap.class);
  Class<?>[] expected=new Class<?>[]{HashMap.class,AbstractMap.class};
  assertTrue(compareArrays(expected,clazz));
}
 

Example 6

From project giraph, under directory /src/main/java/org/apache/giraph/graph/.

Source file: MasterAggregatorHandler.java

  19 
vote

/** 
 * Write aggregators to  {@link AggregatorWriter}
 * @param superstep Superstep which just finished
 * @param superstepState State of the superstep which just finished
 */
public void writeAggregators(long superstep,SuperstepState superstepState){
  try {
    Iterable<Map.Entry<String,Writable>> iter=Iterables.transform(getAggregatorMap().entrySet(),new Function<Map.Entry<String,AggregatorWrapper<Writable>>,Map.Entry<String,Writable>>(){
      @Override public Map.Entry<String,Writable> apply(      Map.Entry<String,AggregatorWrapper<Writable>> entry){
        return new AbstractMap.SimpleEntry<String,Writable>(entry.getKey(),entry.getValue().getPreviousAggregatedValue());
      }
    }
);
    aggregatorWriter.writeAggregator(iter,(superstepState == SuperstepState.ALL_SUPERSTEPS_DONE) ? AggregatorWriter.LAST_SUPERSTEP : superstep);
  }
 catch (  IOException e) {
    throw new IllegalStateException("coordinateSuperstep: IOException while " + "writing aggregators data",e);
  }
}
 

Example 7

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/cache/.

Source file: DatabaseMetaDataSupportImpl.java

  19 
vote

/** 
 * {@inheritDoc}
 * @see net.sf.hajdbc.cache.DatabaseMetaDataSupport#getTypes(java.sql.DatabaseMetaData)
 */
@Override public Map<Integer,Entry<String,Integer>> getTypes(DatabaseMetaData metaData) throws SQLException {
  ResultSet resultSet=metaData.getTypeInfo();
  try {
    Map<Integer,Map.Entry<String,Integer>> types=new HashMap<Integer,Map.Entry<String,Integer>>();
    while (resultSet.next()) {
      int type=resultSet.getInt("DATA_TYPE");
      if (!types.containsKey(type)) {
        String name=resultSet.getString("TYPE_NAME");
        String params=resultSet.getString("CREATE_PARAMS");
        types.put(type,new AbstractMap.SimpleImmutableEntry<String,Integer>(name,(params != null) ? resultSet.getInt("PRECISION") : null));
      }
    }
    return types;
  }
  finally {
    Resources.close(resultSet);
  }
}
 

Example 8

From project harmony, under directory /harmony.ui.webgui/src/server/common/.

Source file: Converter.java

  19 
vote

/** 
 * Call the appropriate method to copy the individual return values.
 * @param dst Destination Object
 * @param methodName Method name of get Method
 * @param returnObject Object returned from get method
 * @param returnType Type of the returned object
 * @throws SecurityException Reflection error
 * @throws IllegalArgumentException Reflection error
 * @throws NoSuchMethodException Reflection error
 * @throws IllegalAccessException Reflection error
 * @throws InvocationTargetException Reflection error
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
private final void splitConversion(final Object dst,final String methodName,final Object returnObject,final Class<?> returnType) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException {
  if (this.exemptionList.containsKey(returnType)) {
    this.convertExemption(dst,methodName,returnObject,returnType,this.exemptionList.get(returnType));
  }
 else   if (returnType.isEnum()) {
    this.convertEnum(dst,methodName,returnObject,returnType);
  }
 else   if (returnType.isPrimitive()) {
    this.convertDefault(dst,methodName,returnObject,returnType);
  }
 else   if (Collection.class.isInstance(returnObject)) {
    this.convertCollection(dst,methodName,returnObject,returnType);
  }
 else   if (AbstractMap.class.isInstance(returnObject)) {
    this.convertMap(dst,methodName,returnObject,returnType);
  }
 else   if (returnType.getPackage().getName().startsWith("java.")) {
    this.convertDefault(dst,methodName,returnObject,returnType);
  }
 else   if (returnType.getPackage().getName().equals(this.package1) || returnType.getPackage().getName().equals(this.package2)) {
    this.convertCustom(dst,methodName,returnObject,returnType);
  }
 else {
  }
}
 

Example 9

From project hotpotato, under directory /src/main/java/com/biasedbit/hotpotato/session/.

Source file: DefaultHttpSession.java

  19 
vote

@Override public void addHeader(String headerName,String headerValue){
  this.headerWriteLock.lock();
  try {
    for (    Map.Entry<String,String> header : this.headers) {
      if (header.getKey().equals(headerName) && header.getValue().equals(headerValue)) {
        return;
      }
    }
    this.headers.add(new AbstractMap.SimpleEntry<String,String>(headerName,headerValue));
  }
  finally {
    this.headerWriteLock.unlock();
  }
}
 

Example 10

From project JDBM3, under directory /src/test/java/org/apache/jdbm/.

Source file: SerialClassInfoTest.java

  19 
vote

public void testRecursion() throws Exception {
  AbstractMap.SimpleEntry b=new AbstractMap.SimpleEntry("abcd",null);
  b.setValue(b.getKey());
  AbstractMap.SimpleEntry bx=serialize(b);
  assertEquals(bx,b);
  assert(bx.getKey() == bx.getValue());
}
 

Example 11

From project jeppetto, under directory /jeppetto-dao-mongo/src/main/java/org/iternine/jeppetto/dao/mongodb/.

Source file: MongoDBSessionCache.java

  19 
vote

private Iterable<? extends Map.Entry<String,String>> flatten(Map.Entry<String,?> entry){
  if (entry.getValue() instanceof DBObject) {
    return flatten(entry.getKey(),((DBObject)entry.getValue()).toMap());
  }
 else   if (entry.getValue() != null) {
    return Collections.singletonList(new AbstractMap.SimpleEntry<String,String>(entry.getKey(),entry.getValue().toString()));
  }
 else {
    return Collections.emptyList();
  }
}
 

Example 12

From project joda-beans, under directory /src/main/java/org/joda/beans/impl/direct/.

Source file: DirectMetaPropertyMap.java

  19 
vote

/** 
 * Constructor.
 * @param metaBean  the meta-bean, not null
 * @param parent  the superclass parent, may be null
 * @param propertyNames  the property names, not null
 */
@SuppressWarnings("unchecked") public DirectMetaPropertyMap(final DirectMetaBean metaBean,DirectMetaPropertyMap parent,String... propertyNames){
  if (metaBean == null) {
    throw new NullPointerException("MetaBean must not be null");
  }
  this.metaBean=metaBean;
  int parentSize=0;
  final Entry<String,MetaProperty<?>>[] metaProperties;
  if (parent != null) {
    parentSize=parent.size();
    metaProperties=Arrays.copyOf(((Entries)parent.entries).metaProperties,parentSize + propertyNames.length);
  }
 else {
    metaProperties=new Entry[propertyNames.length];
  }
  for (int i=0; i < propertyNames.length; i++) {
    metaProperties[i + parentSize]=new AbstractMap.SimpleImmutableEntry(propertyNames[i],metaBean.metaPropertyGet(propertyNames[i]));
  }
  keys=new Keys(metaProperties);
  values=new Values(metaProperties);
  entries=new Entries(metaProperties);
}
 

Example 13

From project juzu, under directory /core/src/main/java/juzu/.

Source file: Response.java

  19 
vote

public Response withHeader(String name,String... value){
  Iterable<Map.Entry<String,String[]>> values=properties.getValues(PropertyType.HEADER);
  if (values != null) {
    for (    Map.Entry<String,String[]> header : values) {
      if (header.getKey().equals(name)) {
        header.setValue(value);
        return this;
      }
    }
  }
  properties.addValue(PropertyType.HEADER,new AbstractMap.SimpleEntry<String,String[]>(name,value));
  return this;
}
 

Example 14

From project krati, under directory /krati-main/src/main/java/krati/store/.

Source file: IndexedDataStore.java

  19 
vote

@Override public Entry<byte[],byte[]> next(){
  Entry<byte[],byte[]> keyMeta=_indexIter.next();
  if (keyMeta != null) {
    IndexMeta meta=IndexMeta.parse(keyMeta.getValue());
    if (meta == null)     return null;
    byte[] value=_bytesDB.get(meta.getDataAddr());
    return new AbstractMap.SimpleEntry<byte[],byte[]>(keyMeta.getKey(),value);
  }
  return null;
}
 

Example 15

From project menagerie, under directory /src/main/java/org/menagerie/collections/.

Source file: JavaEntrySerializer.java

  19 
vote

@Override @SuppressWarnings({"unchecked"}) public Map.Entry<K,V> deserialize(byte[] data){
  try {
    ObjectInputStream inputStream=new ObjectInputStream(new ByteArrayInputStream(data));
    return (AbstractMap.SimpleEntry<K,V>)inputStream.readObject();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
catch (  ClassNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 

Example 16

From project mkgmap, under directory /src/uk/me/parabola/mkgmap/reader/osm/.

Source file: ElementSaver.java

  19 
vote

public void deferRelation(long id,Relation rel,String role){
  Map.Entry<String,Relation> entry=new AbstractMap.SimpleEntry<String,Relation>(role,rel);
  List<Map.Entry<String,Relation>> entries=deferredRelationMap.get(id);
  if (entries == null) {
    entries=new ArrayList<Map.Entry<String,Relation>>();
    deferredRelationMap.put(id,entries);
  }
  entries.add(entry);
}
 

Example 17

From project msgpack-java, under directory /src/main/java/org/msgpack/type/.

Source file: SequentialMapValueImpl.java

  19 
vote

@Override public Map.Entry<Value,Value> next(){
  if (pos >= array.length) {
    throw new NoSuchElementException();
  }
  Map.Entry<Value,Value> pair=new AbstractMap.SimpleImmutableEntry<Value,Value>(array[pos],array[pos + 1]);
  pos+=2;
  return pair;
}
 

Example 18

From project onebusaway-nyc, under directory /onebusaway-nyc-vehicle-tracking/src/main/java/org/onebusaway/nyc/vehicle_tracking/impl/inference/.

Source file: SensorModelImpl.java

  19 
vote

/** 
 * {@link SensorModel} Interface
 */
@Override public SensorModelResult likelihood(Particle particle,Observation observation,Map<Entry<VehicleState,VehicleState>,SensorModelResult> cache) throws BadProbabilityParticleFilterException {
  final VehicleState state=particle.getData();
  VehicleState parentState=null;
  final Particle parent=particle.getParent();
  if (parent != null)   parentState=parent.getData();
  final Entry<VehicleState,VehicleState> key=new AbstractMap.SimpleImmutableEntry<VehicleState,VehicleState>(state,parentState);
  SensorModelResult result=cache.get(key);
  if (result == null) {
    result=likelihood(parentState,state,observation);
    cache.put(key,result);
  }
  return result;
}
 

Example 19

From project platform_external_guava, under directory /src/com/google/common/collect/.

Source file: LinkedListMultimap.java

  19 
vote

public Map<K,Collection<V>> asMap(){
  Map<K,Collection<V>> result=map;
  if (result == null) {
    map=result=new AbstractMap<K,Collection<V>>(){
      Set<Entry<K,Collection<V>>> entrySet;
      @Override public Set<Entry<K,Collection<V>>> entrySet(){
        Set<Entry<K,Collection<V>>> result=entrySet;
        if (result == null) {
          entrySet=result=new AsMapEntries();
        }
        return result;
      }
      @Override public boolean containsKey(      @Nullable Object key){
        return LinkedListMultimap.this.containsKey(key);
      }
      @SuppressWarnings("unchecked") @Override public Collection<V> get(      @Nullable Object key){
        Collection<V> collection=LinkedListMultimap.this.get((K)key);
        return collection.isEmpty() ? null : collection;
      }
      @Override public Collection<V> remove(      @Nullable Object key){
        Collection<V> collection=removeAll(key);
        return collection.isEmpty() ? null : collection;
      }
    }
;
  }
  return result;
}
 

Example 20

From project serialization, under directory /writer/src/main/java/com/ning/metrics/serialization/writer/.

Source file: EventRate.java

  19 
vote

private synchronized void updateRate(){
  final Collection<DateTime> eventList=new ArrayList<DateTime>();
  dateTimeQueue.drainTo(eventList);
  for (  final DateTime dateTime : eventList) {
    rate++;
    final Map.Entry<DateTime,AtomicInteger> lastPair=queue.peekLast();
    if (lastPair != null && lastPair.getKey().equals(dateTime)) {
      lastPair.getValue().incrementAndGet();
    }
 else {
      queue.add(new AbstractMap.SimpleImmutableEntry<DateTime,AtomicInteger>(dateTime,new AtomicInteger(1)));
    }
  }
  final DateTime now=getNow();
  while (!queue.isEmpty() && !queue.peekFirst().getKey().plus(rateWindow).isAfter(now)) {
    final Map.Entry<DateTime,AtomicInteger> firstPair=queue.pollFirst();
    rate-=firstPair.getValue().get();
  }
}
 

Example 21

From project sojo, under directory /src/test/java/test/net/sf/sojo/reflect/.

Source file: ReflectionHelperTest.java

  19 
vote

public void testIsMapTypeByClass() throws Exception {
  assertTrue(ReflectionHelper.isMapType(Map.class));
  assertTrue(ReflectionHelper.isMapType(HashMap.class));
  assertTrue(ReflectionHelper.isMapType(TreeMap.class));
  assertTrue(ReflectionHelper.isMapType(AbstractMap.class));
  assertFalse(ReflectionHelper.isMapType(List.class));
  assertFalse(ReflectionHelper.isMapType(ArrayList.class));
  assertFalse(ReflectionHelper.isMapType(null));
  assertFalse(ReflectionHelper.isMapType(String.class));
  assertFalse(ReflectionHelper.isMapType(Node.class));
}
 

Example 22

From project springfaces, under directory /springfaces/src/test/java/org/springframework/springfaces/.

Source file: SpringFacesIntegrationTest.java

  19 
vote

public SpringFacesIntegrationTest(){
  this.servletContext=new MockServletContext();
  this.externalContext=mock(ExternalContext.class);
  Map<String,Object> applicationMap=new AbstractMap<String,Object>(){
    @Override public Set<java.util.Map.Entry<String,Object>> entrySet(){
      throw new UnsupportedOperationException();
    }
    @Override public Object get(    Object key){
      return SpringFacesIntegrationTest.this.servletContext.getAttribute((String)key);
    }
    @Override public Object put(    String key,    Object value){
      SpringFacesIntegrationTest.this.servletContext.setAttribute(key,value);
      return null;
    }
  }
;
  given(this.externalContext.getApplicationMap()).willReturn(applicationMap);
}
 

Example 23

From project usergrid-stack, under directory /core/src/main/java/org/usergrid/utils/.

Source file: IndexUtils.java

  19 
vote

public static List<Map.Entry<String,Object>> getKeyValueList(String path,Object obj,boolean fulltextIndex){
  Map<String,List<Object>> map=getKeyValues(path,obj,fulltextIndex);
  List<Map.Entry<String,Object>> list=new ArrayList<Map.Entry<String,Object>>();
  for (  Entry<String,List<Object>> entry : map.entrySet()) {
    for (    Object value : entry.getValue()) {
      list.add(new AbstractMap.SimpleEntry<String,Object>(entry.getKey(),value));
    }
  }
  ;
  return list;
}
 

Example 24

From project utils_1, under directory /src/main/java/net/pterodactylus/util/collection/.

Source file: TimedMap.java

  19 
vote

/** 
 * {@inheritDoc}
 */
@Override public Set<Entry<K,V>> entrySet(){
  checkForExpiredValues();
  Set<Entry<K,V>> resultSet=new HashSet<Entry<K,V>>();
  for (  Entry<K,TimedItem<V>> entry : storage.entrySet()) {
    resultSet.add(new AbstractMap.SimpleEntry<K,V>(entry.getKey(),entry.getValue().getItem()));
  }
  return resultSet;
}