diff --git a/pom.xml b/pom.xml
index 28b826d7..d42cf03a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,11 @@
+
+
+ com.massivecraft.massivecore
+ MassiveXlib
+ org.spigotmc
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSON.java b/src/com/massivecraft/massivecore/xlib/bson/BSON.java
deleted file mode 100644
index 1f578113..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSON.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// BSON.java
-
-package com.massivecraft.massivecore.xlib.bson;
-
-import com.massivecraft.massivecore.xlib.bson.util.ClassMap;
-
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.logging.Logger;
-import java.util.regex.Pattern;
-
-@SuppressWarnings({"rawtypes"})
-public class BSON {
-
- static final Logger LOGGER = Logger.getLogger( "org.bson.BSON" );
-
- // ---- basics ----
-
- public static final byte EOO = 0;
- public static final byte NUMBER = 1;
- public static final byte STRING = 2;
- public static final byte OBJECT = 3;
- public static final byte ARRAY = 4;
- public static final byte BINARY = 5;
- public static final byte UNDEFINED = 6;
- public static final byte OID = 7;
- public static final byte BOOLEAN = 8;
- public static final byte DATE = 9;
- public static final byte NULL = 10;
- public static final byte REGEX = 11;
- public static final byte REF = 12;
- public static final byte CODE = 13;
- public static final byte SYMBOL = 14;
- public static final byte CODE_W_SCOPE = 15;
- public static final byte NUMBER_INT = 16;
- public static final byte TIMESTAMP = 17;
- public static final byte NUMBER_LONG = 18;
-
- public static final byte MINKEY = -1;
- public static final byte MAXKEY = 127;
-
- // --- binary types
- /*
- these are binary types
- so the format would look like
- <...>
- */
-
- public static final byte B_GENERAL = 0;
- public static final byte B_FUNC = 1;
- public static final byte B_BINARY = 2;
- public static final byte B_UUID = 3;
-
- // ---- regular expression handling ----
-
- /** Converts a string of regular expression flags from the database in Java regular
- * expression flags.
- * @param flags flags from database
- * @return the Java flags
- */
- public static int regexFlags( String flags ){
- int fint = 0;
- if ( flags == null || flags.length() == 0 )
- return fint;
-
- flags = flags.toLowerCase();
-
- for( int i=0; i 0 ) {
- buf.append( flag.flagChar );
- flags -= flag.javaFlag;
- }
- }
-
- if( flags > 0 )
- throw new IllegalArgumentException( "some flags could not be recognized." );
-
- return buf.toString();
- }
-
- private enum RegexFlag {
- CANON_EQ( Pattern.CANON_EQ, 'c', "Pattern.CANON_EQ" ),
- UNIX_LINES(Pattern.UNIX_LINES, 'd', "Pattern.UNIX_LINES" ),
- GLOBAL( GLOBAL_FLAG, 'g', null ),
- CASE_INSENSITIVE( Pattern.CASE_INSENSITIVE, 'i', null ),
- MULTILINE(Pattern.MULTILINE, 'm', null ),
- DOTALL( Pattern.DOTALL, 's', "Pattern.DOTALL" ),
- LITERAL( Pattern.LITERAL, 't', "Pattern.LITERAL" ),
- UNICODE_CASE( Pattern.UNICODE_CASE, 'u', "Pattern.UNICODE_CASE" ),
- COMMENTS( Pattern.COMMENTS, 'x', null );
-
- private static final Map byCharacter = new HashMap<>();
-
- static {
- for (RegexFlag flag : values()) {
- byCharacter.put(flag.flagChar, flag);
- }
- }
-
- public static RegexFlag getByCharacter(char ch) {
- return byCharacter.get(ch);
- }
- public final int javaFlag;
- public final char flagChar;
- public final String unsupported;
-
- RegexFlag( int f, char ch, String u ) {
- javaFlag = f;
- flagChar = ch;
- unsupported = u;
- }
- }
-
- private static void _warnUnsupportedRegex( String flag ) {
- LOGGER.info( "flag " + flag + " not supported by db." );
- }
-
- private static final int GLOBAL_FLAG = 256;
-
- // --- (en|de)coding hooks -----
-
- public static boolean hasDecodeHooks() { return _decodeHooks; }
-
- public static void addEncodingHook( Class c , Transformer t ){
- _encodeHooks = true;
- List l = _encodingHooks.get( c );
- if ( l == null ){
- l = new CopyOnWriteArrayList<>();
- _encodingHooks.put( c , l );
- }
- l.add( t );
- }
-
- public static void addDecodingHook( Class c , Transformer t ){
- _decodeHooks = true;
- List l = _decodingHooks.get( c );
- if ( l == null ){
- l = new CopyOnWriteArrayList<>();
- _decodingHooks.put( c , l );
- }
- l.add( t );
- }
-
- public static Object applyEncodingHooks( Object o ){
- if ( ! _anyHooks() )
- return o;
-
- if ( _encodingHooks.size() == 0 || o == null )
- return o;
- List l = _encodingHooks.get( o.getClass() );
- if ( l != null )
- for ( Transformer t : l )
- o = t.transform( o );
- return o;
- }
-
- public static Object applyDecodingHooks( Object o ){
- if ( ! _anyHooks() || o == null )
- return o;
-
- List l = _decodingHooks.get( o.getClass() );
- if ( l != null )
- for ( Transformer t : l )
- o = t.transform( o );
- return o;
- }
-
- /**
- * Returns the encoding hook(s) associated with the specified class
- *
- */
- public static List getEncodingHooks( Class c ){
- return _encodingHooks.get( c );
- }
-
- /**
- * Clears *all* encoding hooks.
- */
- public static void clearEncodingHooks(){
- _encodeHooks = false;
- _encodingHooks.clear();
- }
-
- /**
- * Remove all encoding hooks for a specific class.
- */
- public static void removeEncodingHooks( Class c ){
- _encodingHooks.remove( c );
- }
-
- /**
- * Remove a specific encoding hook for a specific class.
- */
- public static void removeEncodingHook( Class c , Transformer t ){
- getEncodingHooks( c ).remove( t );
- }
-
- /**
- * Returns the decoding hook(s) associated with the specific class
- */
- public static List getDecodingHooks( Class c ){
- return _decodingHooks.get( c );
- }
-
- /**
- * Clears *all* decoding hooks.
- */
- public static void clearDecodingHooks(){
- _decodeHooks = false;
- _decodingHooks.clear();
- }
-
- /**
- * Remove all decoding hooks for a specific class.
- */
- public static void removeDecodingHooks( Class c ){
- _decodingHooks.remove( c );
- }
-
- /**
- * Remove a specific encoding hook for a specific class.
- */
- public static void removeDecodingHook( Class c , Transformer t ){
- getDecodingHooks( c ).remove( t );
- }
-
-
- public static void clearAllHooks(){
- clearEncodingHooks();
- clearDecodingHooks();
- }
-
- /**
- * Returns true if any encoding or decoding hooks are loaded.
- */
- private static boolean _anyHooks(){
- return _encodeHooks || _decodeHooks;
- }
-
- private static boolean _encodeHooks = false;
- private static boolean _decodeHooks = false;
- static ClassMap> _encodingHooks =
- new ClassMap<>();
-
- static ClassMap> _decodingHooks =
- new ClassMap<>();
-
- /**
- * @deprecated Use {@link Charset#forName(String)} to create UTF-8 charset.
- */
- @Deprecated
- static protected Charset _utf8 = Charset.forName( "UTF-8" );
-
- // ----- static encode/decode -----
-
- public static byte[] encode( BSONObject o ){
- BSONEncoder e = _staticEncoder.get();
- try {
- return e.encode( o );
- }
- finally {
- e.done();
- }
- }
-
- public static BSONObject decode( byte[] b ){
- BSONDecoder d = _staticDecoder.get();
- return d.readObject( b );
- }
-
- static ThreadLocal _staticEncoder = new ThreadLocal(){
- protected BSONEncoder initialValue(){
- return new BasicBSONEncoder();
- }
- };
-
- static ThreadLocal _staticDecoder = new ThreadLocal(){
- protected BSONDecoder initialValue(){
- return new BasicBSONDecoder();
- }
- };
-
- // --- coercing ---
-
- public static int toInt( Object o ){
- if ( o == null )
- throw new NullPointerException( "can't be null" );
-
- if ( o instanceof Number )
- return ((Number)o).intValue();
-
- if ( o instanceof Boolean )
- return ((Boolean)o) ? 1 : 0;
-
- throw new IllegalArgumentException( "can't convert: " + o.getClass().getName() + " to int" );
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONCallback.java b/src/com/massivecraft/massivecore/xlib/bson/BSONCallback.java
deleted file mode 100644
index e013634f..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONCallback.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// BSONCallback.java
-
-package com.massivecraft.massivecore.xlib.bson;
-
-import com.massivecraft.massivecore.xlib.bson.types.ObjectId;
-
-public interface BSONCallback {
-
- void objectStart();
- void objectStart(String name);
- void objectStart(boolean array);
- Object objectDone();
-
- void reset();
- Object get();
- BSONCallback createBSONCallback();
-
- void arrayStart();
- void arrayStart(String name);
- Object arrayDone();
-
- void gotNull( String name );
- void gotUndefined( String name );
- void gotMinKey( String name );
- void gotMaxKey( String name );
-
- void gotBoolean( String name , boolean v );
- void gotDouble( String name , double v );
- void gotInt( String name , int v );
- void gotLong( String name , long v );
-
- void gotDate( String name , long millis );
- void gotString( String name , String v );
- void gotSymbol( String name , String v );
- void gotRegex( String name , String pattern , String flags );
-
- void gotTimestamp( String name , int time , int inc );
- void gotObjectId( String name , ObjectId id );
-
- /**
- * Invoked when {@link com.massivecraft.massivecore.xlib.bson.BSONDecoder} encountered a DBPointer(0x0c) type field in a byte sequence.
- *
- * @param name the name of the field
- * @param ns the namespace to which reference is pointing to
- * @param id the if of the object to which reference is pointing to
- */
- void gotDBRef(String name, String ns, ObjectId id);
-
- /**
- *
- */
- @Deprecated
- void gotBinaryArray( String name , byte[] data );
- void gotBinary( String name , byte type , byte[] data );
- /**
- * subtype 3
- */
- void gotUUID( String name , long part1, long part2);
-
- void gotCode( String name , String code );
- void gotCodeWScope( String name , String code , Object scope );
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONDecoder.java b/src/com/massivecraft/massivecore/xlib/bson/BSONDecoder.java
deleted file mode 100644
index 716282f3..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONDecoder.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// BSONDecoder.java
-
-package com.massivecraft.massivecore.xlib.bson;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public interface BSONDecoder {
-
- BSONObject readObject(byte[] b);
-
- BSONObject readObject(InputStream in) throws IOException;
-
- int decode(byte[] b, BSONCallback callback);
-
- int decode(InputStream in, BSONCallback callback) throws IOException;
-
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONEncoder.java b/src/com/massivecraft/massivecore/xlib/bson/BSONEncoder.java
deleted file mode 100644
index 53f7bb81..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONEncoder.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson;
-
-import com.massivecraft.massivecore.xlib.bson.io.OutputBuffer;
-
-
-public interface BSONEncoder {
- byte[] encode(BSONObject o);
-
- int putObject(BSONObject o);
-
- void done();
-
- void set( OutputBuffer out );
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONException.java b/src/com/massivecraft/massivecore/xlib/bson/BSONException.java
deleted file mode 100644
index 841ac447..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONException.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson;
-
-/**
- * A general runtime exception raised in BSON processing.
- */
-public class BSONException extends RuntimeException {
-
- private static final long serialVersionUID = -4415279469780082174L;
-
- /**
- * @param msg The error message.
- */
- public BSONException( final String msg ) {
- super( msg );
- }
-
- /**
- * @param errorCode The error code.
- * @param msg The error message.
- */
- public BSONException( final int errorCode, final String msg ) {
- super( msg );
- _errorCode = errorCode;
- }
-
- /**
- * @param msg The error message.
- * @param t The throwable cause.
- */
- public BSONException( final String msg , final Throwable t ) {
- super( msg, t );
- }
-
- /**
- * @param errorCode The error code.
- * @param msg The error message.
- * @param t The throwable cause.
- */
- public BSONException( final int errorCode, final String msg, final Throwable t ) {
- super( msg, t );
- _errorCode = errorCode;
- }
-
- /**
- * Returns the error code.
- * @return The error code.
- */
- public Integer getErrorCode() { return _errorCode; }
-
- /**
- * Returns true if the error code is set (i.e., not null).
- */
- public boolean hasErrorCode() { return (_errorCode != null); }
-
- private Integer _errorCode = null;
-}
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONLazyDecoder.java b/src/com/massivecraft/massivecore/xlib/bson/BSONLazyDecoder.java
deleted file mode 100644
index 35126415..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONLazyDecoder.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson;
-
-/**
- *
- * @author antoine
- *
- * @deprecated This class is NOT a part of public API and will be dropped in 3.x versions.
- */
-@Deprecated
-public class BSONLazyDecoder {
-
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BSONObject.java b/src/com/massivecraft/massivecore/xlib/bson/BSONObject.java
deleted file mode 100644
index a456d57b..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BSONObject.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// BSONObject.java
-
-package com.massivecraft.massivecore.xlib.bson;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A key-value map that can be saved to the database.
- */
-@SuppressWarnings({"rawtypes"})
-public interface BSONObject {
-
- /**
- * Sets a name/value pair in this object.
- * @param key Name to set
- * @param v Corresponding value
- * @return v
- */
- Object put(String key, Object v);
-
- /**
- * Sets all key/value pairs from an object into this object
- * @param o the object
- */
- void putAll(BSONObject o);
-
- /**
- * Sets all key/value pairs from a map into this object
- * @param m the map
- */
- void putAll(Map m);
-
- /**
- * Gets a field from this object by a given name.
- * @param key The name of the field fetch
- * @return The field, if found
- */
- Object get(String key);
-
- /**
- * Returns a map representing this BSONObject.
- * @return the map
- */
- Map toMap();
-
- /**
- * Removes a field with a given name from this object.
- * @param key The name of the field to remove
- * @return The value removed from this object
- */
- Object removeField(String key);
-
- /**
- * Deprecated
- * @param s
- * @return True if the key is present
- * @deprecated
- */
- @Deprecated
- boolean containsKey(String s);
-
- /**
- * Checks if this object contains a field with the given name.
- * @param s Field name for which to check
- * @return True if the field is present
- */
- boolean containsField(String s);
-
- /**
- * Returns this object's fields' names
- * @return The names of the fields in this object
- */
- Set keySet();
-}
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BasicBSONCallback.java b/src/com/massivecraft/massivecore/xlib/bson/BasicBSONCallback.java
deleted file mode 100644
index 1cb3c652..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BasicBSONCallback.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// BasicBSONCallback.java
-
-package com.massivecraft.massivecore.xlib.bson;
-
-import com.massivecraft.massivecore.xlib.bson.types.BSONTimestamp;
-import com.massivecraft.massivecore.xlib.bson.types.BasicBSONList;
-import com.massivecraft.massivecore.xlib.bson.types.Binary;
-import com.massivecraft.massivecore.xlib.bson.types.Code;
-import com.massivecraft.massivecore.xlib.bson.types.CodeWScope;
-import com.massivecraft.massivecore.xlib.bson.types.MaxKey;
-import com.massivecraft.massivecore.xlib.bson.types.MinKey;
-import com.massivecraft.massivecore.xlib.bson.types.ObjectId;
-
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.UUID;
-import java.util.regex.Pattern;
-
-public class BasicBSONCallback implements BSONCallback {
-
- public BasicBSONCallback(){
- reset();
- }
-
- public BSONObject create(){
- return new BasicBSONObject();
- }
-
- protected BSONObject createList() {
- return new BasicBSONList();
- }
-
- public BSONCallback createBSONCallback(){
- return new BasicBSONCallback();
- }
-
- public BSONObject create( boolean array , List path ){
- if ( array )
- return createList();
- return create();
- }
-
- public void objectStart(){
- if ( _stack.size() > 0 )
- throw new IllegalStateException( "something is wrong" );
-
- objectStart(false);
- }
-
- public void objectStart(boolean array){
- _root = create(array, null);
- _stack.add( (BSONObject)_root );
- }
-
- public void objectStart(String name){
- objectStart( false , name );
- }
-
- public void objectStart(boolean array, String name){
- _nameStack.addLast( name );
- final BSONObject o = create( array , _nameStack );
- _stack.getLast().put( name , o);
- _stack.addLast( o );
- }
-
- public Object objectDone(){
- final BSONObject o =_stack.removeLast();
- if ( _nameStack.size() > 0 )
- _nameStack.removeLast();
- else if ( _stack.size() > 0 )
- throw new IllegalStateException( "something is wrong" );
-
- return !BSON.hasDecodeHooks() ? o : (BSONObject)BSON.applyDecodingHooks(o);
- }
-
- public void arrayStart(){
- objectStart( true );
- }
-
- public void arrayStart(String name){
- objectStart( true , name );
- }
-
- public Object arrayDone(){
- return objectDone();
- }
-
- public void gotNull( String name ){
- cur().put( name , null );
- }
-
- public void gotUndefined( String name ) { }
-
- public void gotMinKey( String name ){
- cur().put( name , new MinKey() );
- }
-
- public void gotMaxKey( String name ){
- cur().put( name , new MaxKey() );
- }
-
- public void gotBoolean( String name , boolean v ){
- _put( name , v );
- }
-
- public void gotDouble( final String name , final double v ){
- _put( name , v );
- }
-
- public void gotInt( final String name , final int v ){
- _put( name , v );
- }
-
- public void gotLong( final String name , final long v ){
- _put( name , v );
- }
-
- public void gotDate( String name , long millis ){
- _put( name , new Date( millis ) );
- }
- public void gotRegex( String name , String pattern , String flags ){
- _put( name , Pattern.compile( pattern , BSON.regexFlags( flags ) ) );
- }
-
- public void gotString( final String name , final String v ){
- _put( name , v );
- }
- public void gotSymbol( String name , String v ){
- _put( name , v );
- }
-
- public void gotTimestamp( String name , int time , int inc ){
- _put( name , new BSONTimestamp( time , inc ) );
- }
- public void gotObjectId( String name , ObjectId id ){
- _put( name , id );
- }
- public void gotDBRef( String name , String ns , ObjectId id ){
- _put( name , new BasicBSONObject( "$ns" , ns ).append( "$id" , id ) );
- }
-
- @Deprecated
- public void gotBinaryArray( String name , byte[] data ){
- gotBinary( name, BSON.B_GENERAL, data );
- }
-
- public void gotBinary( String name , byte type , byte[] data ){
- if( type == BSON.B_GENERAL || type == BSON.B_BINARY )
- _put( name , data );
- else
- _put( name , new Binary( type , data ) );
- }
-
- public void gotUUID( String name , long part1, long part2){
- _put( name , new UUID(part1, part2) );
- }
-
- public void gotCode( String name , String code ){
- _put( name , new Code( code ) );
- }
-
- public void gotCodeWScope( String name , String code , Object scope ){
- _put( name , new CodeWScope( code, (BSONObject)scope ) );
- }
-
- protected void _put( final String name , final Object o ){
- cur().put( name , !BSON.hasDecodeHooks() ? o : BSON.applyDecodingHooks( o ) );
- }
-
- protected BSONObject cur(){
- return _stack.getLast();
- }
-
- protected String curName(){
- return (!_nameStack.isEmpty()) ? _nameStack.getLast() : null;
- }
-
- public Object get(){
- return _root;
- }
-
- protected void setRoot(Object o) {
- _root = o;
- }
-
- protected boolean isStackEmpty() {
- return _stack.size() < 1;
- }
-
- public void reset(){
- _root = null;
- _stack.clear();
- _nameStack.clear();
- }
-
- private Object _root;
- private final LinkedList _stack = new LinkedList<>();
- private final LinkedList _nameStack = new LinkedList<>();
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/BasicBSONDecoder.java b/src/com/massivecraft/massivecore/xlib/bson/BasicBSONDecoder.java
deleted file mode 100644
index f21f286f..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/BasicBSONDecoder.java
+++ /dev/null
@@ -1,639 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson;
-
-import com.massivecraft.massivecore.xlib.bson.io.PoolOutputBuffer;
-import com.massivecraft.massivecore.xlib.bson.types.ObjectId;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static com.massivecraft.massivecore.xlib.bson.BSON.ARRAY;
-import static com.massivecraft.massivecore.xlib.bson.BSON.BINARY;
-import static com.massivecraft.massivecore.xlib.bson.BSON.BOOLEAN;
-import static com.massivecraft.massivecore.xlib.bson.BSON.B_BINARY;
-import static com.massivecraft.massivecore.xlib.bson.BSON.B_GENERAL;
-import static com.massivecraft.massivecore.xlib.bson.BSON.B_UUID;
-import static com.massivecraft.massivecore.xlib.bson.BSON.CODE;
-import static com.massivecraft.massivecore.xlib.bson.BSON.CODE_W_SCOPE;
-import static com.massivecraft.massivecore.xlib.bson.BSON.DATE;
-import static com.massivecraft.massivecore.xlib.bson.BSON.EOO;
-import static com.massivecraft.massivecore.xlib.bson.BSON.MAXKEY;
-import static com.massivecraft.massivecore.xlib.bson.BSON.MINKEY;
-import static com.massivecraft.massivecore.xlib.bson.BSON.NULL;
-import static com.massivecraft.massivecore.xlib.bson.BSON.NUMBER;
-import static com.massivecraft.massivecore.xlib.bson.BSON.NUMBER_INT;
-import static com.massivecraft.massivecore.xlib.bson.BSON.NUMBER_LONG;
-import static com.massivecraft.massivecore.xlib.bson.BSON.OBJECT;
-import static com.massivecraft.massivecore.xlib.bson.BSON.OID;
-import static com.massivecraft.massivecore.xlib.bson.BSON.REF;
-import static com.massivecraft.massivecore.xlib.bson.BSON.REGEX;
-import static com.massivecraft.massivecore.xlib.bson.BSON.STRING;
-import static com.massivecraft.massivecore.xlib.bson.BSON.SYMBOL;
-import static com.massivecraft.massivecore.xlib.bson.BSON.TIMESTAMP;
-import static com.massivecraft.massivecore.xlib.bson.BSON.UNDEFINED;
-
-
-/**
- * Basic implementation of BSONDecoder interface that creates BasicBSONObject instances.
- *
- *
Migration instructions
- * In driver versions before 2.12 {@code BasicBSONDecoder} exposed several protected members to its subclasses:
- *
- */
-@SuppressWarnings({"unchecked", "rawtypes", "unused"})
-public class BasicBSONObject extends LinkedHashMap implements BSONObject {
-
- private static final long serialVersionUID = -4415279469780082174L;
-
- /**
- * Creates an empty object.
- */
- public BasicBSONObject(){
- }
-
- public BasicBSONObject(int size){
- super(size);
- }
-
- /**
- * Convenience CTOR
- * @param key key under which to store
- * @param value value to stor
- */
- public BasicBSONObject(String key, Object value){
- put(key, value);
- }
-
- /**
- * Creates a DBObject from a map.
- * @param m map to convert
- */
- public BasicBSONObject(Map m) {
- super(m);
- }
-
- /**
- * Converts a DBObject to a map.
- * @return the DBObject
- */
- public Map toMap() {
- return new LinkedHashMap<>(this);
- }
-
- /** Deletes a field from this object.
- * @param key the field name to remove
- * @return the object removed
- */
- public Object removeField( String key ){
- return remove( key );
- }
-
- /** Checks if this object contains a given field
- * @param field field name
- * @return if the field exists
- */
- public boolean containsField( String field ){
- return super.containsKey(field);
- }
-
- /**
- * @deprecated
- */
- @Deprecated
- public boolean containsKey( String key ){
- return containsField(key);
- }
-
- /** Gets a value from this object
- * @param key field name
- * @return the value
- */
- public Object get( String key ){
- return super.get(key);
- }
-
- /** Returns the value of a field as an int.
- * @param key the field to look for
- * @return the field value (or default)
- */
- public int getInt( String key ){
- Object o = get(key);
- if ( o == null )
- throw new NullPointerException( "no value for: " + key );
-
- return BSON.toInt(o);
- }
-
- /** Returns the value of a field as an int.
- * @param key the field to look for
- * @param def the default to return
- * @return the field value (or default)
- */
- public int getInt( String key , int def ){
- Object foo = get( key );
- if ( foo == null )
- return def;
-
- return BSON.toInt(foo);
- }
-
- /**
- * Returns the value of a field as a long.
- *
- * @param key the field to return
- * @return the field value
- */
- public long getLong( String key){
- Object foo = get( key );
- return ((Number)foo).longValue();
- }
-
- /**
- * Returns the value of a field as an long.
- * @param key the field to look for
- * @param def the default to return
- * @return the field value (or default)
- */
- public long getLong( String key , long def ) {
- Object foo = get( key );
- if ( foo == null )
- return def;
-
- return ((Number)foo).longValue();
- }
-
- /**
- * Returns the value of a field as a double.
- *
- * @param key the field to return
- * @return the field value
- */
- public double getDouble( String key){
- Object foo = get( key );
- return ((Number)foo).doubleValue();
- }
-
- /**
- * Returns the value of a field as an double.
- * @param key the field to look for
- * @param def the default to return
- * @return the field value (or default)
- */
- public double getDouble( String key , double def ) {
- Object foo = get( key );
- if ( foo == null )
- return def;
-
- return ((Number)foo).doubleValue();
- }
-
- /** Returns the value of a field as a string
- * @param key the field to look up
- * @return the value of the field, converted to a string
- */
- public String getString( String key ){
- Object foo = get( key );
- if ( foo == null )
- return null;
- return foo.toString();
- }
-
- /**
- * Returns the value of a field as a string
- * @param key the field to look up
- * @param def the default to return
- * @return the value of the field, converted to a string
- */
- public String getString( String key, final String def ) {
- Object foo = get( key );
- if ( foo == null )
- return def;
-
- return foo.toString();
- }
-
- /** Returns the value of a field as a boolean.
- * @param key the field to look up
- * @return the value of the field, or false if field does not exist
- */
- public boolean getBoolean( String key ){
- return getBoolean(key, false);
- }
-
- /** Returns the value of a field as a boolean
- * @param key the field to look up
- * @param def the default value in case the field is not found
- * @return the value of the field, converted to a string
- */
- public boolean getBoolean( String key , boolean def ){
- Object foo = get( key );
- if ( foo == null )
- return def;
- if ( foo instanceof Number )
- return ((Number)foo).intValue() > 0;
- if ( foo instanceof Boolean )
- return ((Boolean)foo).booleanValue();
- throw new IllegalArgumentException( "can't coerce to bool:" + foo.getClass() );
- }
-
- /**
- * Returns the object id or null if not set.
- * @param field The field to return
- * @return The field object value or null if not found (or if null :-^).
- */
- public ObjectId getObjectId( final String field ) {
- return (ObjectId) get( field );
- }
-
- /**
- * Returns the object id or def if not set.
- * @param field The field to return
- * @param def the default value in case the field is not found
- * @return The field object value or def if not set.
- */
- public ObjectId getObjectId( final String field, final ObjectId def ) {
- final Object foo = get( field );
- return (foo != null) ? (ObjectId)foo : def;
- }
-
- /**
- * Returns the date or null if not set.
- * @param field The field to return
- * @return The field object value or null if not found.
- */
- public Date getDate( final String field ) {
- return (Date) get( field );
- }
-
- /**
- * Returns the date or def if not set.
- * @param field The field to return
- * @param def the default value in case the field is not found
- * @return The field object value or def if not set.
- */
- public Date getDate( final String field, final Date def ) {
- final Object foo = get( field );
- return (foo != null) ? (Date)foo : def;
- }
-
- /** Add a key/value pair to this object
- * @param key the field name
- * @param val the field value
- * @return the val parameter
- */
- public Object put( String key , Object val ){
- return super.put( key , val );
- }
-
- public void putAll( Map m ){
- for ( Map.Entry entry : (Set)m.entrySet() ){
- put( entry.getKey().toString() , entry.getValue() );
- }
- }
-
- public void putAll( BSONObject o ){
- for ( String k : o.keySet() ){
- put( k , o.get( k ) );
- }
- }
-
- /** Add a key/value pair to this object
- * @param key the field name
- * @param val the field value
- * @return this
- */
- public BasicBSONObject append( String key , Object val ){
- put( key , val );
-
- return this;
- }
-
- /** Returns a JSON serialization of this object
- * @return JSON serialization
- */
- public String toString(){
- return JSONSerializers.getStrict().serialize(this);
- }
-
- /**
- * Compares two documents according to their serialized form, ignoring the order of keys.
- *
- * @param o the document to compare to, which must be an instance of {@link com.massivecraft.massivecore.xlib.bson.BSONObject}.
- * @return true if the documents have the same serialized form, ignoring key order.
- */
- @Override
- public boolean equals( Object o ) {
- if (o == this) {
- return true;
- }
-
- if (! (o instanceof BSONObject)) {
- return false;
- }
-
- BSONObject other = (BSONObject) o;
-
- if (!keySet().equals(other.keySet())) {
- return false;
- }
-
- return Arrays.equals(canonicalizeBSONObject(this).encode(), canonicalizeBSONObject(other).encode());
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(canonicalizeBSONObject(this).encode());
- }
-
- private byte[] encode() {
- return new BasicBSONEncoder().encode(this);
- }
-
- private BSONObject decode(final byte[] encodedBytes) {
- return new BasicBSONDecoder().readObject(encodedBytes);
- }
-
- // create a copy of "from", but with keys ordered alphabetically
- private static Object canonicalize(final Object from) {
- if (from instanceof BSONObject && !(from instanceof BasicBSONList)) {
- return canonicalizeBSONObject((BSONObject) from);
- } else if (from instanceof List) {
- return canonicalizeList((List
- *
- * BasicBSONList only supports numeric keys. Passing strings that cannot be converted to ints will cause an
- * IllegalArgumentException.
- *
- * BasicBSONList list = new BasicBSONList();
- * list.put("1", "bar"); // ok
- * list.put("1E1", "bar"); // throws exception
- *
- *
- */
-@SuppressWarnings({"unchecked", "rawtypes"})
-public class BasicBSONList extends ArrayList implements BSONObject {
-
- private static final long serialVersionUID = -4415279469780082174L;
-
- public BasicBSONList() { }
-
- /**
- * Puts a value at an index.
- * For interface compatibility. Must be passed a String that is parsable to an int.
- * @param key the index at which to insert the value
- * @param v the value to insert
- * @return the value
- * @throws IllegalArgumentException if key cannot be parsed into an int
- */
- public Object put( String key , Object v ){
- return put(_getInt( key ), v);
- }
-
- /**
- * Puts a value at an index.
- * This will fill any unset indexes less than index with null.
- * @param key the index at which to insert the value
- * @param v the value to insert
- * @return the value
- */
- public Object put( int key, Object v ) {
- while ( key >= size() )
- add( null );
- set( key , v );
- return v;
- }
-
- public void putAll( Map m ){
- for ( Map.Entry entry : (Set)m.entrySet() ){
- put( entry.getKey().toString() , entry.getValue() );
- }
- }
-
- public void putAll( BSONObject o ){
- for ( String k : o.keySet() ){
- put( k , o.get( k ) );
- }
- }
-
- /**
- * Gets a value at an index.
- * For interface compatibility. Must be passed a String that is parsable to an int.
- * @param key the index
- * @return the value, if found, or null
- * @throws IllegalArgumentException if key cannot be parsed into an int
- */
- public Object get( String key ){
- int i = _getInt( key );
- if ( i < 0 )
- return null;
- if ( i >= size() )
- return null;
- return get( i );
- }
-
- public Object removeField( String key ){
- int i = _getInt( key );
- if ( i < 0 )
- return null;
- if ( i >= size() )
- return null;
- return remove( i );
- }
-
- /**
- * @deprecated
- */
- @Deprecated
- public boolean containsKey( String key ){
- return containsField(key);
- }
-
- public boolean containsField( String key ){
- int i = _getInt( key , false );
- if ( i < 0 )
- return false;
- return i >= 0 && i < size();
- }
-
- public Set keySet(){
- return new StringRangeSet(size());
- }
-
- public Map toMap() {
- Map m = new HashMap();
- Iterator i = this.keySet().iterator();
- while (i.hasNext()) {
- Object s = i.next();
- m.put(s, this.get(String.valueOf(s)));
- }
- return m;
- }
-
- int _getInt( String s ){
- return _getInt( s , true );
- }
-
- int _getInt( String s , boolean err ){
- try {
- return Integer.parseInt( s );
- }
- catch ( Exception e ){
- if ( err )
- throw new IllegalArgumentException( "BasicBSONList can only work with numeric keys, not: [" + s + "]" );
- return -1;
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/Binary.java b/src/com/massivecraft/massivecore/xlib/bson/types/Binary.java
deleted file mode 100644
index 610b6cf6..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/Binary.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// Binary.java
-
-package com.massivecraft.massivecore.xlib.bson.types;
-
-import com.massivecraft.massivecore.xlib.bson.BSON;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-/**
- * generic binary holder
- */
-public class Binary implements Serializable {
-
- private static final long serialVersionUID = 7902997490338209467L;
-
- /**
- * Creates a Binary object with the default binary type of 0
- *
- * @param data raw data
- */
- public Binary(byte[] data) {
- this(BSON.B_GENERAL, data);
- }
-
- /**
- * Creates a Binary object
- *
- * @param type type of the field as encoded in BSON
- * @param data raw data
- */
- public Binary(byte type, byte[] data) {
- _type = type;
- _data = data;
- }
-
- public byte getType() {
- return _type;
- }
-
- public byte[] getData() {
- return _data;
- }
-
- public int length() {
- return _data.length;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Binary)) {
- return false;
- }
-
- Binary binary = (Binary) o;
-
- if (_type != binary._type) {
- return false;
- }
- if (!Arrays.equals(_data, binary._data)) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = (int) _type;
- result = 31 * result + (_data != null ? Arrays.hashCode(_data) : 0);
- return result;
- }
-
- final byte _type;
- final byte[] _data;
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/Code.java b/src/com/massivecraft/massivecore/xlib/bson/types/Code.java
deleted file mode 100644
index a2920dd9..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/Code.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// Code.java
-
-package com.massivecraft.massivecore.xlib.bson.types;
-
-import java.io.Serializable;
-
-/**
- * for using the Code type
- */
-public class Code implements Serializable {
-
- private static final long serialVersionUID = 475535263314046697L;
-
- public Code( String code ){
- _code = code;
- }
-
- public String getCode(){
- return _code;
- }
-
- public boolean equals( Object o ){
- if ( ! ( o instanceof Code ) )
- return false;
-
- Code c = (Code)o;
- return _code.equals( c._code );
- }
-
- public int hashCode(){
- return _code.hashCode();
- }
-
- @Override
- public String toString() {
- return getCode();
- }
-
- final String _code;
-
-}
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/CodeWScope.java b/src/com/massivecraft/massivecore/xlib/bson/types/CodeWScope.java
deleted file mode 100644
index 0965cfa0..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/CodeWScope.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// CodeWScope.java
-
-package com.massivecraft.massivecore.xlib.bson.types;
-
-import com.massivecraft.massivecore.xlib.bson.BSONObject;
-
-/**
- * for using the CodeWScope type
- */
-public class CodeWScope extends Code {
-
- private static final long serialVersionUID = -6284832275113680002L;
-
- public CodeWScope( String code , BSONObject scope ){
- super( code );
- _scope = scope;
- }
-
- public BSONObject getScope(){
- return _scope;
- }
-
- public boolean equals( Object o ){
- if ( ! ( o instanceof CodeWScope ) )
- return false;
-
- CodeWScope c = (CodeWScope)o;
- return _code.equals( c._code ) && _scope.equals( c._scope );
- }
-
- public int hashCode(){
- return _code.hashCode() ^ _scope.hashCode();
- }
-
- final BSONObject _scope;
-}
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/MaxKey.java b/src/com/massivecraft/massivecore/xlib/bson/types/MaxKey.java
deleted file mode 100644
index 287bde3f..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/MaxKey.java
+++ /dev/null
@@ -1,47 +0,0 @@
-
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.types;
-
-import java.io.Serializable;
-
-/**
- * Represent the maximum key value regardless of the key's type
- */
-public class MaxKey implements Serializable {
-
- private static final long serialVersionUID = 5123414776151687185L;
-
- public MaxKey() {
- }
-
- @Override
- public boolean equals(Object o) {
- return o instanceof MaxKey;
- }
-
- @Override
- public int hashCode() {
- return 0;
- }
-
- @Override
- public String toString() {
- return "MaxKey";
- }
-
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/MinKey.java b/src/com/massivecraft/massivecore/xlib/bson/types/MinKey.java
deleted file mode 100644
index e6d35f1a..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/MinKey.java
+++ /dev/null
@@ -1,47 +0,0 @@
-
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.types;
-
-import java.io.Serializable;
-
-/**
- * Represent the minimum key value regardless of the key's type
- */
-public class MinKey implements Serializable {
-
- private static final long serialVersionUID = 4075901136671855684L;
-
- public MinKey() {
- }
-
- @Override
- public boolean equals(Object o) {
- return o instanceof MinKey;
- }
-
- @Override
- public int hashCode() {
- return 0;
- }
-
- @Override
- public String toString() {
- return "MinKey";
- }
-
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/ObjectId.java b/src/com/massivecraft/massivecore/xlib/bson/types/ObjectId.java
deleted file mode 100644
index ff84f158..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/ObjectId.java
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// ObjectId.java
-
-package com.massivecraft.massivecore.xlib.bson.types;
-
-import java.net.NetworkInterface;
-import java.nio.ByteBuffer;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.Random;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A globally unique identifier for objects.
- *
Consists of 12 bytes, divided as follows:
- *
- *
- *
0
1
2
3
4
5
6
- *
7
8
9
10
11
- *
time
machine
- *
pid
inc
- *
- *
- *
- * @dochub objectids
- */
-public class ObjectId implements Comparable , java.io.Serializable {
-
- private static final long serialVersionUID = -4415279469780082174L;
-
- static final Logger LOGGER = Logger.getLogger( "org.bson.ObjectId" );
-
- /** Gets a new object id.
- * @return the new id
- */
- public static ObjectId get(){
- return new ObjectId();
- }
-
- /**
- * Creates an ObjectId using time, machine and inc values. The Java driver has done it this way for a long time, but it
- * does not match the ObjectId specification,
- * which requires four values, not three. The next major release of the Java driver will conform to this specification,
- * but will still need to support clients that are relying on the current behavior. To that end,
- * the constructors that takes these three arguments are now deprecated in favor of this more explicit factory method,
- * and in the next major release those constructors will be removed.
- *
- * NOTE: This will not break any application that use ObjectIds. The 12-byte representation will be round-trippable from old to new
- * driver releases.
- *
- *
- *
- * @param time time in seconds
- * @param machine machine ID
- * @param inc incremental value
- * @see com.massivecraft.massivecore.xlib.bson.types.ObjectId#ObjectId(int, int, int)
- * @since 2.12.0
- */
- public static ObjectId createFromLegacyFormat(final int time, final int machine, final int inc) {
- return new ObjectId(time, machine, inc);
- }
-
-
- /** Checks if a string could be an ObjectId.
- * @return whether the string could be an object id
- */
- public static boolean isValid( String s ){
- if ( s == null )
- return false;
-
- final int len = s.length();
- if ( len != 24 )
- return false;
-
- for ( int i=0; i= '0' && c <= '9' )
- continue;
- if ( c >= 'a' && c <= 'f' )
- continue;
- if ( c >= 'A' && c <= 'F' )
- continue;
-
- return false;
- }
-
- return true;
- }
-
- /** Turn an object into an ObjectId, if possible.
- * Strings will be converted into ObjectIds, if possible, and ObjectIds will
- * be cast and returned. Passing in null returns null.
- * @param o the object to convert
- * @return an ObjectId if it can be massaged, null otherwise
- *
- * @deprecated This method is NOT a part of public API and will be dropped in 3.x versions.
- */
- @Deprecated
- public static ObjectId massageToObjectId( Object o ){
- if ( o == null )
- return null;
-
- if ( o instanceof ObjectId )
- return (ObjectId)o;
-
- if ( o instanceof String ){
- String s = o.toString();
- if ( isValid( s ) )
- return new ObjectId( s );
- }
-
- return null;
- }
-
- public ObjectId( Date time ){
- this(time, _genmachine, _nextInc.getAndIncrement());
- }
-
- public ObjectId( Date time , int inc ){
- this( time , _genmachine , inc );
- }
-
- /**
- * Constructs an ObjectId using time, machine and inc values. The Java driver has done it this way for a long time, but it
- * does not match the ObjectId specification,
- * which requires four values, not three. The next major release of the Java driver will conform to this specification,
- * but will still need to support clients that are relying on the current behavior. To that end,
- * this constructor is now deprecated in favor of the more explicit factory method ObjectId#createFromLegacyFormat(int, int, int)},
- * and in the next major release this constructor will be removed.
- *
- * @see ObjectId#createFromLegacyFormat(int, int, int)
- * @deprecated {@code ObjectId}'s constructed this way do not conform to
- * the ObjectId specification.
- * Please use {@link com.massivecraft.massivecore.xlib.bson.types.ObjectId#ObjectId(byte[])} or
- * {@link ObjectId#createFromLegacyFormat(int, int, int)} instead.
- */
- @Deprecated
- public ObjectId( Date time , int machine , int inc ){
- _time = (int)(time.getTime() / 1000);
- _machine = machine;
- _inc = inc;
- _new = false;
- }
-
- /** Creates a new instance from a string.
- * @param s the string to convert
- * @throws IllegalArgumentException if the string is not a valid id
- */
- public ObjectId( String s ){
- this( s , false );
- }
-
- /**
- * Constructs a new instance of {@code ObjectId} from a string.
- * @param s the string representation of ObjectId. Can contains only [0-9]|[a-f]|[A-F] characters.
- * @param babble if {@code true} - convert to 'babble' objectId format
- *
- * @deprecated 'babble' format is deprecated. Please use {@link #ObjectId(String)} instead.
- */
- @Deprecated
- public ObjectId( String s , boolean babble ){
-
- if ( ! isValid( s ) )
- throw new IllegalArgumentException( "invalid ObjectId [" + s + "]" );
-
- if ( babble )
- s = babbleToMongod( s );
-
- byte b[] = new byte[12];
- for ( int i=0; iObjectId specification,
- * which requires four values, not three. The next major release of the Java driver will conform to this specification,
- * but we will still need to support clients that are relying on the current behavior. To that end,
- * this constructor is now deprecated in favor of the more explicit factory method ObjectId#createFromLegacyFormat(int, int, int)},
- * and in the next major release this constructor will be removed.
- *
- * @param time time in seconds
- * @param machine machine ID
- * @param inc incremental value
- * @see ObjectId#createFromLegacyFormat(int, int, int)
- * @deprecated {@code ObjectId}'s constructed this way do not conform to
- * the ObjectId specification.
- * Please use {@link com.massivecraft.massivecore.xlib.bson.types.ObjectId#ObjectId(byte[])} or
- * {@link ObjectId#createFromLegacyFormat(int, int, int)} instead.
- */
- @Deprecated
- public ObjectId(int time, int machine, int inc) {
- _time = time;
- _machine = machine;
- _inc = inc;
- _new = false;
- }
-
- /** Create a new object id.
- */
- public ObjectId(){
- _time = (int) (System.currentTimeMillis() / 1000);
- _machine = _genmachine;
- _inc = _nextInc.getAndIncrement();
- _new = true;
- }
-
- public int hashCode(){
- int x = _time;
- x += ( _machine * 111 );
- x += ( _inc * 17 );
- return x;
- }
-
- public boolean equals( Object o ){
-
- if ( this == o )
- return true;
-
- ObjectId other = massageToObjectId( o );
- if ( other == null )
- return false;
-
- return
- _time == other._time &&
- _machine == other._machine &&
- _inc == other._inc;
- }
-
- /**
- * @deprecated 'babble' format is deprecated. Please use {@link #toHexString()} instead.
- */
- @Deprecated
- public String toStringBabble(){
- return babbleToMongod( toStringMongod() );
- }
-
- /**
- * Converts this instance into a 24-byte hexadecimal string representation.
- *
- * @return a string representation of the ObjectId in hexadecimal format
- */
- public String toHexString() {
- final StringBuilder buf = new StringBuilder(24);
-
- for (final byte b : toByteArray()) {
- buf.append(String.format("%02x", b & 0xff));
- }
-
- return buf.toString();
- }
-
- /**
- * @return a string representation of the ObjectId in hexadecimal format
- *
- * @deprecated Please use {@link #toHexString()} instead.
- */
- @Deprecated
- public String toStringMongod(){
- byte b[] = toByteArray();
-
- StringBuilder buf = new StringBuilder(24);
-
- for ( int i=0; i=0; i-- )
- buf.append( _pos( b , i ) );
- for ( int i=11; i>=8; i-- )
- buf.append( _pos( b , i ) );
-
- return buf.toString();
- }
-
- public String toString(){
- return toStringMongod();
- }
-
- int _compareUnsigned( int i , int j ){
- long li = 0xFFFFFFFFL;
- li = i & li;
- long lj = 0xFFFFFFFFL;
- lj = j & lj;
- long diff = li - lj;
- if (diff < Integer.MIN_VALUE)
- return Integer.MIN_VALUE;
- if (diff > Integer.MAX_VALUE)
- return Integer.MAX_VALUE;
- return (int) diff;
- }
-
- public int compareTo( ObjectId id ){
- if ( id == null )
- return -1;
-
- int x = _compareUnsigned( _time , id._time );
- if ( x != 0 )
- return x;
-
- x = _compareUnsigned( _machine , id._machine );
- if ( x != 0 )
- return x;
-
- return _compareUnsigned( _inc , id._inc );
- }
-
- /**
- * Gets the timestamp (number of seconds since the Unix epoch).
- *
- * @return the timestamp
- */
- public int getTimestamp() {
- return _time;
- }
-
- /**
- * Gets the timestamp as a {@code Date} instance.
- *
- * @return the Date
- */
- public Date getDate() {
- return new Date(_time * 1000L);
- }
-
- /**
- * Gets the time of this ID, in milliseconds
- *
- * @deprecated Please use {@link #getDate()} ()} instead.
- */
- @Deprecated
- public long getTime(){
- return _time * 1000L;
- }
-
- /**
- * Gets the time of this ID, in seconds.
- * @deprecated Please use {@link #getTimestamp()} ()} instead.
- */
- @Deprecated
- public int getTimeSecond() {
- return _time;
- }
-
-
- /**
- * Gets the counter.
- *
- * @return the counter
- * @deprecated Please use the {@link #toByteArray()} instead.
- */
- @Deprecated
- public int getInc() {
- return _inc;
- }
-
- /**
- * Gets the timestamp.
- *
- * @return the timestamp
- * @deprecated Please use {@link #getTimestamp()} ()} instead.
- */
- @Deprecated
- public int _time(){
- return _time;
- }
-
- /**
- * Gets the machine identifier.
- *
- * @return the machine identifier
- * @see #createFromLegacyFormat(int, int, int)
- * @deprecated Please use {@code #toByteArray()} instead.
- */
- @Deprecated
- public int getMachine() {
- return _machine;
- }
-
- /**
- * Gets the machine identifier.
- *
- * @return the machine identifier
- * @see #createFromLegacyFormat(int, int, int)
- * @deprecated Please use {@link #toByteArray()} instead.
- */
- @Deprecated
- public int _machine(){
- return _machine;
- }
-
- /**
- * Gets the counter.
- *
- * @return the counter
- * @see #createFromLegacyFormat(int, int, int)
- * @deprecated Please use {@link #toByteArray()} instead.
- */
- @Deprecated
- public int _inc(){
- return _inc;
- }
-
- /**
- * @deprecated 'new' flag breaks the immutability of the {@code ObjectId} class
- * and will be dropped in 3.x versions of the driver
- */
- @Deprecated
- public boolean isNew() {
- return _new;
- }
-
- /**
- * @deprecated 'new' flag breaks the immutability of the {@code ObjectId} class
- * and will be dropped in 3.x versions of the driver
- */
- @Deprecated
- public void notNew(){
- _new = false;
- }
-
- /**
- * Gets the machine identifier.
- *
- * @return the machine identifier
- * @see #createFromLegacyFormat(int, int, int)
- * @deprecated
- */
- @Deprecated
- public static int getGenMachineId() {
- return _genmachine;
- }
-
- /**
- * Gets the current value of the auto-incrementing counter.
- */
- public static int getCurrentCounter() {
- return _nextInc.get();
- }
-
- /**
- * Gets the current value of the auto-incrementing counter.
- *
- * @deprecated Please use {@link #getCurrentCounter()} instead.
- */
- @Deprecated
- public static int getCurrentInc() {
- return _nextInc.get();
- }
-
- final int _time;
- final int _machine;
- final int _inc;
-
- boolean _new;
-
- /**
- * @deprecated This method is NOT a part of public API and will be dropped in 3.x versions.
- */
- @Deprecated
- public static int _flip( int x ){
- int z = 0;
- z |= ( ( x << 24 ) & 0xFF000000 );
- z |= ( ( x << 8 ) & 0x00FF0000 );
- z |= ( ( x >> 8 ) & 0x0000FF00 );
- z |= ( ( x >> 24 ) & 0x000000FF );
- return z;
- }
-
- private static AtomicInteger _nextInc = new AtomicInteger( (new java.util.Random()).nextInt() );
-
- private static final int _genmachine;
- static {
-
- try {
- // build a 2-byte machine piece based on NICs info
- int machinePiece;
- {
- try {
- StringBuilder sb = new StringBuilder();
- Enumeration e = NetworkInterface.getNetworkInterfaces();
- while ( e.hasMoreElements() ){
- NetworkInterface ni = e.nextElement();
- sb.append( ni.toString() );
- }
- machinePiece = sb.toString().hashCode() << 16;
- } catch (Throwable e) {
- // exception sometimes happens with IBM JVM, use random
- LOGGER.log(Level.WARNING, e.getMessage(), e);
- machinePiece = (new Random().nextInt()) << 16;
- }
- LOGGER.fine( "machine piece post: " + Integer.toHexString( machinePiece ) );
- }
-
- // add a 2 byte process piece. It must represent not only the JVM but the class loader.
- // Since static var belong to class loader there could be collisions otherwise
- final int processPiece;
- {
- int processId = new java.util.Random().nextInt();
- try {
- processId = java.lang.management.ManagementFactory.getRuntimeMXBean().getName().hashCode();
- }
- catch ( Throwable t ){
- }
-
- ClassLoader loader = ObjectId.class.getClassLoader();
- int loaderId = loader != null ? System.identityHashCode(loader) : 0;
-
- StringBuilder sb = new StringBuilder();
- sb.append(Integer.toHexString(processId));
- sb.append(Integer.toHexString(loaderId));
- processPiece = sb.toString().hashCode() & 0xFFFF;
- LOGGER.fine( "process piece: " + Integer.toHexString( processPiece ) );
- }
-
- _genmachine = machinePiece | processPiece;
- LOGGER.fine( "machine : " + Integer.toHexString( _genmachine ) );
- }
- catch ( Exception e ){
- throw new RuntimeException( e );
- }
-
- }
-}
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/Symbol.java b/src/com/massivecraft/massivecore/xlib/bson/types/Symbol.java
deleted file mode 100644
index 09384f5d..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/Symbol.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// Symbol.java
-
-package com.massivecraft.massivecore.xlib.bson.types;
-
-import java.io.Serializable;
-
-/**
- * Class to hold a BSON symbol object, which is an interned string in Ruby
- */
-public class Symbol implements Serializable {
-
- private static final long serialVersionUID = 1326269319883146072L;
-
- public Symbol(String s) {
- _symbol = s;
- }
-
- public String getSymbol(){
- return _symbol;
- }
-
- /**
- * Will compare equal to a String that is equal to the String that this holds
- * @param o
- * @return
- */
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null) return false;
-
- String otherSymbol;
- if (o instanceof Symbol) {
- otherSymbol = ((Symbol) o)._symbol;
- }
- else if (o instanceof String) {
- otherSymbol = (String) o;
- }
- else {
- return false;
- }
-
- if (_symbol != null ? !_symbol.equals(otherSymbol) : otherSymbol != null) return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- return _symbol != null ? _symbol.hashCode() : 0;
- }
-
- public String toString(){
- return _symbol;
- }
-
- private final String _symbol;
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/types/package.html b/src/com/massivecraft/massivecore/xlib/bson/types/package.html
deleted file mode 100644
index fc1e7aa7..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/types/package.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
Contains classes implementing various BSON types.
-
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/AbstractCopyOnWriteMap.java b/src/com/massivecraft/massivecore/xlib/bson/util/AbstractCopyOnWriteMap.java
deleted file mode 100644
index 74203595..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/AbstractCopyOnWriteMap.java
+++ /dev/null
@@ -1,632 +0,0 @@
-/*
- * Copyright (c) 2008 Atlassian Pty Ltd
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.util;
-
-import com.massivecraft.massivecore.xlib.bson.util.annotations.GuardedBy;
-import com.massivecraft.massivecore.xlib.bson.util.annotations.ThreadSafe;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import static com.massivecraft.massivecore.xlib.bson.util.Assertions.notNull;
-import static java.util.Collections.unmodifiableCollection;
-import static java.util.Collections.unmodifiableSet;
-
-/**
- * Abstract base class for COW {@link Map} implementations that delegate to an
- * internal map.
- *
- * @param The key type
- * @param The value type
- * @param the internal {@link Map} or extension for things like sorted and
- * navigable maps.
- */
-@SuppressWarnings("deprecation")
-@ThreadSafe
-abstract class AbstractCopyOnWriteMap> implements ConcurrentMap, Serializable {
- private static final long serialVersionUID = 4508989182041753878L;
-
- @GuardedBy("lock")
- private volatile M delegate;
-
- // import edu.umd.cs.findbugs.annotations.@SuppressWarnings
- private final transient Lock lock = new ReentrantLock();
-
- // private final transient EntrySet entrySet = new EntrySet();
- // private final transient KeySet keySet = new KeySet();
- // private final transient Values values = new Values();
- // private final View.Type viewType;
- private final View view;
-
- /**
- * Create a new {@link CopyOnWriteMap} with the supplied {@link Map} to
- * initialize the values.
- *
- * @param map the initial map to initialize with
- * @param viewType for writable or read-only key, value and entrySet views
- */
- protected > AbstractCopyOnWriteMap(final N map, final View.Type viewType) {
- this.delegate = notNull("delegate", copy(notNull("map", map)));
- this.view = notNull("viewType", viewType).get(this);
- }
-
- /**
- * Copy function, implemented by sub-classes.
- *
- * @param the map to copy and return.
- * @param map the initial values of the newly created map.
- * @return a new map. Will never be modified after construction.
- */
- @GuardedBy("lock")
- abstract > M copy(N map);
-
- //
- // mutable operations
- //
-
- public final void clear() {
- lock.lock();
- try {
- set(copy(Collections. emptyMap()));
- } finally {
- lock.unlock();
- }
- }
-
- public final V remove(final Object key) {
- lock.lock();
- try {
- // short circuit if key doesn't exist
- if (!delegate.containsKey(key)) {
- return null;
- }
- final M map = copy();
- try {
- return map.remove(key);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean remove(final Object key, final Object value) {
- lock.lock();
- try {
- if (delegate.containsKey(key) && equals(value, delegate.get(key))) {
- final M map = copy();
- map.remove(key);
- set(map);
- return true;
- } else {
- return false;
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean replace(final K key, final V oldValue, final V newValue) {
- lock.lock();
- try {
- if (!delegate.containsKey(key) || !equals(oldValue, delegate.get(key))) {
- return false;
- }
- final M map = copy();
- map.put(key, newValue);
- set(map);
- return true;
- } finally {
- lock.unlock();
- }
- }
-
- public V replace(final K key, final V value) {
- lock.lock();
- try {
- if (!delegate.containsKey(key)) {
- return null;
- }
- final M map = copy();
- try {
- return map.put(key, value);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public final V put(final K key, final V value) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.put(key, value);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public V putIfAbsent(final K key, final V value) {
- lock.lock();
- try {
- if (!delegate.containsKey(key)) {
- final M map = copy();
- try {
- return map.put(key, value);
- } finally {
- set(map);
- }
- }
- return delegate.get(key);
- } finally {
- lock.unlock();
- }
- }
-
- public final void putAll(final Map extends K, ? extends V> t) {
- lock.lock();
- try {
- final M map = copy();
- map.putAll(t);
- set(map);
- } finally {
- lock.unlock();
- }
- }
-
- protected M copy() {
- lock.lock();
- try {
- return copy(delegate);
- } finally {
- lock.unlock();
- }
- }
-
- @GuardedBy("lock")
- protected void set(final M map) {
- delegate = map;
- }
-
- //
- // Collection views
- //
-
- public final Set> entrySet() {
- return view.entrySet();
- }
-
- public final Set keySet() {
- return view.keySet();
- }
-
- public final Collection values() {
- return view.values();
- }
-
- //
- // delegate operations
- //
-
- public final boolean containsKey(final Object key) {
- return delegate.containsKey(key);
- }
-
- public final boolean containsValue(final Object value) {
- return delegate.containsValue(value);
- }
-
- public final V get(final Object key) {
- return delegate.get(key);
- }
-
- public final boolean isEmpty() {
- return delegate.isEmpty();
- }
-
- public final int size() {
- return delegate.size();
- }
-
- @Override
- public final boolean equals(final Object o) {
- return delegate.equals(o);
- }
-
- @Override
- public final int hashCode() {
- return delegate.hashCode();
- }
-
- protected final M getDelegate() {
- return delegate;
- }
-
- @Override
- public String toString() {
- return delegate.toString();
- }
-
- //
- // inner classes
- //
-
- private class KeySet extends CollectionView implements Set {
-
- @Override
- Collection getDelegate() {
- return delegate.keySet();
- }
-
- //
- // mutable operations
- //
-
- public void clear() {
- lock.lock();
- try {
- final M map = copy();
- map.keySet().clear();
- set(map);
- } finally {
- lock.unlock();
- }
- }
-
- public boolean remove(final Object o) {
- return AbstractCopyOnWriteMap.this.remove(o) != null;
- }
-
- public boolean removeAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.keySet().removeAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean retainAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.keySet().retainAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
- }
-
- private final class Values extends CollectionView {
-
- @Override
- Collection getDelegate() {
- return delegate.values();
- }
-
- public void clear() {
- lock.lock();
- try {
- final M map = copy();
- map.values().clear();
- set(map);
- } finally {
- lock.unlock();
- }
- }
-
- public boolean remove(final Object o) {
- lock.lock();
- try {
- if (!contains(o)) {
- return false;
- }
- final M map = copy();
- try {
- return map.values().remove(o);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean removeAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.values().removeAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean retainAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.values().retainAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
- }
-
- private class EntrySet extends CollectionView> implements Set> {
-
- @Override
- Collection> getDelegate() {
- return delegate.entrySet();
- }
-
- public void clear() {
- lock.lock();
- try {
- final M map = copy();
- map.entrySet().clear();
- set(map);
- } finally {
- lock.unlock();
- }
- }
-
- public boolean remove(final Object o) {
- lock.lock();
- try {
- if (!contains(o)) {
- return false;
- }
- final M map = copy();
- try {
- return map.entrySet().remove(o);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean removeAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.entrySet().removeAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
-
- public boolean retainAll(final Collection> c) {
- lock.lock();
- try {
- final M map = copy();
- try {
- return map.entrySet().retainAll(c);
- } finally {
- set(map);
- }
- } finally {
- lock.unlock();
- }
- }
- }
-
- private static class UnmodifiableIterator implements Iterator {
- private final Iterator delegate;
-
- public UnmodifiableIterator(final Iterator delegate) {
- this.delegate = delegate;
- }
-
- public boolean hasNext() {
- return delegate.hasNext();
- }
-
- public T next() {
- return delegate.next();
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- protected static abstract class CollectionView implements Collection {
-
- abstract Collection getDelegate();
-
- //
- // delegate operations
- //
-
- public final boolean contains(final Object o) {
- return getDelegate().contains(o);
- }
-
- public final boolean containsAll(final Collection> c) {
- return getDelegate().containsAll(c);
- }
-
- public final Iterator iterator() {
- return new UnmodifiableIterator<>(getDelegate().iterator());
- }
-
- public final boolean isEmpty() {
- return getDelegate().isEmpty();
- }
-
- public final int size() {
- return getDelegate().size();
- }
-
- public final Object[] toArray() {
- return getDelegate().toArray();
- }
-
- public final T[] toArray(final T[] a) {
- return getDelegate().toArray(a);
- }
-
- @Override
- public int hashCode() {
- return getDelegate().hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return getDelegate().equals(obj);
- }
-
- @Override
- public String toString() {
- return getDelegate().toString();
- }
-
- //
- // unsupported operations
- //
-
- public final boolean add(final E o) {
- throw new UnsupportedOperationException();
- }
-
- public final boolean addAll(final Collection extends E> c) {
- throw new UnsupportedOperationException();
- }
- }
-
- private boolean equals(final Object o1, final Object o2) {
- if (o1 == null) {
- return o2 == null;
- }
- return o1.equals(o2);
- }
-
- /**
- * Provides access to the views of the underlying key, value and entry
- * collections.
- */
- public static abstract class View {
- View() {}
-
- abstract Set keySet();
-
- abstract Set> entrySet();
-
- abstract Collection values();
-
- /**
- * The different types of {@link View} available
- */
- public enum Type {
- STABLE {
- @Override
- > View get(final AbstractCopyOnWriteMap host) {
- return host.new Immutable();
- }
- },
- LIVE {
- @Override
- > View get(final AbstractCopyOnWriteMap host) {
- return host.new Mutable();
- }
- };
- abstract > View get(AbstractCopyOnWriteMap host);
- }
- }
-
- final class Immutable extends View implements Serializable {
-
- private static final long serialVersionUID = -4158727180429303818L;
-
- @Override
- public Set keySet() {
- return unmodifiableSet(delegate.keySet());
- }
-
- @Override
- public Set> entrySet() {
- return unmodifiableSet(delegate.entrySet());
- }
-
- @Override
- public Collection values() {
- return unmodifiableCollection(delegate.values());
- }
- }
-
- final class Mutable extends View implements Serializable {
-
- private static final long serialVersionUID = 1624520291194797634L;
-
- private final transient KeySet keySet = new KeySet();
- private final transient EntrySet entrySet = new EntrySet();
- private final transient Values values = new Values();
-
- @Override
- public Set keySet() {
- return keySet;
- }
-
- @Override
- public Set> entrySet() {
- return entrySet;
- }
-
- @Override
- public Collection values() {
- return values;
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/Assertions.java b/src/com/massivecraft/massivecore/xlib/bson/util/Assertions.java
deleted file mode 100644
index e2b8251f..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/Assertions.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- * Copyright (c) 2008 Atlassian Pty Ltd
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.util;
-
-/**
- * Design by contract assertions.
- *
- * @deprecated This class is NOT a part of public API and will be dropped in 3.x versions.
- */
-@Deprecated
-public class Assertions {
- public static T notNull(final String name, final T notNull) throws IllegalArgumentException {
- if (notNull == null) {
- throw new NullArgumentException(name);
- }
- return notNull;
- }
-
- public static void isTrue(final String name, final boolean check) throws IllegalArgumentException {
- if (!check) {
- throw new IllegalStateException(name);
- }
- }
-
- public static void isTrueArgument(final String name, final boolean check) {
- if (!check) {
- throw new IllegalArgumentException("state should be: " + name);
- }
- }
-
- // /CLOVER:OFF
- private Assertions() {}
-
- // /CLOVER:ON
-
- static class NullArgumentException extends IllegalArgumentException {
- private static final long serialVersionUID = 6178592463723624585L;
-
- NullArgumentException(final String name) {
- super(name + " should not be null!");
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/ClassAncestry.java b/src/com/massivecraft/massivecore/xlib/bson/util/ClassAncestry.java
deleted file mode 100644
index 6409336c..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/ClassAncestry.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.util;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.ConcurrentMap;
-
-import static com.massivecraft.massivecore.xlib.bson.util.CopyOnWriteMap.newHashMap;
-import static java.util.Collections.unmodifiableList;
-
-class ClassAncestry {
-
- /**
- * getAncestry
- *
- * Walks superclass and interface graph, superclasses first, then
- * interfaces, to compute an ancestry list. Supertypes are visited left to
- * right. Duplicates are removed such that no Class will appear in the list
- * before one of its subtypes.
- *
- * Does not need to be synchronized, races are harmless as the Class graph
- * does not change at runtime.
- */
- public static List> getAncestry(Class c) {
- final ConcurrentMap, List>> cache = getClassAncestryCache();
- while (true) {
- List> cachedResult = cache.get(c);
- if (cachedResult != null) {
- return cachedResult;
- }
- cache.putIfAbsent(c, computeAncestry(c));
- }
- }
-
- /**
- * computeAncestry, starting with children and going back to parents
- */
- private static List> computeAncestry(Class> c) {
- final List> result = new ArrayList<>();
- result.add(Object.class);
- computeAncestry(c, result);
- Collections.reverse(result);
- return unmodifiableList(new ArrayList<>(result));
- }
-
- private static void computeAncestry(Class c, List> result) {
- if ((c == null) || (c == Object.class)) {
- return;
- }
-
- // first interfaces (looks backwards but is not)
- Class>[] interfaces = c.getInterfaces();
- for (int i = interfaces.length - 1; i >= 0; i--) {
- computeAncestry(interfaces[i], result);
- }
-
- // next superclass
- computeAncestry(c.getSuperclass(), result);
-
- if (!result.contains(c))
- result.add(c);
- }
-
- /**
- * classAncestryCache
- */
- private static ConcurrentMap, List>> getClassAncestryCache() {
- return (_ancestryCache);
- }
-
- private static final ConcurrentMap, List>> _ancestryCache = newHashMap();
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/ClassMap.java b/src/com/massivecraft/massivecore/xlib/bson/util/ClassMap.java
deleted file mode 100644
index 3a34ecd9..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/ClassMap.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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.
- */
-
-// ClassMap.java
-
-package com.massivecraft.massivecore.xlib.bson.util;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Maps Class objects to values. A ClassMap is different from a regular Map in
- * that get(c) does not only look to see if 'c' is a key in the Map, but also
- * walks the up superclass and interface graph of 'c' to find matches. Derived
- * matches of this sort are then "cached" in the registry so that matches are
- * faster on future gets.
- *
- * This is a very useful class for Class based registries.
- *
- * Example:
- *
- * ClassMap m = new ClassMap(); m.put(Animal.class, "Animal");
- * m.put(Fox.class, "Fox"); m.Fox.class) --> "Fox" m.get(Dog.class) --> "Animal"
- *
- * (assuming Dog.class < Animal.class)
- */
-public class ClassMap {
- /**
- * Walks superclass and interface graph, superclasses first, then
- * interfaces, to compute an ancestry list. Supertypes are visited left to
- * right. Duplicates are removed such that no Class will appear in the list
- * before one of its subtypes.
- */
- public static List> getAncestry(Class c) {
- return ClassAncestry.getAncestry(c);
- }
-
- private final class ComputeFunction implements Function, T> {
- @Override
- public T apply(Class> a) {
- for (Class> cls : getAncestry(a)) {
- T result = map.get(cls);
- if (result != null) {
- return result;
- }
- }
- return null;
- }
- }
-
- private final Map, T> map = CopyOnWriteMap.newHashMap();
- private final Map, T> cache = ComputingMap.create(new ComputeFunction());
-
-
- public T get(Object key) {
- return cache.get(key);
- }
-
- public T put(Class> key, T value) {
- try {
- return map.put(key, value);
- } finally {
- cache.clear();
- }
- }
-
- public T remove(Object key) {
- try {
- return map.remove(key);
- } finally {
- cache.clear();
- }
- }
-
- public void clear() {
- map.clear();
- cache.clear();
- }
-
- public int size() {
- return map.size();
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/ComputingMap.java b/src/com/massivecraft/massivecore/xlib/bson/util/ComputingMap.java
deleted file mode 100644
index 4b5ce000..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/ComputingMap.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2008-2014 MongoDB, Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.util;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-import static com.massivecraft.massivecore.xlib.bson.util.Assertions.notNull;
-
-@SuppressWarnings({"unchecked", "deprecation"})
-final class ComputingMap implements Map, Function {
-
- public static Map create(Function function) {
- return new ComputingMap<>(CopyOnWriteMap.newHashMap(), function);
- }
-
- private final ConcurrentMap map;
- private final Function function;
-
- ComputingMap(ConcurrentMap map, Function function) {
- this.map = notNull("map", map);
- this.function = notNull("function", function);
- }
-
- public V get(Object key) {
- while (true) {
- V v = map.get(key);
- if (v != null)
- return v;
- K k = (K) key;
- V value = function.apply(k);
- if (value == null)
- return null;
- map.putIfAbsent(k, value);
- }
- }
-
- public V apply(K k) {
- return get(k);
- }
-
- public V putIfAbsent(K key, V value) {
- return map.putIfAbsent(key, value);
- }
-
- public boolean remove(Object key, Object value) {
- return map.remove(key, value);
- }
-
- public boolean replace(K key, V oldValue, V newValue) {
- return map.replace(key, oldValue, newValue);
- }
-
- public V replace(K key, V value) {
- return map.replace(key, value);
- }
-
- public int size() {
- return map.size();
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- public boolean containsKey(Object key) {
- return map.containsKey(key);
- }
-
- public boolean containsValue(Object value) {
- return map.containsValue(value);
- }
-
- public V put(K key, V value) {
- return map.put(key, value);
- }
-
- public V remove(Object key) {
- return map.remove(key);
- }
-
- public void putAll(Map extends K, ? extends V> m) {
- map.putAll(m);
- }
-
- public void clear() {
- map.clear();
- }
-
- public Set keySet() {
- return map.keySet();
- }
-
- public Collection values() {
- return map.values();
- }
-
- public Set> entrySet() {
- return map.entrySet();
- }
-
- public boolean equals(Object o) {
- return map.equals(o);
- }
-
- public int hashCode() {
- return map.hashCode();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/bson/util/CopyOnWriteMap.java b/src/com/massivecraft/massivecore/xlib/bson/util/CopyOnWriteMap.java
deleted file mode 100644
index 16900c26..00000000
--- a/src/com/massivecraft/massivecore/xlib/bson/util/CopyOnWriteMap.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (c) 2008 Atlassian Pty Ltd
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.bson.util;
-
-import com.massivecraft.massivecore.xlib.bson.util.AbstractCopyOnWriteMap.View.Type;
-import com.massivecraft.massivecore.xlib.bson.util.annotations.GuardedBy;
-import com.massivecraft.massivecore.xlib.bson.util.annotations.ThreadSafe;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.WeakHashMap;
-
-/**
- * A thread-safe variant of {@link Map} in which all mutative operations (the
- * "destructive" operations described by {@link Map} put, remove and so on) are
- * implemented by making a fresh copy of the underlying map.
- *
- * This is ordinarily too costly, but may be more efficient than
- * alternatives when traversal operations vastly out-number mutations, and is
- * useful when you cannot or don't want to synchronize traversals, yet need to
- * preclude interference among concurrent threads. The "snapshot" style
- * iterators on the collections returned by {@link #entrySet()},
- * {@link #keySet()} and {@link #values()} use a reference to the internal map
- * at the point that the iterator was created. This map never changes during the
- * lifetime of the iterator, so interference is impossible and the iterator is
- * guaranteed not to throw ConcurrentModificationException. The
- * iterators will not reflect additions, removals, or changes to the list since
- * the iterator was created. Removing elements via these iterators is not
- * supported. The mutable operations on these collections (remove, retain etc.)
- * are supported but as with the {@link Map} interface, add and addAll are not
- * and throw {@link UnsupportedOperationException}.
- *
- * The actual copy is performed by an abstract {@link #copy(Map)} method. The
- * method is responsible for the underlying Map implementation (for instance a
- * {@link HashMap}, {@link TreeMap}, {@link LinkedHashMap} etc.) and therefore
- * the semantics of what this map will cope with as far as null keys and values,
- * iteration ordering etc. See the note below about suitable candidates for
- * underlying Map implementations
- *
- * There are supplied implementations for the common j.u.c {@link Map}
- * implementations via the {@link CopyOnWriteMap} static {@link Builder}.
- *
- * Collection views of the keys, values and entries are optionally
- * {@link View.Type.LIVE live} or {@link View.Type.STABLE stable}. Live views
- * are modifiable will cause a copy if a modifying method is called on them.
- * Methods on these will reflect the current state of the collection, although
- * iterators will be snapshot style. If the collection views are stable they are
- * unmodifiable, and will be a snapshot of the state of the map at the time the
- * collection was asked for.
- *
- * Please note that the thread-safety guarantees are limited to
- * the thread-safety of the non-mutative (non-destructive) operations of the
- * underlying map implementation. For instance some implementations such as
- * {@link WeakHashMap} and {@link LinkedHashMap} with access ordering are
- * actually structurally modified by the {@link #get(Object)} method and are
- * therefore not suitable candidates as delegates for this class.
- *
- * @param the key type
- * @param the value type
- * @author Jed Wesley-Smith
- */
-@ThreadSafe
-@SuppressWarnings({"deprecation"})
-abstract class CopyOnWriteMap extends AbstractCopyOnWriteMap> {
- private static final long serialVersionUID = 7935514534647505917L;
-
- /**
- * Get a {@link Builder} for a {@link CopyOnWriteMap} instance.
- *
- * @param key type
- * @param value type
- * @return a fresh builder
- */
- public static Builder builder() {
- return new Builder<>();
- }
-
- /**
- * Build a {@link CopyOnWriteMap} and specify all the options.
- *
- * @param key type
- * @param value type
- */
- public static class Builder {
- private View.Type viewType = View.Type.STABLE;
- private final Map initialValues = new HashMap<>();
-
- Builder() {}
-
- /**
- * Views are stable (fixed in time) and unmodifiable.
- */
- public Builder stableViews() {
- viewType = View.Type.STABLE;
- return this;
- }
-
- /**
- * Views are live (reflecting concurrent updates) and mutator methods
- * are supported.
- */
- public Builder addAll(final Map extends K, ? extends V> values) {
- initialValues.putAll(values);
- return this;
- }
-
- /**
- * Views are live (reflecting concurrent updates) and mutator methods
- * are supported.
- */
- public Builder liveViews() {
- viewType = View.Type.LIVE;
- return this;
- }
-
- public CopyOnWriteMap newHashMap() {
- return new Hash<>(initialValues, viewType);
- }
-
- public CopyOnWriteMap newLinkedMap() {
- return new Linked<>(initialValues, viewType);
- }
- }
-
- /**
- * Creates a new {@link CopyOnWriteMap} with an underlying {@link HashMap}.
- *
- * This map has {@link View.Type.STABLE stable} views.
- */
- public static CopyOnWriteMap newHashMap() {
- final Builder builder = builder();
- return builder.newHashMap();
- }
-
- /**
- * Creates a new {@link CopyOnWriteMap} with an underlying {@link HashMap}
- * using the supplied map as the initial values.
- *
- * This map has {@link View.Type.STABLE stable} views.
- */
- public static CopyOnWriteMap newHashMap(final Map extends K, ? extends V> map) {
- final Builder builder = builder();
- return builder.addAll(map).newHashMap();
- }
-
- /**
- * Creates a new {@link CopyOnWriteMap} with an underlying
- * {@link LinkedHashMap}. Iterators for this map will be return elements in
- * insertion order.
- *
- * This map has {@link View.Type.STABLE stable} views.
- */
- public static CopyOnWriteMap newLinkedMap() {
- final Builder builder = builder();
- return builder.newLinkedMap();
- }
-
- /**
- * Creates a new {@link CopyOnWriteMap} with an underlying
- * {@link LinkedHashMap} using the supplied map as the initial values.
- * Iterators for this map will be return elements in insertion order.
- *
See the Gson User Guide
- * for a more complete set of examples.
- *
- * @see TypeToken
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @author Jesse Wilson
- */
-public final class Gson {
- static final boolean DEFAULT_JSON_NON_EXECUTABLE = false;
- static final boolean DEFAULT_LENIENT = false;
- static final boolean DEFAULT_PRETTY_PRINT = false;
- static final boolean DEFAULT_ESCAPE_HTML = true;
- static final boolean DEFAULT_SERIALIZE_NULLS = false;
- static final boolean DEFAULT_COMPLEX_MAP_KEYS = false;
- static final boolean DEFAULT_SPECIALIZE_FLOAT_VALUES = false;
-
- private static final TypeToken> NULL_KEY_SURROGATE = new TypeToken() {};
- private static final String JSON_NON_EXECUTABLE_PREFIX = ")]}'\n";
-
- /**
- * This thread local guards against reentrant calls to getAdapter(). In
- * certain object graphs, creating an adapter for a type may recursively
- * require an adapter for the same type! Without intervention, the recursive
- * lookup would stack overflow. We cheat by returning a proxy type adapter.
- * The proxy is wired up once the initial adapter has been created.
- */
- private final ThreadLocal
- *
- *
NOTES:
- *
- *
the order of invocation of configuration methods does not matter.
- *
The default serialization of {@link Date} and its subclasses in Gson does
- * not contain time-zone information. So, if you are using date/time instances,
- * use {@code GsonBuilder} and its {@code setDateFormat} methods.
- *
- *
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @author Jesse Wilson
- */
-public final class GsonBuilder {
- private Excluder excluder = Excluder.DEFAULT;
- private LongSerializationPolicy longSerializationPolicy = LongSerializationPolicy.DEFAULT;
- private FieldNamingStrategy fieldNamingPolicy = FieldNamingPolicy.IDENTITY;
- private final Map> instanceCreators
- = new HashMap<>();
- private final List factories = new ArrayList<>();
- /** tree-style hierarchy factories. These come after factories for backwards compatibility. */
- private final List hierarchyFactories = new ArrayList<>();
- private boolean serializeNulls = Gson.DEFAULT_SERIALIZE_NULLS;
- private String datePattern;
- private int dateStyle = DateFormat.DEFAULT;
- private int timeStyle = DateFormat.DEFAULT;
- private boolean complexMapKeySerialization = Gson.DEFAULT_COMPLEX_MAP_KEYS;
- private boolean serializeSpecialFloatingPointValues = Gson.DEFAULT_SPECIALIZE_FLOAT_VALUES;
- private boolean escapeHtmlChars = Gson.DEFAULT_ESCAPE_HTML;
- private boolean prettyPrinting = Gson.DEFAULT_PRETTY_PRINT;
- private boolean generateNonExecutableJson = Gson.DEFAULT_JSON_NON_EXECUTABLE;
- private boolean lenient = Gson.DEFAULT_LENIENT;
-
- /**
- * Creates a GsonBuilder instance that can be used to build Gson with various configuration
- * settings. GsonBuilder follows the builder pattern, and it is typically used by first
- * invoking various configuration methods to set desired options, and finally calling
- * {@link #create()}.
- */
- public GsonBuilder() {
- }
-
- /**
- * Configures Gson to enable versioning support.
- *
- * @param ignoreVersionsAfter any field or type marked with a version higher than this value
- * are ignored during serialization or deserialization.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- public GsonBuilder setVersion(double ignoreVersionsAfter) {
- excluder = excluder.withVersion(ignoreVersionsAfter);
- return this;
- }
-
- /**
- * Configures Gson to excludes all class fields that have the specified modifiers. By default,
- * Gson will exclude all fields marked transient or static. This method will override that
- * behavior.
- *
- * @param modifiers the field modifiers. You must use the modifiers specified in the
- * {@link java.lang.reflect.Modifier} class. For example,
- * {@link java.lang.reflect.Modifier#TRANSIENT},
- * {@link java.lang.reflect.Modifier#STATIC}.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
- excluder = excluder.withModifiers(modifiers);
- return this;
- }
-
- /**
- * Makes the output JSON non-executable in Javascript by prefixing the generated JSON with some
- * special text. This prevents attacks from third-party sites through script sourcing. See
- * Gson Issue 42
- * for details.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder generateNonExecutableJson() {
- this.generateNonExecutableJson = true;
- return this;
- }
-
- /**
- * Configures Gson to exclude all fields from consideration for serialization or deserialization
- * that do not have the {@link Expose} annotation.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- public GsonBuilder excludeFieldsWithoutExposeAnnotation() {
- excluder = excluder.excludeFieldsWithoutExposeAnnotation();
- return this;
- }
-
- /**
- * Configure Gson to serialize null fields. By default, Gson omits all fields that are null
- * during serialization.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.2
- */
- public GsonBuilder serializeNulls() {
- this.serializeNulls = true;
- return this;
- }
-
- /**
- * Enabling this feature will only change the serialized form if the map key is
- * a complex type (i.e. non-primitive) in its serialized JSON
- * form. The default implementation of map serialization uses {@code toString()}
- * on the key; however, when this is called then one of the following cases
- * apply:
- *
- *
Maps as JSON objects
- * For this case, assume that a type adapter is registered to serialize and
- * deserialize some {@code Point} class, which contains an x and y coordinate,
- * to/from the JSON Primitive string value {@code "(x,y)"}. The Java map would
- * then be serialized as a {@link JsonObject}.
- *
- *
- * For this case, assume that a type adapter was NOT registered for some
- * {@code Point} class, but rather the default Gson serialization is applied.
- * In this case, some {@code new Point(2,3)} would serialize as {@code
- * {"x":2,"y":5}}.
- *
- *
Given the assumption above, a {@code Map} will be
- * serialize as an array of arrays (can be viewed as an entry set of pairs).
- *
- *
Below is an example of serializing complex types as JSON arrays:
- *
{@code
- * Gson gson = new GsonBuilder()
- * .enableComplexMapKeySerialization()
- * .create();
- *
- * Map original = new LinkedHashMap();
- * original.put(new Point(5, 6), "a");
- * original.put(new Point(8, 8), "b");
- * System.out.println(gson.toJson(original, type));
- * }
- *
- * The JSON output would look as follows:
- *
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.7
- */
- public GsonBuilder enableComplexMapKeySerialization() {
- complexMapKeySerialization = true;
- return this;
- }
-
- /**
- * Configures Gson to exclude inner classes during serialization.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder disableInnerClassSerialization() {
- excluder = excluder.disableInnerClassSerialization();
- return this;
- }
-
- /**
- * Configures Gson to apply a specific serialization policy for {@code Long} and {@code long}
- * objects.
- *
- * @param serializationPolicy the particular policy to use for serializing longs.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy) {
- this.longSerializationPolicy = serializationPolicy;
- return this;
- }
-
- /**
- * Configures Gson to apply a specific naming policy to an object's field during serialization
- * and deserialization.
- *
- * @param namingConvention the JSON field naming convention to use for serialization and
- * deserialization.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- public GsonBuilder setFieldNamingPolicy(FieldNamingPolicy namingConvention) {
- this.fieldNamingPolicy = namingConvention;
- return this;
- }
-
- /**
- * Configures Gson to apply a specific naming policy strategy to an object's field during
- * serialization and deserialization.
- *
- * @param fieldNamingStrategy the actual naming strategy to apply to the fields
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
- this.fieldNamingPolicy = fieldNamingStrategy;
- return this;
- }
-
- /**
- * Configures Gson to apply a set of exclusion strategies during both serialization and
- * deserialization. Each of the {@code strategies} will be applied as a disjunction rule.
- * This means that if one of the {@code strategies} suggests that a field (or class) should be
- * skipped then that field (or object) is skipped during serialization/deserialization.
- *
- * @param strategies the set of strategy object to apply during object (de)serialization.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.4
- */
- public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
- for (ExclusionStrategy strategy : strategies) {
- excluder = excluder.withExclusionStrategy(strategy, true, true);
- }
- return this;
- }
-
- /**
- * Configures Gson to apply the passed in exclusion strategy during serialization.
- * If this method is invoked numerous times with different exclusion strategy objects
- * then the exclusion strategies that were added will be applied as a disjunction rule.
- * This means that if one of the added exclusion strategies suggests that a field (or
- * class) should be skipped then that field (or object) is skipped during its
- * serialization.
- *
- * @param strategy an exclusion strategy to apply during serialization.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.7
- */
- public GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy strategy) {
- excluder = excluder.withExclusionStrategy(strategy, true, false);
- return this;
- }
-
- /**
- * Configures Gson to apply the passed in exclusion strategy during deserialization.
- * If this method is invoked numerous times with different exclusion strategy objects
- * then the exclusion strategies that were added will be applied as a disjunction rule.
- * This means that if one of the added exclusion strategies suggests that a field (or
- * class) should be skipped then that field (or object) is skipped during its
- * deserialization.
- *
- * @param strategy an exclusion strategy to apply during deserialization.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.7
- */
- public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strategy) {
- excluder = excluder.withExclusionStrategy(strategy, false, true);
- return this;
- }
-
- /**
- * Configures Gson to output Json that fits in a page for pretty printing. This option only
- * affects Json serialization.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- public GsonBuilder setPrettyPrinting() {
- prettyPrinting = true;
- return this;
- }
-
- /**
- * By default, Gson is strict and only accepts JSON as specified by
- * RFC 4627. This option makes the parser
- * liberal in what it accepts.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @see JsonReader#setLenient(boolean)
- */
- public GsonBuilder setLenient() {
- lenient = true;
- return this;
- }
-
- /**
- * By default, Gson escapes HTML characters such as < > etc. Use this option to configure
- * Gson to pass-through HTML characters as is.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder disableHtmlEscaping() {
- this.escapeHtmlChars = false;
- return this;
- }
-
- /**
- * Configures Gson to serialize {@code Date} objects according to the pattern provided. You can
- * call this method or {@link #setDateFormat(int)} multiple times, but only the last invocation
- * will be used to decide the serialization format.
- *
- *
The date format will be used to serialize and deserialize {@link java.util.Date}, {@link
- * java.sql.Timestamp} and {@link java.sql.Date}.
- *
- *
Note that this pattern must abide by the convention provided by {@code SimpleDateFormat}
- * class. See the documentation in {@link java.text.SimpleDateFormat} for more information on
- * valid date and time patterns.
- *
- * @param pattern the pattern that dates will be serialized/deserialized to/from
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.2
- */
- public GsonBuilder setDateFormat(String pattern) {
- // TODO(Joel): Make this fail fast if it is an invalid date format
- this.datePattern = pattern;
- return this;
- }
-
- /**
- * Configures Gson to to serialize {@code Date} objects according to the style value provided.
- * You can call this method or {@link #setDateFormat(String)} multiple times, but only the last
- * invocation will be used to decide the serialization format.
- *
- *
Note that this style value should be one of the predefined constants in the
- * {@code DateFormat} class. See the documentation in {@link java.text.DateFormat} for more
- * information on the valid style constants.
- *
- * @param style the predefined date style that date objects will be serialized/deserialized
- * to/from
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.2
- */
- public GsonBuilder setDateFormat(int style) {
- this.dateStyle = style;
- this.datePattern = null;
- return this;
- }
-
- /**
- * Configures Gson to to serialize {@code Date} objects according to the style value provided.
- * You can call this method or {@link #setDateFormat(String)} multiple times, but only the last
- * invocation will be used to decide the serialization format.
- *
- *
Note that this style value should be one of the predefined constants in the
- * {@code DateFormat} class. See the documentation in {@link java.text.DateFormat} for more
- * information on the valid style constants.
- *
- * @param dateStyle the predefined date style that date objects will be serialized/deserialized
- * to/from
- * @param timeStyle the predefined style for the time portion of the date objects
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.2
- */
- public GsonBuilder setDateFormat(int dateStyle, int timeStyle) {
- this.dateStyle = dateStyle;
- this.timeStyle = timeStyle;
- this.datePattern = null;
- return this;
- }
-
- /**
- * Configures Gson for custom serialization or deserialization. This method combines the
- * registration of an {@link TypeAdapter}, {@link InstanceCreator}, {@link JsonSerializer}, and a
- * {@link JsonDeserializer}. It is best used when a single object {@code typeAdapter} implements
- * all the required interfaces for custom serialization with Gson. If a type adapter was
- * previously registered for the specified {@code type}, it is overwritten.
- *
- *
This registers the type specified and no other types: you must manually register related
- * types! For example, applications registering {@code boolean.class} should also register {@code
- * Boolean.class}.
- *
- * @param type the type definition for the type adapter being registered
- * @param typeAdapter This object must implement at least one of the {@link TypeAdapter},
- * {@link InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
- $Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer>
- || typeAdapter instanceof JsonDeserializer>
- || typeAdapter instanceof InstanceCreator>
- || typeAdapter instanceof TypeAdapter>);
- if (typeAdapter instanceof InstanceCreator>) {
- instanceCreators.put(type, (InstanceCreator) typeAdapter);
- }
- if (typeAdapter instanceof JsonSerializer> || typeAdapter instanceof JsonDeserializer>) {
- TypeToken> typeToken = TypeToken.get(type);
- factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter));
- }
- if (typeAdapter instanceof TypeAdapter>) {
- factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter)typeAdapter));
- }
- return this;
- }
-
- /**
- * Register a factory for type adapters. Registering a factory is useful when the type
- * adapter needs to be configured based on the type of the field being processed. Gson
- * is designed to handle a large number of factories, so you should consider registering
- * them to be at par with registering an individual type adapter.
- *
- * @since 2.1
- */
- public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
- factories.add(factory);
- return this;
- }
-
- /**
- * Configures Gson for custom serialization or deserialization for an inheritance type hierarchy.
- * This method combines the registration of a {@link TypeAdapter}, {@link JsonSerializer} and
- * a {@link JsonDeserializer}. If a type adapter was previously registered for the specified
- * type hierarchy, it is overridden. If a type adapter is registered for a specific type in
- * the type hierarchy, it will be invoked instead of the one registered for the type hierarchy.
- *
- * @param baseType the class definition for the type adapter being registered for the base class
- * or interface
- * @param typeAdapter This object must implement at least one of {@link TypeAdapter},
- * {@link JsonSerializer} or {@link JsonDeserializer} interfaces.
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.7
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public GsonBuilder registerTypeHierarchyAdapter(Class> baseType, Object typeAdapter) {
- $Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer>
- || typeAdapter instanceof JsonDeserializer>
- || typeAdapter instanceof TypeAdapter>);
- if (typeAdapter instanceof JsonDeserializer || typeAdapter instanceof JsonSerializer) {
- hierarchyFactories.add(0,
- TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter));
- }
- if (typeAdapter instanceof TypeAdapter>) {
- factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter)typeAdapter));
- }
- return this;
- }
-
- /**
- * Section 2.4 of JSON specification disallows
- * special double values (NaN, Infinity, -Infinity). However,
- * Javascript
- * specification (see section 4.3.20, 4.3.22, 4.3.23) allows these values as valid Javascript
- * values. Moreover, most JavaScript engines will accept these special values in JSON without
- * problem. So, at a practical level, it makes sense to accept these values as valid JSON even
- * though JSON specification disallows them.
- *
- *
Gson always accepts these special values during deserialization. However, it outputs
- * strictly compliant JSON. Hence, if it encounters a float value {@link Float#NaN},
- * {@link Float#POSITIVE_INFINITY}, {@link Float#NEGATIVE_INFINITY}, or a double value
- * {@link Double#NaN}, {@link Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, it
- * will throw an {@link IllegalArgumentException}. This method provides a way to override the
- * default behavior when you know that the JSON receiver will be able to handle these special
- * values.
- *
- * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
- * @since 1.3
- */
- public GsonBuilder serializeSpecialFloatingPointValues() {
- this.serializeSpecialFloatingPointValues = true;
- return this;
- }
-
- /**
- * Creates a {@link Gson} instance based on the current configuration. This method is free of
- * side-effects to this {@code GsonBuilder} instance and hence can be called multiple times.
- *
- * @return an instance of Gson configured with the options currently set in this builder
- */
- public Gson create() {
- List factories = new ArrayList<>();
- factories.addAll(this.factories);
- Collections.reverse(factories);
- factories.addAll(this.hierarchyFactories);
- addTypeAdaptersForDate(datePattern, dateStyle, timeStyle, factories);
-
- return new Gson(excluder, fieldNamingPolicy, instanceCreators,
- serializeNulls, complexMapKeySerialization,
- generateNonExecutableJson, escapeHtmlChars, prettyPrinting, lenient,
- serializeSpecialFloatingPointValues, longSerializationPolicy, factories);
- }
-
- private void addTypeAdaptersForDate(String datePattern, int dateStyle, int timeStyle,
- List factories) {
- DefaultDateTypeAdapter dateTypeAdapter;
- if (datePattern != null && !"".equals(datePattern.trim())) {
- dateTypeAdapter = new DefaultDateTypeAdapter(datePattern);
- } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) {
- dateTypeAdapter = new DefaultDateTypeAdapter(dateStyle, timeStyle);
- } else {
- return;
- }
-
- factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Date.class), dateTypeAdapter));
- factories.add(TreeTypeAdapter.newFactory(TypeToken.get(Timestamp.class), dateTypeAdapter));
- factories.add(TreeTypeAdapter.newFactory(TypeToken.get(java.sql.Date.class), dateTypeAdapter));
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/InstanceCreator.java b/src/com/massivecraft/massivecore/xlib/gson/InstanceCreator.java
deleted file mode 100644
index cb9d25e5..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/InstanceCreator.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.lang.reflect.Type;
-
-/**
- * This interface is implemented to create instances of a class that does not define a no-args
- * constructor. If you can modify the class, you should instead add a private, or public
- * no-args constructor. However, that is not possible for library classes, such as JDK classes, or
- * a third-party library that you do not have source-code of. In such cases, you should define an
- * instance creator for the class. Implementations of this interface should be registered with
- * {@link GsonBuilder#registerTypeAdapter(Type, Object)} method before Gson will be able to use
- * them.
- *
Let us look at an example where defining an InstanceCreator might be useful. The
- * {@code Id} class defined below does not have a default no-args constructor.
- *
- *
- * public class Id<T> {
- * private final Class<T> clazz;
- * private final long value;
- * public Id(Class<T> clazz, long value) {
- * this.clazz = clazz;
- * this.value = value;
- * }
- * }
- *
- *
- *
If Gson encounters an object of type {@code Id} during deserialization, it will throw an
- * exception. The easiest way to solve this problem will be to add a (public or private) no-args
- * constructor as follows:
However, let us assume that the developer does not have access to the source-code of the
- * {@code Id} class, or does not want to define a no-args constructor for it. The developer
- * can solve this problem by defining an {@code InstanceCreator} for {@code Id}:
- *
- *
- * class IdInstanceCreator implements InstanceCreator<Id> {
- * public Id createInstance(Type type) {
- * return new Id(Object.class, 0L);
- * }
- * }
- *
- *
- *
Note that it does not matter what the fields of the created instance contain since Gson will
- * overwrite them with the deserialized values specified in Json. You should also ensure that a
- * new object is returned, not a common object since its fields will be overwritten.
- * The developer will need to register {@code IdInstanceCreator} with Gson as follows:
- *
- *
- * Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdInstanceCreator()).create();
- *
- *
- * @param the type of object that will be created by this implementation.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public interface InstanceCreator {
-
- /**
- * Gson invokes this call-back method during deserialization to create an instance of the
- * specified type. The fields of the returned instance are overwritten with the data present
- * in the Json. Since the prior contents of the object are destroyed and overwritten, do not
- * return an instance that is useful elsewhere. In particular, do not return a common instance,
- * always use {@code new} to create a new instance.
- *
- * @param type the parameterized T represented as a {@link Type}.
- * @return a default object instance of type T.
- */
- public T createInstance(Type type);
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonArray.java b/src/com/massivecraft/massivecore/xlib/gson/JsonArray.java
deleted file mode 100644
index d300a8f7..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonArray.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A class representing an array type in Json. An array is a list of {@link JsonElement}s each of
- * which can be of a different type. This is an ordered list, meaning that the order in which
- * elements are added is preserved.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class JsonArray extends JsonElement implements Iterable {
- private final List elements;
-
- /**
- * Creates an empty JsonArray.
- */
- public JsonArray() {
- elements = new ArrayList<>();
- }
-
- @Override
- JsonArray deepCopy() {
- JsonArray result = new JsonArray();
- for (JsonElement element : elements) {
- result.add(element.deepCopy());
- }
- return result;
- }
-
- /**
- * Adds the specified boolean to self.
- *
- * @param bool the boolean that needs to be added to the array.
- */
- public void add(Boolean bool) {
- elements.add(bool == null ? JsonNull.INSTANCE : new JsonPrimitive(bool));
- }
-
- /**
- * Adds the specified character to self.
- *
- * @param character the character that needs to be added to the array.
- */
- public void add(Character character) {
- elements.add(character == null ? JsonNull.INSTANCE : new JsonPrimitive(character));
- }
-
- /**
- * Adds the specified number to self.
- *
- * @param number the number that needs to be added to the array.
- */
- public void add(Number number) {
- elements.add(number == null ? JsonNull.INSTANCE : new JsonPrimitive(number));
- }
-
- /**
- * Adds the specified string to self.
- *
- * @param string the string that needs to be added to the array.
- */
- public void add(String string) {
- elements.add(string == null ? JsonNull.INSTANCE : new JsonPrimitive(string));
- }
-
- /**
- * Adds the specified element to self.
- *
- * @param element the element that needs to be added to the array.
- */
- public void add(JsonElement element) {
- if (element == null) {
- element = JsonNull.INSTANCE;
- }
- elements.add(element);
- }
-
- /**
- * Adds all the elements of the specified array to self.
- *
- * @param array the array whose elements need to be added to the array.
- */
- public void addAll(JsonArray array) {
- elements.addAll(array.elements);
- }
-
- /**
- * Replaces the element at the specified position in this array with the specified element.
- * Element can be null.
- * @param index index of the element to replace
- * @param element element to be stored at the specified position
- * @return the element previously at the specified position
- * @throws IndexOutOfBoundsException if the specified index is outside the array bounds
- */
- public JsonElement set(int index, JsonElement element) {
- return elements.set(index, element);
- }
-
- /**
- * Removes the first occurrence of the specified element from this array, if it is present.
- * If the array does not contain the element, it is unchanged.
- * @param element element to be removed from this array, if present
- * @return true if this array contained the specified element, false otherwise
- * @since 2.3
- */
- public boolean remove(JsonElement element) {
- return elements.remove(element);
- }
-
- /**
- * Removes the element at the specified position in this array. Shifts any subsequent elements
- * to the left (subtracts one from their indices). Returns the element that was removed from
- * the array.
- * @param index index the index of the element to be removed
- * @return the element previously at the specified position
- * @throws IndexOutOfBoundsException if the specified index is outside the array bounds
- * @since 2.3
- */
- public JsonElement remove(int index) {
- return elements.remove(index);
- }
-
- /**
- * Returns true if this array contains the specified element.
- * @return true if this array contains the specified element.
- * @param element whose presence in this array is to be tested
- * @since 2.3
- */
- public boolean contains(JsonElement element) {
- return elements.contains(element);
- }
-
- /**
- * Returns the number of elements in the array.
- *
- * @return the number of elements in the array.
- */
- public int size() {
- return elements.size();
- }
-
- /**
- * Returns an iterator to navigate the elements of the array. Since the array is an ordered list,
- * the iterator navigates the elements in the order they were inserted.
- *
- * @return an iterator to navigate the elements of the array.
- */
- public Iterator iterator() {
- return elements.iterator();
- }
-
- /**
- * Returns the ith element of the array.
- *
- * @param i the index of the element that is being sought.
- * @return the element present at the ith index.
- * @throws IndexOutOfBoundsException if i is negative or greater than or equal to the
- * {@link #size()} of the array.
- */
- public JsonElement get(int i) {
- return elements.get(i);
- }
-
- /**
- * convenience method to get this array as a {@link Number} if it contains a single element.
- *
- * @return get this element as a number if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid Number.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public Number getAsNumber() {
- if (elements.size() == 1) {
- return elements.get(0).getAsNumber();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a {@link String} if it contains a single element.
- *
- * @return get this element as a String if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid String.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public String getAsString() {
- if (elements.size() == 1) {
- return elements.get(0).getAsString();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a double if it contains a single element.
- *
- * @return get this element as a double if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid double.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public double getAsDouble() {
- if (elements.size() == 1) {
- return elements.get(0).getAsDouble();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
- *
- * @return get this element as a {@link BigDecimal} if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
- * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
- * @throws IllegalStateException if the array has more than one element.
- * @since 1.2
- */
- @Override
- public BigDecimal getAsBigDecimal() {
- if (elements.size() == 1) {
- return elements.get(0).getAsBigDecimal();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a {@link BigInteger} if it contains a single element.
- *
- * @return get this element as a {@link BigInteger} if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
- * @throws NumberFormatException if the element at index 0 is not a valid {@link BigInteger}.
- * @throws IllegalStateException if the array has more than one element.
- * @since 1.2
- */
- @Override
- public BigInteger getAsBigInteger() {
- if (elements.size() == 1) {
- return elements.get(0).getAsBigInteger();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a float if it contains a single element.
- *
- * @return get this element as a float if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid float.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public float getAsFloat() {
- if (elements.size() == 1) {
- return elements.get(0).getAsFloat();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a long if it contains a single element.
- *
- * @return get this element as a long if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid long.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public long getAsLong() {
- if (elements.size() == 1) {
- return elements.get(0).getAsLong();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as an integer if it contains a single element.
- *
- * @return get this element as an integer if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid integer.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public int getAsInt() {
- if (elements.size() == 1) {
- return elements.get(0).getAsInt();
- }
- throw new IllegalStateException();
- }
-
- @Override
- public byte getAsByte() {
- if (elements.size() == 1) {
- return elements.get(0).getAsByte();
- }
- throw new IllegalStateException();
- }
-
- @Override
- public char getAsCharacter() {
- if (elements.size() == 1) {
- return elements.get(0).getAsCharacter();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a primitive short if it contains a single element.
- *
- * @return get this element as a primitive short if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid short.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public short getAsShort() {
- if (elements.size() == 1) {
- return elements.get(0).getAsShort();
- }
- throw new IllegalStateException();
- }
-
- /**
- * convenience method to get this array as a boolean if it contains a single element.
- *
- * @return get this element as a boolean if it is single element array.
- * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
- * is not a valid boolean.
- * @throws IllegalStateException if the array has more than one element.
- */
- @Override
- public boolean getAsBoolean() {
- if (elements.size() == 1) {
- return elements.get(0).getAsBoolean();
- }
- throw new IllegalStateException();
- }
-
- @Override
- public boolean equals(Object o) {
- return (o == this) || (o instanceof JsonArray && ((JsonArray) o).elements.equals(elements));
- }
-
- @Override
- public int hashCode() {
- return elements.hashCode();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializationContext.java b/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializationContext.java
deleted file mode 100644
index 8e446c34..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializationContext.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.lang.reflect.Type;
-
-/**
- * Context for deserialization that is passed to a custom deserializer during invocation of its
- * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)}
- * method.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public interface JsonDeserializationContext {
-
- /**
- * Invokes default deserialization on the specified object. It should never be invoked on
- * the element received as a parameter of the
- * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)} method. Doing
- * so will result in an infinite loop since Gson will in-turn call the custom deserializer again.
- *
- * @param json the parse tree.
- * @param typeOfT type of the expected return value.
- * @param The type of the deserialized object.
- * @return An object of type typeOfT.
- * @throws JsonParseException if the parse tree does not contain expected data.
- */
- public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
-}
\ No newline at end of file
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializer.java b/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializer.java
deleted file mode 100644
index b4e1d6e1..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonDeserializer.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.lang.reflect.Type;
-
-/**
- *
Interface representing a custom deserializer for Json. You should write a custom
- * deserializer, if you are not happy with the default deserialization done by Gson. You will
- * also need to register this deserializer through
- * {@link GsonBuilder#registerTypeAdapter(Type, Object)}.
- *
- *
Let us look at example where defining a deserializer will be useful. The {@code Id} class
- * defined below has two fields: {@code clazz} and {@code value}.
- *
- *
- * public class Id<T> {
- * private final Class<T> clazz;
- * private final long value;
- * public Id(Class<T> clazz, long value) {
- * this.clazz = clazz;
- * this.value = value;
- * }
- * public long getValue() {
- * return value;
- * }
- * }
- *
- *
- *
The default deserialization of {@code Id(com.foo.MyObject.class, 20L)} will require the
- * Json string to be {"clazz":com.foo.MyObject,"value":20}. Suppose, you already know
- * the type of the field that the {@code Id} will be deserialized into, and hence just want to
- * deserialize it from a Json string {@code 20}. You can achieve that by writing a custom
- * deserializer:
- *
- *
- * class IdDeserializer implements JsonDeserializer<Id>() {
- * public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- * throws JsonParseException {
- * return new Id((Class)typeOfT, id.getValue());
- * }
- *
- *
- *
You will also need to register {@code IdDeserializer} with Gson as follows:
- *
- *
- * Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdDeserializer()).create();
- *
- *
- *
New applications should prefer {@link TypeAdapter}, whose streaming API
- * is more efficient than this interface's tree API.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- *
- * @param type for which the deserializer is being registered. It is possible that a
- * deserializer may be asked to deserialize a specific generic type of the T.
- */
-public interface JsonDeserializer {
-
- /**
- * Gson invokes this call-back method during deserialization when it encounters a field of the
- * specified type.
- *
In the implementation of this call-back method, you should consider invoking
- * {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects
- * for any non-trivial field of the returned object. However, you should never invoke it on the
- * the same type passing {@code json} since that will cause an infinite loop (Gson will call your
- * call-back method again).
- *
- * @param json The Json data being deserialized
- * @param typeOfT The type of the Object to deserialize to
- * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
- * @throws JsonParseException if json is not in the expected format of {@code typeofT}
- */
- public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException;
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonElement.java b/src/com/massivecraft/massivecore/xlib/gson/JsonElement.java
deleted file mode 100644
index 22af9eec..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonElement.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.Streams;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonWriter;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/**
- * A class representing an element of Json. It could either be a {@link JsonObject}, a
- * {@link JsonArray}, a {@link JsonPrimitive} or a {@link JsonNull}.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public abstract class JsonElement {
- /**
- * Returns a deep copy of this element. Immutable elements like primitives
- * and nulls are not copied.
- */
- abstract JsonElement deepCopy();
-
- /**
- * provides check for verifying if this element is an array or not.
- *
- * @return true if this element is of type {@link JsonArray}, false otherwise.
- */
- public boolean isJsonArray() {
- return this instanceof JsonArray;
- }
-
- /**
- * provides check for verifying if this element is a Json object or not.
- *
- * @return true if this element is of type {@link JsonObject}, false otherwise.
- */
- public boolean isJsonObject() {
- return this instanceof JsonObject;
- }
-
- /**
- * provides check for verifying if this element is a primitive or not.
- *
- * @return true if this element is of type {@link JsonPrimitive}, false otherwise.
- */
- public boolean isJsonPrimitive() {
- return this instanceof JsonPrimitive;
- }
-
- /**
- * provides check for verifying if this element represents a null value or not.
- *
- * @return true if this element is of type {@link JsonNull}, false otherwise.
- * @since 1.2
- */
- public boolean isJsonNull() {
- return this instanceof JsonNull;
- }
-
- /**
- * convenience method to get this element as a {@link JsonObject}. If the element is of some
- * other type, a {@link IllegalStateException} will result. Hence it is best to use this method
- * after ensuring that this element is of the desired type by calling {@link #isJsonObject()}
- * first.
- *
- * @return get this element as a {@link JsonObject}.
- * @throws IllegalStateException if the element is of another type.
- */
- public JsonObject getAsJsonObject() {
- if (isJsonObject()) {
- return (JsonObject) this;
- }
- throw new IllegalStateException("Not a JSON Object: " + this);
- }
-
- /**
- * convenience method to get this element as a {@link JsonArray}. If the element is of some
- * other type, a {@link IllegalStateException} will result. Hence it is best to use this method
- * after ensuring that this element is of the desired type by calling {@link #isJsonArray()}
- * first.
- *
- * @return get this element as a {@link JsonArray}.
- * @throws IllegalStateException if the element is of another type.
- */
- public JsonArray getAsJsonArray() {
- if (isJsonArray()) {
- return (JsonArray) this;
- }
- throw new IllegalStateException("This is not a JSON Array.");
- }
-
- /**
- * convenience method to get this element as a {@link JsonPrimitive}. If the element is of some
- * other type, a {@link IllegalStateException} will result. Hence it is best to use this method
- * after ensuring that this element is of the desired type by calling {@link #isJsonPrimitive()}
- * first.
- *
- * @return get this element as a {@link JsonPrimitive}.
- * @throws IllegalStateException if the element is of another type.
- */
- public JsonPrimitive getAsJsonPrimitive() {
- if (isJsonPrimitive()) {
- return (JsonPrimitive) this;
- }
- throw new IllegalStateException("This is not a JSON Primitive.");
- }
-
- /**
- * convenience method to get this element as a {@link JsonNull}. If the element is of some
- * other type, a {@link IllegalStateException} will result. Hence it is best to use this method
- * after ensuring that this element is of the desired type by calling {@link #isJsonNull()}
- * first.
- *
- * @return get this element as a {@link JsonNull}.
- * @throws IllegalStateException if the element is of another type.
- * @since 1.2
- */
- public JsonNull getAsJsonNull() {
- if (isJsonNull()) {
- return (JsonNull) this;
- }
- throw new IllegalStateException("This is not a JSON Null.");
- }
-
- /**
- * convenience method to get this element as a boolean value.
- *
- * @return get this element as a primitive boolean value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * boolean value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public boolean getAsBoolean() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a {@link Boolean} value.
- *
- * @return get this element as a {@link Boolean} value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * boolean value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- Boolean getAsBooleanWrapper() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a {@link Number}.
- *
- * @return get this element as a {@link Number}.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * number.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public Number getAsNumber() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a string value.
- *
- * @return get this element as a string value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * string value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public String getAsString() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive double value.
- *
- * @return get this element as a primitive double value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * double value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public double getAsDouble() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive float value.
- *
- * @return get this element as a primitive float value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * float value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public float getAsFloat() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive long value.
- *
- * @return get this element as a primitive long value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * long value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public long getAsLong() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive integer value.
- *
- * @return get this element as a primitive integer value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * integer value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public int getAsInt() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive byte value.
- *
- * @return get this element as a primitive byte value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * byte value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- * @since 1.3
- */
- public byte getAsByte() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive character value.
- *
- * @return get this element as a primitive char value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * char value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- * @since 1.3
- */
- public char getAsCharacter() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a {@link BigDecimal}.
- *
- * @return get this element as a {@link BigDecimal}.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive}.
- * * @throws NumberFormatException if the element is not a valid {@link BigDecimal}.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- * @since 1.2
- */
- public BigDecimal getAsBigDecimal() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a {@link BigInteger}.
- *
- * @return get this element as a {@link BigInteger}.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive}.
- * @throws NumberFormatException if the element is not a valid {@link BigInteger}.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- * @since 1.2
- */
- public BigInteger getAsBigInteger() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * convenience method to get this element as a primitive short value.
- *
- * @return get this element as a primitive short value.
- * @throws ClassCastException if the element is of not a {@link JsonPrimitive} and is not a valid
- * short value.
- * @throws IllegalStateException if the element is of the type {@link JsonArray} but contains
- * more than a single element.
- */
- public short getAsShort() {
- throw new UnsupportedOperationException(getClass().getSimpleName());
- }
-
- /**
- * Returns a String representation of this element.
- */
- @Override
- public String toString() {
- try {
- StringWriter stringWriter = new StringWriter();
- JsonWriter jsonWriter = new JsonWriter(stringWriter);
- jsonWriter.setLenient(true);
- Streams.write(this, jsonWriter);
- return stringWriter.toString();
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonIOException.java b/src/com/massivecraft/massivecore/xlib/gson/JsonIOException.java
deleted file mode 100644
index 91e740e2..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonIOException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-/**
- * This exception is raised when Gson was unable to read an input stream
- * or write to one.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class JsonIOException extends JsonParseException {
- private static final long serialVersionUID = 1L;
-
- public JsonIOException(String msg) {
- super(msg);
- }
-
- public JsonIOException(String msg, Throwable cause) {
- super(msg, cause);
- }
-
- /**
- * Creates exception with the specified cause. Consider using
- * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened.
- *
- * @param cause root exception that caused this exception to be thrown.
- */
- public JsonIOException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonNull.java b/src/com/massivecraft/massivecore/xlib/gson/JsonNull.java
deleted file mode 100644
index 0b4a93b4..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonNull.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-/**
- * A class representing a Json {@code null} value.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @since 1.2
- */
-public final class JsonNull extends JsonElement {
- /**
- * singleton for JsonNull
- *
- * @since 1.8
- */
- public static final JsonNull INSTANCE = new JsonNull();
-
- /**
- * Creates a new JsonNull object.
- * Deprecated since Gson version 1.8. Use {@link #INSTANCE} instead
- */
- @Deprecated
- public JsonNull() {
- // Do nothing
- }
-
- @Override
- JsonNull deepCopy() {
- return INSTANCE;
- }
-
- /**
- * All instances of JsonNull have the same hash code since they are indistinguishable
- */
- @Override
- public int hashCode() {
- return JsonNull.class.hashCode();
- }
-
- /**
- * All instances of JsonNull are the same
- */
- @Override
- public boolean equals(Object other) {
- return this == other || other instanceof JsonNull;
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonObject.java b/src/com/massivecraft/massivecore/xlib/gson/JsonObject.java
deleted file mode 100644
index 2420fcfd..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonObject.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.LinkedTreeMap;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A class representing an object type in Json. An object consists of name-value pairs where names
- * are strings, and values are any other type of {@link JsonElement}. This allows for a creating a
- * tree of JsonElements. The member elements of this object are maintained in order they were added.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class JsonObject extends JsonElement {
- private final LinkedTreeMap members =
- new LinkedTreeMap<>();
-
- @Override
- JsonObject deepCopy() {
- JsonObject result = new JsonObject();
- for (Map.Entry entry : members.entrySet()) {
- result.add(entry.getKey(), entry.getValue().deepCopy());
- }
- return result;
- }
-
- /**
- * Adds a member, which is a name-value pair, to self. The name must be a String, but the value
- * can be an arbitrary JsonElement, thereby allowing you to build a full tree of JsonElements
- * rooted at this node.
- *
- * @param property name of the member.
- * @param value the member object.
- */
- public void add(String property, JsonElement value) {
- if (value == null) {
- value = JsonNull.INSTANCE;
- }
- members.put(property, value);
- }
-
- /**
- * Removes the {@code property} from this {@link JsonObject}.
- *
- * @param property name of the member that should be removed.
- * @return the {@link JsonElement} object that is being removed.
- * @since 1.3
- */
- public JsonElement remove(String property) {
- return members.remove(property);
- }
-
- /**
- * Convenience method to add a primitive member. The specified value is converted to a
- * JsonPrimitive of String.
- *
- * @param property name of the member.
- * @param value the string value associated with the member.
- */
- public void addProperty(String property, String value) {
- add(property, createJsonElement(value));
- }
-
- /**
- * Convenience method to add a primitive member. The specified value is converted to a
- * JsonPrimitive of Number.
- *
- * @param property name of the member.
- * @param value the number value associated with the member.
- */
- public void addProperty(String property, Number value) {
- add(property, createJsonElement(value));
- }
-
- /**
- * Convenience method to add a boolean member. The specified value is converted to a
- * JsonPrimitive of Boolean.
- *
- * @param property name of the member.
- * @param value the number value associated with the member.
- */
- public void addProperty(String property, Boolean value) {
- add(property, createJsonElement(value));
- }
-
- /**
- * Convenience method to add a char member. The specified value is converted to a
- * JsonPrimitive of Character.
- *
- * @param property name of the member.
- * @param value the number value associated with the member.
- */
- public void addProperty(String property, Character value) {
- add(property, createJsonElement(value));
- }
-
- /**
- * Creates the proper {@link JsonElement} object from the given {@code value} object.
- *
- * @param value the object to generate the {@link JsonElement} for
- * @return a {@link JsonPrimitive} if the {@code value} is not null, otherwise a {@link JsonNull}
- */
- private JsonElement createJsonElement(Object value) {
- return value == null ? JsonNull.INSTANCE : new JsonPrimitive(value);
- }
-
- /**
- * Returns a set of members of this object. The set is ordered, and the order is in which the
- * elements were added.
- *
- * @return a set of members of this object.
- */
- public Set> entrySet() {
- return members.entrySet();
- }
-
- /**
- * Returns the number of key/value pairs in the object.
- *
- * @return the number of key/value pairs in the object.
- */
- public int size() {
- return members.size();
- }
-
- /**
- * Convenience method to check if a member with the specified name is present in this object.
- *
- * @param memberName name of the member that is being checked for presence.
- * @return true if there is a member with the specified name, false otherwise.
- */
- public boolean has(String memberName) {
- return members.containsKey(memberName);
- }
-
- /**
- * Returns the member with the specified name.
- *
- * @param memberName name of the member that is being requested.
- * @return the member matching the name. Null if no such member exists.
- */
- public JsonElement get(String memberName) {
- return members.get(memberName);
- }
-
- /**
- * Convenience method to get the specified member as a JsonPrimitive element.
- *
- * @param memberName name of the member being requested.
- * @return the JsonPrimitive corresponding to the specified member.
- */
- public JsonPrimitive getAsJsonPrimitive(String memberName) {
- return (JsonPrimitive) members.get(memberName);
- }
-
- /**
- * Convenience method to get the specified member as a JsonArray.
- *
- * @param memberName name of the member being requested.
- * @return the JsonArray corresponding to the specified member.
- */
- public JsonArray getAsJsonArray(String memberName) {
- return (JsonArray) members.get(memberName);
- }
-
- /**
- * Convenience method to get the specified member as a JsonObject.
- *
- * @param memberName name of the member being requested.
- * @return the JsonObject corresponding to the specified member.
- */
- public JsonObject getAsJsonObject(String memberName) {
- return (JsonObject) members.get(memberName);
- }
-
- @Override
- public boolean equals(Object o) {
- return (o == this) || (o instanceof JsonObject
- && ((JsonObject) o).members.equals(members));
- }
-
- @Override
- public int hashCode() {
- return members.hashCode();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonParseException.java b/src/com/massivecraft/massivecore/xlib/gson/JsonParseException.java
deleted file mode 100644
index 71a652a8..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonParseException.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-/**
- * This exception is raised if there is a serious issue that occurs during parsing of a Json
- * string. One of the main usages for this class is for the Gson infrastructure. If the incoming
- * Json is bad/malicious, an instance of this exception is raised.
- *
- *
This exception is a {@link RuntimeException} because it is exposed to the client. Using a
- * {@link RuntimeException} avoids bad coding practices on the client side where they catch the
- * exception and do nothing. It is often the case that you want to blow up if there is a parsing
- * error (i.e. often clients do not know how to recover from a {@link JsonParseException}.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public class JsonParseException extends RuntimeException {
- static final long serialVersionUID = -4086729973971783390L;
-
- /**
- * Creates exception with the specified message. If you are wrapping another exception, consider
- * using {@link #JsonParseException(String, Throwable)} instead.
- *
- * @param msg error message describing a possible cause of this exception.
- */
- public JsonParseException(String msg) {
- super(msg);
- }
-
- /**
- * Creates exception with the specified message and cause.
- *
- * @param msg error message describing what happened.
- * @param cause root exception that caused this exception to be thrown.
- */
- public JsonParseException(String msg, Throwable cause) {
- super(msg, cause);
- }
-
- /**
- * Creates exception with the specified cause. Consider using
- * {@link #JsonParseException(String, Throwable)} instead if you can describe what happened.
- *
- * @param cause root exception that caused this exception to be thrown.
- */
- public JsonParseException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonParser.java b/src/com/massivecraft/massivecore/xlib/gson/JsonParser.java
deleted file mode 100644
index f2110bac..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonParser.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.Streams;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonReader;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonToken;
-import com.massivecraft.massivecore.xlib.gson.stream.MalformedJsonException;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
-/**
- * A parser to parse Json into a parse tree of {@link JsonElement}s
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @since 1.3
- */
-public final class JsonParser {
-
- /**
- * Parses the specified JSON string into a parse tree
- *
- * @param json JSON text
- * @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
- * @throws JsonParseException if the specified text is not valid JSON
- * @since 1.3
- */
- public JsonElement parse(String json) throws JsonSyntaxException {
- return parse(new StringReader(json));
- }
-
- /**
- * Parses the specified JSON string into a parse tree
- *
- * @param json JSON text
- * @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
- * @throws JsonParseException if the specified text is not valid JSON
- * @since 1.3
- */
- public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
- try {
- JsonReader jsonReader = new JsonReader(json);
- JsonElement element = parse(jsonReader);
- if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) {
- throw new JsonSyntaxException("Did not consume the entire document.");
- }
- return element;
- } catch (MalformedJsonException e) {
- throw new JsonSyntaxException(e);
- } catch (IOException e) {
- throw new JsonIOException(e);
- } catch (NumberFormatException e) {
- throw new JsonSyntaxException(e);
- }
- }
-
- /**
- * Returns the next value from the JSON stream as a parse tree.
- *
- * @throws JsonParseException if there is an IOException or if the specified
- * text is not valid JSON
- * @since 1.6
- */
- public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
- boolean lenient = json.isLenient();
- json.setLenient(true);
- try {
- return Streams.parse(json);
- } catch (StackOverflowError e) {
- throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
- } catch (OutOfMemoryError e) {
- throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
- } finally {
- json.setLenient(lenient);
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonPrimitive.java b/src/com/massivecraft/massivecore/xlib/gson/JsonPrimitive.java
deleted file mode 100644
index a301b452..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonPrimitive.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.$Gson$Preconditions;
-import com.massivecraft.massivecore.xlib.gson.internal.LazilyParsedNumber;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/**
- * A class representing a Json primitive value. A primitive value
- * is either a String, a Java primitive, or a Java primitive
- * wrapper type.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class JsonPrimitive extends JsonElement {
-
- private static final Class>[] PRIMITIVE_TYPES = { int.class, long.class, short.class,
- float.class, double.class, byte.class, boolean.class, char.class, Integer.class, Long.class,
- Short.class, Float.class, Double.class, Byte.class, Boolean.class, Character.class };
-
- private Object value;
-
- /**
- * Create a primitive containing a boolean value.
- *
- * @param bool the value to create the primitive with.
- */
- public JsonPrimitive(Boolean bool) {
- setValue(bool);
- }
-
- /**
- * Create a primitive containing a {@link Number}.
- *
- * @param number the value to create the primitive with.
- */
- public JsonPrimitive(Number number) {
- setValue(number);
- }
-
- /**
- * Create a primitive containing a String value.
- *
- * @param string the value to create the primitive with.
- */
- public JsonPrimitive(String string) {
- setValue(string);
- }
-
- /**
- * Create a primitive containing a character. The character is turned into a one character String
- * since Json only supports String.
- *
- * @param c the value to create the primitive with.
- */
- public JsonPrimitive(Character c) {
- setValue(c);
- }
-
- /**
- * Create a primitive using the specified Object. It must be an instance of {@link Number}, a
- * Java primitive type, or a String.
- *
- * @param primitive the value to create the primitive with.
- */
- JsonPrimitive(Object primitive) {
- setValue(primitive);
- }
-
- @Override
- JsonPrimitive deepCopy() {
- return this;
- }
-
- void setValue(Object primitive) {
- if (primitive instanceof Character) {
- // convert characters to strings since in JSON, characters are represented as a single
- // character string
- char c = ((Character) primitive).charValue();
- this.value = String.valueOf(c);
- } else {
- $Gson$Preconditions.checkArgument(primitive instanceof Number
- || isPrimitiveOrString(primitive));
- this.value = primitive;
- }
- }
-
- /**
- * Check whether this primitive contains a boolean value.
- *
- * @return true if this primitive contains a boolean value, false otherwise.
- */
- public boolean isBoolean() {
- return value instanceof Boolean;
- }
-
- /**
- * convenience method to get this element as a {@link Boolean}.
- *
- * @return get this element as a {@link Boolean}.
- */
- @Override
- Boolean getAsBooleanWrapper() {
- return (Boolean) value;
- }
-
- /**
- * convenience method to get this element as a boolean value.
- *
- * @return get this element as a primitive boolean value.
- */
- @Override
- public boolean getAsBoolean() {
- if (isBoolean()) {
- return getAsBooleanWrapper().booleanValue();
- } else {
- // Check to see if the value as a String is "true" in any case.
- return Boolean.parseBoolean(getAsString());
- }
- }
-
- /**
- * Check whether this primitive contains a Number.
- *
- * @return true if this primitive contains a Number, false otherwise.
- */
- public boolean isNumber() {
- return value instanceof Number;
- }
-
- /**
- * convenience method to get this element as a Number.
- *
- * @return get this element as a Number.
- * @throws NumberFormatException if the value contained is not a valid Number.
- */
- @Override
- public Number getAsNumber() {
- return value instanceof String ? new LazilyParsedNumber((String) value) : (Number) value;
- }
-
- /**
- * Check whether this primitive contains a String value.
- *
- * @return true if this primitive contains a String value, false otherwise.
- */
- public boolean isString() {
- return value instanceof String;
- }
-
- /**
- * convenience method to get this element as a String.
- *
- * @return get this element as a String.
- */
- @Override
- public String getAsString() {
- if (isNumber()) {
- return getAsNumber().toString();
- } else if (isBoolean()) {
- return getAsBooleanWrapper().toString();
- } else {
- return (String) value;
- }
- }
-
- /**
- * convenience method to get this element as a primitive double.
- *
- * @return get this element as a primitive double.
- * @throws NumberFormatException if the value contained is not a valid double.
- */
- @Override
- public double getAsDouble() {
- return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString());
- }
-
- /**
- * convenience method to get this element as a {@link BigDecimal}.
- *
- * @return get this element as a {@link BigDecimal}.
- * @throws NumberFormatException if the value contained is not a valid {@link BigDecimal}.
- */
- @Override
- public BigDecimal getAsBigDecimal() {
- return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString());
- }
-
- /**
- * convenience method to get this element as a {@link BigInteger}.
- *
- * @return get this element as a {@link BigInteger}.
- * @throws NumberFormatException if the value contained is not a valid {@link BigInteger}.
- */
- @Override
- public BigInteger getAsBigInteger() {
- return value instanceof BigInteger ?
- (BigInteger) value : new BigInteger(value.toString());
- }
-
- /**
- * convenience method to get this element as a float.
- *
- * @return get this element as a float.
- * @throws NumberFormatException if the value contained is not a valid float.
- */
- @Override
- public float getAsFloat() {
- return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString());
- }
-
- /**
- * convenience method to get this element as a primitive long.
- *
- * @return get this element as a primitive long.
- * @throws NumberFormatException if the value contained is not a valid long.
- */
- @Override
- public long getAsLong() {
- return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString());
- }
-
- /**
- * convenience method to get this element as a primitive short.
- *
- * @return get this element as a primitive short.
- * @throws NumberFormatException if the value contained is not a valid short value.
- */
- @Override
- public short getAsShort() {
- return isNumber() ? getAsNumber().shortValue() : Short.parseShort(getAsString());
- }
-
- /**
- * convenience method to get this element as a primitive integer.
- *
- * @return get this element as a primitive integer.
- * @throws NumberFormatException if the value contained is not a valid integer.
- */
- @Override
- public int getAsInt() {
- return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString());
- }
-
- @Override
- public byte getAsByte() {
- return isNumber() ? getAsNumber().byteValue() : Byte.parseByte(getAsString());
- }
-
- @Override
- public char getAsCharacter() {
- return getAsString().charAt(0);
- }
-
- private static boolean isPrimitiveOrString(Object target) {
- if (target instanceof String) {
- return true;
- }
-
- Class> classOfPrimitive = target.getClass();
- for (Class> standardPrimitive : PRIMITIVE_TYPES) {
- if (standardPrimitive.isAssignableFrom(classOfPrimitive)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- if (value == null) {
- return 31;
- }
- // Using recommended hashing algorithm from Effective Java for longs and doubles
- if (isIntegral(this)) {
- long value = getAsNumber().longValue();
- return (int) (value ^ (value >>> 32));
- }
- if (value instanceof Number) {
- long value = Double.doubleToLongBits(getAsNumber().doubleValue());
- return (int) (value ^ (value >>> 32));
- }
- return value.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- JsonPrimitive other = (JsonPrimitive)obj;
- if (value == null) {
- return other.value == null;
- }
- if (isIntegral(this) && isIntegral(other)) {
- return getAsNumber().longValue() == other.getAsNumber().longValue();
- }
- if (value instanceof Number && other.value instanceof Number) {
- double a = getAsNumber().doubleValue();
- // Java standard types other than double return true for two NaN. So, need
- // special handling for double.
- double b = other.getAsNumber().doubleValue();
- return a == b || (Double.isNaN(a) && Double.isNaN(b));
- }
- return value.equals(other.value);
- }
-
- /**
- * Returns true if the specified number is an integral type
- * (Long, Integer, Short, Byte, BigInteger)
- */
- private static boolean isIntegral(JsonPrimitive primitive) {
- if (primitive.value instanceof Number) {
- Number number = (Number) primitive.value;
- return number instanceof BigInteger || number instanceof Long || number instanceof Integer
- || number instanceof Short || number instanceof Byte;
- }
- return false;
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonSerializationContext.java b/src/com/massivecraft/massivecore/xlib/gson/JsonSerializationContext.java
deleted file mode 100644
index ed310f08..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonSerializationContext.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.lang.reflect.Type;
-
-/**
- * Context for serialization that is passed to a custom serializer during invocation of its
- * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public interface JsonSerializationContext {
-
- /**
- * Invokes default serialization on the specified object.
- *
- * @param src the object that needs to be serialized.
- * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
- */
- public JsonElement serialize(Object src);
-
- /**
- * Invokes default serialization on the specified object passing the specific type information.
- * It should never be invoked on the element received as a parameter of the
- * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method. Doing
- * so will result in an infinite loop since Gson will in-turn call the custom serializer again.
- *
- * @param src the object that needs to be serialized.
- * @param typeOfSrc the actual genericized type of src object.
- * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
- */
- public JsonElement serialize(Object src, Type typeOfSrc);
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonSerializer.java b/src/com/massivecraft/massivecore/xlib/gson/JsonSerializer.java
deleted file mode 100644
index 54faa562..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonSerializer.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import java.lang.reflect.Type;
-
-/**
- * Interface representing a custom serializer for Json. You should write a custom serializer, if
- * you are not happy with the default serialization done by Gson. You will also need to register
- * this serializer through {@link GsonBuilder#registerTypeAdapter(Type, Object)}.
- *
- *
Let us look at example where defining a serializer will be useful. The {@code Id} class
- * defined below has two fields: {@code clazz} and {@code value}.
- *
- *
- * public class Id<T> {
- * private final Class<T> clazz;
- * private final long value;
- *
- * public Id(Class<T> clazz, long value) {
- * this.clazz = clazz;
- * this.value = value;
- * }
- *
- * public long getValue() {
- * return value;
- * }
- * }
- *
- *
- *
The default serialization of {@code Id(com.foo.MyObject.class, 20L)} will be
- * {"clazz":com.foo.MyObject,"value":20}. Suppose, you just want the output to be
- * the value instead, which is {@code 20} in this case. You can achieve that by writing a custom
- * serializer:
- *
- *
- * class IdSerializer implements JsonSerializer<Id>() {
- * public JsonElement serialize(Id id, Type typeOfId, JsonSerializationContext context) {
- * return new JsonPrimitive(id.getValue());
- * }
- * }
- *
- *
- *
You will also need to register {@code IdSerializer} with Gson as follows:
- *
- * Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdSerializer()).create();
- *
- *
- *
New applications should prefer {@link TypeAdapter}, whose streaming API
- * is more efficient than this interface's tree API.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- *
- * @param type for which the serializer is being registered. It is possible that a serializer
- * may be asked to serialize a specific generic type of the T.
- */
-public interface JsonSerializer {
-
- /**
- * Gson invokes this call-back method during serialization when it encounters a field of the
- * specified type.
- *
- *
In the implementation of this call-back method, you should consider invoking
- * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any
- * non-trivial field of the {@code src} object. However, you should never invoke it on the
- * {@code src} object itself since that will cause an infinite loop (Gson will call your
- * call-back method again).
- *
- * @param src the object that needs to be converted to Json.
- * @param typeOfSrc the actual type (fully genericized version) of the source object.
- * @return a JsonElement corresponding to the specified object.
- */
- public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context);
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonStreamParser.java b/src/com/massivecraft/massivecore/xlib/gson/JsonStreamParser.java
deleted file mode 100644
index 350e19c5..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonStreamParser.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.Streams;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonReader;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonToken;
-import com.massivecraft.massivecore.xlib.gson.stream.MalformedJsonException;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * A streaming parser that allows reading of multiple {@link JsonElement}s from the specified reader
- * asynchronously.
- *
- *
This class is conditionally thread-safe (see Item 70, Effective Java second edition). To
- * properly use this class across multiple threads, you will need to add some external
- * synchronization. For example:
- *
- *
- * JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'");
- * JsonElement element;
- * synchronized (parser) { // synchronize on an object shared by threads
- * if (parser.hasNext()) {
- * element = parser.next();
- * }
- * }
- *
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @since 1.4
- */
-public final class JsonStreamParser implements Iterator {
- private final JsonReader parser;
- private final Object lock;
-
- /**
- * @param json The string containing JSON elements concatenated to each other.
- * @since 1.4
- */
- public JsonStreamParser(String json) {
- this(new StringReader(json));
- }
-
- /**
- * @param reader The data stream containing JSON elements concatenated to each other.
- * @since 1.4
- */
- public JsonStreamParser(Reader reader) {
- parser = new JsonReader(reader);
- parser.setLenient(true);
- lock = new Object();
- }
-
- /**
- * Returns the next available {@link JsonElement} on the reader. Null if none available.
- *
- * @return the next available {@link JsonElement} on the reader. Null if none available.
- * @throws JsonParseException if the incoming stream is malformed JSON.
- * @since 1.4
- */
- public JsonElement next() throws JsonParseException {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- try {
- return Streams.parse(parser);
- } catch (StackOverflowError e) {
- throw new JsonParseException("Failed parsing JSON source to Json", e);
- } catch (OutOfMemoryError e) {
- throw new JsonParseException("Failed parsing JSON source to Json", e);
- } catch (JsonParseException e) {
- throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e;
- }
- }
-
- /**
- * Returns true if a {@link JsonElement} is available on the input for consumption
- * @return true if a {@link JsonElement} is available on the input, false otherwise
- * @since 1.4
- */
- public boolean hasNext() {
- synchronized (lock) {
- try {
- return parser.peek() != JsonToken.END_DOCUMENT;
- } catch (MalformedJsonException e) {
- throw new JsonSyntaxException(e);
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
- }
-
- /**
- * This optional {@link Iterator} method is not relevant for stream parsing and hence is not
- * implemented.
- * @since 1.4
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/JsonSyntaxException.java b/src/com/massivecraft/massivecore/xlib/gson/JsonSyntaxException.java
deleted file mode 100644
index a619bf3f..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/JsonSyntaxException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-/**
- * This exception is raised when Gson attempts to read (or write) a malformed
- * JSON element.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class JsonSyntaxException extends JsonParseException {
-
- private static final long serialVersionUID = 1L;
-
- public JsonSyntaxException(String msg) {
- super(msg);
- }
-
- public JsonSyntaxException(String msg, Throwable cause) {
- super(msg, cause);
- }
-
- /**
- * Creates exception with the specified cause. Consider using
- * {@link #JsonSyntaxException(String, Throwable)} instead if you can
- * describe what actually happened.
- *
- * @param cause root exception that caused this exception to be thrown.
- */
- public JsonSyntaxException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/LongSerializationPolicy.java b/src/com/massivecraft/massivecore/xlib/gson/LongSerializationPolicy.java
deleted file mode 100644
index 1c43b929..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/LongSerializationPolicy.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-/**
- * Defines the expected format for a {@code long} or {@code Long} type when its serialized.
- *
- * @since 1.3
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public enum LongSerializationPolicy {
- /**
- * This is the "default" serialization policy that will output a {@code long} object as a JSON
- * number. For example, assume an object has a long field named "f" then the serialized output
- * would be:
- * {@code {"f":123}}.
- */
- DEFAULT() {
- @Override public JsonElement serialize(Long value) {
- return new JsonPrimitive(value);
- }
- },
-
- /**
- * Serializes a long value as a quoted string. For example, assume an object has a long field
- * named "f" then the serialized output would be:
- * {@code {"f":"123"}}.
- */
- STRING() {
- @Override public JsonElement serialize(Long value) {
- return new JsonPrimitive(String.valueOf(value));
- }
- };
-
- /**
- * Serialize this {@code value} using this serialization policy.
- *
- * @param value the long value to be serialized into a {@link JsonElement}
- * @return the serialized version of {@code value}
- */
- public abstract JsonElement serialize(Long value);
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/TypeAdapter.java b/src/com/massivecraft/massivecore/xlib/gson/TypeAdapter.java
deleted file mode 100644
index dca170e8..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/TypeAdapter.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.internal.bind.JsonTreeReader;
-import com.massivecraft.massivecore.xlib.gson.internal.bind.JsonTreeWriter;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonReader;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonToken;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonWriter;
-
-import java.io.*;
-
-/**
- * Converts Java objects to and from JSON.
- *
- *
Defining a type's JSON form
- * By default Gson converts application classes to JSON using its built-in type
- * adapters. If Gson's default JSON conversion isn't appropriate for a type,
- * extend this class to customize the conversion. Here's an example of a type
- * adapter for an (X,Y) coordinate point:
{@code
- *
- * public class PointAdapter extends TypeAdapter {
- * public Point read(JsonReader reader) throws IOException {
- * if (reader.peek() == JsonToken.NULL) {
- * reader.nextNull();
- * return null;
- * }
- * String xy = reader.nextString();
- * String[] parts = xy.split(",");
- * int x = Integer.parseInt(parts[0]);
- * int y = Integer.parseInt(parts[1]);
- * return new Point(x, y);
- * }
- * public void write(JsonWriter writer, Point value) throws IOException {
- * if (value == null) {
- * writer.nullValue();
- * return;
- * }
- * String xy = value.getX() + "," + value.getY();
- * writer.value(xy);
- * }
- * }}
- * With this type adapter installed, Gson will convert {@code Points} to JSON as
- * strings like {@code "5,8"} rather than objects like {@code {"x":5,"y":8}}. In
- * this case the type adapter binds a rich Java class to a compact JSON value.
- *
- *
The {@link #read(JsonReader) read()} method must read exactly one value
- * and {@link #write(JsonWriter,Object) write()} must write exactly one value.
- * For primitive types this is means readers should make exactly one call to
- * {@code nextBoolean()}, {@code nextDouble()}, {@code nextInt()}, {@code
- * nextLong()}, {@code nextString()} or {@code nextNull()}. Writers should make
- * exactly one call to one of value() or nullValue().
- * For arrays, type adapters should start with a call to {@code beginArray()},
- * convert all elements, and finish with a call to {@code endArray()}. For
- * objects, they should start with {@code beginObject()}, convert the object,
- * and finish with {@code endObject()}. Failing to convert a value or converting
- * too many values may cause the application to crash.
- *
- *
Type adapters should be prepared to read null from the stream and write it
- * to the stream. Alternatively, they should use {@link #nullSafe()} method while
- * registering the type adapter with Gson. If your {@code Gson} instance
- * has been configured to {@link GsonBuilder#serializeNulls()}, these nulls will be
- * written to the final document. Otherwise the value (and the corresponding name
- * when writing to a JSON object) will be omitted automatically. In either case
- * your type adapter must handle null.
- *
- *
To use a custom type adapter with Gson, you must register it with a
- * {@link GsonBuilder}:
{@code
- *
- * GsonBuilder builder = new GsonBuilder();
- * builder.registerTypeAdapter(Point.class, new PointAdapter());
- * // if PointAdapter didn't check for nulls in its read/write methods, you should instead use
- * // builder.registerTypeAdapter(Point.class, new PointAdapter().nullSafe());
- * ...
- * Gson gson = builder.create();
- * }
- *
- * @since 2.1
- */
-// non-Javadoc:
-//
-//
JSON Conversion
-//
A type adapter registered with Gson is automatically invoked while serializing
-// or deserializing JSON. However, you can also use type adapters directly to serialize
-// and deserialize JSON. Here is an example for deserialization:
Type adapters are type-specific. For example, a {@code
-// TypeAdapter} can convert {@code Date} instances to JSON and JSON to
-// instances of {@code Date}, but cannot convert any other types.
-//
-public abstract class TypeAdapter {
-
- /**
- * Writes one JSON value (an array, object, string, number, boolean or null)
- * for {@code value}.
- *
- * @param value the Java object to write. May be null.
- */
- public abstract void write(JsonWriter out, T value) throws IOException;
-
- /**
- * Converts {@code value} to a JSON document and writes it to {@code out}.
- * Unlike Gson's similar {@link Gson#toJson(JsonElement, Appendable) toJson}
- * method, this write is strict. Create a {@link
- * JsonWriter#setLenient(boolean) lenient} {@code JsonWriter} and call
- * {@link #write(JsonWriter, Object)} for lenient
- * writing.
- *
- * @param value the Java object to convert. May be null.
- * @since 2.2
- */
- public final void toJson(Writer out, T value) throws IOException {
- JsonWriter writer = new JsonWriter(out);
- write(writer, value);
- }
-
- /**
- * This wrapper method is used to make a type adapter null tolerant. In general, a
- * type adapter is required to handle nulls in write and read methods. Here is how this
- * is typically done:
- *
{@code
- *
- * Gson gson = new GsonBuilder().registerTypeAdapter(Foo.class,
- * new TypeAdapter() {
- * public Foo read(JsonReader in) throws IOException {
- * if (in.peek() == JsonToken.NULL) {
- * in.nextNull();
- * return null;
- * }
- * // read a Foo from in and return it
- * }
- * public void write(JsonWriter out, Foo src) throws IOException {
- * if (src == null) {
- * out.nullValue();
- * return;
- * }
- * // write src as JSON to out
- * }
- * }).create();
- * }
- * You can avoid this boilerplate handling of nulls by wrapping your type adapter with
- * this method. Here is how we will rewrite the above example:
- *
{@code
- *
- * Gson gson = new GsonBuilder().registerTypeAdapter(Foo.class,
- * new TypeAdapter() {
- * public Foo read(JsonReader in) throws IOException {
- * // read a Foo from in and return it
- * }
- * public void write(JsonWriter out, Foo src) throws IOException {
- * // write src as JSON to out
- * }
- * }.nullSafe()).create();
- * }
- * Note that we didn't need to check for nulls in our type adapter after we used nullSafe.
- */
- public final TypeAdapter nullSafe() {
- return new TypeAdapter() {
- @Override public void write(JsonWriter out, T value) throws IOException {
- if (value == null) {
- out.nullValue();
- } else {
- TypeAdapter.this.write(out, value);
- }
- }
- @Override public T read(JsonReader reader) throws IOException {
- if (reader.peek() == JsonToken.NULL) {
- reader.nextNull();
- return null;
- }
- return TypeAdapter.this.read(reader);
- }
- };
- }
-
- /**
- * Converts {@code value} to a JSON document. Unlike Gson's similar {@link
- * Gson#toJson(Object) toJson} method, this write is strict. Create a {@link
- * JsonWriter#setLenient(boolean) lenient} {@code JsonWriter} and call
- * {@link #write(JsonWriter, Object)} for lenient
- * writing.
- *
- * @param value the Java object to convert. May be null.
- * @since 2.2
- */
- public final String toJson(T value) {
- StringWriter stringWriter = new StringWriter();
- try {
- toJson(stringWriter, value);
- } catch (IOException e) {
- throw new AssertionError(e); // No I/O writing to a StringWriter.
- }
- return stringWriter.toString();
- }
-
- /**
- * Converts {@code value} to a JSON tree.
- *
- * @param value the Java object to convert. May be null.
- * @return the converted JSON tree. May be {@link JsonNull}.
- * @since 2.2
- */
- public final JsonElement toJsonTree(T value) {
- try {
- JsonTreeWriter jsonWriter = new JsonTreeWriter();
- write(jsonWriter, value);
- return jsonWriter.get();
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
-
- /**
- * Reads one JSON value (an array, object, string, number, boolean or null)
- * and converts it to a Java object. Returns the converted object.
- *
- * @return the converted Java object. May be null.
- */
- public abstract T read(JsonReader in) throws IOException;
-
- /**
- * Converts the JSON document in {@code in} to a Java object. Unlike Gson's
- * similar {@link Gson#fromJson(java.io.Reader, Class) fromJson} method, this
- * read is strict. Create a {@link JsonReader#setLenient(boolean) lenient}
- * {@code JsonReader} and call {@link #read(JsonReader)} for lenient reading.
- *
- * @return the converted Java object. May be null.
- * @since 2.2
- */
- public final T fromJson(Reader in) throws IOException {
- JsonReader reader = new JsonReader(in);
- return read(reader);
- }
-
- /**
- * Converts the JSON document in {@code json} to a Java object. Unlike Gson's
- * similar {@link Gson#fromJson(String, Class) fromJson} method, this read is
- * strict. Create a {@link JsonReader#setLenient(boolean) lenient} {@code
- * JsonReader} and call {@link #read(JsonReader)} for lenient reading.
- *
- * @return the converted Java object. May be null.
- * @since 2.2
- */
- public final T fromJson(String json) throws IOException {
- return fromJson(new StringReader(json));
- }
-
- /**
- * Converts {@code jsonTree} to a Java object.
- *
- * @param jsonTree the Java object to convert. May be {@link JsonNull}.
- * @since 2.2
- */
- public final T fromJsonTree(JsonElement jsonTree) {
- try {
- JsonReader jsonReader = new JsonTreeReader(jsonTree);
- return read(jsonReader);
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/TypeAdapterFactory.java b/src/com/massivecraft/massivecore/xlib/gson/TypeAdapterFactory.java
deleted file mode 100644
index 6d531938..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/TypeAdapterFactory.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson;
-
-import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
-
-/**
- * Creates type adapters for set of related types. Type adapter factories are
- * most useful when several types share similar structure in their JSON form.
- *
- *
Example: Converting enums to lowercase
- * In this example, we implement a factory that creates type adapters for all
- * enums. The type adapters will write enums in lowercase, despite the fact
- * that they're defined in {@code CONSTANT_CASE} in the corresponding Java
- * model:
Type adapter factories select which types they provide type adapters
- * for. If a factory cannot support a given type, it must return null when
- * that type is passed to {@link #create}. Factories should expect {@code
- * create()} to be called on them for many types and should return null for
- * most of those types. In the above example the factory returns null for
- * calls to {@code create()} where {@code type} is not an enum.
- *
- *
A factory is typically called once per type, but the returned type
- * adapter may be used many times. It is most efficient to do expensive work
- * like reflection in {@code create()} so that the type adapter's {@code
- * read()} and {@code write()} methods can be very fast. In this example the
- * mapping from lowercase name to enum value is computed eagerly.
- *
- *
As with type adapters, factories must be registered with a {@link
- * GsonBuilder} for them to take effect:
- * If multiple factories support the same type, the factory registered earlier
- * takes precedence.
- *
- *
Example: composing other type adapters
- * In this example we implement a factory for Guava's {@code Multiset}
- * collection type. The factory can be used to create type adapters for
- * multisets of any element type: the type adapter for {@code
- * Multiset} is different from the type adapter for {@code
- * Multiset}.
- *
- *
The type adapter delegates to another type adapter for the
- * multiset elements. It figures out the element type by reflecting on the
- * multiset's type token. A {@code Gson} is passed in to {@code create} for
- * just this purpose:
- * Delegating from one type adapter to another is extremely powerful; it's
- * the foundation of how Gson converts Java objects and collections. Whenever
- * possible your factory should retrieve its delegate type adapter in the
- * {@code create()} method; this ensures potentially-expensive type adapter
- * creation happens only once.
- *
- * @since 2.1
- */
-public interface TypeAdapterFactory {
-
- /**
- * Returns a type adapter for {@code type}, or null if this factory doesn't
- * support {@code type}.
- */
- TypeAdapter create(Gson gson, TypeToken type);
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/Expose.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/Expose.java
deleted file mode 100644
index 18bba08b..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/Expose.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.annotations;
-
-import com.massivecraft.massivecore.xlib.gson.Gson;
-import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
-
-import java.lang.annotation.*;
-
-/**
- * An annotation that indicates this member should be exposed for JSON
- * serialization or deserialization.
- *
- *
This annotation has no effect unless you build {@link Gson}
- * with a {@link GsonBuilder} and invoke
- * {@link GsonBuilder#excludeFieldsWithoutExposeAnnotation()}
- * method.
- *
- *
Here is an example of how this annotation is meant to be used:
- *
- * If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
- * methods will use the {@code password} field along-with {@code firstName}, {@code lastName},
- * and {@code emailAddress} for serialization and deserialization. However, if you created Gson
- * with {@code Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()}
- * then the {@code toJson()} and {@code fromJson()} methods of Gson will exclude the
- * {@code password} field. This is because the {@code password} field is not marked with the
- * {@code @Expose} annotation. Gson will also exclude {@code lastName} and {@code emailAddress}
- * from serialization since {@code serialize} is set to {@code false}. Similarly, Gson will
- * exclude {@code emailAddress} from deserialization since {@code deserialize} is set to false.
- *
- *
Note that another way to achieve the same effect would have been to just mark the
- * {@code password} field as {@code transient}, and Gson would have excluded it even with default
- * settings. The {@code @Expose} annotation is useful in a style of programming where you want to
- * explicitly specify all fields that should get considered for serialization or deserialization.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface Expose {
-
- /**
- * If {@code true}, the field marked with this annotation is written out in the JSON while
- * serializing. If {@code false}, the field marked with this annotation is skipped from the
- * serialized output. Defaults to {@code true}.
- * @since 1.4
- */
- public boolean serialize() default true;
-
- /**
- * If {@code true}, the field marked with this annotation is deserialized from the JSON.
- * If {@code false}, the field marked with this annotation is skipped during deserialization.
- * Defaults to {@code true}.
- * @since 1.4
- */
- public boolean deserialize() default true;
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/JsonAdapter.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/JsonAdapter.java
deleted file mode 100644
index b7e4e02e..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/JsonAdapter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2014 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.annotations;
-
-import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
-import com.massivecraft.massivecore.xlib.gson.TypeAdapter;
-import com.massivecraft.massivecore.xlib.gson.TypeAdapterFactory;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * An annotation that indicates the Gson {@link TypeAdapter} to use with a class
- * or field.
- *
- *
Here is an example of how this annotation is used:
- *
- * @JsonAdapter(UserJsonAdapter.class)
- * public class User {
- * public final String firstName, lastName;
- * private User(String firstName, String lastName) {
- * this.firstName = firstName;
- * this.lastName = lastName;
- * }
- * }
- * public class UserJsonAdapter extends TypeAdapter<User> {
- * @Override public void write(JsonWriter out, User user) throws IOException {
- * // implement write: combine firstName and lastName into name
- * out.beginObject();
- * out.name("name");
- * out.value(user.firstName + " " + user.lastName);
- * out.endObject();
- * // implement the write method
- * }
- * @Override public User read(JsonReader in) throws IOException {
- * // implement read: split name into firstName and lastName
- * in.beginObject();
- * in.nextName();
- * String[] nameParts = in.nextString().split(" ");
- * in.endObject();
- * return new User(nameParts[0], nameParts[1]);
- * }
- * }
- *
- *
- * Since User class specified UserJsonAdapter.class in @JsonAdapter annotation, it
- * will automatically be invoked to serialize/deserialize User instances.
- *
- *
Here is an example of how to apply this annotation to a field.
- *
- * private static final class Gadget {
- * @JsonAdapter(UserJsonAdapter2.class)
- * final User user;
- * Gadget(User user) {
- * this.user = user;
- * }
- * }
- *
- *
- * It's possible to specify different type adapters on a field, that
- * field's type, and in the {@link GsonBuilder}. Field
- * annotations take precedence over {@code GsonBuilder}-registered type
- * adapters, which in turn take precedence over annotated types.
- *
- *
The class referenced by this annotation must be either a {@link
- * TypeAdapter} or a {@link TypeAdapterFactory}. Using the factory interface
- * makes it possible to delegate to the enclosing {@code Gson} instance.
- *
- * @since 2.3
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @author Jesse Wilson
- */
-// Note that the above example is taken from AdaptAnnotationTest.
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.FIELD})
-public @interface JsonAdapter {
-
- /** Either a {@link TypeAdapter} or {@link TypeAdapterFactory}. */
- Class> value();
-
- /** false, to be able to handle {@code null} values within the adapter, default value is true. */
- boolean nullSafe() default true;
-
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/SerializedName.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/SerializedName.java
deleted file mode 100644
index aa0edcbf..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/SerializedName.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.annotations;
-
-import com.massivecraft.massivecore.xlib.gson.FieldNamingPolicy;
-import com.massivecraft.massivecore.xlib.gson.Gson;
-import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
-
-import java.lang.annotation.*;
-
-/**
- * An annotation that indicates this member should be serialized to JSON with
- * the provided name value as its field name.
- *
- *
This annotation will override any {@link FieldNamingPolicy}, including
- * the default field naming policy, that may have been set on the {@link Gson}
- * instance. A different naming policy can set using the {@code GsonBuilder} class. See
- * {@link GsonBuilder#setFieldNamingPolicy(FieldNamingPolicy)}
- * for more information.
- *
- *
Here is an example of how this annotation is meant to be used:
- * Note that MyClass.b is now deserialized from either name1, name2 or name3.
- *
- * @see FieldNamingPolicy
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface SerializedName {
-
- /**
- * @return the desired name of the field when it is serialized or deserialized
- */
- String value();
- /**
- * @return the alternative names of the field when it is deserialized
- */
- String[] alternate() default {};
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/Since.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/Since.java
deleted file mode 100644
index 99be8cc1..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/Since.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.annotations;
-
-import com.massivecraft.massivecore.xlib.gson.Gson;
-import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
-
-import java.lang.annotation.*;
-
-/**
- * An annotation that indicates the version number since a member or a type has been present.
- * This annotation is useful to manage versioning of your Json classes for a web-service.
- *
- *
- * This annotation has no effect unless you build {@link Gson} with a
- * {@link GsonBuilder} and invoke
- * {@link GsonBuilder#setVersion(double)} method.
- *
- *
Here is an example of how this annotation is meant to be used:
If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
- * methods will use all the fields for serialization and deserialization. However, if you created
- * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.0).create()} then the
- * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code address} field
- * since it's version number is set to {@code 1.1}.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.TYPE})
-public @interface Since {
- /**
- * the value indicating a version number since this member
- * or type has been present.
- */
- double value();
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/Until.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/Until.java
deleted file mode 100644
index 8ae2c133..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/Until.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.annotations;
-
-import com.massivecraft.massivecore.xlib.gson.Gson;
-import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
-
-import java.lang.annotation.*;
-
-/**
- * An annotation that indicates the version number until a member or a type should be present.
- * Basically, if Gson is created with a version number that exceeds the value stored in the
- * {@code Until} annotation then the field will be ignored from the JSON output. This annotation
- * is useful to manage versioning of your JSON classes for a web-service.
- *
- *
- * This annotation has no effect unless you build {@link Gson} with a
- * {@link GsonBuilder} and invoke
- * {@link GsonBuilder#setVersion(double)} method.
- *
- *
Here is an example of how this annotation is meant to be used:
If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
- * methods will use all the fields for serialization and deserialization. However, if you created
- * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.2).create()} then the
- * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code emailAddress}
- * and {@code password} fields from the example above, because the version number passed to the
- * GsonBuilder, {@code 1.2}, exceeds the version number set on the {@code Until} annotation,
- * {@code 1.1}, for those fields.
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- * @since 1.3
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.TYPE})
-public @interface Until {
-
- /**
- * the value indicating a version number until this member
- * or type should be ignored.
- */
- double value();
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/annotations/package-info.java b/src/com/massivecraft/massivecore/xlib/gson/annotations/package-info.java
deleted file mode 100644
index 14ad1187..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/annotations/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * This package provides annotations that can be used with {@link com.massivecraft.massivecore.xlib.gson.Gson}.
- *
- * @author Inderjeet Singh, Joel Leitch
- */
-package com.massivecraft.massivecore.xlib.gson.annotations;
\ No newline at end of file
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Preconditions.java b/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Preconditions.java
deleted file mode 100644
index dcea08d7..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Preconditions.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-/**
- * A simple utility class used to check method Preconditions.
- *
- *
- *
- * @author Inderjeet Singh
- * @author Joel Leitch
- */
-public final class $Gson$Preconditions {
- private $Gson$Preconditions() {
- throw new UnsupportedOperationException();
- }
-
- public static T checkNotNull(T obj) {
- if (obj == null) {
- throw new NullPointerException();
- }
- return obj;
- }
-
- public static void checkArgument(boolean condition) {
- if (!condition) {
- throw new IllegalArgumentException();
- }
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Types.java b/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Types.java
deleted file mode 100644
index b192889c..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/$Gson$Types.java
+++ /dev/null
@@ -1,577 +0,0 @@
-/**
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import java.io.Serializable;
-import java.lang.reflect.*;
-import java.util.*;
-
-import static com.massivecraft.massivecore.xlib.gson.internal.$Gson$Preconditions.checkArgument;
-import static com.massivecraft.massivecore.xlib.gson.internal.$Gson$Preconditions.checkNotNull;
-
-/**
- * Static methods for working with types.
- *
- * @author Bob Lee
- * @author Jesse Wilson
- */
-public final class $Gson$Types {
- static final Type[] EMPTY_TYPE_ARRAY = new Type[] {};
-
- private $Gson$Types() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Returns a new parameterized type, applying {@code typeArguments} to
- * {@code rawType} and enclosed by {@code ownerType}.
- *
- * @return a {@link java.io.Serializable serializable} parameterized type.
- */
- public static ParameterizedType newParameterizedTypeWithOwner(
- Type ownerType, Type rawType, Type... typeArguments) {
- return new ParameterizedTypeImpl(ownerType, rawType, typeArguments);
- }
-
- /**
- * Returns an array type whose elements are all instances of
- * {@code componentType}.
- *
- * @return a {@link java.io.Serializable serializable} generic array type.
- */
- public static GenericArrayType arrayOf(Type componentType) {
- return new GenericArrayTypeImpl(componentType);
- }
-
- /**
- * Returns a type that represents an unknown type that extends {@code bound}.
- * For example, if {@code bound} is {@code CharSequence.class}, this returns
- * {@code ? extends CharSequence}. If {@code bound} is {@code Object.class},
- * this returns {@code ?}, which is shorthand for {@code ? extends Object}.
- */
- public static WildcardType subtypeOf(Type bound) {
- return new WildcardTypeImpl(new Type[] { bound }, EMPTY_TYPE_ARRAY);
- }
-
- /**
- * Returns a type that represents an unknown supertype of {@code bound}. For
- * example, if {@code bound} is {@code String.class}, this returns {@code ?
- * super String}.
- */
- public static WildcardType supertypeOf(Type bound) {
- return new WildcardTypeImpl(new Type[] { Object.class }, new Type[] { bound });
- }
-
- /**
- * Returns a type that is functionally equal but not necessarily equal
- * according to {@link Object#equals(Object) Object.equals()}. The returned
- * type is {@link java.io.Serializable}.
- */
- public static Type canonicalize(Type type) {
- if (type instanceof Class) {
- Class> c = (Class>) type;
- return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;
-
- } else if (type instanceof ParameterizedType) {
- ParameterizedType p = (ParameterizedType) type;
- return new ParameterizedTypeImpl(p.getOwnerType(),
- p.getRawType(), p.getActualTypeArguments());
-
- } else if (type instanceof GenericArrayType) {
- GenericArrayType g = (GenericArrayType) type;
- return new GenericArrayTypeImpl(g.getGenericComponentType());
-
- } else if (type instanceof WildcardType) {
- WildcardType w = (WildcardType) type;
- return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
-
- } else {
- // type is either serializable as-is or unsupported
- return type;
- }
- }
-
- public static Class> getRawType(Type type) {
- if (type instanceof Class>) {
- // type is a normal class.
- return (Class>) type;
-
- } else if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType) type;
-
- // I'm not exactly sure why getRawType() returns Type instead of Class.
- // Neal isn't either but suspects some pathological case related
- // to nested classes exists.
- Type rawType = parameterizedType.getRawType();
- checkArgument(rawType instanceof Class);
- return (Class>) rawType;
-
- } else if (type instanceof GenericArrayType) {
- Type componentType = ((GenericArrayType)type).getGenericComponentType();
- return Array.newInstance(getRawType(componentType), 0).getClass();
-
- } else if (type instanceof TypeVariable) {
- // we could use the variable's bounds, but that won't work if there are multiple.
- // having a raw type that's more general than necessary is okay
- return Object.class;
-
- } else if (type instanceof WildcardType) {
- return getRawType(((WildcardType) type).getUpperBounds()[0]);
-
- } else {
- String className = type == null ? "null" : type.getClass().getName();
- throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
- + "GenericArrayType, but <" + type + "> is of type " + className);
- }
- }
-
- static boolean equal(Object a, Object b) {
- return a == b || (a != null && a.equals(b));
- }
-
- /**
- * Returns true if {@code a} and {@code b} are equal.
- */
- public static boolean equals(Type a, Type b) {
- if (a == b) {
- // also handles (a == null && b == null)
- return true;
-
- } else if (a instanceof Class) {
- // Class already specifies equals().
- return a.equals(b);
-
- } else if (a instanceof ParameterizedType) {
- if (!(b instanceof ParameterizedType)) {
- return false;
- }
-
- // TODO: save a .clone() call
- ParameterizedType pa = (ParameterizedType) a;
- ParameterizedType pb = (ParameterizedType) b;
- return equal(pa.getOwnerType(), pb.getOwnerType())
- && pa.getRawType().equals(pb.getRawType())
- && Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());
-
- } else if (a instanceof GenericArrayType) {
- if (!(b instanceof GenericArrayType)) {
- return false;
- }
-
- GenericArrayType ga = (GenericArrayType) a;
- GenericArrayType gb = (GenericArrayType) b;
- return equals(ga.getGenericComponentType(), gb.getGenericComponentType());
-
- } else if (a instanceof WildcardType) {
- if (!(b instanceof WildcardType)) {
- return false;
- }
-
- WildcardType wa = (WildcardType) a;
- WildcardType wb = (WildcardType) b;
- return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
- && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());
-
- } else if (a instanceof TypeVariable) {
- if (!(b instanceof TypeVariable)) {
- return false;
- }
- TypeVariable> va = (TypeVariable>) a;
- TypeVariable> vb = (TypeVariable>) b;
- return va.getGenericDeclaration() == vb.getGenericDeclaration()
- && va.getName().equals(vb.getName());
-
- } else {
- // This isn't a type we support. Could be a generic array type, wildcard type, etc.
- return false;
- }
- }
-
- static int hashCodeOrZero(Object o) {
- return o != null ? o.hashCode() : 0;
- }
-
- public static String typeToString(Type type) {
- return type instanceof Class ? ((Class>) type).getName() : type.toString();
- }
-
- /**
- * Returns the generic supertype for {@code supertype}. For example, given a class {@code
- * IntegerSet}, the result for when supertype is {@code Set.class} is {@code Set} and the
- * result when the supertype is {@code Collection.class} is {@code Collection}.
- */
- static Type getGenericSupertype(Type context, Class> rawType, Class> toResolve) {
- if (toResolve == rawType) {
- return context;
- }
-
- // we skip searching through interfaces if unknown is an interface
- if (toResolve.isInterface()) {
- Class>[] interfaces = rawType.getInterfaces();
- for (int i = 0, length = interfaces.length; i < length; i++) {
- if (interfaces[i] == toResolve) {
- return rawType.getGenericInterfaces()[i];
- } else if (toResolve.isAssignableFrom(interfaces[i])) {
- return getGenericSupertype(rawType.getGenericInterfaces()[i], interfaces[i], toResolve);
- }
- }
- }
-
- // check our supertypes
- if (!rawType.isInterface()) {
- while (rawType != Object.class) {
- Class> rawSupertype = rawType.getSuperclass();
- if (rawSupertype == toResolve) {
- return rawType.getGenericSuperclass();
- } else if (toResolve.isAssignableFrom(rawSupertype)) {
- return getGenericSupertype(rawType.getGenericSuperclass(), rawSupertype, toResolve);
- }
- rawType = rawSupertype;
- }
- }
-
- // we can't resolve this further
- return toResolve;
- }
-
- /**
- * Returns the generic form of {@code supertype}. For example, if this is {@code
- * ArrayList}, this returns {@code Iterable} given the input {@code
- * Iterable.class}.
- *
- * @param supertype a superclass of, or interface implemented by, this.
- */
- static Type getSupertype(Type context, Class> contextRawType, Class> supertype) {
- checkArgument(supertype.isAssignableFrom(contextRawType));
- return resolve(context, contextRawType,
- $Gson$Types.getGenericSupertype(context, contextRawType, supertype));
- }
-
- /**
- * Returns the component type of this array type.
- * @throws ClassCastException if this type is not an array.
- */
- public static Type getArrayComponentType(Type array) {
- return array instanceof GenericArrayType
- ? ((GenericArrayType) array).getGenericComponentType()
- : ((Class>) array).getComponentType();
- }
-
- /**
- * Returns the element type of this collection type.
- * @throws IllegalArgumentException if this type is not a collection.
- */
- public static Type getCollectionElementType(Type context, Class> contextRawType) {
- Type collectionType = getSupertype(context, contextRawType, Collection.class);
-
- if (collectionType instanceof WildcardType) {
- collectionType = ((WildcardType)collectionType).getUpperBounds()[0];
- }
- if (collectionType instanceof ParameterizedType) {
- return ((ParameterizedType) collectionType).getActualTypeArguments()[0];
- }
- return Object.class;
- }
-
- /**
- * Returns a two element array containing this map's key and value types in
- * positions 0 and 1 respectively.
- */
- public static Type[] getMapKeyAndValueTypes(Type context, Class> contextRawType) {
- /*
- * Work around a problem with the declaration of java.util.Properties. That
- * class should extend Hashtable, but it's declared to
- * extend Hashtable.
- */
- if (context == Properties.class) {
- return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties!
- }
-
- Type mapType = getSupertype(context, contextRawType, Map.class);
- // TODO: strip wildcards?
- if (mapType instanceof ParameterizedType) {
- ParameterizedType mapParameterizedType = (ParameterizedType) mapType;
- return mapParameterizedType.getActualTypeArguments();
- }
- return new Type[] { Object.class, Object.class };
- }
-
- public static Type resolve(Type context, Class> contextRawType, Type toResolve) {
- // this implementation is made a little more complicated in an attempt to avoid object-creation
- while (true) {
- if (toResolve instanceof TypeVariable) {
- TypeVariable> typeVariable = (TypeVariable>) toResolve;
- toResolve = resolveTypeVariable(context, contextRawType, typeVariable);
- if (toResolve == typeVariable) {
- return toResolve;
- }
-
- } else if (toResolve instanceof Class && ((Class>) toResolve).isArray()) {
- Class> original = (Class>) toResolve;
- Type componentType = original.getComponentType();
- Type newComponentType = resolve(context, contextRawType, componentType);
- return componentType == newComponentType
- ? original
- : arrayOf(newComponentType);
-
- } else if (toResolve instanceof GenericArrayType) {
- GenericArrayType original = (GenericArrayType) toResolve;
- Type componentType = original.getGenericComponentType();
- Type newComponentType = resolve(context, contextRawType, componentType);
- return componentType == newComponentType
- ? original
- : arrayOf(newComponentType);
-
- } else if (toResolve instanceof ParameterizedType) {
- ParameterizedType original = (ParameterizedType) toResolve;
- Type ownerType = original.getOwnerType();
- Type newOwnerType = resolve(context, contextRawType, ownerType);
- boolean changed = newOwnerType != ownerType;
-
- Type[] args = original.getActualTypeArguments();
- for (int t = 0, length = args.length; t < length; t++) {
- Type resolvedTypeArgument = resolve(context, contextRawType, args[t]);
- if (resolvedTypeArgument != args[t]) {
- if (!changed) {
- args = args.clone();
- changed = true;
- }
- args[t] = resolvedTypeArgument;
- }
- }
-
- return changed
- ? newParameterizedTypeWithOwner(newOwnerType, original.getRawType(), args)
- : original;
-
- } else if (toResolve instanceof WildcardType) {
- WildcardType original = (WildcardType) toResolve;
- Type[] originalLowerBound = original.getLowerBounds();
- Type[] originalUpperBound = original.getUpperBounds();
-
- if (originalLowerBound.length == 1) {
- Type lowerBound = resolve(context, contextRawType, originalLowerBound[0]);
- if (lowerBound != originalLowerBound[0]) {
- return supertypeOf(lowerBound);
- }
- } else if (originalUpperBound.length == 1) {
- Type upperBound = resolve(context, contextRawType, originalUpperBound[0]);
- if (upperBound != originalUpperBound[0]) {
- return subtypeOf(upperBound);
- }
- }
- return original;
-
- } else {
- return toResolve;
- }
- }
- }
-
- static Type resolveTypeVariable(Type context, Class> contextRawType, TypeVariable> unknown) {
- Class> declaredByRaw = declaringClassOf(unknown);
-
- // we can't reduce this further
- if (declaredByRaw == null) {
- return unknown;
- }
-
- Type declaredBy = getGenericSupertype(context, contextRawType, declaredByRaw);
- if (declaredBy instanceof ParameterizedType) {
- int index = indexOf(declaredByRaw.getTypeParameters(), unknown);
- return ((ParameterizedType) declaredBy).getActualTypeArguments()[index];
- }
-
- return unknown;
- }
-
- private static int indexOf(Object[] array, Object toFind) {
- for (int i = 0; i < array.length; i++) {
- if (toFind.equals(array[i])) {
- return i;
- }
- }
- throw new NoSuchElementException();
- }
-
- /**
- * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
- * a class.
- */
- private static Class> declaringClassOf(TypeVariable> typeVariable) {
- GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
- return genericDeclaration instanceof Class
- ? (Class>) genericDeclaration
- : null;
- }
-
- static void checkNotPrimitive(Type type) {
- checkArgument(!(type instanceof Class>) || !((Class>) type).isPrimitive());
- }
-
- private static final class ParameterizedTypeImpl implements ParameterizedType, Serializable {
- private final Type ownerType;
- private final Type rawType;
- private final Type[] typeArguments;
-
- public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
- // require an owner type if the raw type needs it
- if (rawType instanceof Class>) {
- Class> rawTypeAsClass = (Class>) rawType;
- boolean isStaticOrTopLevelClass = Modifier.isStatic(rawTypeAsClass.getModifiers())
- || rawTypeAsClass.getEnclosingClass() == null;
- checkArgument(ownerType != null || isStaticOrTopLevelClass);
- }
-
- this.ownerType = ownerType == null ? null : canonicalize(ownerType);
- this.rawType = canonicalize(rawType);
- this.typeArguments = typeArguments.clone();
- for (int t = 0; t < this.typeArguments.length; t++) {
- checkNotNull(this.typeArguments[t]);
- checkNotPrimitive(this.typeArguments[t]);
- this.typeArguments[t] = canonicalize(this.typeArguments[t]);
- }
- }
-
- public Type[] getActualTypeArguments() {
- return typeArguments.clone();
- }
-
- public Type getRawType() {
- return rawType;
- }
-
- public Type getOwnerType() {
- return ownerType;
- }
-
- @Override public boolean equals(Object other) {
- return other instanceof ParameterizedType
- && $Gson$Types.equals(this, (ParameterizedType) other);
- }
-
- @Override public int hashCode() {
- return Arrays.hashCode(typeArguments)
- ^ rawType.hashCode()
- ^ hashCodeOrZero(ownerType);
- }
-
- @Override public String toString() {
- StringBuilder stringBuilder = new StringBuilder(30 * (typeArguments.length + 1));
- stringBuilder.append(typeToString(rawType));
-
- if (typeArguments.length == 0) {
- return stringBuilder.toString();
- }
-
- stringBuilder.append("<").append(typeToString(typeArguments[0]));
- for (int i = 1; i < typeArguments.length; i++) {
- stringBuilder.append(", ").append(typeToString(typeArguments[i]));
- }
- return stringBuilder.append(">").toString();
- }
-
- private static final long serialVersionUID = 0;
- }
-
- private static final class GenericArrayTypeImpl implements GenericArrayType, Serializable {
- private final Type componentType;
-
- public GenericArrayTypeImpl(Type componentType) {
- this.componentType = canonicalize(componentType);
- }
-
- public Type getGenericComponentType() {
- return componentType;
- }
-
- @Override public boolean equals(Object o) {
- return o instanceof GenericArrayType
- && $Gson$Types.equals(this, (GenericArrayType) o);
- }
-
- @Override public int hashCode() {
- return componentType.hashCode();
- }
-
- @Override public String toString() {
- return typeToString(componentType) + "[]";
- }
-
- private static final long serialVersionUID = 0;
- }
-
- /**
- * The WildcardType interface supports multiple upper bounds and multiple
- * lower bounds. We only support what the Java 6 language needs - at most one
- * bound. If a lower bound is set, the upper bound must be Object.class.
- */
- private static final class WildcardTypeImpl implements WildcardType, Serializable {
- private final Type upperBound;
- private final Type lowerBound;
-
- public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
- checkArgument(lowerBounds.length <= 1);
- checkArgument(upperBounds.length == 1);
-
- if (lowerBounds.length == 1) {
- checkNotNull(lowerBounds[0]);
- checkNotPrimitive(lowerBounds[0]);
- checkArgument(upperBounds[0] == Object.class);
- this.lowerBound = canonicalize(lowerBounds[0]);
- this.upperBound = Object.class;
-
- } else {
- checkNotNull(upperBounds[0]);
- checkNotPrimitive(upperBounds[0]);
- this.lowerBound = null;
- this.upperBound = canonicalize(upperBounds[0]);
- }
- }
-
- public Type[] getUpperBounds() {
- return new Type[] { upperBound };
- }
-
- public Type[] getLowerBounds() {
- return lowerBound != null ? new Type[] { lowerBound } : EMPTY_TYPE_ARRAY;
- }
-
- @Override public boolean equals(Object other) {
- return other instanceof WildcardType
- && $Gson$Types.equals(this, (WildcardType) other);
- }
-
- @Override public int hashCode() {
- // this equals Arrays.hashCode(getLowerBounds()) ^ Arrays.hashCode(getUpperBounds());
- return (lowerBound != null ? 31 + lowerBound.hashCode() : 1)
- ^ (31 + upperBound.hashCode());
- }
-
- @Override public String toString() {
- if (lowerBound != null) {
- return "? super " + typeToString(lowerBound);
- } else if (upperBound == Object.class) {
- return "?";
- } else {
- return "? extends " + typeToString(upperBound);
- }
- }
-
- private static final long serialVersionUID = 0;
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/ConstructorConstructor.java b/src/com/massivecraft/massivecore/xlib/gson/internal/ConstructorConstructor.java
deleted file mode 100644
index e76118af..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/ConstructorConstructor.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import com.massivecraft.massivecore.xlib.gson.InstanceCreator;
-import com.massivecraft.massivecore.xlib.gson.JsonIOException;
-import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentNavigableMap;
-import java.util.concurrent.ConcurrentSkipListMap;
-
-/**
- * Returns a function that can construct an instance of a requested type.
- */
-public final class ConstructorConstructor {
- private final Map> instanceCreators;
-
- public ConstructorConstructor(Map> instanceCreators) {
- this.instanceCreators = instanceCreators;
- }
-
- public ObjectConstructor get(TypeToken typeToken) {
- final Type type = typeToken.getType();
- final Class super T> rawType = typeToken.getRawType();
-
- // first try an instance creator
-
- @SuppressWarnings("unchecked") // types must agree
- final InstanceCreator typeCreator = (InstanceCreator) instanceCreators.get(type);
- if (typeCreator != null) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return typeCreator.createInstance(type);
- }
- };
- }
-
- // Next try raw type match for instance creators
- @SuppressWarnings("unchecked") // types must agree
- final InstanceCreator rawTypeCreator =
- (InstanceCreator) instanceCreators.get(rawType);
- if (rawTypeCreator != null) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return rawTypeCreator.createInstance(type);
- }
- };
- }
-
- ObjectConstructor defaultConstructor = newDefaultConstructor(rawType);
- if (defaultConstructor != null) {
- return defaultConstructor;
- }
-
- ObjectConstructor defaultImplementation = newDefaultImplementationConstructor(type, rawType);
- if (defaultImplementation != null) {
- return defaultImplementation;
- }
-
- // finally try unsafe
- return newUnsafeAllocator(type, rawType);
- }
-
- private ObjectConstructor newDefaultConstructor(Class super T> rawType) {
- try {
- final Constructor super T> constructor = rawType.getDeclaredConstructor();
- if (!constructor.isAccessible()) {
- constructor.setAccessible(true);
- }
- return new ObjectConstructor() {
- @SuppressWarnings("unchecked") // T is the same raw type as is requested
- @Override public T construct() {
- try {
- Object[] args = null;
- return (T) constructor.newInstance(args);
- } catch (InstantiationException e) {
- // TODO: JsonParseException ?
- throw new RuntimeException("Failed to invoke " + constructor + " with no args", e);
- } catch (InvocationTargetException e) {
- // TODO: don't wrap if cause is unchecked!
- // TODO: JsonParseException ?
- throw new RuntimeException("Failed to invoke " + constructor + " with no args",
- e.getTargetException());
- } catch (IllegalAccessException e) {
- throw new AssertionError(e);
- }
- }
- };
- } catch (NoSuchMethodException e) {
- return null;
- }
- }
-
- /**
- * Constructors for common interface types like Map and List and their
- * subtypes.
- */
- @SuppressWarnings("unchecked") // use runtime checks to guarantee that 'T' is what it is
- private ObjectConstructor newDefaultImplementationConstructor(
- final Type type, Class super T> rawType) {
- if (Collection.class.isAssignableFrom(rawType)) {
- if (SortedSet.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new TreeSet<>();
- }
- };
- } else if (EnumSet.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @SuppressWarnings("rawtypes")
- @Override public T construct() {
- if (type instanceof ParameterizedType) {
- Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
- if (elementType instanceof Class) {
- return (T) EnumSet.noneOf((Class)elementType);
- } else {
- throw new JsonIOException("Invalid EnumSet type: " + type.toString());
- }
- } else {
- throw new JsonIOException("Invalid EnumSet type: " + type.toString());
- }
- }
- };
- } else if (Set.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new LinkedHashSet<>();
- }
- };
- } else if (Queue.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new ArrayDeque<>();
- }
- };
- } else {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new ArrayList<>();
- }
- };
- }
- }
-
- if (Map.class.isAssignableFrom(rawType)) {
- if (ConcurrentNavigableMap.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new ConcurrentSkipListMap<>();
- }
- };
- } else if (ConcurrentMap.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new ConcurrentHashMap<>();
- }
- };
- } else if (SortedMap.class.isAssignableFrom(rawType)) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new TreeMap<>();
- }
- };
- } else if (type instanceof ParameterizedType && !(String.class.isAssignableFrom(
- TypeToken.get(((ParameterizedType) type).getActualTypeArguments()[0]).getRawType()))) {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new LinkedHashMap<>();
- }
- };
- } else {
- return new ObjectConstructor() {
- @Override public T construct() {
- return (T) new LinkedTreeMap();
- }
- };
- }
- }
-
- return null;
- }
-
- private ObjectConstructor newUnsafeAllocator(
- final Type type, final Class super T> rawType) {
- return new ObjectConstructor() {
- private final UnsafeAllocator unsafeAllocator = UnsafeAllocator.create();
- @SuppressWarnings("unchecked")
- @Override public T construct() {
- try {
- Object newInstance = unsafeAllocator.newInstance(rawType);
- return (T) newInstance;
- } catch (Exception e) {
- throw new RuntimeException(("Unable to invoke no-args constructor for " + type + ". "
- + "Register an InstanceCreator with Gson for this type may fix this problem."), e);
- }
- }
- };
- }
-
- @Override public String toString() {
- return instanceCreators.toString();
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/Excluder.java b/src/com/massivecraft/massivecore/xlib/gson/internal/Excluder.java
deleted file mode 100644
index 17099b61..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/Excluder.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import com.massivecraft.massivecore.xlib.gson.*;
-import com.massivecraft.massivecore.xlib.gson.annotations.Expose;
-import com.massivecraft.massivecore.xlib.gson.annotations.Since;
-import com.massivecraft.massivecore.xlib.gson.annotations.Until;
-import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonReader;
-import com.massivecraft.massivecore.xlib.gson.stream.JsonWriter;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * This class selects which fields and types to omit. It is configurable,
- * supporting version attributes {@link Since} and {@link Until}, modifiers,
- * synthetic fields, anonymous and local classes, inner classes, and fields with
- * the {@link Expose} annotation.
- *
- *
This class is a type adapter factory; types that are excluded will be
- * adapted to null. It may delegate to another type adapter if only one
- * direction is excluded.
- *
- * @author Joel Leitch
- * @author Jesse Wilson
- */
-public final class Excluder implements TypeAdapterFactory, Cloneable {
- private static final double IGNORE_VERSIONS = -1.0d;
- public static final Excluder DEFAULT = new Excluder();
-
- private double version = IGNORE_VERSIONS;
- private int modifiers = Modifier.TRANSIENT | Modifier.STATIC;
- private boolean serializeInnerClasses = true;
- private boolean requireExpose;
- private List serializationStrategies = Collections.emptyList();
- private List deserializationStrategies = Collections.emptyList();
-
- @Override protected Excluder clone() {
- try {
- return (Excluder) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new AssertionError(e);
- }
- }
-
- public Excluder withVersion(double ignoreVersionsAfter) {
- Excluder result = clone();
- result.version = ignoreVersionsAfter;
- return result;
- }
-
- public Excluder withModifiers(int... modifiers) {
- Excluder result = clone();
- result.modifiers = 0;
- for (int modifier : modifiers) {
- result.modifiers |= modifier;
- }
- return result;
- }
-
- public Excluder disableInnerClassSerialization() {
- Excluder result = clone();
- result.serializeInnerClasses = false;
- return result;
- }
-
- public Excluder excludeFieldsWithoutExposeAnnotation() {
- Excluder result = clone();
- result.requireExpose = true;
- return result;
- }
-
- public Excluder withExclusionStrategy(ExclusionStrategy exclusionStrategy,
- boolean serialization, boolean deserialization) {
- Excluder result = clone();
- if (serialization) {
- result.serializationStrategies = new ArrayList<>(serializationStrategies);
- result.serializationStrategies.add(exclusionStrategy);
- }
- if (deserialization) {
- result.deserializationStrategies
- = new ArrayList<>(deserializationStrategies);
- result.deserializationStrategies.add(exclusionStrategy);
- }
- return result;
- }
-
- public TypeAdapter create(final Gson gson, final TypeToken type) {
- Class> rawType = type.getRawType();
- final boolean skipSerialize = excludeClass(rawType, true);
- final boolean skipDeserialize = excludeClass(rawType, false);
-
- if (!skipSerialize && !skipDeserialize) {
- return null;
- }
-
- return new TypeAdapter() {
- /** The delegate is lazily created because it may not be needed, and creating it may fail. */
- private TypeAdapter delegate;
-
- @Override public T read(JsonReader in) throws IOException {
- if (skipDeserialize) {
- in.skipValue();
- return null;
- }
- return delegate().read(in);
- }
-
- @Override public void write(JsonWriter out, T value) throws IOException {
- if (skipSerialize) {
- out.nullValue();
- return;
- }
- delegate().write(out, value);
- }
-
- private TypeAdapter delegate() {
- TypeAdapter d = delegate;
- return d != null
- ? d
- : (delegate = gson.getDelegateAdapter(Excluder.this, type));
- }
- };
- }
-
- public boolean excludeField(Field field, boolean serialize) {
- if ((modifiers & field.getModifiers()) != 0) {
- return true;
- }
-
- if (version != Excluder.IGNORE_VERSIONS
- && !isValidVersion(field.getAnnotation(Since.class), field.getAnnotation(Until.class))) {
- return true;
- }
-
- if (field.isSynthetic()) {
- return true;
- }
-
- if (requireExpose) {
- Expose annotation = field.getAnnotation(Expose.class);
- if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
- return true;
- }
- }
-
- if (!serializeInnerClasses && isInnerClass(field.getType())) {
- return true;
- }
-
- if (isAnonymousOrLocal(field.getType())) {
- return true;
- }
-
- List list = serialize ? serializationStrategies : deserializationStrategies;
- if (!list.isEmpty()) {
- FieldAttributes fieldAttributes = new FieldAttributes(field);
- for (ExclusionStrategy exclusionStrategy : list) {
- if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- public boolean excludeClass(Class> clazz, boolean serialize) {
- if (version != Excluder.IGNORE_VERSIONS
- && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
- return true;
- }
-
- if (!serializeInnerClasses && isInnerClass(clazz)) {
- return true;
- }
-
- if (isAnonymousOrLocal(clazz)) {
- return true;
- }
-
- List list = serialize ? serializationStrategies : deserializationStrategies;
- for (ExclusionStrategy exclusionStrategy : list) {
- if (exclusionStrategy.shouldSkipClass(clazz)) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean isAnonymousOrLocal(Class> clazz) {
- return !Enum.class.isAssignableFrom(clazz)
- && (clazz.isAnonymousClass() || clazz.isLocalClass());
- }
-
- private boolean isInnerClass(Class> clazz) {
- return clazz.isMemberClass() && !isStatic(clazz);
- }
-
- private boolean isStatic(Class> clazz) {
- return (clazz.getModifiers() & Modifier.STATIC) != 0;
- }
-
- private boolean isValidVersion(Since since, Until until) {
- return isValidSince(since) && isValidUntil(until);
- }
-
- private boolean isValidSince(Since annotation) {
- if (annotation != null) {
- double annotationVersion = annotation.value();
- if (annotationVersion > version) {
- return false;
- }
- }
- return true;
- }
-
- private boolean isValidUntil(Until annotation) {
- if (annotation != null) {
- double annotationVersion = annotation.value();
- if (annotationVersion <= version) {
- return false;
- }
- }
- return true;
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/JsonReaderInternalAccess.java b/src/com/massivecraft/massivecore/xlib/gson/internal/JsonReaderInternalAccess.java
deleted file mode 100644
index 91e74520..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/JsonReaderInternalAccess.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import com.massivecraft.massivecore.xlib.gson.stream.JsonReader;
-
-import java.io.IOException;
-
-/**
- * Internal-only APIs of JsonReader available only to other classes in Gson.
- */
-public abstract class JsonReaderInternalAccess {
- public static JsonReaderInternalAccess INSTANCE;
-
- /**
- * Changes the type of the current property name token to a string value.
- */
- public abstract void promoteNameToValue(JsonReader reader) throws IOException;
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/LazilyParsedNumber.java b/src/com/massivecraft/massivecore/xlib/gson/internal/LazilyParsedNumber.java
deleted file mode 100644
index a71936d8..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/LazilyParsedNumber.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import java.io.ObjectStreamException;
-import java.math.BigDecimal;
-
-/**
- * This class holds a number value that is lazily converted to a specific number type
- *
- * @author Inderjeet Singh
- */
-public final class LazilyParsedNumber extends Number {
- private final String value;
-
- /** @param value must not be null */
- public LazilyParsedNumber(String value) {
- this.value = value;
- }
-
- @Override
- public int intValue() {
- try {
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- try {
- return (int) Long.parseLong(value);
- } catch (NumberFormatException nfe) {
- return new BigDecimal(value).intValue();
- }
- }
- }
-
- @Override
- public long longValue() {
- try {
- return Long.parseLong(value);
- } catch (NumberFormatException e) {
- return new BigDecimal(value).longValue();
- }
- }
-
- @Override
- public float floatValue() {
- return Float.parseFloat(value);
- }
-
- @Override
- public double doubleValue() {
- return Double.parseDouble(value);
- }
-
- @Override
- public String toString() {
- return value;
- }
-
- /**
- * If somebody is unlucky enough to have to serialize one of these, serialize
- * it as a BigDecimal so that they won't need Gson on the other side to
- * deserialize it.
- */
- private Object writeReplace() throws ObjectStreamException {
- return new BigDecimal(value);
- }
-
- @Override
- public int hashCode() {
- return value.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof LazilyParsedNumber) {
- LazilyParsedNumber other = (LazilyParsedNumber) obj;
- return value == other.value || value.equals(other.value);
- }
- return false;
- }
-}
diff --git a/src/com/massivecraft/massivecore/xlib/gson/internal/LinkedHashTreeMap.java b/src/com/massivecraft/massivecore/xlib/gson/internal/LinkedHashTreeMap.java
deleted file mode 100644
index 37623373..00000000
--- a/src/com/massivecraft/massivecore/xlib/gson/internal/LinkedHashTreeMap.java
+++ /dev/null
@@ -1,856 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * Copyright (C) 2012 Google Inc.
- *
- * Licensed 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 com.massivecraft.massivecore.xlib.gson.internal;
-
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * A map of comparable keys to values. Unlike {@code TreeMap}, this class uses
- * insertion order for iteration order. Comparison order is only used as an
- * optimization for efficient insertion and removal.
- *
- *
This implementation was derived from Android 4.1's TreeMap and
- * LinkedHashMap classes.
- */
-public final class LinkedHashTreeMap extends AbstractMap implements Serializable {
- @SuppressWarnings({ "unchecked", "rawtypes" }) // to avoid Comparable>>
- private static final Comparator NATURAL_ORDER = new Comparator() {
- public int compare(Comparable a, Comparable b) {
- return a.compareTo(b);
- }
- };
-
- Comparator super K> comparator;
- Node[] table;
- final Node header;
- int size = 0;
- int modCount = 0;
- int threshold;
-
- /**
- * Create a natural order, empty tree map whose keys must be mutually
- * comparable and non-null.
- */
- @SuppressWarnings("unchecked") // unsafe! this assumes K is comparable
- public LinkedHashTreeMap() {
- this((Comparator super K>) NATURAL_ORDER);
- }
-
- /**
- * Create a tree map ordered by {@code comparator}. This map's keys may only
- * be null if {@code comparator} permits.
- *
- * @param comparator the comparator to order elements with, or {@code null} to
- * use the natural ordering.
- */
- @SuppressWarnings({ "unchecked", "rawtypes" }) // unsafe! if comparator is null, this assumes K is comparable
- public LinkedHashTreeMap(Comparator super K> comparator) {
- this.comparator = comparator != null
- ? comparator
- : (Comparator) NATURAL_ORDER;
- this.header = new Node<>();
- this.table = new Node[16]; // TODO: sizing/resizing policies
- this.threshold = (table.length / 2) + (table.length / 4); // 3/4 capacity
- }
-
- @Override public int size() {
- return size;
- }
-
- @Override public V get(Object key) {
- Node node = findByObject(key);
- return node != null ? node.value : null;
- }
-
- @Override public boolean containsKey(Object key) {
- return findByObject(key) != null;
- }
-
- @Override public V put(K key, V value) {
- if (key == null) {
- throw new NullPointerException("key == null");
- }
- Node created = find(key, true);
- V result = created.value;
- created.value = value;
- return result;
- }
-
- @Override public void clear() {
- Arrays.fill(table, null);
- size = 0;
- modCount++;
-
- // Clear all links to help GC
- Node header = this.header;
- for (Node e = header.next; e != header; ) {
- Node next = e.next;
- e.next = e.prev = null;
- e = next;
- }
-
- header.next = header.prev = header;
- }
-
- @Override public V remove(Object key) {
- Node node = removeInternalByKey(key);
- return node != null ? node.value : null;
- }
-
- /**
- * Returns the node at or adjacent to the given key, creating it if requested.
- *
- * @throws ClassCastException if {@code key} and the tree's keys aren't
- * mutually comparable.
- */
- Node find(K key, boolean create) {
- Comparator super K> comparator = this.comparator;
- Node[] table = this.table;
- int hash = secondaryHash(key.hashCode());
- int index = hash & (table.length - 1);
- Node nearest = table[index];
- int comparison = 0;
-
- if (nearest != null) {
- // Micro-optimization: avoid polymorphic calls to Comparator.compare().
- @SuppressWarnings("unchecked") // Throws a ClassCastException below if there's trouble.
- Comparable comparableKey = (comparator == NATURAL_ORDER)
- ? (Comparable) key
- : null;
-
- while (true) {
- comparison = (comparableKey != null)
- ? comparableKey.compareTo(nearest.key)
- : comparator.compare(key, nearest.key);
-
- // We found the requested key.
- if (comparison == 0) {
- return nearest;
- }
-
- // If it exists, the key is in a subtree. Go deeper.
- Node child = (comparison < 0) ? nearest.left : nearest.right;
- if (child == null) {
- break;
- }
-
- nearest = child;
- }
- }
-
- // The key doesn't exist in this tree.
- if (!create) {
- return null;
- }
-
- // Create the node and add it to the tree or the table.
- Node header = this.header;
- Node created;
- if (nearest == null) {
- // Check that the value is comparable if we didn't do any comparisons.
- if (comparator == NATURAL_ORDER && !(key instanceof Comparable)) {
- throw new ClassCastException(key.getClass().getName() + " is not Comparable");
- }
- created = new Node<>(nearest, key, hash, header, header.prev);
- table[index] = created;
- } else {
- created = new Node<>(nearest, key, hash, header, header.prev);
- if (comparison < 0) { // nearest.key is higher
- nearest.left = created;
- } else { // comparison > 0, nearest.key is lower
- nearest.right = created;
- }
- rebalance(nearest, true);
- }
-
- if (size++ > threshold) {
- doubleCapacity();
- }
- modCount++;
-
- return created;
- }
-
- @SuppressWarnings("unchecked")
- Node findByObject(Object key) {
- try {
- return key != null ? find((K) key, false) : null;
- } catch (ClassCastException e) {
- return null;
- }
- }
-
- /**
- * Returns this map's entry that has the same key and value as {@code
- * entry}, or null if this map has no such entry.
- *
- *
This method uses the comparator for key equality rather than {@code
- * equals}. If this map's comparator isn't consistent with equals (such as
- * {@code String.CASE_INSENSITIVE_ORDER}), then {@code remove()} and {@code
- * contains()} will violate the collections API.
- */
- Node findByEntry(Entry, ?> entry) {
- Node mine = findByObject(entry.getKey());
- boolean valuesEqual = mine != null && equal(mine.value, entry.getValue());
- return valuesEqual ? mine : null;
- }
-
- private boolean equal(Object a, Object b) {
- return a == b || (a != null && a.equals(b));
- }
-
- /**
- * Applies a supplemental hash function to a given hashCode, which defends
- * against poor quality hash functions. This is critical because HashMap
- * uses power-of-two length hash tables, that otherwise encounter collisions
- * for hashCodes that do not differ in lower or upper bits.
- */
- private static int secondaryHash(int h) {
- // Doug Lea's supplemental hash function
- h ^= (h >>> 20) ^ (h >>> 12);
- return h ^ (h >>> 7) ^ (h >>> 4);
- }
-
- /**
- * Removes {@code node} from this tree, rearranging the tree's structure as
- * necessary.
- *
- * @param unlink true to also unlink this node from the iteration linked list.
- */
- void removeInternal(Node node, boolean unlink) {
- if (unlink) {
- node.prev.next = node.next;
- node.next.prev = node.prev;
- node.next = node.prev = null; // Help the GC (for performance)
- }
-
- Node left = node.left;
- Node right = node.right;
- Node originalParent = node.parent;
- if (left != null && right != null) {
-
- /*
- * To remove a node with both left and right subtrees, move an
- * adjacent node from one of those subtrees into this node's place.
- *
- * Removing the adjacent node may change this node's subtrees. This
- * node may no longer have two subtrees once the adjacent node is
- * gone!
- */
-
- Node adjacent = (left.height > right.height) ? left.last() : right.first();
- removeInternal(adjacent, false); // takes care of rebalance and size--
-
- int leftHeight = 0;
- left = node.left;
- if (left != null) {
- leftHeight = left.height;
- adjacent.left = left;
- left.parent = adjacent;
- node.left = null;
- }
- int rightHeight = 0;
- right = node.right;
- if (right != null) {
- rightHeight = right.height;
- adjacent.right = right;
- right.parent = adjacent;
- node.right = null;
- }
- adjacent.height = Math.max(leftHeight, rightHeight) + 1;
- replaceInParent(node, adjacent);
- return;
- } else if (left != null) {
- replaceInParent(node, left);
- node.left = null;
- } else if (right != null) {
- replaceInParent(node, right);
- node.right = null;
- } else {
- replaceInParent(node, null);
- }
-
- rebalance(originalParent, false);
- size--;
- modCount++;
- }
-
- Node removeInternalByKey(Object key) {
- Node node = findByObject(key);
- if (node != null) {
- removeInternal(node, true);
- }
- return node;
- }
-
- private void replaceInParent(Node node, Node replacement) {
- Node parent = node.parent;
- node.parent = null;
- if (replacement != null) {
- replacement.parent = parent;
- }
-
- if (parent != null) {
- if (parent.left == node) {
- parent.left = replacement;
- } else {
- assert (parent.right == node);
- parent.right = replacement;
- }
- } else {
- int index = node.hash & (table.length - 1);
- table[index] = replacement;
- }
- }
-
- /**
- * Rebalances the tree by making any AVL rotations necessary between the
- * newly-unbalanced node and the tree's root.
- *
- * @param insert true if the node was unbalanced by an insert; false if it
- * was by a removal.
- */
- private void rebalance(Node unbalanced, boolean insert) {
- for (Node node = unbalanced; node != null; node = node.parent) {
- Node left = node.left;
- Node right = node.right;
- int leftHeight = left != null ? left.height : 0;
- int rightHeight = right != null ? right.height : 0;
-
- int delta = leftHeight - rightHeight;
- if (delta == -2) {
- Node rightLeft = right.left;
- Node rightRight = right.right;
- int rightRightHeight = rightRight != null ? rightRight.height : 0;
- int rightLeftHeight = rightLeft != null ? rightLeft.height : 0;
-
- int rightDelta = rightLeftHeight - rightRightHeight;
- if (rightDelta == -1 || (rightDelta == 0 && !insert)) {
- rotateLeft(node); // AVL right right
- } else {
- assert (rightDelta == 1);
- rotateRight(right); // AVL right left
- rotateLeft(node);
- }
- if (insert) {
- break; // no further rotations will be necessary
- }
-
- } else if (delta == 2) {
- Node leftLeft = left.left;
- Node leftRight = left.right;
- int leftRightHeight = leftRight != null ? leftRight.height : 0;
- int leftLeftHeight = leftLeft != null ? leftLeft.height : 0;
-
- int leftDelta = leftLeftHeight - leftRightHeight;
- if (leftDelta == 1 || (leftDelta == 0 && !insert)) {
- rotateRight(node); // AVL left left
- } else {
- assert (leftDelta == -1);
- rotateLeft(left); // AVL left right
- rotateRight(node);
- }
- if (insert) {
- break; // no further rotations will be necessary
- }
-
- } else if (delta == 0) {
- node.height = leftHeight + 1; // leftHeight == rightHeight
- if (insert) {
- break; // the insert caused balance, so rebalancing is done!
- }
-
- } else {
- assert (delta == -1 || delta == 1);
- node.height = Math.max(leftHeight, rightHeight) + 1;
- if (!insert) {
- break; // the height hasn't changed, so rebalancing is done!
- }
- }
- }
- }
-
- /**
- * Rotates the subtree so that its root's right child is the new root.
- */
- private void rotateLeft(Node root) {
- Node left = root.left;
- Node pivot = root.right;
- Node pivotLeft = pivot.left;
- Node pivotRight = pivot.right;
-
- // move the pivot's left child to the root's right
- root.right = pivotLeft;
- if (pivotLeft != null) {
- pivotLeft.parent = root;
- }
-
- replaceInParent(root, pivot);
-
- // move the root to the pivot's left
- pivot.left = root;
- root.parent = pivot;
-
- // fix heights
- root.height = Math.max(left != null ? left.height : 0,
- pivotLeft != null ? pivotLeft.height : 0) + 1;
- pivot.height = Math.max(root.height,
- pivotRight != null ? pivotRight.height : 0) + 1;
- }
-
- /**
- * Rotates the subtree so that its root's left child is the new root.
- */
- private void rotateRight(Node root) {
- Node pivot = root.left;
- Node right = root.right;
- Node pivotLeft = pivot.left;
- Node pivotRight = pivot.right;
-
- // move the pivot's right child to the root's left
- root.left = pivotRight;
- if (pivotRight != null) {
- pivotRight.parent = root;
- }
-
- replaceInParent(root, pivot);
-
- // move the root to the pivot's right
- pivot.right = root;
- root.parent = pivot;
-
- // fixup heights
- root.height = Math.max(right != null ? right.height : 0,
- pivotRight != null ? pivotRight.height : 0) + 1;
- pivot.height = Math.max(root.height,
- pivotLeft != null ? pivotLeft.height : 0) + 1;
- }
-
- private EntrySet entrySet;
- private KeySet keySet;
-
- @Override public Set> entrySet() {
- EntrySet result = entrySet;
- return result != null ? result : (entrySet = new EntrySet());
- }
-
- @Override public Set keySet() {
- KeySet result = keySet;
- return result != null ? result : (keySet = new KeySet());
- }
-
- static final class Node implements Entry {
- Node parent;
- Node left;
- Node right;
- Node next;
- Node