You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by sa...@apache.org on 2014/09/11 20:29:27 UTC
[11/22] renamed fleece to johnzon
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/FloatConverter.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/FloatConverter.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/FloatConverter.java
deleted file mode 100644
index 7e6fb1e..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/FloatConverter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.apache.fleece.mapper.Converter;
-
-public class FloatConverter implements Converter<Float> {
- @Override
- public String toString(final Float instance) {
- return Float.toString(instance);
- }
-
- @Override
- public Float fromString(final String text) {
- return Float.valueOf(text);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/IntegerConverter.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/IntegerConverter.java
deleted file mode 100644
index 8677b3e..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/IntegerConverter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.apache.fleece.mapper.Converter;
-
-public class IntegerConverter implements Converter<Integer> {
- @Override
- public String toString(final Integer instance) {
- return Integer.toString(instance);
- }
-
- @Override
- public Integer fromString(final String text) {
- return Integer.valueOf(text);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/LongConverter.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/LongConverter.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/LongConverter.java
deleted file mode 100644
index 62b17ec..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/LongConverter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.apache.fleece.mapper.Converter;
-
-public class LongConverter implements Converter<Long> {
- @Override
- public String toString(final Long instance) {
- return Long.toString(instance);
- }
-
- @Override
- public Long fromString(final String text) {
- return Long.valueOf(text);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/ShortConverter.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/ShortConverter.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/ShortConverter.java
deleted file mode 100644
index e9c48ec..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/ShortConverter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.apache.fleece.mapper.Converter;
-
-public class ShortConverter implements Converter<Short> {
- @Override
- public String toString(final Short instance) {
- return Short.toString(instance);
- }
-
- @Override
- public Short fromString(final String text) {
- return Short.valueOf(text);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/StringConverter.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/StringConverter.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/StringConverter.java
deleted file mode 100644
index 713702f..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/converter/StringConverter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.apache.fleece.mapper.Converter;
-
-public class StringConverter implements Converter<String> {
- @Override
- public String toString(final String instance) {
- return instance;
- }
-
- @Override
- public String fromString(final String text) {
- return text;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/main/java/org/apache/fleece/mapper/reflection/Mappings.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/main/java/org/apache/fleece/mapper/reflection/Mappings.java b/fleece-mapper/src/main/java/org/apache/fleece/mapper/reflection/Mappings.java
deleted file mode 100644
index 4006515..0000000
--- a/fleece-mapper/src/main/java/org/apache/fleece/mapper/reflection/Mappings.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.reflection;
-
-import org.apache.fleece.mapper.Converter;
-import org.apache.fleece.mapper.FleeceConverter;
-import org.apache.fleece.mapper.FleeceIgnore;
-import org.apache.fleece.mapper.MapperException;
-
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-public class Mappings {
- public static class ClassMapping {
- public final Class<?> clazz;
- public final Map<String, Getter> getters;
- public final Map<String, Setter> setters;
-
- protected ClassMapping(final Class<?> clazz,
- final Map<String, Getter> getters, final Map<String, Setter> setters) {
- this.clazz = clazz;
- this.getters = getters;
- this.setters = setters;
- }
- }
-
- public static class CollectionMapping {
- public final Class<?> raw;
- public final Type arg;
- public final boolean primitive;
-
- public CollectionMapping(final boolean primitive, final Class<?> collectionType, final Type fieldArgType) {
- this.raw = collectionType;
- this.arg = fieldArgType;
- this.primitive = primitive;
- }
- }
-
- public static class Getter {
- public final Method setter;
- public final int version;
- public final Converter<Object> converter;
- public final boolean primitive;
- public final boolean array;
- public final boolean map;
- public final boolean collection;
-
- public Getter(final Method setter,
- final boolean primitive, final boolean array,
- final boolean collection, final boolean map,
- final Converter<Object> converter, final int version) {
- this.setter = setter;
- this.converter = converter;
- this.version = version;
- this.array = array;
- this.map = map && converter == null;
- this.collection = collection;
- this.primitive = primitive;
- }
- }
-
- public static class Setter {
- public final Method setter;
- public final int version;
- public final Type paramType;
- public final Converter<?> converter;
- public final boolean primitive;
-
- public Setter(final Method setter, final boolean primitive, final Type paramType, final Converter<?> converter, final int version) {
- this.setter = setter;
- this.paramType = paramType;
- this.converter = converter;
- this.version = version;
- this.primitive = primitive;
- }
- }
-
- protected final ConcurrentMap<Type, ClassMapping> classes = new ConcurrentHashMap<Type, ClassMapping>();
- protected final ConcurrentMap<Type, CollectionMapping> collections = new ConcurrentHashMap<Type, CollectionMapping>();
- protected final Comparator<String> fieldOrdering;
-
- public Mappings(final Comparator<String> attributeOrder) {
- this.fieldOrdering = attributeOrder;
- }
-
- public <T> CollectionMapping findCollectionMapping(final ParameterizedType genericType, final Class<T> raw) {
- CollectionMapping collectionMapping = collections.get(genericType);
- if (collectionMapping == null) {
- collectionMapping = createCollectionMapping(genericType, raw);
- if (collectionMapping == null) {
- return null;
- }
- final CollectionMapping existing = collections.putIfAbsent(genericType, collectionMapping);
- if (existing != null) {
- collectionMapping = existing;
- }
- }
- return collectionMapping;
- }
-
- private <T> CollectionMapping createCollectionMapping(final ParameterizedType aType, final Class<T> raw) {
- final Type[] fieldArgTypes = aType.getActualTypeArguments();
- if (fieldArgTypes.length == 1) {
- final Class<?> collectionType;
- if (List.class.isAssignableFrom(raw)) {
- collectionType = List.class;
- }else if (SortedSet.class.isAssignableFrom(raw)) {
- collectionType = SortedSet.class;
- } else if (Set.class.isAssignableFrom(raw)) {
- collectionType = Set.class;
- } else if (Queue.class.isAssignableFrom(raw)) {
- collectionType = Queue.class;
- } else if (Collection.class.isAssignableFrom(raw)) {
- collectionType = Collection.class;
- } else {
- return null;
- }
-
- final CollectionMapping mapping = new CollectionMapping(isPrimitive(fieldArgTypes[0]), collectionType, fieldArgTypes[0]);
- collections.putIfAbsent(aType, mapping);
- return mapping;
- }
- return null;
- }
-
- // has JSon API a method for this type
- public static boolean isPrimitive(final Type type) {
- if (type == String.class) {
- return true;
- } else if (type == char.class || type == Character.class) {
- return true;
- } else if (type == long.class || type == Long.class) {
- return true;
- } else if (type == int.class || type == Integer.class
- || type == byte.class || type == Byte.class
- || type == short.class || type == Short.class) {
- return true;
- } else if (type == double.class || type == Double.class
- || type == float.class || type == Float.class) {
- return true;
- } else if (type == boolean.class || type == Boolean.class) {
- return true;
- } else if (type == BigDecimal.class) {
- return true;
- } else if (type == BigInteger.class) {
- return true;
- }
- return false;
- }
-
- public ClassMapping getClassMapping(final Type clazz) {
- return classes.get(clazz);
- }
-
- public ClassMapping findOrCreateClassMapping(final Type clazz) {
- ClassMapping classMapping = classes.get(clazz);
- if (classMapping == null) {
- if (!Class.class.isInstance(clazz) || Map.class.isAssignableFrom(Class.class.cast(clazz))) {
- return null;
- }
-
- classMapping = createClassMapping(Class.class.cast(clazz));
- final ClassMapping existing = classes.putIfAbsent(clazz, classMapping);
- if (existing != null) {
- classMapping = existing;
- }
- }
- return classMapping;
- }
-
- private ClassMapping createClassMapping(final Class<?> clazz) {
- try {
- final Map<String, Getter> getters = fieldOrdering != null ?
- new TreeMap<String, Getter>(fieldOrdering) : new HashMap<String, Getter>();
- final Map<String, Setter> setters = fieldOrdering != null ?
- new TreeMap<String, Setter>(fieldOrdering) : new HashMap<String, Setter>();
-
- final PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
- for (final PropertyDescriptor descriptor : propertyDescriptors) {
- final Method writeMethod = descriptor.getWriteMethod();
- final FleeceIgnore writeIgnore = writeMethod != null ? writeMethod.getAnnotation(FleeceIgnore.class) : null;
- if (writeMethod != null && writeMethod.getDeclaringClass() != Object.class
- && (writeIgnore == null || writeIgnore.minVersion() >= 0)) {
- if (descriptor.getName().equals("metaClass")) {
- continue;
- }
- final Type param = writeMethod.getGenericParameterTypes()[0];
- setters.put(descriptor.getName(), new Setter(
- writeMethod,
- isPrimitive(param),
- param,
- findConverter(writeMethod),
- writeIgnore != null ? writeIgnore.minVersion() : -1));
- }
-
- final Method readMethod = descriptor.getReadMethod();
- final FleeceIgnore readIgnore = readMethod != null ? readMethod.getAnnotation(FleeceIgnore.class) : null;
- if (readMethod != null && readMethod.getDeclaringClass() != Object.class
- && (readIgnore == null || readIgnore.minVersion() >= 0)) {
- if (descriptor.getName().equals("metaClass")) {
- continue;
- }
-
- final Class<?> returnType = readMethod.getReturnType();
- getters.put(descriptor.getName(), new Getter(
- readMethod,
- isPrimitive(returnType),
- returnType.isArray(),
- Collection.class.isAssignableFrom(returnType),
- Map.class.isAssignableFrom(returnType),
- findConverter(readMethod),
- readIgnore != null ? readIgnore.minVersion() : -1));
- }
- }
-
- return new ClassMapping(clazz, getters, setters);
- } catch (final IntrospectionException e) {
- throw new MapperException(e);
- }
- }
-
- private static Converter findConverter(final Method method) {
- Converter converter = null;
- if (method.getAnnotation(FleeceConverter.class) != null) {
- try {
- converter = method.getAnnotation(FleeceConverter.class).value().newInstance();
- } catch (final Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
- return converter;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/test/java/org/apache/fleece/mapper/LiteralTest.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/test/java/org/apache/fleece/mapper/LiteralTest.java b/fleece-mapper/src/test/java/org/apache/fleece/mapper/LiteralTest.java
deleted file mode 100644
index 9ba12d9..0000000
--- a/fleece-mapper/src/test/java/org/apache/fleece/mapper/LiteralTest.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper;
-
-import org.junit.Test;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Comparator;
-
-import static org.junit.Assert.assertEquals;
-
-public class LiteralTest {
- @Test
- public void writeReadNumbers() {
- NumberClass nc = new NumberClass();
- final StringWriter sw = new StringWriter();
- nc.setBg(new BigDecimal("123.123"));
- nc.setBi(new BigInteger("123"));
- nc.setDoubleNumber(123.123);
- nc.setBool(true);
- nc.setByteNumber((byte) 1);
- nc.setFloatNumber(123);
- nc.setShortNumber((short) 1);
- nc.setLongNumber(123L);
- nc.setIntNumber(123);
-
- final String expectedJson = "{\"shortNumber\":1,\"byteNumber\":1,\"intNumber\":123,\"floatNumber\":123.0,\"bg\":123.123,\"bool\":true,\"bi\":123,\"longNumber\":123,\"doubleNumber\":123.123}";
- final Comparator<String> attributeOrder = new Comparator<String>() {
- @Override
- public int compare(final String o1, final String o2) {
- return expectedJson.indexOf(o1) - expectedJson.indexOf(o2);
- }
- };
- new MapperBuilder().setAttributeOrder(attributeOrder).build().writeObject(nc, sw);
- assertEquals(expectedJson, sw.toString());
- final NumberClass read = new MapperBuilder().setAttributeOrder(attributeOrder).build()
- .readObject(new StringReader(sw.toString()), NumberClass.class);
- assertEquals(nc, read);
-
- }
-
- @Test(expected = NumberFormatException.class)
- public void writeReadNumbersInf() {
- NumberClass nc = new NumberClass();
- final StringWriter sw = new StringWriter();
- nc.setBg(new BigDecimal("123.123"));
- nc.setBi(new BigInteger("123"));
- nc.setDoubleNumber(Double.POSITIVE_INFINITY);
- nc.setBool(true);
- nc.setByteNumber((byte) 1);
- nc.setFloatNumber(123);
- nc.setShortNumber((short) 1);
- nc.setLongNumber(123L);
- nc.setIntNumber(123);
-
- new MapperBuilder().build().writeObject(nc, sw);
-
- }
-
- @Test(expected = NumberFormatException.class)
- public void writeReadNumbersNaN() {
- NumberClass nc = new NumberClass();
- final StringWriter sw = new StringWriter();
- nc.setBg(new BigDecimal("123.123"));
- nc.setBi(new BigInteger("123"));
- nc.setDoubleNumber(Double.NaN);
- nc.setBool(true);
- nc.setByteNumber((byte) 1);
- nc.setFloatNumber(123);
- nc.setShortNumber((short) 1);
- nc.setLongNumber(123L);
- nc.setIntNumber(123);
-
- new MapperBuilder().build().writeObject(nc, sw);
-
- }
-
- public static class NumberClass {
- private BigDecimal bg;
- private BigInteger bi;
- private int intNumber;
- private long longNumber;
- private byte byteNumber;
- private short shortNumber;
- private double doubleNumber;
- private float floatNumber;
- private boolean bool;
-
- public BigDecimal getBg() {
- return bg;
- }
-
- public void setBg(BigDecimal bg) {
- this.bg = bg;
- }
-
- public BigInteger getBi() {
- return bi;
- }
-
- public void setBi(BigInteger bi) {
- this.bi = bi;
- }
-
- public int getIntNumber() {
- return intNumber;
- }
-
- public void setIntNumber(int intNumber) {
- this.intNumber = intNumber;
- }
-
- public long getLongNumber() {
- return longNumber;
- }
-
- public void setLongNumber(long longNumber) {
- this.longNumber = longNumber;
- }
-
- public byte getByteNumber() {
- return byteNumber;
- }
-
- public void setByteNumber(byte byteNumber) {
- this.byteNumber = byteNumber;
- }
-
- public short getShortNumber() {
- return shortNumber;
- }
-
- public void setShortNumber(short shortNumber) {
- this.shortNumber = shortNumber;
- }
-
- public double getDoubleNumber() {
- return doubleNumber;
- }
-
- public void setDoubleNumber(double doubleNumber) {
- this.doubleNumber = doubleNumber;
- }
-
- public float getFloatNumber() {
- return floatNumber;
- }
-
- public void setFloatNumber(float floatNumber) {
- this.floatNumber = floatNumber;
- }
-
- public boolean isBool() {
- return bool;
- }
-
- public void setBool(boolean bool) {
- this.bool = bool;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((bg == null) ? 0 : bg.hashCode());
- result = prime * result + ((bi == null) ? 0 : bi.hashCode());
- result = prime * result + (bool ? 1231 : 1237);
- result = prime * result + byteNumber;
- long temp;
- temp = Double.doubleToLongBits(doubleNumber);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- result = prime * result + Float.floatToIntBits(floatNumber);
- result = prime * result + intNumber;
- result = prime * result + (int) (longNumber ^ (longNumber >>> 32));
- result = prime * result + shortNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- NumberClass other = (NumberClass) obj;
- if (bg == null) {
- if (other.bg != null) {
- return false;
- }
- } else if (!bg.equals(other.bg)) {
- return false;
- }
- if (bi == null) {
- if (other.bi != null) {
- return false;
- }
- } else if (!bi.equals(other.bi)) {
- return false;
- }
- if (bool != other.bool) {
- return false;
- }
- if (byteNumber != other.byteNumber) {
- return false;
- }
- if (Double.doubleToLongBits(doubleNumber) != Double.doubleToLongBits(other.doubleNumber)) {
- return false;
- }
- if (Float.floatToIntBits(floatNumber) != Float.floatToIntBits(other.floatNumber)) {
- return false;
- }
- if (intNumber != other.intNumber) {
- return false;
- }
- if (longNumber != other.longNumber) {
- return false;
- }
- if (shortNumber != other.shortNumber) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "NumberClass [bg=" + bg + ", bi=" + bi + ", intNumber=" + intNumber + ", longNumber=" + longNumber + ", byteNumber=" + byteNumber + ", shortNumber=" + shortNumber + ", doubleNumber=" + doubleNumber + ", floatNumber=" + floatNumber + ", bool=" + bool + "]";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperEnhancedTest.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperEnhancedTest.java b/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperEnhancedTest.java
deleted file mode 100644
index 4f020e6..0000000
--- a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperEnhancedTest.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.concurrent.ArrayBlockingQueue;
-
-import static org.junit.Assert.assertEquals;
-
-public class MapperEnhancedTest {
-
- @Test
- public void writeNull() {
- final StringWriter sw = new StringWriter();
- new MapperBuilder().build().writeObject(null, sw);
- assertEquals("{}", sw.toString());
- }
-
- @Test
- public void writeReadChar() {
- CharClass charClass = new CharClass();
- charClass.setCharValue('G');
- charClass.setCharArr(new char[]{'G','O'});
- final StringWriter sw = new StringWriter();
-
- new MapperBuilder().build().writeObject(charClass, sw);
- assertEquals("{\"charArr\":[\"G\",\"O\"],\"charValue\":\"G\"}", sw.toString());
- CharClass read = new MapperBuilder().build().readObject(new StringReader(sw.toString()), CharClass.class);
- Assert.assertNotNull(read);
- Assert.assertEquals('G', read.getCharValue());
- Assert.assertTrue(Arrays.equals(new char[]{'G','O'}, read.getCharArr()));
- }
-
- @Test
- public void writeReadSortedMap() {
- SomaClass soseClass = new SomaClass();
- soseClass.getSoma().put("key1", "val1");
- soseClass.getSoma().put("key2", "val2");
- final StringWriter sw = new StringWriter();
-
- new MapperBuilder().build().writeObject(soseClass, sw);
- assertEquals("{\"soma\":{\"key1\":\"val1\",\"key2\":\"val2\"}}", sw.toString());
- new MapperBuilder().build().readObject(new StringReader(sw.toString()), SomaClass.class);
-
- }
-
- @Test
- public void writeReadSortedSet() {
- SoseClass soseClass = new SoseClass();
- soseClass.getSose().add("string1");
- soseClass.getSose().add("string2");
- final StringWriter sw = new StringWriter();
-
- new MapperBuilder().build().writeObject(soseClass, sw);
-
- assertEquals("{\"sose\":[\"string1\",\"string2\"]}", sw.toString());
- new MapperBuilder().build().readObject(new StringReader(sw.toString()), SoseClass.class);
-
- }
-
- @Test
- public void writeReadQueue() {
- QueueClass queueClass = new QueueClass();
- queueClass.getQueue().add("string1");
- queueClass.getQueue().add("string2");
- final StringWriter sw = new StringWriter();
-
- new MapperBuilder().build().writeObject(queueClass, sw);
-
- assertEquals("{\"queue\":[\"string1\",\"string2\"]}", sw.toString());
- new MapperBuilder().build().readObject(new StringReader(sw.toString()), QueueClass.class);
-
- }
-
- @Test
- public void writeTestclass() {
- final StringWriter sw = new StringWriter();
- final TestClass tc2 = buildTestClassInstance();
-
- final String json = "{" +
- "\"bd\":-456.4567890987654321,\"string\":\"some \\t \\u0001 unicode: ÖÄÜ pppন\"," +
- "\"dates\":[]," +
-
- "\"inner\":{" +
- "\"bd\":-456.4567890987654321," +
- "\"string\":\"some \\t \\u0001 unicode: ÖÄÜ pppন\"," +
- "\"dates\":[]," +
- "\"sose\":[\"string1\",\"string2\"]," +
- "\"map\":{\"[{key1=-100, key11=-1002, key2=100, key22=1002}, {}]\":100}" +
- "}," +
- "\"sose\":[]," +
- "\"map\":{\"[{key1=-100, key11=-1002, key2=100, key22=1002}, {}]\":200}}";
- new MapperBuilder().setAttributeOrder(new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- return json.indexOf(o1) - json.indexOf(o2);
- }
- }).build().writeObject(tc2, sw);
- assertEquals(json, sw.toString());
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void needConvertersForComplexTypes() {
- final String str = "{" +
- "\"bd\":-456.4567890987654321,\"string\":\"some \\t \\u0001 unicode: ÖÄÜ pppন\"," +
- "\"dates\":[]," +
- "\"sose\":[]," +
- "\"inner\":{" +
- "\"bd\":-456.4567890987654321," +
- "\"string\":\"some \\t \\u0001 unicode: ÖÄÜ pppন\"," +
- "\"dates\":[]," +
- "\"sose\":[\"string1\",\"string2\"]," +
- "\"map\":{\"[{key1=-100, key11=-1002, key2=100, key22=1002}, {}]\":100}" +
- "}," +
- "\"map\":{\"[{key1=-100, key11=-1002, key2=100, key22=1002}, {}]\":200}}";
-
- new MapperBuilder().build().readObject(new StringReader(str), TestClass.class);
- }
-
- private TestClass buildTestClassInstance() {
- final TestClass tc1 = new TestClass(null);
- final Map<String, Integer> m = new TreeMap<String, Integer>();
- m.put("key1", -100);
- m.put("key2", +100);
- final Map<String, Integer> m2 = new TreeMap<String, Integer>();
- m.put("key11", -1002);
- m.put("key22", +1002);
- final List<Map<String, Integer>> l = new ArrayList<Map<String, Integer>>();
- l.add(m);
- l.add(m2);
- tc1.sose.add("string1");
- tc1.sose.add("string2");
- tc1.map.put(l, 100L);
-
- final TestClass tc2 = new TestClass(tc1);
- final Map<String, Integer> m3 = new TreeMap<String, Integer>();
- m3.put("key1", -100);
- m3.put("key2", +100);
- final Map<String, Integer> m4 = new TreeMap<String, Integer>();
- m4.put("key11", -1002);
- m4.put("key22", +1002);
- final List<Map<String, Integer>> l1 = new ArrayList<Map<String, Integer>>();
- l1.add(m);
- l1.add(m2);
- tc2.map.put(l1, 200L);
- return tc2;
- }
-
- public static class QueueClass {
- private Queue<String> queue = new ArrayBlockingQueue<String>(5);
-
- public Queue<String> getQueue() {
- return queue;
- }
-
- public void setQueue(Queue<String> queue) {
- this.queue = queue;
- }
- }
-
- public static class SoseClass {
- private SortedSet<String> sose = new TreeSet<String>();
-
- public SortedSet<String> getSose() {
- return sose;
- }
-
- public void setSose(SortedSet<String> sose) {
- this.sose = sose;
- }
- }
-
- public static class SomaClass {
- private SortedMap<String, String> soma = new TreeMap<String, String>();
-
- public SortedMap<String, String> getSoma() {
- return soma;
- }
-
- public void setSoma(SortedMap<String, String> soma) {
- this.soma = soma;
- }
- }
-
- public static class CharClass {
- private char charValue;
- private char charArr[];
-
- public char[] getCharArr() {
- return charArr;
- }
-
- public void setCharArr(char[] charArr) {
- this.charArr = charArr;
- }
-
- public char getCharValue() {
- return charValue;
- }
-
- public void setCharValue(char charValue) {
- this.charValue = charValue;
- }
- }
-
- public static class TestClass {
- private List<Map<String, Date>> dates = new ArrayList<Map<String, Date>>();
- private Map<List<Map<String, Integer>>, Long> map = new HashMap<List<Map<String, Integer>>, Long>();
- private TestClass inner;
- private String string = "some \t \u0001 unicode: ÖÄÜ \u0070\u0070\u0070ন\udbff\udfff";
- private BigDecimal bd = new BigDecimal("-456.4567890987654321");
- private SortedSet<String> sose = new TreeSet<String>();
-
- public SortedSet<String> getSose() {
- return sose;
- }
-
- public void setSose(SortedSet<String> sose) {
- this.sose = sose;
- }
-
- public TestClass(final TestClass inner) {
- super();
- this.inner = inner;
- }
-
- public TestClass() {
- super();
- }
-
- public List<Map<String, Date>> getDates() {
- return dates;
- }
-
- public void setDates(final List<Map<String, Date>> dates) {
- this.dates = dates;
- }
-
- public Map<List<Map<String, Integer>>, Long> getMap() {
- return map;
- }
-
- public void setMap(final Map<List<Map<String, Integer>>, Long> map) {
- this.map = map;
- }
-
- public TestClass getInner() {
- return inner;
- }
-
- public void setInner(final TestClass inner) {
- this.inner = inner;
- }
-
- public String getString() {
- return string;
- }
-
- public void setString(final String string) {
- this.string = string;
- }
-
- public BigDecimal getBd() {
- return bd;
- }
-
- public void setBd(final BigDecimal bd) {
- this.bd = bd;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperTest.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperTest.java b/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperTest.java
deleted file mode 100644
index 6779f0b..0000000
--- a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperTest.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper;
-
-import junit.framework.AssertionFailedError;
-
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.StringWriter;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class MapperTest {
- private static final String BIG_OBJECT_STR = "{" +
- "\"name\":\"the string\"," +
- "\"integer\":56," +
- "\"longnumber\":118," +
- "\"bool\":true," +
- "\"nested\":{" +
- "\"name\":\"another value\"," +
- "\"integer\":97," +
- "\"longnumber\":34" +
- "}," +
- "\"array\":[" +
- "{" +
- "\"name\":\"a1\"," +
- "\"integer\":1," +
- "\"longnumber\":2" +
- "}," +
- "{" +
- "\"name\":\"a2\"," +
- "\"integer\":3," +
- "\"longnumber\":4" +
- "}" +
- "]," +
- "\"list\":[" +
- "{" +
- "\"name\":\"a3\"," +
- "\"integer\":5," +
- "\"longnumber\":6" +
- "}," +
- "{" +
- "\"name\":\"a4\"," +
- "\"integer\":7," +
- "\"longnumber\":8" +
- "}" +
- "]," +
- "\"primitives\":[1,2,3,4,5]," +
- "\"collectionWrapper\":[1,2,3,4,5]," +
- "\"map\":{\"uno\":true,\"duos\":false}" +
- "}";
-
- @Test
- public void writeEmptyObject() {
- final StringWriter writer = new StringWriter();
- new MapperBuilder().build().writeObject(null, writer);
- assertEquals("{}", writer.toString());
- }
-
- @Test
- public void readEmptyObject() {
- final TheObject object = new MapperBuilder().build().readObject(new ByteArrayInputStream("{}".getBytes()), TheObject.class);
- assertNotNull(object);
- assertNull(object.name);
- }
-
- @Test
- public void readEmptyArray() {
- final TheObject[] object = new MapperBuilder().build().readArray(new ByteArrayInputStream("[]".getBytes()), TheObject.class);
- assertNotNull(object);
- assertEquals(0, object.length);
- }
-
- @Test
- public void writeMap() {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new MapperBuilder().build().writeObject(new LinkedHashMap<String, Integer>() {{
- put("a", 1);
- put("b", 2);
- }}, baos);
- assertEquals("{\"a\":1,\"b\":2}", new String(baos.toByteArray()));
- }
-
- @Test
- public void writeObject() {
- final TheObject instance = new MapperBuilder().build()
- .readObject(new ByteArrayInputStream(BIG_OBJECT_STR.getBytes()), TheObject.class); // suppose reader writes but this is tested
- final StringWriter writer = new StringWriter();
- new MapperBuilder().build().writeObject(instance, writer);
- final String serialized = writer.toString();
- assertTrue(serialized.contains("\"primitives\":[1,2,3,4,5]"));
- assertTrue(serialized.contains("\"collectionWrapper\":[1,2,3,4,5]"));
- assertTrue(serialized.contains("\"bool\":true"));
-
- //Assert fail with oracle java 1.7.0_45, works well with apple java 1.6.0_65
- //assertTrue(serialized.contains("\"map\":{\"uno\":true,\"duos\":false}"));
- assertTrue(serialized.contains("\"map\":{"));
- assertTrue(serialized.contains("\"uno\":true"));
- assertTrue(serialized.contains("\"duos\":false"));
-
- TheObject instance2 = new MapperBuilder().build()
- .readObject(new ByteArrayInputStream(serialized.getBytes()), TheObject.class); // suppose reader writes but this is tested
-
- assertEquals(instance, instance2);
- }
-
- static class Bool{
- boolean bool;
-
- public boolean isBool() {
- return bool;
- }
-
- public void setBool(boolean bool) {
- this.bool = bool;
- }
-
-
- }
-
- static class Bool2{
- Map<String, Boolean> map;
-
- public Map<String, Boolean> getMap() {
- return map;
- }
-
- public void setMap(Map<String, Boolean> map) {
- this.map = map;
- }
-
-
-
-
- }
-
- @Test
- public void literal() {
-
-
-
- final Bool instance = new MapperBuilder().build()
- .readObject(new ByteArrayInputStream("{\"bool\":true}".getBytes()), Bool.class);
-
- assertTrue(instance.bool);
-
- final StringWriter writer = new StringWriter();
- new MapperBuilder().build().writeObject(instance, writer);
- final String serialized = writer.toString();
- assertEquals("{\"bool\":true}", serialized);
-
- }
-
- @Test(expected= MapperException.class)
- public void literalFail() {
-
- final Bool instance = new MapperBuilder().build()
- .readObject(new ByteArrayInputStream("{\"bool\":\"true\"}".getBytes()), Bool.class);
-
- assertTrue(instance.bool);
-
- }
-
- @Test(expected= MapperException.class)
- public void literalFail2() {
-
- final Bool2 instance = new MapperBuilder().build()
- .readObject(new ByteArrayInputStream("{\"map\":{\"key\":\"true\"}}".getBytes()), Bool2.class);
-
-
-
- }
-
- @Test
- public void writeArray() {
- { // integer
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new MapperBuilder().build().writeArray(new Integer[]{1, 2}, baos);
- assertEquals("[1,2]", new String(baos.toByteArray()));
- }
- { // object
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new MapperBuilder().build().writeArray(new Pair[]{new Pair(1, "a"), new Pair(2, "b")}, baos);
- try {
- assertEquals("[{\"s\":\"a\",\"i\":1},{\"s\":\"b\",\"i\":2}]", new String(baos.toByteArray()));
- } catch (final AssertionFailedError afe) { // a bit lazy but to avoid field ordering on java > 6
- assertEquals("[{\"i\":1,\"s\":\"a\"},{\"i\":2,\"s\":\"b\"}]", new String(baos.toByteArray()));
- }
- }
- }
-
- @Test
- public void readObject() {
- final TheObject object = new MapperBuilder().build().readObject(new ByteArrayInputStream(BIG_OBJECT_STR.getBytes()), TheObject.class);
-
- assertNotNull(object);
- assertEquals("the string", object.name);
- assertEquals(56, object.integer);
- assertEquals(118, object.longnumber);
- assertTrue(object.bool);
- assertEquals("another value", object.nested.name);
- assertEquals(97, object.nested.integer);
- assertEquals(34, object.nested.longnumber);
- assertFalse(object.nested.bool);
- assertNotNull(object.array);
- assertEquals(2, object.array.length);
- assertEquals("a1", object.array[0].name);
- assertEquals(1, object.array[0].integer);
- assertEquals(2, object.array[0].longnumber);
- assertEquals("a2", object.array[1].name);
- assertEquals(3, object.array[1].integer);
- assertEquals(4, object.array[1].longnumber);
- assertEquals("a3", object.list.get(0).name);
- assertEquals(5, object.list.get(0).integer);
- assertEquals(6, object.list.get(0).longnumber);
- assertEquals("a4", object.list.get(1).name);
- assertEquals(7, object.list.get(1).integer);
- assertEquals(8, object.list.get(1).longnumber);
- assertEquals(5, object.primitives.length);
- for (int i = 0; i < object.primitives.length; i++) {
- assertEquals(i + 1, object.primitives[i]);
- }
- assertNotNull(object.collectionWrapper);
- assertEquals(5, object.collectionWrapper.size());
- for (int i = 0; i < object.collectionWrapper.size(); i++) {
- assertEquals(i + 1, object.collectionWrapper.get(i).intValue());
- }
- assertNotNull(object.map);
- assertEquals(2, object.map.size());
- assertTrue(object.map.containsKey("uno"));
- assertTrue(object.map.containsKey("duos"));
- assertTrue(object.map.get("uno"));
- assertFalse(object.map.get("duos"));
- }
-
- @Test
- public void readArray() {
- final TheObject[] object = new MapperBuilder().build().readArray(new ByteArrayInputStream(("[" +
- "{" +
- "\"name\":\"a3\"," +
- "\"integer\":5," +
- "\"longnumber\":6" +
- "}," +
- "{" +
- "\"name\":\"a4\"," +
- "\"integer\":7," +
- "\"longnumber\":8" +
- "}" +
- "]").getBytes()), TheObject.class);
- assertNotNull(object);
- assertEquals(2, object.length);
- assertEquals("a3", object[0].name);
- assertEquals(5, object[0].integer);
- assertEquals(6, object[0].longnumber);
- assertEquals("a4", object[1].name);
- assertEquals(7, object[1].integer);
- assertEquals(8, object[1].longnumber);
- }
-
- @Test
- public void converters() {
- final String json = "{\"s\":\"eceelf\"}";
- final Converted v = new MapperBuilder().build().readObject(new ByteArrayInputStream(json.getBytes()), Converted.class);
- assertEquals("fleece", v.getS());
- final StringWriter stream = new StringWriter();
- new MapperBuilder().build().writeObject(v, stream);
- assertEquals(json, stream.toString());
- }
-
- public static class TheObject {
- private String name;
- private int integer;
- private long longnumber;
- private boolean bool;
- private TheObject nested;
- private TheObject[] array;
- private List<TheObject> list;
- private int[] primitives;
- private List<Integer> collectionWrapper;
- private Map<String, Boolean> map;
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public int getInteger() {
- return integer;
- }
-
- public void setInteger(final int integer) {
- this.integer = integer;
- }
-
- public long getLongnumber() {
- return longnumber;
- }
-
- public void setLongnumber(final long longnumber) {
- this.longnumber = longnumber;
- }
-
- public boolean isBool() {
- return bool;
- }
-
- public void setBool(final boolean bool) {
- this.bool = bool;
- }
-
- public TheObject getNested() {
- return nested;
- }
-
- public void setNested(final TheObject nested) {
- this.nested = nested;
- }
-
- public TheObject[] getArray() {
- return array;
- }
-
- public void setArray(final TheObject[] array) {
- this.array = array;
- }
-
- public List<TheObject> getList() {
- return list;
- }
-
- public void setList(final List<TheObject> list) {
- this.list = list;
- }
-
- public int[] getPrimitives() {
- return primitives;
- }
-
- public void setPrimitives(final int[] primitives) {
- this.primitives = primitives;
- }
-
- public List<Integer> getCollectionWrapper() {
- return collectionWrapper;
- }
-
- public void setCollectionWrapper(final List<Integer> collectionWrapper) {
- this.collectionWrapper = collectionWrapper;
- }
-
- public Map<String, Boolean> getMap() {
- return map;
- }
-
- public void setMap(final Map<String, Boolean> map) {
- this.map = map;
- }
-
- @Override
- public String toString() {
- return "TheObject [name=" + name + ", integer=" + integer + ", longnumber=" + longnumber + ", bool=" + bool + ", nested="
- + nested + ", array=" + Arrays.toString(array) + ", list=" + list + ", primitives=" + Arrays.toString(primitives)
- + ", collectionWrapper=" + collectionWrapper + ", map=" + map + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(array);
- result = prime * result + (bool ? 1231 : 1237);
- result = prime * result + ((collectionWrapper == null) ? 0 : collectionWrapper.hashCode());
- result = prime * result + integer;
- result = prime * result + ((list == null) ? 0 : list.hashCode());
- result = prime * result + (int) (longnumber ^ (longnumber >>> 32));
- result = prime * result + ((map == null) ? 0 : map.hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((nested == null) ? 0 : nested.hashCode());
- result = prime * result + Arrays.hashCode(primitives);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TheObject other = (TheObject) obj;
- if (!Arrays.equals(array, other.array))
- return false;
- if (bool != other.bool)
- return false;
- if (collectionWrapper == null) {
- if (other.collectionWrapper != null)
- return false;
- } else if (!collectionWrapper.equals(other.collectionWrapper))
- return false;
- if (integer != other.integer)
- return false;
- if (list == null) {
- if (other.list != null)
- return false;
- } else if (!list.equals(other.list))
- return false;
- if (longnumber != other.longnumber)
- return false;
- if (map == null) {
- if (other.map != null)
- return false;
- } else if (!map.equals(other.map))
- return false;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (nested == null) {
- if (other.nested != null)
- return false;
- } else if (!nested.equals(other.nested))
- return false;
- if (!Arrays.equals(primitives, other.primitives))
- return false;
- return true;
- }
-
-
- }
-
- public static class Pair {
- private final int i;
- private final String s;
-
- public Pair(final int i, final String s) {
- this.i = i;
- this.s = s;
- }
-
- public int getI() {
- return i;
- }
-
- public String getS() {
- return s;
- }
- }
-
- public static class Converted {
- private String s;
-
- @FleeceConverter(ReverseConverter.class)
- public String getS() {
- return s;
- }
-
- @FleeceConverter(ReverseConverter.class)
- public void setS(String v) {
- s = v;
- }
- }
-
- public static class ReverseConverter implements Converter<String> {
- @Override
- public String toString(final String instance) {
- return new StringBuilder(instance).reverse().toString();
- }
-
- @Override
- public String fromString(final String text) {
- return toString(text);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperVersionTest.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperVersionTest.java b/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperVersionTest.java
deleted file mode 100644
index 05e3ebb..0000000
--- a/fleece-mapper/src/test/java/org/apache/fleece/mapper/MapperVersionTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper;
-
-import org.junit.Test;
-
-import java.io.StringWriter;
-
-import static org.junit.Assert.assertEquals;
-
-public class MapperVersionTest {
- @Test
- public void version() {
- { // no version
- final Mapper mapper = new MapperBuilder().build();
- final Versioned versioned = new Versioned();
- versioned.name = "foo";
- final StringWriter writer = new StringWriter();
- mapper.writeObject(versioned, writer);
- assertEquals("{\"name\":\"foo\"}", writer.toString());
- }
- { // version ko
- for (int i = 0; i < 2; i++) {
- final Mapper mapper = new MapperBuilder().setVersion(i).build();
- final Versioned versioned = new Versioned();
- versioned.name = "foo";
- final StringWriter writer = new StringWriter();
- mapper.writeObject(versioned, writer);
- assertEquals("{\"name\":\"foo\"}", writer.toString());
- }
- }
- { // version ok
- for (int i = 2; i < 4; i++) {
- final Mapper mapper = new MapperBuilder().setVersion(i).build();
- final Versioned versioned = new Versioned();
- versioned.name = "foo";
- final StringWriter writer = new StringWriter();
- mapper.writeObject(versioned, writer);
- assertEquals("{}", writer.toString());
- }
- }
- }
-
- public static class Versioned {
- private String name;
-
- @FleeceIgnore(minVersion = 2)
- public String getName() {
- return name;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/fleece-mapper/src/test/java/org/apache/fleece/mapper/converter/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/fleece-mapper/src/test/java/org/apache/fleece/mapper/converter/EnumConverterTest.java b/fleece-mapper/src/test/java/org/apache/fleece/mapper/converter/EnumConverterTest.java
deleted file mode 100644
index 501599c..0000000
--- a/fleece-mapper/src/test/java/org/apache/fleece/mapper/converter/EnumConverterTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fleece.mapper.converter;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class EnumConverterTest {
- @Test
- public void fromEnumToString() {
- assertEquals("B", new EnumConverter<AnEnum>(AnEnum.class).toString(AnEnum.B));
- }
-
- @Test
- public void fromStringToEnum() {
- assertEquals(AnEnum.B, new EnumConverter<AnEnum>(AnEnum.class).fromString("B"));
- }
-
- public enum AnEnum {
- A, B
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-core/pom.xml b/johnzon-core/pom.xml
new file mode 100644
index 0000000..06fb184
--- /dev/null
+++ b/johnzon-core/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>johnzon</artifactId>
+ <groupId>org.apache.johnzon</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>johnzon-core</artifactId>
+ <name>Johnzon :: Core</name>
+
+ <properties>
+ <staging.directory>${project.parent.reporting.outputDirectory}</staging.directory>
+ </properties>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/src/main/java/org/apache/johnzon/core/BufferStrategy.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/BufferStrategy.java b/johnzon-core/src/main/java/org/apache/johnzon/core/BufferStrategy.java
new file mode 100644
index 0000000..c37ecfb
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/BufferStrategy.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.core;
+
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+public enum BufferStrategy {
+ BY_INSTANCE {
+ @Override
+ public BufferProvider<char[]> newCharProvider(final int size) {
+ return new CharBufferByInstanceProvider(size);
+ }
+
+ @Override
+ public BufferProvider<StringBuilder> newStringBuilderProvider(final int size) {
+ return new StringBuilderByInstanceProvider(size);
+ }
+ },
+ THREAD_LOCAL {
+ @Override
+ public BufferProvider<char[]> newCharProvider(final int size) {
+ return new CharBufferThreadLocalProvider(size);
+ }
+
+ @Override
+ public BufferProvider<StringBuilder> newStringBuilderProvider(final int size) {
+ return new StringBuilderThreadLocalProvider(size);
+ }
+ },
+ QUEUE {
+ @Override
+ public BufferProvider<char[]> newCharProvider(final int size) {
+ return new CharBufferQueueProvider(size);
+ }
+
+ @Override
+ public BufferProvider<StringBuilder> newStringBuilderProvider(final int size) {
+ return new StringBuilderQueueProvider(size);
+ }
+ },
+ SINGLETON {
+ @Override
+ public BufferProvider<char[]> newCharProvider(final int size) {
+ return new CharBufferSingletonProvider(size);
+ }
+
+ @Override
+ public BufferProvider<StringBuilder> newStringBuilderProvider(final int size) {
+ return new StringBuilderSingletonProvider(size);
+ }
+ };
+
+ public abstract BufferProvider<char[]> newCharProvider(int size);
+ public abstract BufferProvider<StringBuilder> newStringBuilderProvider(int size);
+
+ public static interface BufferProvider<T> extends Serializable {
+ T newBuffer();
+
+ void release(T value);
+ }
+
+ private static class CharBufferSingletonProvider extends SingletonProvider<char[]> {
+ public CharBufferSingletonProvider(final int size) {
+ super(size);
+ }
+
+ @Override
+ protected char[] newInstance(int size) {
+ return new char[size];
+ }
+
+ @Override
+ public void release(final char[] value) {
+ // no-op
+ }
+ }
+
+ private static class StringBuilderSingletonProvider extends SingletonProvider<StringBuilder> {
+ public StringBuilderSingletonProvider(final int size) {
+ super(size);
+ }
+
+ @Override
+ protected StringBuilder newInstance(final int size) {
+ return new StringBuilder(size);
+ }
+
+ @Override
+ public void release(final StringBuilder value) {
+ value.setLength(0);
+ }
+ }
+
+ private static abstract class SingletonProvider<T> implements BufferProvider<T> {
+ protected final T buffer;
+
+ public SingletonProvider(final int size) {
+ buffer = newInstance(size);
+ }
+
+ protected abstract T newInstance(int size);
+
+ @Override
+ public T newBuffer() {
+ return buffer;
+ }
+
+ @Override
+ public void release(final T value) {
+ // no-op
+ }
+ }
+
+ private static abstract class ThreadLocalProvider<T> implements BufferProvider<T> {
+ private final ThreadLocalBufferCache<T> cache;
+
+ public ThreadLocalProvider(final int size) {
+ cache = new ThreadLocalBufferCache<T>(size) {
+ @Override
+ protected T newValue(int defaultSize) {
+ return newInstance(size);
+ }
+ };
+ }
+
+ protected abstract T newInstance(int size);
+
+ @Override
+ public T newBuffer() {
+ return cache.getCache();
+ }
+
+ @Override
+ public void release(final T value) {
+ cache.release(value);
+ }
+ }
+
+ private static class CharBufferThreadLocalProvider extends ThreadLocalProvider<char[]> {
+ public CharBufferThreadLocalProvider(int size) {
+ super(size);
+ }
+
+ @Override
+ protected char[] newInstance(final int size) {
+ return new char[size];
+ }
+ }
+
+ private static class StringBuilderThreadLocalProvider extends ThreadLocalProvider<StringBuilder> {
+ public StringBuilderThreadLocalProvider(int size) {
+ super(size);
+ }
+
+ @Override
+ protected StringBuilder newInstance(final int size) {
+ return new StringBuilder(size);
+ }
+
+ @Override
+ public void release(final StringBuilder value) {
+ value.setLength(0);
+ super.release(value);
+ }
+ }
+
+ private static class CharBufferByInstanceProvider implements BufferProvider<char[]> {
+ private final int size;
+
+ public CharBufferByInstanceProvider(final int size) {
+ this.size = size;
+ }
+
+ @Override
+ public char[] newBuffer() {
+ return new char[size];
+ }
+
+ @Override
+ public void release(final char[] value) {
+ // no-op
+ }
+ }
+
+ private static class StringBuilderByInstanceProvider implements BufferProvider<StringBuilder> {
+ private final int size;
+
+ public StringBuilderByInstanceProvider(final int size) {
+ this.size = size;
+ }
+
+ @Override
+ public StringBuilder newBuffer() {
+ return new StringBuilder(size);
+ }
+
+ @Override
+ public void release(final StringBuilder value) {
+ // no-op
+ }
+ }
+
+ private static abstract class QueueProvider<T> implements BufferProvider<T> {
+ private final int size;
+ private final ConcurrentLinkedQueue<T> queue = new ConcurrentLinkedQueue<T>();
+
+ public QueueProvider(final int size) {
+ this.size = size;
+ }
+
+ protected abstract T newInstance(int size);
+
+ @Override
+ public T newBuffer() {
+ final T buffer = queue.poll();
+ if (buffer == null) {
+ return newInstance(size);
+ }
+ return buffer;
+ }
+
+ @Override
+ public void release(final T value) {
+ queue.offer(value);
+ }
+ }
+
+ private static class CharBufferQueueProvider extends QueueProvider<char[]> {
+ public CharBufferQueueProvider(final int size) {
+ super(size);
+ }
+
+ @Override
+ protected char[] newInstance(int size) {
+ return new char[size];
+ }
+ }
+
+ private static class StringBuilderQueueProvider extends QueueProvider<StringBuilder> {
+ public StringBuilderQueueProvider(final int size) {
+ super(size);
+ }
+
+ @Override
+ protected StringBuilder newInstance(int size) {
+ return new StringBuilder(size);
+ }
+
+ @Override
+ public void release(final StringBuilder value) {
+ value.setLength(0);
+ super.release(value);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
new file mode 100644
index 0000000..5dfd839
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.core;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonValue;
+
+class JsonArrayBuilderImpl implements JsonArrayBuilder, Serializable {
+ private List<JsonValue> tmpList;
+
+ @Override
+ public JsonArrayBuilder add(final JsonValue value) {
+ addValue(value);
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final String value) {
+ addValue(new JsonStringImpl(value));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final BigDecimal value) {
+ addValue(new JsonNumberImpl(value));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final BigInteger value) {
+ addValue(new JsonNumberImpl(new BigDecimal(value)));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final int value) {
+ addValue(new JsonLongImpl(value));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final long value) {
+ addValue(new JsonLongImpl(value));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final double value) {
+ addValue(new JsonDoubleImpl(value));
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final boolean value) {
+ addValue(value ? JsonValue.TRUE : JsonValue.FALSE);
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder addNull() {
+ addValue(JsonValue.NULL);
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final JsonObjectBuilder builder) {
+ addValue(builder.build());
+ return this;
+ }
+
+ @Override
+ public JsonArrayBuilder add(final JsonArrayBuilder builder) {
+ addValue(builder.build());
+ return this;
+ }
+
+ private void addValue(JsonValue value){
+ if (value == null) {
+ throw npe();
+ }
+
+ if(tmpList==null){
+ tmpList=new ArrayList<JsonValue>();
+ }
+
+ tmpList.add(value);
+ }
+
+ @Override
+ public JsonArray build() {
+
+ if(tmpList == null) {
+ return new JsonArrayImpl(Collections.EMPTY_LIST);
+ } else {
+ List<JsonValue> dump = (Collections.unmodifiableList(tmpList));
+ tmpList=null;
+ return new JsonArrayImpl(dump);
+ }
+
+ }
+
+ private static NullPointerException npe() {
+ throw new NullPointerException("value/builder must not be null");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayImpl.java
new file mode 100644
index 0000000..809d709
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayImpl.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.core;
+
+import java.io.Serializable;
+import java.util.AbstractList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonString;
+import javax.json.JsonValue;
+
+class JsonArrayImpl extends AbstractList<JsonValue> implements JsonArray, Serializable {
+ private Integer hashCode = null;
+ private final List<JsonValue> unmodifieableBackingList;
+
+ JsonArrayImpl(List<JsonValue> backingList) {
+ super();
+ this.unmodifieableBackingList = backingList;
+ }
+
+
+
+ private <T> T value(final int idx, final Class<T> type) {
+ if (idx > unmodifieableBackingList.size()) {
+ throw new IndexOutOfBoundsException(idx + "/" + unmodifieableBackingList.size());
+ }
+ return type.cast(unmodifieableBackingList.get(idx));
+ }
+
+
+
+ @Override
+ public JsonObject getJsonObject(final int index) {
+ return value(index, JsonObject.class);
+ }
+
+ @Override
+ public JsonArray getJsonArray(final int index) {
+ return value(index, JsonArray.class);
+ }
+
+ @Override
+ public JsonNumber getJsonNumber(final int index) {
+ return value(index, JsonNumber.class);
+ }
+
+ @Override
+ public JsonString getJsonString(final int index) {
+ return value(index, JsonString.class);
+ }
+
+ @Override
+ public <T extends JsonValue> List<T> getValuesAs(final Class<T> clazz) {
+ return (List<T>) unmodifieableBackingList;
+ }
+
+ @Override
+ public String getString(final int index) {
+ return value(index, JsonString.class).getString();
+ }
+
+ @Override
+ public String getString(final int index, final String defaultValue) {
+ try {
+ return getString(index);
+ } catch (final IndexOutOfBoundsException ioobe) {
+ return defaultValue;
+ }
+ }
+
+ @Override
+ public int getInt(final int index) {
+ return value(index, JsonNumber.class).intValue();
+ }
+
+ @Override
+ public int getInt(final int index, final int defaultValue) {
+ try {
+ return getInt(index);
+ } catch (final IndexOutOfBoundsException ioobe) {
+ return defaultValue;
+ }
+ }
+
+ @Override
+ public boolean getBoolean(final int index) {
+ return value(index, JsonValue.class) == JsonValue.TRUE;
+ }
+
+ @Override
+ public boolean getBoolean(final int index, final boolean defaultValue) {
+ try {
+ return getBoolean(index);
+ } catch (final IndexOutOfBoundsException ioobe) {
+ return defaultValue;
+ }
+ }
+
+ @Override
+ public boolean isNull(final int index) {
+ return value(index, JsonValue.class) == JsonValue.NULL;
+ }
+
+ @Override
+ public ValueType getValueType() {
+ return ValueType.ARRAY;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder("[");
+ final Iterator<JsonValue> it = unmodifieableBackingList.iterator();
+ boolean hasNext = it.hasNext();
+ while (hasNext) {
+ final JsonValue jsonValue = it.next();
+ if (JsonString.class.isInstance(jsonValue)) {
+ builder.append(jsonValue.toString());
+ } else {
+ builder.append(jsonValue != JsonValue.NULL ? jsonValue.toString() : JsonChars.NULL);
+ }
+ hasNext = it.hasNext();
+ if (hasNext) {
+ builder.append(",");
+ }
+ }
+ return builder.append(']').toString();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return JsonArrayImpl.class.isInstance(obj) && unmodifieableBackingList.equals(JsonArrayImpl.class.cast(obj).unmodifieableBackingList);
+ }
+
+
+ @Override
+ public int hashCode() {
+ Integer h=hashCode;
+ if (h == null) {
+ h = unmodifieableBackingList.hashCode();
+ h=hashCode;
+ }
+ return h;
+ }
+
+ @Override
+ public JsonValue get(int index) {
+ return unmodifieableBackingList.get(index);
+ }
+
+ @Override
+ public int size() {
+ return unmodifieableBackingList.size();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/src/main/java/org/apache/johnzon/core/JsonBuilderFactoryImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonBuilderFactoryImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonBuilderFactoryImpl.java
new file mode 100644
index 0000000..e84a37d
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonBuilderFactoryImpl.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.core;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonBuilderFactory;
+import javax.json.JsonObjectBuilder;
+
+class JsonBuilderFactoryImpl implements JsonBuilderFactory {
+ private final Map<String, Object> internalConfig = new HashMap<String, Object>();
+ private static final String[] SUPPORTED_CONFIG_KEYS = new String[] {
+ //nothing yet
+
+ };
+
+ JsonBuilderFactoryImpl(final Map<String, ?> config) {
+ if (config != null) {
+
+ for (final String configKey : SUPPORTED_CONFIG_KEYS) {
+ if (config.containsKey(configKey)) {
+ internalConfig.put(configKey, config.get(configKey));
+ }
+ }
+ }
+ }
+
+ @Override
+ public JsonObjectBuilder createObjectBuilder() {
+ return new JsonObjectBuilderImpl();
+ }
+
+ @Override
+ public JsonArrayBuilder createArrayBuilder() {
+ return new JsonArrayBuilderImpl();
+ }
+
+ @Override
+ public Map<String, ?> getConfigInUse() {
+ return Collections.unmodifiableMap(internalConfig);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-johnzon/blob/6e86a53e/johnzon-core/src/main/java/org/apache/johnzon/core/JsonChars.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonChars.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonChars.java
new file mode 100644
index 0000000..1e36913
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonChars.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.johnzon.core;
+
+import javax.json.stream.JsonParser.Event;
+
+public interface JsonChars {
+ char EOF = Character.MIN_VALUE;
+
+ char START_OBJECT_CHAR = '{';
+ char END_OBJECT_CHAR = '}';
+ char START_ARRAY_CHAR = '[';
+ char END_ARRAY_CHAR = ']';
+ char QUOTE_CHAR = '"';
+ char COMMA_CHAR = ',';
+ char KEY_SEPARATOR = ':';
+
+ char EOL = '\n';
+ char SPACE = ' ';
+
+ char TRUE_T = 't';
+ char TRUE_R = 'r';
+ char TRUE_U = 'u';
+ char TRUE_E = 'e';
+ char FALSE_F = 'f';
+ char FALSE_A = 'a';
+ char FALSE_L = 'l';
+ char FALSE_S = 's';
+ char FALSE_E = 'e';
+ char NULL_N = 'n';
+ char NULL_U = 'u';
+ char NULL_L = 'l';
+
+ char ZERO = '0';
+ char NINE = '9';
+ char DOT = '.';
+ char MINUS = '-';
+ char PLUS = '+';
+ char EXP_LOWERCASE = 'e';
+ char EXP_UPPERCASE = 'E';
+ char ESCAPE_CHAR = '\\';
+
+ char TAB = '\t';
+ char BACKSPACE = '\b';
+ char FORMFEED = '\f';
+ char CR = '\r';
+
+ String NULL = "null".intern();
+
+ static final byte START_ARRAY = (byte) Event.START_ARRAY.ordinal();
+ static final byte START_OBJECT = (byte) Event.START_OBJECT.ordinal();
+ static final byte KEY_NAME=(byte) Event.KEY_NAME.ordinal();
+ static final byte VALUE_STRING=(byte) Event.VALUE_STRING.ordinal();
+ static final byte VALUE_NUMBER=(byte) Event.VALUE_NUMBER.ordinal();
+ static final byte VALUE_TRUE=(byte) Event.VALUE_TRUE.ordinal();
+ static final byte VALUE_FALSE=(byte) Event.VALUE_FALSE.ordinal();
+ static final byte VALUE_NULL=(byte) Event.VALUE_NULL.ordinal();
+ static final byte END_OBJECT=(byte) Event.END_OBJECT.ordinal();
+ static final byte END_ARRAY=(byte) Event.END_ARRAY.ordinal();
+
+ static final byte COMMA_EVENT=Byte.MAX_VALUE;
+ static final byte KEY_SEPARATOR_EVENT=Byte.MIN_VALUE;
+
+ static final Event[] EVT_MAP =Event.values();
+
+}