Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/libadblockplus/JsValue.java

Issue 29345540: Issue 4030 - Move JNI bindings into separate library project (Closed)
Patch Set: Changeset in adblockplusandroid repo Created July 22, 2016, 12:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 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
18 package org.adblockplus.libadblockplus;
19
20 import java.util.List;
21
22 public class JsValue implements Disposable
23 {
24 private final Disposer disposer;
25 protected final long ptr;
26
27 static
28 {
29 System.loadLibrary("adblockplus-jni");
30 registerNatives();
31 }
32
33 protected JsValue(final long ptr)
34 {
35 this.ptr = ptr;
36 this.disposer = new Disposer(this, new DisposeWrapper(ptr));
37 }
38
39 @Override
40 public void dispose()
41 {
42 this.disposer.dispose();
43 }
44
45 public boolean isUndefined()
46 {
47 return isUndefined(this.ptr);
48 }
49
50 public boolean isNull()
51 {
52 return isNull(this.ptr);
53 }
54
55 public boolean isString()
56 {
57 return isString(this.ptr);
58 }
59
60 public boolean isNumber()
61 {
62 return isNumber(this.ptr);
63 }
64
65 public boolean isBoolean()
66 {
67 return isBoolean(this.ptr);
68 }
69
70 public boolean isObject()
71 {
72 return isObject(this.ptr);
73 }
74
75 public boolean isArray()
76 {
77 return isArray(this.ptr);
78 }
79
80 public boolean isFunction()
81 {
82 return isFunction(this.ptr);
83 }
84
85 public String asString()
86 {
87 return asString(this.ptr);
88 }
89
90 public long asLong()
91 {
92 return asLong(this.ptr);
93 }
94
95 public boolean asBoolean()
96 {
97 return asBoolean(this.ptr);
98 }
99
100 public JsValue getProperty(final String name)
101 {
102 return getProperty(this.ptr, name);
103 }
104
105 public List<JsValue> asList()
106 {
107 return asList(this.ptr);
108 }
109
110 @Override
111 public String toString()
112 {
113 return asString(this.ptr);
114 }
115
116 private final static class DisposeWrapper implements Disposable
117 {
118 private final long ptr;
119
120 public DisposeWrapper(final long ptr)
121 {
122 this.ptr = ptr;
123 }
124
125 @Override
126 public void dispose()
127 {
128 dtor(this.ptr);
129 }
130 }
131
132 private final static native void registerNatives();
133
134 private final static native boolean isUndefined(long ptr);
135
136 private final static native boolean isNull(long ptr);
137
138 private final static native boolean isString(long ptr);
139
140 private final static native boolean isNumber(long ptr);
141
142 private final static native boolean isBoolean(long ptr);
143
144 private final static native boolean isObject(long ptr);
145
146 private final static native boolean isArray(long ptr);
147
148 private final static native boolean isFunction(long ptr);
149
150 private final static native String asString(long ptr);
151
152 private final static native long asLong(long ptr);
153
154 private final static native boolean asBoolean(long ptr);
155
156 private final static native JsValue getProperty(long ptr, String name);
157
158 private final static native List<JsValue> asList(long ptr);
159
160 private final static native void dtor(long ptr);
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld