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 {
32 public abstract boolean contains(String key);
33
47 public abstract ArrayList<String> getKeys();
48
65 public abstract int getInt(String key, int defaultValue);
66
83 public abstract long getLong(String key, long defaultValue);
84
101 public abstract boolean getBool(String key, boolean defaultValue);
102
119 public abstract float getFloat(String key, float defaultValue);
120
137 public abstract double getDouble(String key, double defaultValue);
138
155 public abstract String getString(String key, String defaultValue);
156
171 public abstract void putInt(String key, int value);
172
187 public abstract void putLong(String key, long value);
188
203 public abstract void putBool(String key, boolean value);
204
219 public abstract void putFloat(String key, float value);
220
235 public abstract void putDouble(String key, double value);
236
251 public abstract void putString(String key, String value);
252
266 public abstract void remove(String key);
267
280 public abstract void clear();
281
282 private static final class CppProxy extends KeyValueStorage
283 {
284 private final long nativeRef;
285 private final AtomicBoolean destroyed = new AtomicBoolean(false);
286
287 private CppProxy(long nativeRef)
288 {
289 if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
290 this.nativeRef = nativeRef;
291 }
292
293 private native void nativeDestroy(long nativeRef);
294 public void _djinni_private_destroy()
295 {
296 boolean destroyed = this.destroyed.getAndSet(true);
297 if (!destroyed) nativeDestroy(this.nativeRef);
298 }
299 protected void finalize() throws java.lang.Throwable
300 {
301 _djinni_private_destroy();
302 super.finalize();
303 }
304
305 // KeyValueStorage methods
306
307 @Override
308 public boolean contains(String key)
309 {
310 assert !this.destroyed.get() : "trying to use a destroyed object";
311 return native_contains(this.nativeRef, key);
312 }
313 private native boolean native_contains(long _nativeRef, String key);
314
315 @Override
316 public ArrayList<String> getKeys()
317 {
318 assert !this.destroyed.get() : "trying to use a destroyed object";
319 return native_getKeys(this.nativeRef);
320 }
321 private native ArrayList<String> native_getKeys(long _nativeRef);
322
323 @Override
324 public int getInt(String key, int defaultValue)
325 {
326 assert !this.destroyed.get() : "trying to use a destroyed object";
327 return native_getInt(this.nativeRef, key, defaultValue);
328 }
329 private native int native_getInt(long _nativeRef, String key, int defaultValue);
330
331 @Override
332 public long getLong(String key, long defaultValue)
333 {
334 assert !this.destroyed.get() : "trying to use a destroyed object";
335 return native_getLong(this.nativeRef, key, defaultValue);
336 }
337 private native long native_getLong(long _nativeRef, String key, long defaultValue);
338
339 @Override
340 public boolean getBool(String key, boolean defaultValue)
341 {
342 assert !this.destroyed.get() : "trying to use a destroyed object";
343 return native_getBool(this.nativeRef, key, defaultValue);
344 }
345 private native boolean native_getBool(long _nativeRef, String key, boolean defaultValue);
346
347 @Override
348 public float getFloat(String key, float defaultValue)
349 {
350 assert !this.destroyed.get() : "trying to use a destroyed object";
351 return native_getFloat(this.nativeRef, key, defaultValue);
352 }
353 private native float native_getFloat(long _nativeRef, String key, float defaultValue);
354
355 @Override
356 public double getDouble(String key, double defaultValue)
357 {
358 assert !this.destroyed.get() : "trying to use a destroyed object";
359 return native_getDouble(this.nativeRef, key, defaultValue);
360 }
361 private native double native_getDouble(long _nativeRef, String key, double defaultValue);
362
363 @Override
364 public String getString(String key, String defaultValue)
365 {
366 assert !this.destroyed.get() : "trying to use a destroyed object";
367 return native_getString(this.nativeRef, key, defaultValue);
368 }
369 private native String native_getString(long _nativeRef, String key, String defaultValue);
370
371 @Override
372 public void putInt(String key, int value)
373 {
374 assert !this.destroyed.get() : "trying to use a destroyed object";
375 native_putInt(this.nativeRef, key, value);
376 }
377 private native void native_putInt(long _nativeRef, String key, int value);
378
379 @Override
380 public void putLong(String key, long value)
381 {
382 assert !this.destroyed.get() : "trying to use a destroyed object";
383 native_putLong(this.nativeRef, key, value);
384 }
385 private native void native_putLong(long _nativeRef, String key, long value);
386
387 @Override
388 public void putBool(String key, boolean value)
389 {
390 assert !this.destroyed.get() : "trying to use a destroyed object";
391 native_putBool(this.nativeRef, key, value);
392 }
393 private native void native_putBool(long _nativeRef, String key, boolean value);
394
395 @Override
396 public void putFloat(String key, float value)
397 {
398 assert !this.destroyed.get() : "trying to use a destroyed object";
399 native_putFloat(this.nativeRef, key, value);
400 }
401 private native void native_putFloat(long _nativeRef, String key, float value);
402
403 @Override
404 public void putDouble(String key, double value)
405 {
406 assert !this.destroyed.get() : "trying to use a destroyed object";
407 native_putDouble(this.nativeRef, key, value);
408 }
409 private native void native_putDouble(long _nativeRef, String key, double value);
410
411 @Override
412 public void putString(String key, String value)
413 {
414 assert !this.destroyed.get() : "trying to use a destroyed object";
415 native_putString(this.nativeRef, key, value);
416 }
417 private native void native_putString(long _nativeRef, String key, String value);
418
419 @Override
420 public void remove(String key)
421 {
422 assert !this.destroyed.get() : "trying to use a destroyed object";
423 native_remove(this.nativeRef, key);
424 }
425 private native void native_remove(long _nativeRef, String key);
426
427 @Override
428 public void clear()
429 {
430 assert !this.destroyed.get() : "trying to use a destroyed object";
431 native_clear(this.nativeRef);
432 }
433 private native void native_clear(long _nativeRef);
434 }
435}