public HKMetadata() { this.data = new NSMutableDictionary<>(); } /*<bind>*/static { Bro.bind(HKMetadata.class); }/*</bind>*/
@Override public Preferences getPreferences (String name) { File libraryPath = new File(System.getenv("HOME"), "Library"); File finalPath = new File(libraryPath, name + ".plist"); @SuppressWarnings("unchecked") NSMutableDictionary<NSString, NSObject> nsDictionary = (NSMutableDictionary<NSString, NSObject>)NSMutableDictionary .read(finalPath); // if it fails to get an existing dictionary, create a new one. if (nsDictionary == null) { nsDictionary = new NSMutableDictionary<NSString, NSObject>(); nsDictionary.write(finalPath, false); } return new IOSPreferences(nsDictionary, finalPath.getAbsolutePath()); }
@Override public float getFloat (String key) { NSNumber value = (NSNumber)nsDictionary.get(convertKey(key)); if (value == null) return 0f; return value.floatValue(); }
public static <V extends NSObject> NSMutableDictionary<NSString, V> fromStringMap (Map<String, V> map) { NSMutableDictionary<NSString, V> dictionary = new NSMutableDictionary<>(); for (Map.Entry<String, V> entry : map.entrySet()) { dictionary.put(new NSString(entry.getKey()), entry.getValue()); } return dictionary; }
@Override public void putAll(Map<? extends K, ? extends V> m) { for (Map.Entry<? extends K, ? extends V> entry : m.entrySet()) { put(entry.getKey(), entry.getValue()); } }
IOSSettings(String name) { path = new File(new File(System.getenv("HOME"), "Library"), name + ".plist"); preferences = NSMutableDictionary.read(path); if (preferences == null) { preferences = new NSMutableDictionary<>(); preferences.write(path, false); } }
@Override public V remove(Object key) { if (key == null) throw new IllegalArgumentException("key cannot be null"); V oldValue = get(key); if (key instanceof NSObject) { removeObject((NSObject) key); } else { String strKey = String.valueOf(key); removeObjectForKey$(NSString.create(NSString.getChars(strKey), strKey.length())); } return oldValue; }
public void put(Object key, NSObject value) { putObject(key, value); }
public NSMutableDictionary(@MachineSizedUInt long numItems) { super((SkipInit) null); initObject(init(numItems)); } /*</constructors>*/
@Method(selector = "dictionaryWithContentsOfURL:") public static native NSMutableDictionary<?, ?> read(NSURL url);
@MarshalsPointer public static long toNative(Map<String, List<String>> l, long flags) { if (l == null) { return 0L; } NSMutableDictionary<NSString, NSArray<NSString>> dict = new NSMutableDictionary<>(); for (Map.Entry<String, List<String>> e : l.entrySet()) { dict.put(new NSString(e.getKey()), NSArray.fromStrings(e.getValue())); } return NSObject.Marshaler.toNative(dict, flags); } }
@Override public Preferences putFloat (String key, float val) { nsDictionary.put(convertKey(key), NSNumber.valueOf(val)); return this; }
public void put(Object key, long value) { putObject(key, NSNumber.valueOf(value)); } public void put(Object key, float value) {
@Method(selector = "initWithCapacity:") public NSMutableDictionary(@MachineSizedUInt long numItems) { super((SkipInit) null); initObject(init(numItems)); } /*</constructors>*/