Urbi SDK Remote for Java  2.7.5
UDictionary.java
00001 /* ----------------------------------------------------------------------------
00002  * This file was automatically generated by SWIG (http://www.swig.org).
00003  * Version 2.0.4
00004  *
00005  * Do not make changes to this file unless you know what you are doing--modify
00006  * the SWIG interface file instead.
00007  * ----------------------------------------------------------------------------- */
00008 
00009 package urbi;
00010 
00011 import java.util.AbstractMap;
00012 import java.util.AbstractSet;
00013 import java.util.ArrayList;
00014 import java.util.Collection;
00015 import java.util.Iterator;
00016 import java.util.List;
00017 import java.util.Map;
00018 import java.util.Set;
00019 
00020 public class UDictionary extends AbstractMap<String, UValue> implements Map<String, UValue> {
00021   private long swigCPtr;
00022   protected boolean swigCMemOwn;
00023 
00024   public UDictionary(long cPtr, boolean cMemoryOwn) {
00025     swigCMemOwn = cMemoryOwn;
00026     swigCPtr = cPtr;
00027   }
00028 
00029   public static long getCPtr(UDictionary obj) {
00030     return (obj == null) ? 0 : obj.swigCPtr;
00031   }
00032 
00033   protected void finalize() {
00034     delete();
00035   }
00036 
00037   public synchronized void delete() {
00038     if (swigCPtr != 0) {
00039       if (swigCMemOwn) {
00040         swigCMemOwn = false;
00041         urbiJNI.delete_UDictionary(swigCPtr);
00042       }
00043       swigCPtr = 0;
00044     }
00045   }
00046 
00047 
00048 
00049   private UDictionarySet dictionarySet = null;
00050 
00051   @Override
00052   public Set<Entry<String, UValue>> entrySet() {
00053     if (dictionarySet == null)
00054       dictionarySet = new UDictionarySet(this);
00055     return dictionarySet;
00056   }
00057 
00058   @SuppressWarnings("unchecked")
00059   public UValue remove(String key) {
00060     UValue old;
00061     try {
00062       old = get(key);
00063     }
00064     catch (RuntimeException e) {
00065       return null;
00066     }
00067     del(key);
00068     return old;
00069   }
00070 
00071   /**
00072    * {@inheritDoc}
00073    * <p>
00074    * Unsupported
00075    */
00076   public boolean containsValue(UValue value) {
00077     throw new UnsupportedOperationException();
00078   }
00079 
00080   protected class UDictionaryEntry implements Entry<String, UValue> {
00081     private final String key;
00082     private UValue value;
00083     private UDictionary dict;
00084 
00085     protected UDictionaryEntry(UDictionary d, String key, UValue value) {
00086       this.dict = d;
00087       this.key = key;
00088       this.value = value;
00089     }
00090 
00091     public String getKey() {
00092       return key;
00093     }
00094 
00095     public UValue getValue() {
00096       return value;
00097     }
00098 
00099     public UValue setValue(UValue value) {
00100       UValue old = this.value;
00101       this.value = value;
00102       put(key, value);
00103       return old;
00104     }
00105   }
00106 
00107   protected class UDictionarySet extends AbstractSet<Entry<String, UValue>>
00108     implements Set<Entry<String, UValue>> {
00109 
00110     private UDictionary dict;
00111 
00112     UDictionarySet(UDictionary d) {
00113       this.dict = d;
00114     }
00115 
00116     @Override
00117     public boolean add(Entry<String, UValue> item) {
00118       dict.put(item.getKey(), item.getValue());
00119       return true;
00120     }
00121 
00122     @Override
00123     public void clear() {
00124       dict.clear();
00125     }
00126 
00127     @Override
00128     public Iterator<Entry<String, UValue>> iterator() {
00129       return new UDictionarySetIterator(this.dict);
00130     }
00131 
00132     @Override
00133     public boolean remove(Object item) {
00134       return dict.remove(item) != null;
00135     }
00136 
00137     @Override
00138     public boolean removeAll(Collection<?> collection) {
00139       boolean modified = false;
00140       for (Object item : collection) {
00141         modified |= this.remove(item);
00142       }
00143       return modified;
00144     }
00145 
00146     @Override
00147     public boolean retainAll(Collection<?> collection) {
00148       //best way?
00149       List<Entry<String, UValue>> toRemove =
00150           new ArrayList<Entry<String, UValue>>(this.size());
00151       for (Entry<String, UValue> item : this) {
00152         if (!collection.contains(item)) {
00153           toRemove.add(item);
00154         }
00155       }
00156       return removeAll(toRemove);
00157     }
00158 
00159     @Override
00160     public int size() {
00161       return dict.size();
00162     }
00163   }
00164 
00165   protected class UDictionarySetIterator
00166       implements Iterator<Entry<String, UValue>> {
00167 
00168     private UDictionary dict;
00169     private UDictionaryCPPIterator iterator;
00170 
00171     private UDictionarySetIterator(UDictionary d) {
00172       this.dict = d;
00173       this.iterator = d.getIterator();
00174     }
00175 
00176     public boolean hasNext() {
00177       return iterator.hasNext();
00178     }
00179 
00180     @SuppressWarnings("unchecked")
00181     public UDictionaryEntry next() {
00182       UDictionaryEntry res =
00183           new UDictionaryEntry(dict, iterator.getKey(), iterator.getValue());
00184       iterator.next();
00185       return res;
00186     }
00187 
00188     /**
00189      * {@inheritDoc}
00190      * <p>
00191      * Unsupported
00192      */
00193     public void remove() {
00194       throw new UnsupportedOperationException();
00195     }
00196   }
00197 
00198 
00199   public UDictionary() {
00200     this(urbiJNI.new_UDictionary__SWIG_0(), true);
00201   }
00202 
00203   public UDictionary(UDictionary arg0) {
00204     this(urbiJNI.new_UDictionary__SWIG_1(UDictionary.getCPtr(arg0), arg0), true);
00205   }
00206 
00207   public int size() {
00208     return urbiJNI.UDictionary_size(swigCPtr, this);
00209   }
00210 
00211   public boolean empty() {
00212     return urbiJNI.UDictionary_empty(swigCPtr, this);
00213   }
00214 
00215   public void clear() {
00216     urbiJNI.UDictionary_clear(swigCPtr, this);
00217   }
00218 
00219   public boolean isEmpty() {
00220     return urbiJNI.UDictionary_isEmpty(swigCPtr, this);
00221   }
00222 
00223   public boolean containsKey(String key) {
00224     return urbiJNI.UDictionary_containsKey(swigCPtr, this, key);
00225   }
00226 
00227   public UValue get(String key) {
00228     return new UValue(urbiJNI.UDictionary_get(swigCPtr, this, key), false);
00229   }
00230 
00231   public UValue put(String key, UValue x) {
00232     return new UValue(urbiJNI.UDictionary_put__SWIG_0(swigCPtr, this, key, UValue.getCPtr(x), x), false);
00233   }
00234 
00235   public void del(String key) {
00236     urbiJNI.UDictionary_del(swigCPtr, this, key);
00237   }
00238 
00239   public UDictionaryCPPIterator getIterator() {
00240     return new UDictionaryCPPIterator(urbiJNI.UDictionary_getIterator(swigCPtr, this), true);
00241   }
00242 
00243   public UList put(String key, UList v) {
00244     return new UList(urbiJNI.UDictionary_put__SWIG_1(swigCPtr, this, key, UList.getCPtr(v), v), false);
00245   }
00246 
00247   public UBinary put(String key, UBinary v) {
00248     return new UBinary(urbiJNI.UDictionary_put__SWIG_2(swigCPtr, this, key, UBinary.getCPtr(v), v), false);
00249   }
00250 
00251   public USound put(String key, USound v) {
00252     return new USound(urbiJNI.UDictionary_put__SWIG_3(swigCPtr, this, key, USound.getCPtr(v), v), false);
00253   }
00254 
00255   public UImage put(String key, UImage v) {
00256     return new UImage(urbiJNI.UDictionary_put__SWIG_4(swigCPtr, this, key, UImage.getCPtr(v), v), false);
00257   }
00258 
00259   public String put(String key, String v) {
00260     return urbiJNI.UDictionary_put__SWIG_5(swigCPtr, this, key, v);
00261   }
00262 
00263   public int put(String key, int v) {
00264     return urbiJNI.UDictionary_put__SWIG_6(swigCPtr, this, key, v);
00265   }
00266 
00267   public long put(String key, long v) {
00268     return urbiJNI.UDictionary_put__SWIG_7(swigCPtr, this, key, v);
00269   }
00270 
00271   public double put(String key, double v) {
00272     return urbiJNI.UDictionary_put__SWIG_8(swigCPtr, this, key, v);
00273   }
00274 
00275   public boolean put(String key, boolean v) {
00276     return urbiJNI.UDictionary_put__SWIG_9(swigCPtr, this, key, v);
00277   }
00278 
00279   public float put(String key, float v) {
00280     return urbiJNI.UDictionary_put__SWIG_10(swigCPtr, this, key, v);
00281   }
00282 
00283   public char put(String key, char v) {
00284     return urbiJNI.UDictionary_put__SWIG_11(swigCPtr, this, key, v);
00285   }
00286 
00287   public String toString() {
00288     return urbiJNI.UDictionary_toString(swigCPtr, this);
00289   }
00290 
00291 }