Latest bnd code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1350613 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/lib/json/ArrayHandler.java b/bundleplugin/src/main/java/aQute/lib/json/ArrayHandler.java
index 62af4a7..1eb83ac 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/ArrayHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/ArrayHandler.java
@@ -12,8 +12,7 @@
}
@Override
- void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
app.append("[");
String del = "";
int l = Array.getLength(object);
@@ -29,8 +28,7 @@
Object decodeArray(Decoder r) throws Exception {
ArrayList<Object> list = new ArrayList<Object>();
r.codec.parseArray(list, componentType, r);
- Object array = Array.newInstance(r.codec.getRawClass(componentType),
- list.size());
+ Object array = Array.newInstance(r.codec.getRawClass(componentType), list.size());
int n = 0;
for (Object o : list)
Array.set(array, n++, o);
diff --git a/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java b/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
index d3b56ea..5dd4990 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
@@ -6,24 +6,28 @@
public class BooleanHandler extends Handler {
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
- app.append( object.toString());
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
+ app.append(object.toString());
}
-
- @Override Object decode(boolean s) {
+
+ @Override
+ Object decode(boolean s) {
return s;
}
- @Override Object decode(String s) {
+ @Override
+ Object decode(String s) {
return Boolean.parseBoolean(s);
}
- @Override Object decode(Number s) {
+ @Override
+ Object decode(Number s) {
return s.intValue() != 0;
}
- @Override Object decode() {
+ @Override
+ Object decode() {
return false;
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
index 65f5f74..d956a6c 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
@@ -8,12 +8,13 @@
public class ByteArrayHandler extends Handler {
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
StringHandler.string(app, Base64.encodeBase64((byte[]) object));
}
- @Override Object decodeArray(Decoder r) throws Exception {
+ @Override
+ Object decodeArray(Decoder r) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArrayList<Object> list = new ArrayList<Object>();
@@ -24,7 +25,8 @@
return out.toByteArray();
}
- @Override Object decode(String s) throws Exception {
+ @Override
+ Object decode(String s) throws Exception {
return Base64.decodeBase64(s);
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java b/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
index 7009e0c..3d00cdc 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
@@ -5,26 +5,30 @@
public class CharacterHandler extends Handler {
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws Exception {
- Character c = (Character) object;
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws Exception {
+ Character c = (Character) object;
int v = (int) c.charValue();
- app.append( v+"" );
+ app.append(v + "");
}
-
- @Override Object decode(boolean s) {
+
+ @Override
+ Object decode(boolean s) {
return s ? 't' : 'f';
}
- @Override Object decode(String s) {
+ @Override
+ Object decode(String s) {
return (char) Integer.parseInt(s);
}
- @Override Object decode(Number s) {
+ @Override
+ Object decode(Number s) {
return (char) s.shortValue();
}
- @Override Object decode() {
+ @Override
+ Object decode() {
return 0;
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/CollectionHandler.java b/bundleplugin/src/main/java/aQute/lib/json/CollectionHandler.java
index 89492c1..0ebfc62 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/CollectionHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/CollectionHandler.java
@@ -6,10 +6,10 @@
import java.util.concurrent.*;
public class CollectionHandler extends Handler {
- Class<?> rawClass;
+ Class< ? > rawClass;
Type componentType;
-
- CollectionHandler(Class<?> rawClass, Type componentType) {
+
+ CollectionHandler(Class< ? > rawClass, Type componentType) {
this.componentType = componentType;
if (rawClass.isInterface()) {
if (rawClass.isAssignableFrom(ArrayList.class))
@@ -29,15 +29,14 @@
else if (rawClass.isAssignableFrom(CopyOnWriteArraySet.class))
rawClass = CopyOnWriteArraySet.class;
else
- throw new IllegalArgumentException("Unknown interface type for collection: "
- + rawClass);
+ throw new IllegalArgumentException("Unknown interface type for collection: " + rawClass);
}
this.rawClass = rawClass;
}
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
- Iterable<?> collection = (Iterable<?>) object;
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
+ Iterable< ? > collection = (Iterable< ? >) object;
app.append("[");
String del = "";
@@ -49,7 +48,9 @@
app.append("]");
}
- @SuppressWarnings("unchecked") @Override Object decodeArray(Decoder r) throws Exception {
+ @SuppressWarnings("unchecked")
+ @Override
+ Object decodeArray(Decoder r) throws Exception {
Collection<Object> c = (Collection<Object>) rawClass.newInstance();
r.codec.parseArray(c, componentType, r);
return c;
diff --git a/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java b/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
index d4f262e..784fcbe 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
@@ -8,8 +8,8 @@
public class DateHandler extends Handler {
final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
String s;
synchronized (sdf) {
s = sdf.format((Date) object);
@@ -17,13 +17,15 @@
StringHandler.string(app, s);
}
- @Override Object decode(String s) throws Exception {
+ @Override
+ Object decode(String s) throws Exception {
synchronized (sdf) {
return sdf.parse(s);
}
}
- @Override Object decode(Number s) throws Exception {
+ @Override
+ Object decode(Number s) throws Exception {
return new Date(s.longValue());
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/Decoder.java b/bundleplugin/src/main/java/aQute/lib/json/Decoder.java
index 3cbed4b..703331d 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/Decoder.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/Decoder.java
@@ -5,15 +5,17 @@
import java.security.*;
import java.util.*;
+import aQute.lib.converter.*;
+
public class Decoder implements Closeable {
final JSONCodec codec;
Reader reader;
int current;
MessageDigest digest;
- Map<String, Object> extra;
- String encoding = "UTF-8";
-
- boolean strict;
+ Map<String,Object> extra;
+ String encoding = "UTF-8";
+
+ boolean strict;
Decoder(JSONCodec codec) {
this.codec = codec;
@@ -26,12 +28,12 @@
public Decoder from(InputStream in) throws Exception {
return from(new InputStreamReader(in, encoding));
}
-
+
public Decoder charset(String encoding) {
this.encoding = encoding;
return this;
}
-
+
public Decoder strict() {
this.strict = true;
return this;
@@ -65,7 +67,8 @@
return digest.digest();
}
- @SuppressWarnings("unchecked") public <T> T get(Class<T> clazz) throws Exception {
+ @SuppressWarnings("unchecked")
+ public <T> T get(Class<T> clazz) throws Exception {
return (T) codec.decode(clazz, this);
}
@@ -77,6 +80,11 @@
return codec.decode(null, this);
}
+ @SuppressWarnings("unchecked")
+ public <T> T get(TypeReference<T> ref) throws Exception {
+ return (T) codec.decode(ref.getType(), this);
+ }
+
int read() throws Exception {
current = reader.read();
if (digest != null) {
@@ -129,9 +137,9 @@
reader.close();
}
- public Map<String, Object> getExtra() {
+ public Map<String,Object> getExtra() {
if (extra == null)
- extra = new HashMap<String, Object>();
+ extra = new HashMap<String,Object>();
return extra;
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/Encoder.java b/bundleplugin/src/main/java/aQute/lib/json/Encoder.java
index 09990ed..b6112e7 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/Encoder.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/Encoder.java
@@ -20,7 +20,7 @@
if (app == null)
to();
- codec.encode(this, object, null, new IdentityHashMap<Object, Type>());
+ codec.encode(this, object, null, new IdentityHashMap<Object,Type>());
return this;
}
@@ -95,7 +95,7 @@
((Closeable) app).close();
}
- void encode(Object object, Type type, Map<Object, Type> visited) throws Exception {
+ void encode(Object object, Type type, Map<Object,Type> visited) throws Exception {
codec.encode(this, object, type, visited);
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java b/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
index dbdb492..85aad12 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
@@ -6,18 +6,19 @@
public class EnumHandler extends Handler {
@SuppressWarnings("rawtypes")
- final Class type;
+ final Class type;
- public EnumHandler(Class<?> type) {
+ public EnumHandler(Class< ? > type) {
this.type = type;
}
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
StringHandler.string(app, object.toString());
}
- @SuppressWarnings("unchecked") Object decode(String s) throws Exception {
+ @SuppressWarnings("unchecked")
+ Object decode(String s) throws Exception {
return Enum.valueOf(type, s);
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
index 2f0eea5..c024090 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
@@ -8,18 +8,19 @@
public class FileHandler extends Handler {
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
File f = (File) object;
- if ( !f.isFile())
- throw new RuntimeException("Encoding a file requires the file to exist and to be a normal file " + f );
-
+ if (!f.isFile())
+ throw new RuntimeException("Encoding a file requires the file to exist and to be a normal file " + f);
+
FileInputStream in = new FileInputStream(f);
try {
app.append('"');
Base64.encode(in, app);
app.append('"');
- } finally {
+ }
+ finally {
in.close();
}
}
@@ -29,7 +30,8 @@
FileOutputStream fout = new FileOutputStream(tmp);
try {
Base64.decode(new StringReader(s), fout);
- } finally {
+ }
+ finally {
fout.close();
}
return tmp;
diff --git a/bundleplugin/src/main/java/aQute/lib/json/Handler.java b/bundleplugin/src/main/java/aQute/lib/json/Handler.java
index 18957e8..f002f50 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/Handler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/Handler.java
@@ -5,8 +5,7 @@
import java.util.*;
abstract class Handler {
- abstract void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception;
+ abstract void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception;
Object decodeObject(Decoder isr) throws Exception {
throw new UnsupportedOperationException("Cannot be mapped to object " + this);
diff --git a/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java b/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
index fa5c751..032f08f 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
@@ -39,22 +39,18 @@
final static String START_CHARACTERS = "[{\"-0123456789tfn";
// Handlers
- private final static WeakHashMap<Type, Handler> handlers = new WeakHashMap<Type, Handler>();
+ private final static WeakHashMap<Type,Handler> handlers = new WeakHashMap<Type,Handler>();
private static StringHandler sh = new StringHandler();
private static BooleanHandler bh = new BooleanHandler();
private static CharacterHandler ch = new CharacterHandler();
- private static CollectionHandler dch = new CollectionHandler(
- ArrayList.class,
+ private static CollectionHandler dch = new CollectionHandler(ArrayList.class,
Object.class);
- private static SpecialHandler sph = new SpecialHandler(
- Pattern.class,
- null, null);
+ private static SpecialHandler sph = new SpecialHandler(Pattern.class, null, null);
private static DateHandler sdh = new DateHandler();
private static FileHandler fh = new FileHandler();
private static ByteArrayHandler byteh = new ByteArrayHandler();
- boolean ignorenull;
-
+ boolean ignorenull;
/**
* Create a new Encoder with the state and appropriate API.
@@ -77,7 +73,7 @@
/*
* Work horse encode methods, all encoding ends up here.
*/
- void encode(Encoder app, Object object, Type type, Map<Object, Type> visited) throws Exception {
+ void encode(Encoder app, Object object, Type type, Map<Object,Type> visited) throws Exception {
// Get the null out of the way
@@ -104,11 +100,8 @@
* stuff. It returns a handler for each type. If no appropriate handler
* exists, it will create one for the given type. There are actually quite a
* lot of handlers since Java is not very object oriented.
- *
* @param type
- *
* @return
- *
* @throws Exception
*/
Handler getHandler(Type type) throws Exception {
@@ -146,7 +139,7 @@
if (type instanceof Class) {
- Class<?> clazz = (Class<?>) type;
+ Class< ? > clazz = (Class< ? >) type;
if (Enum.class.isAssignableFrom(clazz))
h = new EnumHandler(clazz);
@@ -162,16 +155,18 @@
h = new NumberHandler(clazz);
else {
Method valueOf = null;
- Constructor<?> constructor = null;
+ Constructor< ? > constructor = null;
try {
constructor = clazz.getConstructor(String.class);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
// Ignore
}
try {
valueOf = clazz.getMethod("valueOf", String.class);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
// Ignore
}
if (constructor != null || valueOf != null)
@@ -190,22 +185,19 @@
ParameterizedType pt = (ParameterizedType) type;
Type rawType = pt.getRawType();
if (rawType instanceof Class) {
- Class<?> rawClass = (Class<?>) rawType;
+ Class< ? > rawClass = (Class< ? >) rawType;
if (Iterable.class.isAssignableFrom(rawClass))
h = new CollectionHandler(rawClass, pt.getActualTypeArguments()[0]);
else if (Map.class.isAssignableFrom(rawClass))
- h = new MapHandler(rawClass, pt.getActualTypeArguments()[0],
- pt.getActualTypeArguments()[1]);
+ h = new MapHandler(rawClass, pt.getActualTypeArguments()[0], pt.getActualTypeArguments()[1]);
else
- throw new IllegalArgumentException(
- "Found a parameterized type that is not a map or collection");
+ throw new IllegalArgumentException("Found a parameterized type that is not a map or collection");
}
} else if (type instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) type;
h = new ArrayHandler(getRawClass(type), gat.getGenericComponentType());
} else
- throw new IllegalArgumentException(
- "Found a parameterized type that is not a map or collection");
+ throw new IllegalArgumentException("Found a parameterized type that is not a map or collection");
}
synchronized (handlers) {
// We might actually have duplicates
@@ -225,87 +217,86 @@
// type information
switch (c) {
- case '{':
- type = LinkedHashMap.class;
- break;
+ case '{' :
+ type = LinkedHashMap.class;
+ break;
- case '[':
- type = ArrayList.class;
- break;
+ case '[' :
+ type = ArrayList.class;
+ break;
- case '"':
- return parseString(isr);
+ case '"' :
+ return parseString(isr);
- case 'n':
- isr.expect("ull");
- return null;
+ case 'n' :
+ isr.expect("ull");
+ return null;
- case 't':
- isr.expect("rue");
- return true;
+ case 't' :
+ isr.expect("rue");
+ return true;
- case 'f':
- isr.expect("alse");
- return false;
+ case 'f' :
+ isr.expect("alse");
+ return false;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- return parseNumber(isr);
+ case '0' :
+ case '1' :
+ case '2' :
+ case '3' :
+ case '4' :
+ case '5' :
+ case '6' :
+ case '7' :
+ case '8' :
+ case '9' :
+ case '-' :
+ return parseNumber(isr);
- default:
- throw new IllegalArgumentException("Invalid character at begin of token: "
- + (char) c);
+ default :
+ throw new IllegalArgumentException("Invalid character at begin of token: " + (char) c);
}
}
h = getHandler(type);
switch (c) {
- case '{':
- return h.decodeObject(isr);
+ case '{' :
+ return h.decodeObject(isr);
- case '[':
- return h.decodeArray(isr);
+ case '[' :
+ return h.decodeArray(isr);
- case '"':
- return h.decode(parseString(isr));
+ case '"' :
+ return h.decode(parseString(isr));
- case 'n':
- isr.expect("ull");
- return h.decode();
+ case 'n' :
+ isr.expect("ull");
+ return h.decode();
- case 't':
- isr.expect("rue");
- return h.decode(Boolean.TRUE);
+ case 't' :
+ isr.expect("rue");
+ return h.decode(Boolean.TRUE);
- case 'f':
- isr.expect("alse");
- return h.decode(Boolean.FALSE);
+ case 'f' :
+ isr.expect("alse");
+ return h.decode(Boolean.FALSE);
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- return h.decode(parseNumber(isr));
+ case '0' :
+ case '1' :
+ case '2' :
+ case '3' :
+ case '4' :
+ case '5' :
+ case '6' :
+ case '7' :
+ case '8' :
+ case '9' :
+ case '-' :
+ return h.decode(parseNumber(isr));
- default:
- throw new IllegalArgumentException("Unexpected character in input stream: " + (char) c);
+ default :
+ throw new IllegalArgumentException("Unexpected character in input stream: " + (char) c);
}
}
@@ -317,47 +308,45 @@
StringBuilder sb = new StringBuilder();
while (c != '"') {
if (c < 0 || Character.isISOControl(c))
- throw new IllegalArgumentException(
- "JSON strings may not contain control characters: " + r.current());
+ throw new IllegalArgumentException("JSON strings may not contain control characters: " + r.current());
if (c == '\\') {
c = r.read();
switch (c) {
- case '"':
- case '\\':
- case '/':
- sb.append((char)c);
- break;
+ case '"' :
+ case '\\' :
+ case '/' :
+ sb.append((char) c);
+ break;
- case 'b':
- sb.append('\b');
- break;
+ case 'b' :
+ sb.append('\b');
+ break;
- case 'f':
- sb.append('\f');
- break;
- case 'n':
- sb.append('\n');
- break;
- case 'r':
- sb.append('\r');
- break;
- case 't':
- sb.append('\t');
- break;
- case 'u':
- int a3 = hexDigit(r.read()) << 12;
- int a2 = hexDigit(r.read()) << 8;
- int a1 = hexDigit(r.read()) << 4;
- int a0 = hexDigit(r.read()) << 0;
- c = a3 + a2 + a1 + a0;
- sb.append((char) c);
- break;
+ case 'f' :
+ sb.append('\f');
+ break;
+ case 'n' :
+ sb.append('\n');
+ break;
+ case 'r' :
+ sb.append('\r');
+ break;
+ case 't' :
+ sb.append('\t');
+ break;
+ case 'u' :
+ int a3 = hexDigit(r.read()) << 12;
+ int a2 = hexDigit(r.read()) << 8;
+ int a1 = hexDigit(r.read()) << 4;
+ int a0 = hexDigit(r.read()) << 0;
+ c = a3 + a2 + a1 + a0;
+ sb.append((char) c);
+ break;
- default:
- throw new IllegalArgumentException(
- "The only characters after a backslash are \", \\, b, f, n, r, t, and u but got "
- + c);
+ default :
+ throw new IllegalArgumentException(
+ "The only characters after a backslash are \", \\, b, f, n, r, t, and u but got " + c);
}
} else
sb.append((char) c);
@@ -455,15 +444,15 @@
continue;
}
- throw new IllegalArgumentException(
- "Invalid character in parsing list, expected ] or , but found " + (char) c);
+ throw new IllegalArgumentException("Invalid character in parsing list, expected ] or , but found "
+ + (char) c);
}
assert r.current() == ']';
r.read(); // skip closing
}
@SuppressWarnings("rawtypes")
- Class<?> getRawClass(Type type) {
+ Class< ? > getRawClass(Type type) {
if (type instanceof Class)
return (Class) type;
@@ -477,12 +466,12 @@
}
throw new IllegalArgumentException(
- "Does not support generics beyond Parameterized Type and GenericArrayType, got "
- + type);
+ "Does not support generics beyond Parameterized Type and GenericArrayType, got " + type);
}
/**
* Ignore null values in output and input
+ *
* @param ignorenull
* @return
*/
diff --git a/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java b/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
index 9299878..4a12c02 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
@@ -5,11 +5,11 @@
import java.util.*;
public class MapHandler extends Handler {
- final Class<?> rawClass;
- final Type keyType;
- final Type valueType;
+ final Class< ? > rawClass;
+ final Type keyType;
+ final Type valueType;
- MapHandler(Class<?> rawClass, Type keyType, Type valueType) {
+ MapHandler(Class< ? > rawClass, Type keyType, Type valueType) {
this.keyType = keyType;
this.valueType = valueType;
if (rawClass.isInterface()) {
@@ -27,13 +27,13 @@
this.rawClass = rawClass;
}
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
- Map<?, ?> map = (Map<?, ?>) object;
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
+ Map< ? , ? > map = (Map< ? , ? >) object;
app.append("{");
String del = "";
- for (Map.Entry<?, ?> e : map.entrySet()) {
+ for (Map.Entry< ? , ? > e : map.entrySet()) {
app.append(del);
String key;
if (e.getKey() != null && (keyType == String.class || keyType == Object.class))
@@ -49,31 +49,33 @@
app.append("}");
}
- @SuppressWarnings("unchecked") @Override Object decodeObject(Decoder r) throws Exception {
+ @SuppressWarnings("unchecked")
+ @Override
+ Object decodeObject(Decoder r) throws Exception {
assert r.current() == '{';
-
- Map<Object, Object> map = (Map<Object, Object>) rawClass.newInstance();
-
+
+ Map<Object,Object> map = (Map<Object,Object>) rawClass.newInstance();
+
int c = r.next();
while (JSONCodec.START_CHARACTERS.indexOf(c) >= 0) {
Object key = r.codec.parseString(r);
- if ( !(keyType == null || keyType == Object.class)) {
+ if (!(keyType == null || keyType == Object.class)) {
Handler h = r.codec.getHandler(keyType);
- key = h.decode((String)key);
+ key = h.decode((String) key);
}
-
+
c = r.skipWs();
- if ( c != ':')
+ if (c != ':')
throw new IllegalArgumentException("Expected ':' but got " + (char) c);
c = r.next();
Object value = r.codec.decode(valueType, r);
- if ( value != null || !r.codec.ignorenull)
+ if (value != null || !r.codec.ignorenull)
map.put(key, value);
c = r.skipWs();
-
- if (c == '}')
+
+ if (c == '}')
break;
if (c == ',') {
@@ -81,8 +83,8 @@
continue;
}
- throw new IllegalArgumentException(
- "Invalid character in parsing list, expected } or , but found " + (char) c);
+ throw new IllegalArgumentException("Invalid character in parsing list, expected } or , but found "
+ + (char) c);
}
assert r.current() == '}';
r.read(); // skip closing
diff --git a/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java b/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
index 644d49a..310ca3e 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
@@ -5,42 +5,45 @@
import java.util.*;
public class NumberHandler extends Handler {
- final Class<?> type;
+ final Class< ? > type;
- NumberHandler(Class<?> clazz) {
+ NumberHandler(Class< ? > clazz) {
this.type = clazz;
}
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws Exception {
String s = object.toString();
- if ( s.endsWith(".0"))
- s = s.substring(0,s.length()-2);
-
+ if (s.endsWith(".0"))
+ s = s.substring(0, s.length() - 2);
+
app.append(s);
}
- @Override Object decode(boolean s) {
+ @Override
+ Object decode(boolean s) {
return decode(s ? 1d : 0d);
}
- @Override Object decode(String s) {
+ @Override
+ Object decode(String s) {
double d = Double.parseDouble(s);
return decode(d);
}
- @Override Object decode() {
+ @Override
+ Object decode() {
return decode(0d);
}
- @Override Object decode(Number s) {
+ @Override
+ Object decode(Number s) {
double dd = s.doubleValue();
-
+
if (type == double.class || type == Double.class)
return s.doubleValue();
- if ((type == int.class || type == Integer.class)
- && within(dd, Integer.MIN_VALUE, Integer.MAX_VALUE))
+ if ((type == int.class || type == Integer.class) && within(dd, Integer.MIN_VALUE, Integer.MAX_VALUE))
return s.intValue();
if ((type == long.class || type == Long.class) && within(dd, Long.MIN_VALUE, Long.MAX_VALUE))
@@ -49,8 +52,7 @@
if ((type == byte.class || type == Byte.class) && within(dd, Byte.MIN_VALUE, Byte.MAX_VALUE))
return s.byteValue();
- if ((type == short.class || type == Short.class)
- && within(dd, Short.MIN_VALUE, Short.MAX_VALUE))
+ if ((type == short.class || type == Short.class) && within(dd, Short.MIN_VALUE, Short.MAX_VALUE))
return s.shortValue();
if (type == float.class || type == Float.class)
diff --git a/bundleplugin/src/main/java/aQute/lib/json/ObjectHandler.java b/bundleplugin/src/main/java/aQute/lib/json/ObjectHandler.java
index 2a876a4..50aaac0 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/ObjectHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/ObjectHandler.java
@@ -11,7 +11,7 @@
final Object defaults[];
final Field extra;
- ObjectHandler(JSONCodec codec, Class<?> c) throws Exception {
+ ObjectHandler(JSONCodec codec, Class< ? > c) throws Exception {
rawClass = c;
fields = c.getFields();
@@ -35,19 +35,21 @@
extra = x;
else
extra = null;
-
+
try {
Object template = c.newInstance();
for (int i = 0; i < fields.length; i++) {
defaults[i] = fields[i].get(template);
}
- } catch (Exception e) {
+ }
+ catch (Exception e) {
// Ignore
}
}
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited) throws Exception {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws Exception {
app.append("{");
String del = "";
for (int i = 0; i < fields.length; i++) {
@@ -72,7 +74,9 @@
app.append("}");
}
- @SuppressWarnings("unchecked") @Override Object decodeObject(Decoder r) throws Exception {
+ @SuppressWarnings("unchecked")
+ @Override
+ Object decodeObject(Decoder r) throws Exception {
assert r.current() == '{';
Object targetObject = rawClass.newInstance();
@@ -95,7 +99,7 @@
if (f != null) {
// We have a field and thus a type
Object value = r.codec.decode(f.getGenericType(), r);
- if ( value != null || !r.codec.ignorenull)
+ if (value != null || !r.codec.ignorenull)
f.set(targetObject, value);
} else {
// No field, but may extra is defined
@@ -106,9 +110,9 @@
r.getExtra().put(rawClass.getName() + "." + key, value);
} else {
- Map<String, Object> map = (Map<String, Object>) extra.get(targetObject);
+ Map<String,Object> map = (Map<String,Object>) extra.get(targetObject);
if (map == null) {
- map = new LinkedHashMap<String, Object>();
+ map = new LinkedHashMap<String,Object>();
extra.set(targetObject, map);
}
Object value = r.codec.decode(null, r);
@@ -126,8 +130,8 @@
continue;
}
- throw new IllegalArgumentException(
- "Invalid character in parsing object, expected } or , but found " + (char) c);
+ throw new IllegalArgumentException("Invalid character in parsing object, expected } or , but found "
+ + (char) c);
}
assert r.current() == '}';
r.read(); // skip closing
diff --git a/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java b/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
index 33bde8f..bcd05ef 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
@@ -13,16 +13,14 @@
final Constructor< ? > constructor;
final static SimpleDateFormat sdf = new SimpleDateFormat();
- public SpecialHandler(Class< ? > type, Constructor< ? > constructor,
- Method valueOf) {
+ public SpecialHandler(Class< ? > type, Constructor< ? > constructor, Method valueOf) {
this.type = type;
this.constructor = constructor;
this.valueOf = valueOf;
}
@Override
- void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException, Exception {
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
StringHandler.string(app, object.toString());
}
@@ -37,8 +35,7 @@
if (valueOf != null)
return valueOf.invoke(null, s);
- throw new IllegalArgumentException("Do not know how to convert a "
- + type + " from a string");
+ throw new IllegalArgumentException("Do not know how to convert a " + type + " from a string");
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
index 2450ed0..8ebfee2 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
@@ -6,8 +6,8 @@
public class StringHandler extends Handler {
- @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
- throws IOException {
+ @Override
+ void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException {
string(app, object.toString());
}
@@ -17,43 +17,43 @@
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
switch (c) {
- case '"':
- app.append("\\\"");
- break;
+ case '"' :
+ app.append("\\\"");
+ break;
- case '\\':
- app.append("\\\\");
- break;
+ case '\\' :
+ app.append("\\\\");
+ break;
- case '\b':
- app.append("\\b");
- break;
+ case '\b' :
+ app.append("\\b");
+ break;
- case '\f':
- app.append("\\f");
- break;
+ case '\f' :
+ app.append("\\f");
+ break;
- case '\n':
- app.append("\\n");
- break;
+ case '\n' :
+ app.append("\\n");
+ break;
- case '\r':
- app.append("\\r");
- break;
+ case '\r' :
+ app.append("\\r");
+ break;
- case '\t':
- app.append("\\t");
- break;
+ case '\t' :
+ app.append("\\t");
+ break;
- default:
- if (Character.isISOControl(c)) {
- app.append("\\u");
- app.append("0123456789ABCDEF".charAt(0xF & (c >> 12)));
- app.append("0123456789ABCDEF".charAt(0xF & (c >> 8)));
- app.append("0123456789ABCDEF".charAt(0xF & (c >> 4)));
- app.append("0123456789ABCDEF".charAt(0xF & (c >> 0)));
- } else
- app.append(c);
+ default :
+ if (Character.isISOControl(c)) {
+ app.append("\\u");
+ app.append("0123456789ABCDEF".charAt(0xF & (c >> 12)));
+ app.append("0123456789ABCDEF".charAt(0xF & (c >> 8)));
+ app.append("0123456789ABCDEF".charAt(0xF & (c >> 4)));
+ app.append("0123456789ABCDEF".charAt(0xF & (c >> 0)));
+ } else
+ app.append(c);
}
}
app.append('"');
@@ -113,29 +113,29 @@
sb.append((char) c);
if (instring)
switch (c) {
- case '"':
- instring = true;
- break;
+ case '"' :
+ instring = true;
+ break;
- case '[':
- case '{':
- level++;
- break;
+ case '[' :
+ case '{' :
+ level++;
+ break;
- case ']':
- case '}':
- level--;
- break;
+ case ']' :
+ case '}' :
+ level--;
+ break;
}
else
switch (c) {
- case '"':
- instring = false;
- break;
+ case '"' :
+ instring = false;
+ break;
- case '\\':
- sb.append((char) isr.read());
- break;
+ case '\\' :
+ sb.append((char) isr.read());
+ break;
}
c = isr.read();