Loading...
Searching...
No Matches
KeyValueStorage.java
Go to the documentation of this file.
1package com.navigine.idl.java;
2
3import java.util.ArrayList;
4import java.util.concurrent.atomic.AtomicBoolean;
5
17public abstract class KeyValueStorage {
33 public abstract boolean contains(String key);
34
49 public abstract ArrayList<String> getKeys();
50
68 public abstract int getInt(String key, int defaultValue);
69
87 public abstract long getLong(String key, long defaultValue);
88
106 public abstract boolean getBool(String key, boolean defaultValue);
107
125 public abstract float getFloat(String key, float defaultValue);
126
144 public abstract double getDouble(String key, double defaultValue);
145
163 public abstract String getString(String key, String defaultValue);
164
180 public abstract void putInt(String key, int value);
181
197 public abstract void putLong(String key, long value);
198
214 public abstract void putBool(String key, boolean value);
215
231 public abstract void putFloat(String key, float value);
232
248 public abstract void putDouble(String key, double value);
249
265 public abstract void putString(String key, String value);
266
281 public abstract void remove(String key);
282
296 public abstract void clear();
297
298 private static final class CppProxy extends KeyValueStorage
299 {
300 private final long nativeRef;
301 private final AtomicBoolean destroyed = new AtomicBoolean(false);
302
303 private CppProxy(long nativeRef)
304 {
305 if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
306 this.nativeRef = nativeRef;
307 }
308
309 private native void nativeDestroy(long nativeRef);
310 public void _djinni_private_destroy()
311 {
312 boolean destroyed = this.destroyed.getAndSet(true);
313 if (!destroyed) nativeDestroy(this.nativeRef);
314 }
315 protected void finalize() throws java.lang.Throwable
316 {
317 _djinni_private_destroy();
318 super.finalize();
319 }
320
321 // KeyValueStorage methods
322
323 @Override
324 public boolean contains(String key)
325 {
326 assert !this.destroyed.get() : "trying to use a destroyed object";
327 return native_contains(this.nativeRef, key);
328 }
329 private native boolean native_contains(long _nativeRef, String key);
330
331 @Override
332 public ArrayList<String> getKeys()
333 {
334 assert !this.destroyed.get() : "trying to use a destroyed object";
335 return native_getKeys(this.nativeRef);
336 }
337 private native ArrayList<String> native_getKeys(long _nativeRef);
338
339 @Override
340 public int getInt(String key, int defaultValue)
341 {
342 assert !this.destroyed.get() : "trying to use a destroyed object";
343 return native_getInt(this.nativeRef, key, defaultValue);
344 }
345 private native int native_getInt(long _nativeRef, String key, int defaultValue);
346
347 @Override
348 public long getLong(String key, long defaultValue)
349 {
350 assert !this.destroyed.get() : "trying to use a destroyed object";
351 return native_getLong(this.nativeRef, key, defaultValue);
352 }
353 private native long native_getLong(long _nativeRef, String key, long defaultValue);
354
355 @Override
356 public boolean getBool(String key, boolean defaultValue)
357 {
358 assert !this.destroyed.get() : "trying to use a destroyed object";
359 return native_getBool(this.nativeRef, key, defaultValue);
360 }
361 private native boolean native_getBool(long _nativeRef, String key, boolean defaultValue);
362
363 @Override
364 public float getFloat(String key, float defaultValue)
365 {
366 assert !this.destroyed.get() : "trying to use a destroyed object";
367 return native_getFloat(this.nativeRef, key, defaultValue);
368 }
369 private native float native_getFloat(long _nativeRef, String key, float defaultValue);
370
371 @Override
372 public double getDouble(String key, double defaultValue)
373 {
374 assert !this.destroyed.get() : "trying to use a destroyed object";
375 return native_getDouble(this.nativeRef, key, defaultValue);
376 }
377 private native double native_getDouble(long _nativeRef, String key, double defaultValue);
378
379 @Override
380 public String getString(String key, String defaultValue)
381 {
382 assert !this.destroyed.get() : "trying to use a destroyed object";
383 return native_getString(this.nativeRef, key, defaultValue);
384 }
385 private native String native_getString(long _nativeRef, String key, String defaultValue);
386
387 @Override
388 public void putInt(String key, int value)
389 {
390 assert !this.destroyed.get() : "trying to use a destroyed object";
391 native_putInt(this.nativeRef, key, value);
392 }
393 private native void native_putInt(long _nativeRef, String key, int value);
394
395 @Override
396 public void putLong(String key, long value)
397 {
398 assert !this.destroyed.get() : "trying to use a destroyed object";
399 native_putLong(this.nativeRef, key, value);
400 }
401 private native void native_putLong(long _nativeRef, String key, long value);
402
403 @Override
404 public void putBool(String key, boolean value)
405 {
406 assert !this.destroyed.get() : "trying to use a destroyed object";
407 native_putBool(this.nativeRef, key, value);
408 }
409 private native void native_putBool(long _nativeRef, String key, boolean value);
410
411 @Override
412 public void putFloat(String key, float value)
413 {
414 assert !this.destroyed.get() : "trying to use a destroyed object";
415 native_putFloat(this.nativeRef, key, value);
416 }
417 private native void native_putFloat(long _nativeRef, String key, float value);
418
419 @Override
420 public void putDouble(String key, double value)
421 {
422 assert !this.destroyed.get() : "trying to use a destroyed object";
423 native_putDouble(this.nativeRef, key, value);
424 }
425 private native void native_putDouble(long _nativeRef, String key, double value);
426
427 @Override
428 public void putString(String key, String value)
429 {
430 assert !this.destroyed.get() : "trying to use a destroyed object";
431 native_putString(this.nativeRef, key, value);
432 }
433 private native void native_putString(long _nativeRef, String key, String value);
434
435 @Override
436 public void remove(String key)
437 {
438 assert !this.destroyed.get() : "trying to use a destroyed object";
439 native_remove(this.nativeRef, key);
440 }
441 private native void native_remove(long _nativeRef, String key);
442
443 @Override
444 public void clear()
445 {
446 assert !this.destroyed.get() : "trying to use a destroyed object";
447 native_clear(this.nativeRef);
448 }
449 private native void native_clear(long _nativeRef);
450 }
451}