-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
1,029 additions
and
606 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
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
68 changes: 68 additions & 0 deletions
68
nitrite/src/main/java/org/dizitart/no2/common/EntityType.java
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,68 @@ | ||
package org.dizitart.no2.common; | ||
|
||
import lombok.Getter; | ||
import org.dizitart.no2.exceptions.ValidationException; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.lang.reflect.TypeVariable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* An abstract class representing the type of entity in Nitrite database. | ||
* It provides the raw type and parameterized type information of the entity. | ||
* | ||
* @param <T> the type of the entity | ||
* @since 4.2 | ||
* @author Anindya Chatterjee | ||
*/ | ||
@Getter | ||
public abstract class EntityType<T> implements Comparable<EntityType<T>> { | ||
/** | ||
* Represents the parameterized type of entity. | ||
*/ | ||
protected final Type type; | ||
|
||
/** | ||
* The raw type of the entity. | ||
*/ | ||
protected final Class<T> rawType; | ||
|
||
@SuppressWarnings("unchecked") | ||
protected EntityType() { | ||
Type superClass = getClass().getGenericSuperclass(); | ||
if (superClass instanceof Class<?>) { | ||
throw new ValidationException("EntityType constructed without actual type information"); | ||
} else if (!(superClass instanceof ParameterizedType)) { | ||
throw new ValidationException(superClass.getTypeName() + " is not a parameterized type"); | ||
} | ||
|
||
type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; | ||
rawType = type instanceof ParameterizedType | ||
? (Class<T>) ((ParameterizedType) type).getRawType() | ||
: type instanceof TypeVariable | ||
? (Class<T>) ((TypeVariable<?>) type).getBounds()[0] | ||
: (Class<T>) type; | ||
} | ||
|
||
@Override | ||
public int compareTo(EntityType<T> o) { return 0; } | ||
|
||
@Override | ||
public String toString() { | ||
return type.getTypeName(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
EntityType<?> that = (EntityType<?>) o; | ||
return Objects.equals(type, that.type) && Objects.equals(rawType, that.rawType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(type, rawType); | ||
} | ||
} |
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
Oops, something went wrong.