本文整理匯總了Java中java.lang.reflect.Modifier.TRANSIENT屬性的典型用法代碼示例。如果您正苦於以下問題:Java Modifier.TRANSIENT屬性的具體用法?Java Modifier.TRANSIENT怎麽用?Java Modifier.TRANSIENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.TRANSIENT屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encodeFields
/**
* Encodes the declared fields of the given object into the given node.
*
* @param enc Codec that controls the encoding process.
* @param obj Object whose fields should be encoded.
* @param node XML node that contains the encoded object.
*/
protected void encodeFields(mxCodec enc, Object obj, Node node)
{
// LATER: Use PropertyDescriptors in Introspector.getBeanInfo(clazz)
// see http://forum.jgraph.com/questions/1424
Class<?> type = obj.getClass();
while (type != null)
{
Field[] fields = type.getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
Field f = fields[i];
if ((f.getModifiers() & Modifier.TRANSIENT) != Modifier.TRANSIENT)
{
String fieldname = f.getName();
Object value = getFieldValue(obj, fieldname);
encodeValue(enc, obj, fieldname, value, node);
}
}
type = type.getSuperclass();
}
}
示例2: encodeFields
/**
* Encodes the declared fields of the given object into the given node.
*
* @param enc Codec that controls the encoding process.
* @param obj Object whose fields should be encoded.
* @param node XML node that contains the encoded object.
*/
protected void encodeFields(mxCodec enc, Object obj, Node node) {
// LATER: Use PropertyDescriptors in Introspector.getBeanInfo(clazz)
// see http://forum.jgraph.com/questions/1424
Class<?> type = obj.getClass();
while (type != null) {
Field[] fields = type.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
if ((f.getModifiers() & Modifier.TRANSIENT) != Modifier.TRANSIENT) {
String fieldname = f.getName();
Object value = getFieldValue(obj, fieldname);
encodeValue(enc, obj, fieldname, value, node);
}
}
type = type.getSuperclass();
}
}
示例3: main
public static void main(String [] argv) {
int allMods = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED |
Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE;
String allModsString = "public protected private abstract static " +
"final transient volatile synchronized native strictfp interface";
/* zero should have an empty string */
testString(0, "");
/* test to make sure all modifiers print out in the proper order */
testString(allMods, allModsString);
/* verify no extraneous modifiers are printed */
testString(~0, allModsString);
}
示例4: retreiveCodeData
/**
* Writes edited code back to the CustomCodeData structure.
*/
CustomCodeData retreiveCodeData() {
retreiveCodeData(CodeCategory.CREATE_AND_INIT);
retreiveCodeData(CodeCategory.DECLARATION);
VariableDeclaration decl = codeData.getDeclarationData();
boolean local = variableValues[variableCombo.getSelectedIndex()];
int modifiers;
if (local != decl.local) {
modifiers = local ? lastLocalModifiers : lastFieldModifiers;
if (finalCheckBox.isSelected()) // only final makes sense for both local and field scope
modifiers |= Modifier.FINAL;
else
modifiers &= ~Modifier.FINAL;
}
else {
modifiers = accessValues[accessCombo.getSelectedIndex()];
if (staticCheckBox.isSelected())
modifiers |= Modifier.STATIC;
if (finalCheckBox.isSelected())
modifiers |= Modifier.FINAL;
if (transientCheckBox.isSelected())
modifiers |= Modifier.TRANSIENT;
if (volatileCheckBox.isSelected())
modifiers |= Modifier.VOLATILE;
if (local)
modifiers &= ~(Modifier.STATIC | Modifier.TRANSIENT | Modifier.VOLATILE);
}
decl.local = local;
decl.modifiers = modifiers;
return codeData;
}
示例5: translateModifiers
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
示例6: getDefaultSerialFields
/**
* Returns array of ObjectStreamFields corresponding to all non-static
* non-transient fields declared by given class. Each ObjectStreamField
* contains a Field object for the field it represents. If no default
* serializable fields exist, NO_FIELDS is returned.
*/
private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
Field[] clFields = cl.getDeclaredFields();
ArrayList<ObjectStreamField> list = new ArrayList<>();
int mask = Modifier.STATIC | Modifier.TRANSIENT;
for (int i = 0; i < clFields.length; i++) {
if ((clFields[i].getModifiers() & mask) == 0) {
list.add(new ObjectStreamField(clFields[i], false, true));
}
}
int size = list.size();
return (size == 0) ? NO_FIELDS :
list.toArray(new ObjectStreamField[size]);
}
示例7: processTypes
private void processTypes(final Set<Class<?>> types) {
while (!types.isEmpty()) {
final Iterator<Class<?>> iter = types.iterator();
final Class<?> type = iter.next();
iter.remove();
synchronized (type) {
if (annotatedTypes.contains(type)) {
continue;
}
try {
if (type.isPrimitive()) {
continue;
}
addParametrizedTypes(type, types);
processConverterAnnotations(type);
processAliasAnnotation(type, types);
processAliasTypeAnnotation(type);
if (type.isInterface()) {
continue;
}
final Field[] fields = type.getDeclaredFields();
for (final Field field : fields) {
if (field.isEnumConstant()
|| (field.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) > 0) {
continue;
}
addParametrizedTypes(field.getGenericType(), types);
if (field.isSynthetic()) {
continue;
}
processFieldAliasAnnotation(field);
processAsAttributeAnnotation(field);
processImplicitAnnotation(field);
processOmitFieldAnnotation(field);
processLocalConverterAnnotation(field);
}
} finally {
annotatedTypes.add(type);
}
}
}
}
示例8: populateCriteriaForExample
private void populateCriteriaForExample(Criteria criteria, Object object) {
Class<?> clazz = object.getClass();
if (ExampleLimit.class.isAssignableFrom(clazz)) {
ExampleLimit limit = (ExampleLimit) object;
if (limit.getFirstResult() != null) {
criteria.setFirstResult(limit.getFirstResult());
}
if (limit.getMaxResults() != null) {
criteria.setMaxResults(limit.getMaxResults());
}
}
List <Criterion> ors = new LinkedList<Criterion>();
while (!Object.class.equals(clazz)) {
Field[] fields = clazz.getDeclaredFields();
int max = fields.length;
for (int i = 0; i < max; i++) {
Field field = fields[i];
if ((field.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0
/* && (field.getType().isPrimitive()
||field.getType().getName().startsWith("java.lang")) */) {
field.setAccessible(true);
String name = field.getName();
Object value = null;
try {
value = field.get(object);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
if (value != null) {
if (name.endsWith("From")) {
} else if (name.endsWith("To")) {
} else if (name.endsWith("NotIn")) {
criteria.add(Restrictions.not(Restrictions.in(name.substring(0, name.length() - 5), (Collection<?>) value)));
} else if (name.endsWith("In") && value instanceof Collection<?>) {
criteria.add(Restrictions.in(name.substring(0, name.length() - 2), (Collection<?>) value));
} else if (name.endsWith("Like")) {
ors.add(Restrictions.ilike(name.substring(0, name.length() - 4), value.toString().toLowerCase() + "%"));
} else if (value.getClass().getName().startsWith("java.lang")){
criteria.add(Restrictions.eq(name, value));
}
}
}
}
clazz = clazz.getSuperclass();
}
switch (ors.size()) {
case 0:
break;
case 1:
criteria.add(ors.get(0));
break;
default:
criteria.add(Restrictions.or((Criterion[]) ors.toArray(new Criterion[ors.size()])));
break;
}
}
示例9: computeDefaultSUID
/**
* 計算默認的 serialVersionUID
*
* @see java.io.ObjectStreamClass#lookup(Class)
* @see java.io.ObjectStreamClass#computeDefaultSUID(Class)
*/
public static long computeDefaultSUID(String className, List<Field> fields) {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
// simple class name
dout.writeUTF(className);
int classMods = Modifier.PUBLIC & (Modifier.PUBLIC | Modifier.FINAL | Modifier.INTERFACE | Modifier.ABSTRACT);
dout.writeInt(classMods);
// interface name
dout.writeUTF("java.io.Serializable");
// fields
// fields.sort(Comparator.comparing(Field::getField));
for (Field field : fields) {
int mods = Modifier.PRIVATE &
(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED |
Modifier.STATIC | Modifier.FINAL | Modifier.VOLATILE |
Modifier.TRANSIENT);
if (((mods & Modifier.PRIVATE) == 0) ||
((mods & (Modifier.STATIC | Modifier.TRANSIENT)) == 0)) {
dout.writeUTF(field.getField());
dout.writeInt(mods);
dout.writeUTF(field.getFieldType());
}
}
// method ignore
dout.flush();
MessageDigest md = MessageDigest.getInstance("SHA");
byte[] hashBytes = md.digest(bout.toByteArray());
long hash = 0;
for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
hash = (hash << 8) | (hashBytes[i] & 0xFF);
}
return hash;
} catch (Exception e) {
// ignore
}
return 1;
}
示例10: validateClassFormat
synchronized void validateClassFormat(Class<? extends MVO> clazz) {
if (wellFormedMvoClasses_.contains(clazz)) {
return;
}
try {
getMvoConstructorImpl(clazz);
} catch (NoSuchMethodException nsme) {
throw new MvoClassFormatException.ConstructorDefinition
("no mvo constructor found: " + clazz.getName());
}
for (Field field : getReflectionFields(clazz)) {
String fieldFqn = clazz.getName() + "." + field.getName();
if (MVO.MvoField.class.isAssignableFrom(field.getType())) {
if ((field.getModifiers() & Modifier.FINAL) != Modifier.FINAL) {
throw new MvoClassFormatException.FieldDefinition
("mvo-field must be final: " + fieldFqn);
}
if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
throw new MvoClassFormatException.FieldDefinition
("mvo-field must not be static: " + fieldFqn);
}
if ((field.getModifiers() & Modifier.TRANSIENT) == Modifier.TRANSIENT) {
throw new MvoClassFormatException.FieldDefinition
("mvo-field is transient: " + fieldFqn);
}
} else {
if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
continue;
}
if ((field.getModifiers() & Modifier.TRANSIENT) == Modifier.TRANSIENT) {
continue;
}
throw new MvoClassFormatException.FieldDefinition
("the field is not serializable: " + fieldFqn);
}
}
wellFormedMvoClasses_.add(clazz);
}
示例11: getModifiers
public static long getModifiers( PsiModifierList modifierList )
{
long modifiers = 0;
if( modifierList.hasExplicitModifier( PsiModifier.ABSTRACT ) )
{
modifiers |= Modifier.ABSTRACT;
}
if( modifierList.hasExplicitModifier( PsiModifier.DEFAULT ) )
{
modifiers |= 0x80000000000L; //Flags.DEFAULT;
}
if( modifierList.hasExplicitModifier( PsiModifier.FINAL ) )
{
modifiers |= Modifier.FINAL;
}
if( modifierList.hasExplicitModifier( PsiModifier.PRIVATE ) )
{
modifiers |= Modifier.PRIVATE;
}
if( modifierList.hasExplicitModifier( PsiModifier.PROTECTED ) )
{
modifiers |= Modifier.PROTECTED;
}
if( modifierList.hasExplicitModifier( PsiModifier.PUBLIC ) )
{
modifiers |= Modifier.PUBLIC;
}
if( modifierList.hasExplicitModifier( PsiModifier.STATIC ) )
{
modifiers |= Modifier.STATIC;
}
if( modifierList.hasExplicitModifier( PsiModifier.SYNCHRONIZED ) )
{
modifiers |= Modifier.SYNCHRONIZED;
}
if( modifierList.hasExplicitModifier( PsiModifier.TRANSIENT ) )
{
modifiers |= Modifier.TRANSIENT;
}
if( modifierList.hasExplicitModifier( PsiModifier.VOLATILE ) )
{
modifiers |= Modifier.VOLATILE;
}
return modifiers;
}
示例12: modifiersFrom
public static long modifiersFrom( Set<javax.lang.model.element.Modifier> modifiers )
{
long mods = 0;
for( javax.lang.model.element.Modifier mod : modifiers )
{
switch( mod )
{
case PUBLIC:
mods |= Modifier.PUBLIC;
break;
case PROTECTED:
mods |= Modifier.PROTECTED;
break;
case PRIVATE:
mods |= Modifier.PRIVATE;
break;
case ABSTRACT:
mods |= Modifier.ABSTRACT;
break;
case DEFAULT:
mods |= Flags.DEFAULT;
break;
case STATIC:
mods |= Modifier.STATIC;
break;
case FINAL:
mods |= Modifier.FINAL;
break;
case TRANSIENT:
mods |= Modifier.TRANSIENT;
break;
case VOLATILE:
mods |= Modifier.VOLATILE;
break;
case SYNCHRONIZED:
mods |= Modifier.SYNCHRONIZED;
break;
case NATIVE:
mods |= Modifier.NATIVE;
break;
case STRICTFP:
mods |= Flags.STRICTFP;
break;
}
}
return mods;
}
示例13: renderModifiers
protected String renderModifiers( StringBuilder sb, long modifiers, boolean isDefault, int defModifier )
{
if( isDefault )
{
sb.append( "default " );
}
if( (modifiers & Modifier.PUBLIC) != 0 )
{
sb.append( "public " );
}
else if( (modifiers & Modifier.PROTECTED) != 0 )
{
sb.append( "protected " );
}
else if( (modifiers & Modifier.PRIVATE) != 0 )
{
sb.append( "private " );
}
else if( defModifier != 0 )
{
renderModifiers( sb, defModifier, false, 0 );
}
// Canonical order
if( (modifiers & Modifier.ABSTRACT) != 0 )
{
sb.append( "abstract " );
}
if( (modifiers & Modifier.STATIC) != 0 )
{
sb.append( "static " );
}
if( (modifiers & Modifier.FINAL) != 0 )
{
sb.append( "final " );
}
if( (modifiers & Modifier.TRANSIENT) != 0 )
{
sb.append( "transient " );
}
if( (modifiers & Modifier.VOLATILE) != 0 )
{
sb.append( "volatile " );
}
if( (modifiers & Modifier.SYNCHRONIZED) != 0 )
{
sb.append( "synchronized " );
}
if( (modifiers & Modifier.INTERFACE) != 0 )
{
sb.append( "interface " );
}
return "";
}