本文整理汇总了Java中java.lang.reflect.Modifier.isTransient方法的典型用法代码示例。如果您正苦于以下问题:Java Modifier.isTransient方法的具体用法?Java Modifier.isTransient怎么用?Java Modifier.isTransient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.isTransient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFields
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public Map<String, FieldInfo> getFields(final Type entityClass) {
Map<String, FieldInfo> fields = cache.get(entityClass);
if (fields == null) {
fields = new HashMap<String, VPackCache.FieldInfo>();
Class<?> tmp = (Class<?>) entityClass;
while (tmp != null && tmp != Object.class) {
final Field[] declaredFields = tmp.getDeclaredFields();
for (final Field field : declaredFields) {
if (!field.isSynthetic() && !Modifier.isStatic(field.getModifiers())
&& !Modifier.isTransient(field.getModifiers())) {
field.setAccessible(true);
final FieldInfo fieldInfo = createFieldInfo(field);
if (fieldInfo.serialize || fieldInfo.deserialize) {
fields.put(fieldInfo.getFieldName(), fieldInfo);
}
}
}
tmp = tmp.getSuperclass();
}
fields = sort(fields.entrySet());
cache.put(entityClass, fields);
}
return fields;
}
示例2: getBeanPropertyFields
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static Map<String, Field> getBeanPropertyFields(Class cl) {
Map<String, Field> properties = new HashMap<String, Field>();
for(; cl != null; cl = cl.getSuperclass()) {
Field[] fields = cl.getDeclaredFields();
for(Field field : fields) {
if (Modifier.isTransient(field.getModifiers())
|| Modifier.isStatic(field.getModifiers())) {
continue;
}
field.setAccessible(true);
properties.put(field.getName(), field);
}
}
return properties;
}
示例3: getFieldList
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* 获取该类的所有属性列表
*
* @param clazz 反射类
* @return
*/
public static List<Field> getFieldList(Class<?> clazz) {
if (null == clazz) {
return null;
}
List<Field> fieldList = new LinkedList<>();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
/* 过滤静态属性 */
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
/* 过滤 transient关键字修饰的属性 */
if (Modifier.isTransient(field.getModifiers())) {
continue;
}
fieldList.add(field);
}
/* 处理父类字段 */
Class<?> superClass = clazz.getSuperclass();
if (superClass.equals(Object.class)) {
return fieldList;
}
/* 排除重载属性 */
return excludeOverrideSuperField(fieldList, getFieldList(superClass));
}
示例4: getNonStaticFields
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* Get all non-static fields of the Class passed in or its super classes.
*
* @param clazz
* Class to parse.
* @return field list
*/
public static List<Field> getNonStaticFields(final Class<?> clazz) {
List<Field> result = new ArrayList<Field>();
Class<?> target = clazz;
while (target != null) {
if (JaketConfigurationUtils.isExcludedType(target)) {
break;
}
Field[] fields = target.getDeclaredFields();
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
continue;
}
result.add(field);
}
target = target.getSuperclass();
}
return result;
}
示例5: writeObject
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
private void writeObject(String key, Object object) throws IllegalArgumentException, IllegalAccessException {
if (alreadyWritten.containsKey(object)) {
throw new IllegalArgumentException("Object " + object + " is already present in the stream");
}
alreadyWritten.put(object, object);
writer.beginObject(key, object.getClass().getName());
Class<?> clazz = object.getClass();
while (clazz != Object.class) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isVolatile(modifiers)) {
// Skip
continue;
}
if (field.isSynthetic()) {
// Skip
continue;
}
writeProperty(field.getName(), field.get(object));
}
clazz = clazz.getSuperclass();
}
writer.endObject();
}
示例6: getProfileMeasurements
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* Return a list of all of the ProfileMeasurement handles for this profiler
* @return
*/
public final ProfileMeasurement[] getProfileMeasurements() {
if (pm_cache == null) {
synchronized (this) {
if (pm_cache == null) {
final List<ProfileMeasurement> temp = new ArrayList<ProfileMeasurement>();
for (Field f : this.getClass().getDeclaredFields()) {
int modifiers = f.getModifiers();
if (Modifier.isTransient(modifiers) == false &&
Modifier.isPrivate(modifiers) == false &&
Modifier.isStatic(modifiers) == false) {
Object obj = null;
try {
obj = f.get(this);
} catch (Exception ex) {
throw new RuntimeException("Failed to get value for field '" + f.getName() + "'", ex);
}
if (obj instanceof ProfileMeasurement) temp.add((ProfileMeasurement)obj);
}
} // FOR
pm_cache = temp.toArray(new ProfileMeasurement[temp.size()]);
}
} // SYNCH
}
return (pm_cache);
}
示例7: getFieldsByType
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* @param clazz
* @return
*/
public static <T> Field[] getFieldsByType(Class<?> clazz, Class<? extends T> fieldType) {
List<Field> fields = new ArrayList<Field>();
for (Field f : clazz.getDeclaredFields()) {
int modifiers = f.getModifiers();
if (Modifier.isTransient(modifiers) == false &&
Modifier.isPublic(modifiers) == true &&
Modifier.isStatic(modifiers) == false &&
ClassUtil.getSuperClasses(f.getType()).contains(fieldType)) {
fields.add(f);
}
} // FOR
return (fields.toArray(new Field[fields.size()]));
}
示例8: isPersistableField
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* Is this field persistable.
*/
static boolean isPersistableField(Field f) {
if (f.isAnnotationPresent(Transient.class)) {
return false;
}
int mod = f.getModifiers();
if (Modifier.isFinal(mod) || Modifier.isTransient(mod) || Modifier.isStatic(mod)) {
return false;
}
getSqlType(f);
return true;
}
示例9: isTransient
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
@Override
public boolean isTransient() {
Field field = fieldInBack();
return field != null && Modifier.isTransient(field.getModifiers());
}
示例10: loadFields
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
static void loadFields( IJsonIO obj, Class cls, Bindings bindings )
{
Field[] fields = cls.getDeclaredFields();
for( Field f : fields )
{
if( f.isSynthetic() || Modifier.isStatic( f.getModifiers() ) || Modifier.isTransient( f.getModifiers() ) )
{
continue;
}
f.setAccessible( true );
try
{
Object value = bindings.get( f.getName() );
if( value instanceof Bindings )
{
value = read( (Bindings)value );
}
else if( value instanceof List && ((List)value).size() > 0 && ((List)value).get( 0 ) instanceof Bindings )
{
value = readList( bindings );
}
else if( f.getType().isEnum() && value instanceof String )
{
value = Enum.valueOf( (Class)f.getType(), (String)value );
}
else if( f.getType() == Boolean.class || f.getType() == boolean.class )
{
value = (Integer)value != 0;
}
else if( !isSimpleType( f.getType() ) )
{
throw new UnsupportedOperationException( "Unsupported Json type: " + f.getType() );
}
f.set( obj, value );
}
catch( IllegalAccessException e )
{
throw new RuntimeException( e );
}
}
Class superclass = cls.getSuperclass();
if( superclass != null )
{
loadFields( obj, superclass, bindings );
}
}
示例11: isTransient
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/** Returns true if the field is transient. */
final boolean isTransient() {
return Modifier.isTransient(getModifiers());
}
示例12: isTransient
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* @see Modifier#isTransient(int)
*/
default boolean isTransient() {
return Modifier.isTransient(getModifiers());
}
示例13: isTransient
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public boolean isTransient(Field f) {
return Modifier.isTransient(f.getModifiers());
}
示例14: computeStructuralUID
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
public static long computeStructuralUID(boolean hasWriteObject, Class<?> cl) {
ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);
long h = 0;
try {
if ((!java.io.Serializable.class.isAssignableFrom(cl)) ||
(cl.isInterface())){
return 0;
}
if (java.io.Externalizable.class.isAssignableFrom(cl)) {
return 1;
}
MessageDigest md = MessageDigest.getInstance("SHA");
DigestOutputStream mdo = new DigestOutputStream(devnull, md);
DataOutputStream data = new DataOutputStream(mdo);
//In the old case, for the caller class, the write Method wasn't considered
// for rep-id calculations correctly, but for parent classes it was taken
// into account. That is the reason there is the klude of getting the write
// Object method in there
// Get SUID of parent
Class<?> parent = cl.getSuperclass();
if ((parent != null) && (parent != java.lang.Object.class)) {
boolean hasWriteObjectFlag = false;
Class [] args = {java.io.ObjectOutputStream.class};
Method hasWriteObjectMethod = ObjectStreamClassUtil_1_3.getDeclaredMethod(parent, "writeObject", args,
Modifier.PRIVATE, Modifier.STATIC);
if (hasWriteObjectMethod != null)
hasWriteObjectFlag = true;
data.writeLong(ObjectStreamClassUtil_1_3.computeStructuralUID(hasWriteObjectFlag, parent));
}
if (hasWriteObject)
data.writeInt(2);
else
data.writeInt(1);
/* Sort the field names to get a deterministic order */
Field[] field = ObjectStreamClassUtil_1_3.getDeclaredFields(cl);
Arrays.sort(field, compareMemberByName);
for (int i = 0; i < field.length; i++) {
Field f = field[i];
/* Include in the hash all fields except those that are
* transient or static.
*/
int m = f.getModifiers();
if (Modifier.isTransient(m) || Modifier.isStatic(m))
continue;
data.writeUTF(f.getName());
data.writeUTF(getSignature(f.getType()));
}
/* Compute the hash value for this class.
* Use only the first 64 bits of the hash.
*/
data.flush();
byte hasharray[] = md.digest();
int minimum = Math.min(8, hasharray.length);
for (int i = minimum; i > 0; i--) {
h += (long)(hasharray[i] & 255) << (i * 8);
}
} catch (IOException ignore) {
/* can't happen, but be deterministic anyway. */
h = -1;
} catch (NoSuchAlgorithmException complain) {
throw new SecurityException(complain.getMessage());
}
return h;
}
示例15: includeField
import java.lang.reflect.Modifier; //导入方法依赖的package包/类
/**
* Returns true if fields with {@code modifiers} are included in the emitted JSON.
*/
@SuppressWarnings("SimplifiableIfStatement")
private boolean includeField(boolean platformType, int modifiers) {
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) return false;
return Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || !platformType;
}