Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.landawn.abacus.type.Type Maven / Gradle / Ivy
Go to download
A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.
/*
* Copyright (C) 2015 HaiYang Li
*
* 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.landawn.abacus.type;
import java.io.IOException;
import java.io.Writer;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import com.landawn.abacus.parser.SerializationConfig;
import com.landawn.abacus.util.Array;
import com.landawn.abacus.util.CharacterWriter;
import com.landawn.abacus.util.ClassUtil;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.TypeReference;
/**
*
* @author Haiyang Li
* @param
* @since 0.8
* @see com.landawn.abacus.util.TypeReference
* @see com.landawn.abacus.util.TypeReference.TypeToken
*/
public interface Type {
/**
*
* @param
* @param type
* @return
*/
static Type of(final java.lang.reflect.Type type) {
return TypeFactory.getType(type);
}
/**
*
*
* @param
* @param typeRef
* @return
*/
static Type of(final TypeReference typeRef) {
return typeRef.type();
}
/**
*
* @param
* @param cls
* @return
*/
static Type of(final Class cls) {
return TypeFactory.getType(cls);
}
/**
*
* @param
* @param typeName
* @return
*/
static Type of(final String typeName) {
return TypeFactory.getType(typeName);
}
/**
*
* @param
* @param classes
* @return
*/
@SuppressWarnings("unchecked")
@SafeVarargs
static List> ofAll(final Class... classes) {
return ofAll(Array.asList(classes));
}
/**
*
* @param
* @param classes
* @return
*/
@SuppressWarnings("unchecked")
static List> ofAll(final Collection> classes) {
final List> types = new ArrayList<>(N.size(classes));
if (N.notNullOrEmpty(classes)) {
for (Class cls : classes) {
types.add((Type) of(cls));
}
}
return types;
}
/**
*
* @param
* @param eleClass
* @return
*/
static Type> ofList(Class eleClass) {
return TypeFactory.getType("List<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of linked list.
*
* @param
* @param eleClass
* @return
*/
static Type> ofLinkedList(Class eleClass) {
return TypeFactory.getType("LinkedList<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of list of map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type>> ofListOfMap(Class keyClass, Class valClass) {
return TypeFactory.getType("List>");
}
/**
* Of list of linked hash map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type>> ofListOfLinkedHashMap(Class keyClass, Class valClass) {
return TypeFactory.getType("List>");
}
/**
*
* @param
* @param eleClass
* @return
*/
static Type> ofSet(Class eleClass) {
return TypeFactory.getType("Set<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of set of map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type>> ofSetOfMap(Class keyClass, Class valClass) {
return TypeFactory.getType("Set>");
}
/**
* Of set of linked hash map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type>> ofSetOfLinkedHashMap(Class keyClass, Class valClass) {
return TypeFactory.getType("Set>");
}
/**
* Of linked hash set.
*
* @param
* @param eleClass
* @return
*/
static Type> ofLinkedHashSet(Class eleClass) {
return TypeFactory.getType("LinkedHashSet<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of sorted set.
*
* @param
* @param eleClass
* @return
*/
static Type> ofSortedSet(Class eleClass) {
return TypeFactory.getType("SortedSet<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of navigable set.
*
* @param
* @param eleClass
* @return
*/
static Type> ofNavigableSet(Class eleClass) {
return TypeFactory.getType("NavigableSet<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of tree set.
*
* @param
* @param eleClass
* @return
*/
static Type> ofTreeSet(Class eleClass) {
return TypeFactory.getType("TreeSet<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
*
* @param
* @param eleClass
* @return
*/
static Type> ofQueue(Class eleClass) {
return TypeFactory.getType("Queue<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
*
* @param
* @param eleClass
* @return
*/
static Type> ofDeque(Class eleClass) {
return TypeFactory.getType("Deque<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of array deque.
*
* @param
* @param eleClass
* @return
*/
static Type> ofArrayDeque(Class eleClass) {
return TypeFactory.getType("ArrayDeque<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of linked blocking queue.
*
* @param
* @param eleClass
* @return
*/
static Type> ofLinkedBlockingQueue(Class eleClass) {
return TypeFactory.getType("LinkedBlockingQueue<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of concurrent linked queue.
*
* @param
* @param eleClass
* @return
*/
static Type> ofConcurrentLinkedQueue(Class eleClass) {
return TypeFactory.getType("ConcurrentLinkedQueue<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
* Of priority queue.
*
* @param
* @param eleClass
* @return
*/
static Type> ofPriorityQueue(Class eleClass) {
return TypeFactory.getType("PriorityQueue<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
*
* @return
*/
static Type> ofPropsMap() {
return TypeFactory.getType("LinkedHashMap");
}
/**
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofMap(Class keyClass, Class valClass) {
return TypeFactory.getType("Map<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of linked hash map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofLinkedHashMap(Class keyClass, Class valClass) {
return TypeFactory.getType("LinkedHashMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of sorted map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofSortedMap(Class keyClass, Class valClass) {
return TypeFactory.getType("SortedMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of navigable map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofNavigableMap(Class keyClass, Class valClass) {
return TypeFactory.getType("NavigableMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of tree map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofTreeMap(Class keyClass, Class valClass) {
return TypeFactory.getType("TreeMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of concurrent map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofConcurrentMap(Class keyClass, Class valClass) {
return TypeFactory.getType("ConcurrentMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
* Of concurrent hash map.
*
* @param the key type
* @param the value type
* @param keyClass
* @param valClass
* @return
*/
static Type> ofConcurrentHashMap(Class keyClass, Class valClass) {
return TypeFactory.getType("ConcurrentHashMap<" + ClassUtil.getCanonicalClassName(keyClass) + ", " + ClassUtil.getCanonicalClassName(valClass) + ">");
}
/**
*
* @param
* @param eleClass
* @return
*/
static Type> ofMultiset(Class eleClass) {
return TypeFactory.getType("Multiset<" + ClassUtil.getCanonicalClassName(eleClass) + ">");
}
/**
*
*
* @return
*/
String name();
/**
*
*
* @return
*/
String declaringName();
/**
*
*
* @return
*/
String xmlName();
/**
*
*
* @return
*/
Class clazz();
/**
* Checks if is primitive type.
*
* @return true, if is primitive type
*/
boolean isPrimitiveType();
/**
* Checks if is primitive wrapper.
*
* @return true, if is primitive wrapper
*/
boolean isPrimitiveWrapper();
/**
* Checks if is primitive list.
*
* @return true, if is primitive list
*/
boolean isPrimitiveList();
/**
* Checks if is boolean.
*
* @return true, if is boolean
*/
boolean isBoolean();
/**
* Checks if is number.
*
* @return true, if is number
*/
boolean isNumber();
/**
* Checks if is string.
*
* @return true, if is string
*/
boolean isString();
/**
*
*
* @return
*/
boolean isCharSequence();
/**
* Checks if is date.
*
* @return true, if is date
*/
boolean isDate();
/**
* Checks if is calendar.
*
* @return true, if is calendar
*/
boolean isCalendar();
/**
* Checks if is joda date time.
*
* @return true, if is joda date time
*/
boolean isJodaDateTime();
/**
* Checks if is primitive array.
*
* @return true, if is primitive array
*/
boolean isPrimitiveArray();
/**
* Checks if is primitive byte array.
*
* @return true, if is primitive byte array
*/
boolean isPrimitiveByteArray();
/**
* Checks if is object array.
*
* @return true, if is object array
*/
boolean isObjectArray();
/**
* Checks if is array.
*
* @return true, if is array
*/
boolean isArray();
/**
* Checks if is list.
*
* @return true, if is list
*/
boolean isList();
/**
* Checks if is sets the.
*
* @return true, if is sets the
*/
boolean isSet();
/**
* Checks if is collection.
*
* @return true, if is collection
*/
boolean isCollection();
/**
* Checks if is map.
*
* @return true, if is map
*/
boolean isMap();
/**
* Checks if is bean.
*
* @return true, if is bean
*/
boolean isBean();
/**
* Checks if is map bean.
*
* @return true, if is map bean
*/
boolean isMapEntity();
/**
* Checks if is bean id.
*
* @return true, if is bean id
*/
boolean isEntityId();
/**
* Checks if is data set.
*
* @return true, if is data set
*/
boolean isDataSet();
/**
* Checks if is input stream.
*
* @return true, if is input stream
*/
boolean isInputStream();
/**
* Checks if is reader.
*
* @return true, if is reader
*/
boolean isReader();
/**
* Checks if is byte buffer.
*
* @return true, if is byte buffer
*/
boolean isByteBuffer();
/**
* Checks if is generic type.
*
* @return true, if is generic type
*/
boolean isGenericType();
/**
*
* @return
*/
boolean isObjectType();
/**
* Checks if is immutable.
*
* @return true, if is immutable
*/
boolean isImmutable();
/**
* Checks if is comparable.
*
* @return true, if is comparable
*/
boolean isComparable();
/**
* Returns {@code true} if the value of this type can be serialized to json/xml/... String directly. The primitive
* type/array/wrapper, date, calendar ... belong to this category. Object Array/Collection/Map/Bean are not.
*
* @return true, if is serializable
*/
boolean isSerializable();
/**
* Checks if is optional or nullable.
*
* @return true, if is optional or nullable
*/
boolean isOptionalOrNullable();
/**
* Gets the serialization type.
*
* @return
*/
SerializationType getSerializationType();
/**
* Gets the element type.
*
* @return
*/
Type getElementType(); //NOSONAR
/**
* Gets the parameter types.
*
* @return
*/
Type[] getParameterTypes(); //NOSONAR
/**
*
* @return
*/
T defaultValue();
/**
*
* @param value
* @return
*/
boolean isDefaultValue(T value);
/**
*
* @param x
* @param y
* @return
*/
int compare(T x, T y);
/**
*
* @param x
* @return
*/
String stringOf(T x);
/**
*
* @param str
* @return
*/
T valueOf(String str);
/**
*
* @param obj
* @return
*/
T valueOf(Object obj);
/**
*
* @param cbuf
* @param offset
* @param len
* @return
*/
T valueOf(char[] cbuf, int offset, int len);
/**
*
* @param rs
* @param columnIndex
* @return
* @throws SQLException the SQL exception
*/
T get(ResultSet rs, int columnIndex) throws SQLException;
/**
*
* @param rs
* @param columnLabel
* @return
* @throws SQLException the SQL exception
*/
T get(ResultSet rs, String columnLabel) throws SQLException;
/**
*
* @param stmt
* @param columnIndex
* @param x
* @throws SQLException the SQL exception
*/
void set(PreparedStatement stmt, int columnIndex, T x) throws SQLException;
/**
*
* @param stmt
* @param parameterName
* @param x
* @throws SQLException the SQL exception
*/
void set(CallableStatement stmt, String parameterName, T x) throws SQLException;
/**
*
* @param stmt
* @param columnIndex
* @param x
* @param sqlTypeOrLength
* @throws SQLException the SQL exception
*/
void set(PreparedStatement stmt, int columnIndex, T x, int sqlTypeOrLength) throws SQLException;
/**
*
* @param stmt
* @param parameterName
* @param x
* @param sqlTypeOrLength
* @throws SQLException the SQL exception
*/
void set(CallableStatement stmt, String parameterName, T x, int sqlTypeOrLength) throws SQLException;
/**
*
* @param writer
* @param x
* @throws IOException Signals that an I/O exception has occurred.
*/
void write(Writer writer, T x) throws IOException;
/**
*
* @param writer
* @param x
* @param config
* @throws IOException Signals that an I/O exception has occurred.
*/
void writeCharacter(CharacterWriter writer, T x, SerializationConfig config) throws IOException;
/**
* Collection 2 array.
*
* @param c
* @return
*/
T collection2Array(Collection c);
/**
* Array 2 collection.
*
* @param
* @param collClass
* @param x
* @return
*/
Collection array2Collection(Class collClass, T x);
/**
* Array 2 collection.
*
* @param
* @param resultCollection
* @param x
* @return
*/
Collection array2Collection(Collection resultCollection, T x);
/**
*
* @param x
* @return
*/
int hashCode(T x);
/**
* Deep hash code.
*
* @param x
* @return
*/
int deepHashCode(T x);
/**
*
* @param x
* @param y
* @return true, if successful
*/
boolean equals(T x, T y);
/**
*
* @param x
* @param y
* @return true, if successful
*/
boolean deepEquals(T x, T y);
/**
*
* @param x
* @return
*/
String toString(T x);
/**
* Deep to string.
*
* @param x
* @return
*/
String deepToString(T x);
enum SerializationType {
SERIALIZABLE, ENTITY, MAP, ARRAY, COLLECTION, MAP_ENTITY, ENTITY_ID, DATA_SET, UNKNOWN;
}
}