OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 package org.adblockplus.libadblockplus; |
| 18 |
| 19 import java.util.List; |
| 20 |
| 21 import com.github.rjeschke.neetutils.dispose.Disposable; |
| 22 import com.github.rjeschke.neetutils.dispose.Disposer; |
| 23 |
| 24 public class JsValue implements Disposable |
| 25 { |
| 26 private final Disposer disposer; |
| 27 protected final long ptr; |
| 28 |
| 29 static |
| 30 { |
| 31 System.loadLibrary("adblockplus-jni"); |
| 32 registerNatives(); |
| 33 } |
| 34 |
| 35 protected JsValue(final long ptr) |
| 36 { |
| 37 this.ptr = ptr; |
| 38 this.disposer = new Disposer(this, new DisposeWrapper(ptr)); |
| 39 } |
| 40 |
| 41 @Override |
| 42 public void dispose() |
| 43 { |
| 44 this.disposer.dispose(); |
| 45 } |
| 46 |
| 47 public boolean isUndefined() |
| 48 { |
| 49 return isUndefined(this.ptr); |
| 50 } |
| 51 |
| 52 public boolean isNull() |
| 53 { |
| 54 return isNull(this.ptr); |
| 55 } |
| 56 |
| 57 public boolean isString() |
| 58 { |
| 59 return isString(this.ptr); |
| 60 } |
| 61 |
| 62 public boolean isNumber() |
| 63 { |
| 64 return isNumber(this.ptr); |
| 65 } |
| 66 |
| 67 public boolean isBoolean() |
| 68 { |
| 69 return isBoolean(this.ptr); |
| 70 } |
| 71 |
| 72 public boolean isObject() |
| 73 { |
| 74 return isObject(this.ptr); |
| 75 } |
| 76 |
| 77 public boolean isArray() |
| 78 { |
| 79 return isArray(this.ptr); |
| 80 } |
| 81 |
| 82 public boolean isFunction() |
| 83 { |
| 84 return isFunction(this.ptr); |
| 85 } |
| 86 |
| 87 public String asString() |
| 88 { |
| 89 return asString(this.ptr); |
| 90 } |
| 91 |
| 92 public long asLong() |
| 93 { |
| 94 return asLong(this.ptr); |
| 95 } |
| 96 |
| 97 public boolean asBoolean() |
| 98 { |
| 99 return asBoolean(this.ptr); |
| 100 } |
| 101 |
| 102 public boolean isValid() |
| 103 { |
| 104 return isValid(this.ptr); |
| 105 } |
| 106 |
| 107 public List<JsValue> asList() |
| 108 { |
| 109 return asList(this.ptr); |
| 110 } |
| 111 |
| 112 @Override |
| 113 public String toString() |
| 114 { |
| 115 return asString(this.ptr); |
| 116 } |
| 117 |
| 118 private final static class DisposeWrapper implements Disposable |
| 119 { |
| 120 private final long ptr; |
| 121 |
| 122 public DisposeWrapper(final long ptr) |
| 123 { |
| 124 this.ptr = ptr; |
| 125 } |
| 126 |
| 127 @Override |
| 128 public void dispose() |
| 129 { |
| 130 dtor(this.ptr); |
| 131 } |
| 132 } |
| 133 |
| 134 private final static native void registerNatives(); |
| 135 |
| 136 private final static native boolean isUndefined(long ptr); |
| 137 |
| 138 private final static native boolean isNull(long ptr); |
| 139 |
| 140 private final static native boolean isString(long ptr); |
| 141 |
| 142 private final static native boolean isNumber(long ptr); |
| 143 |
| 144 private final static native boolean isBoolean(long ptr); |
| 145 |
| 146 private final static native boolean isObject(long ptr); |
| 147 |
| 148 private final static native boolean isArray(long ptr); |
| 149 |
| 150 private final static native boolean isFunction(long ptr); |
| 151 |
| 152 private final static native String asString(long ptr); |
| 153 |
| 154 private final static native long asLong(long ptr); |
| 155 |
| 156 private final static native boolean asBoolean(long ptr); |
| 157 |
| 158 private final static native boolean isValid(long ptr); |
| 159 |
| 160 private final static native List<JsValue> asList(long ptr); |
| 161 |
| 162 private final static native void dtor(long ptr); |
| 163 } |
OLD | NEW |