-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TrustedDataFramework/v.1.1
V.1.1
- Loading branch information
Showing
32 changed files
with
1,919 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "automatic" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ plugins { | |
} | ||
|
||
group 'org.tdf' | ||
version '1.0.7' | ||
version '1.1.7' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.tdf.rlp; | ||
|
||
import java.util.Collection; | ||
|
||
class CollectionContainer implements Container { | ||
Class<? extends Collection> collectionType; | ||
|
||
public ContainerType getContainerType() { | ||
return ContainerType.COLLECTION; | ||
} | ||
|
||
Container contentType; | ||
|
||
@Override | ||
public Class<?> asRawType() { | ||
throw new RuntimeException("not a raw type"); | ||
} | ||
|
||
@Override | ||
public CollectionContainer asCollectionContainer() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public MapContainer asMapContainer() { | ||
throw new RuntimeException("not a map container"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.tdf.rlp; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
interface Container { | ||
ContainerType getContainerType(); | ||
|
||
Class<?> asRawType(); | ||
|
||
CollectionContainer asCollectionContainer(); | ||
|
||
MapContainer asMapContainer(); | ||
|
||
static Container resolveField(Field field) { | ||
Container container = resolveContainerofGeneric(field.getGenericType()); | ||
Class clazz = null; | ||
if (field.isAnnotationPresent(RLPDecoding.class)) { | ||
clazz = field.getAnnotation(RLPDecoding.class).as(); | ||
} | ||
|
||
if(clazz == null || clazz == Void.class) return container; | ||
if(container.getContainerType() == ContainerType.RAW) | ||
throw new RuntimeException("@RLPDecoding.as is used on collection or map type"); | ||
if(!field.getType().isAssignableFrom(clazz)) | ||
throw new RuntimeException("cannot assign " + clazz + " as " + field.getType()); | ||
if(container.getContainerType() == ContainerType.COLLECTION){ | ||
container.asCollectionContainer().collectionType = clazz; | ||
} | ||
if(container.getContainerType() == ContainerType.MAP){ | ||
container.asMapContainer().mapType = clazz; | ||
} | ||
return container; | ||
} | ||
|
||
static Container resolveContainerOfNoGeneric(Class clazz){ | ||
if(Collection.class.isAssignableFrom(clazz)){ | ||
CollectionContainer con = new CollectionContainer(); | ||
con.contentType = new Raw(RLPElement.class); | ||
con.collectionType = clazz; | ||
return con; | ||
} | ||
if(Map.class.isAssignableFrom(clazz)){ | ||
MapContainer con = new MapContainer(); | ||
con.keyType = new Raw(RLPElement.class); | ||
con.valueType = new Raw(RLPElement.class); | ||
con.mapType = clazz; | ||
return con; | ||
} | ||
return new Raw(clazz); | ||
} | ||
|
||
static Container resolveContainerofGeneric(Type type) { | ||
if (!(type instanceof ParameterizedType)) { | ||
Class clazz = (Class<?>) type; | ||
return resolveContainerOfNoGeneric(clazz); | ||
} | ||
ParameterizedType parameterizedType = (ParameterizedType) type; | ||
Class clazz = (Class) parameterizedType.getRawType(); | ||
if (Collection.class.isAssignableFrom(clazz)) { | ||
CollectionContainer con = new CollectionContainer(); | ||
con.contentType = resolveContainerofGeneric(parameterizedType.getActualTypeArguments()[0]); | ||
con.collectionType = clazz; | ||
return con; | ||
} | ||
if (Map.class.isAssignableFrom(clazz)) { | ||
MapContainer con = new MapContainer(); | ||
con.keyType = resolveContainerofGeneric(parameterizedType.getActualTypeArguments()[0]); | ||
con.valueType = resolveContainerofGeneric(parameterizedType.getActualTypeArguments()[1]); | ||
con.mapType = clazz; | ||
return con; | ||
} | ||
return resolveContainerOfNoGeneric(clazz); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.tdf.rlp; | ||
|
||
public enum ContainerType { | ||
RAW, | ||
COLLECTION, | ||
MAP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.