當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.setLong方法代碼示例

本文整理匯總了Java中java.lang.reflect.Field.setLong方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.setLong方法的具體用法?Java Field.setLong怎麽用?Java Field.setLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.setLong方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setField

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static final <T> void setField(Cursor cursor, int columnIndex,
		T instance, Field field) throws IllegalArgumentException,
		IllegalAccessException {
	Class<?> type = field.getType();
	field.setAccessible(true);
	
	int index = cursor.getColumnIndex(field.getName());
	
	if (type.equals(int.class) || type.equals(Integer.class)) {
		field.setInt(instance, cursor.getInt(index));
	} else if (type.equals(String.class)) {
		field.set(instance, cursor.getString(index));
	} else if (type.equals(long.class) || type.equals(Long.class)) {
		field.setLong(instance, cursor.getLong(index));
	} else if (type.equals(double.class) || type.equals(Double.class)) {
		field.setDouble(instance, cursor.getDouble(index));
	}else if (type.equals(Date.class)) {
		long datetime = cursor.getLong(index);
		if(datetime>0){
			field.set(instance, new Date(datetime));
		}
	}
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:24,代碼來源:DaoUtils.java

示例2: patchUriField

import java.lang.reflect.Field; //導入方法依賴的package包/類
private void patchUriField(String methodName, String fieldName)
        throws IOException {
    try {
        Method lowMask = URI.class.getDeclaredMethod(methodName, String.class);
        lowMask.setAccessible(true);
        Long lowMaskValue = (Long) lowMask.invoke(null, "-_");
        
        Field lowDash = URI.class.getDeclaredField(fieldName);
        
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(lowDash, lowDash.getModifiers() & ~Modifier.FINAL);
        
        lowDash.setAccessible(true);
        lowDash.setLong(null, lowMaskValue);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:ConfigSupport.java

示例3: testToGatheredEvent_MultiplierWrong

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Test(expected = ValidationException.class)
public void testToGatheredEvent_MultiplierWrong() throws Exception {

    // "old"(unchanged) v1.1 setter sets the multiplier to "1"
    // the multiplier is set to "-1" via reflection
    Field declaredField = VOGatheredEvent.class
            .getDeclaredField("multiplier");
    declaredField.setAccessible(true);
    declaredField.setLong(event, -1);

    try {
        GatheredEventAssembler.toGatheredEvent(event);
    } catch (ValidationException e) {
        assertTrue(Arrays.asList(e.getMember()).contains("multiplier"));
        assertTrue(Arrays.asList(e.getMessageParams()).contains("-1"));
        assertEquals(ReasonEnum.VALUE_NOT_IN_RANGE, e.getReason());
        throw e;
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:GatheredEventAssemblerTest.java

示例4: putLongVolatile

import java.lang.reflect.Field; //導入方法依賴的package包/類
public void putLongVolatile(Object obj, long offset, long newValue)
{
    if (obj instanceof cli.System.Array)
    {
        synchronized(this)
        {
            WriteInt64(obj, offset, newValue);
        }
    }
    else
    {
        Field field = getField(offset);
        synchronized(field)
        {
            try
            {
                field.setLong(obj, newValue);
            }
            catch(IllegalAccessException x)
            {
                throw (InternalError)new InternalError().initCause(x);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:Unsafe.java

示例5: setVal

import java.lang.reflect.Field; //導入方法依賴的package包/類
void setVal(Field f, int i) {
    try {
        if (f.getType() == int.class) {
            f.setInt(this, i);
            return;
        } else if (f.getType() == short.class) {
            f.setShort(this, (short)i);
            return;
        } else if (f.getType() == byte.class) {
            f.setByte(this, (byte)i);
            return;
        } else if (f.getType() == long.class) {
            f.setLong(this, i);
            return;
        }
    } catch(IllegalAccessException iae) {
        throw new RuntimeException("Getting fields failed");
    }
    throw new RuntimeException("unexpected field type");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TestInstanceCloneUtils.java

示例6: setProperties

import java.lang.reflect.Field; //導入方法依賴的package包/類
protected void setProperties(Object configBean, String id){
  Class clazz = configBean.getClass();
  while(clazz != Object.class){
    Field[] fields = clazz.getDeclaredFields();
    for(Field f : fields){
      String fieldName = f.getName();
      String fieldValue = ClientConfig.getProperty(id + "." + fieldName);
      if(fieldValue != null){
        f.setAccessible(true);
        Class cls = f.getType();
        try {
          if(cls == int.class || cls == Integer.class){
            f.setInt(configBean, Integer.parseInt(fieldValue));
           }else if(cls == String.class){
            f.set(configBean, fieldValue);
          }else if(cls == long.class || cls == Long.class){
            f.setLong(configBean, Long.parseLong(fieldValue));
          }else if(cls == boolean.class || cls == Boolean.class){
            f.setBoolean(configBean, Boolean.parseBoolean(fieldValue));
          }else if(cls == double.class || cls == Double.class){
            f.setDouble(configBean, Double.parseDouble(fieldValue));
          }
          else{
            LOG.error("skip not supported config bean field type ! "+fieldName+", "+cls);
          }
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }

      }
    }

    clazz = clazz.getSuperclass();
  }
}
 
開發者ID:eXcellme,項目名稱:eds,代碼行數:36,代碼來源:AbstractEventPublisher.java

示例7: executeConsole

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public void executeConsole(CommandSender sender, String[] args) {
    try {
        if (args.length == 3) {
            PlayerDataRPG pd = plugin.getPD(plugin.getServer().getPlayer(args[0]));
            if (pd == null) {
                sender.sendMessage("Could not get data for player " + args[0]);
            } else {
                Field f = PlayerDataRPG.class.getDeclaredField(args[1]);
                f.setAccessible(true);
                Object o = f.get(pd);
                Class<?> c = f.getType();
                if (c == int.class || c == Integer.class) {
                    f.setInt(pd, Integer.parseInt(args[2]));
                } else if (c == long.class || c == Long.class) {
                    f.setLong(pd, Long.parseLong(args[2]));
                } else if (c == double.class || c == Double.class) {
                    f.setDouble(pd, Double.parseDouble(args[2]));
                } else if (c == String.class) {
                    f.set(pd, args[2]);
                } else if (c == boolean.class) {
                    f.setBoolean(pd, Boolean.parseBoolean(args[2]));
                }
                sender.sendMessage("Updated value for " + args[0] + " from " + o + " to " + f.get(pd));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:31,代碼來源:ReflectCommand.java

示例8: setField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static void setField(Object instance, Field field, Object value) throws IllegalAccessException {
	if (value == null && field.getType().isPrimitive()) {
		return;
	}
	
	if (UNSAFE != null) {
		if (int.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (int) value);
		} else if (long.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (long) value);
		} else if (double.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (double) value);
		} else if (void.class.equals(field.getType())) {
		
		} else if (float.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (float) value);
		} else if (byte.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (byte) value);
		} else if (char.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (char) value);
		} else if (boolean.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (boolean) value);
		} else if (short.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (short) value);
		} else {
			((sun.misc.Unsafe) UNSAFE).putObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), value);
		}
	} else { //Fallback if unsafe isn't available
		field.setAccessible(true);
		if (int.class.equals(field.getType())) {
			field.setInt(instance, (int) value);
		} else if (long.class.equals(field.getType())) {
			field.setLong(instance, (long) value);
		} else if (double.class.equals(field.getType())) {
			field.setDouble(instance, (double) value);
		} else if (void.class.equals(field.getType())) {
			
		} else if (float.class.equals(field.getType())) {
			field.setFloat(instance, (float) value);
		} else if (byte.class.equals(field.getType())) {
			field.setByte(instance, (byte) value);
		} else if (char.class.equals(field.getType())) {
			field.setChar(instance, (char) value);
		} else if (boolean.class.equals(field.getType())) {
			field.setBoolean(instance, (boolean) value);
		} else if (short.class.equals(field.getType())) {
			field.setShort(instance, (short) value);
		} else {
			field.set(instance, value);
		}
	}
}
 
開發者ID:austinv11,項目名稱:ETF-Java,代碼行數:53,代碼來源:ReflectionUtils.java

示例9: deserializePrimitiveField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public void deserializePrimitiveField(Field f, Property prop, Object instance) throws IllegalArgumentException, IllegalAccessException
{
	switch(fromJavaPrimitiveType(f.getType()))
	{
		case INTEGER:
		{
			if (f.getType().equals(Byte.TYPE))
			{
				f.setByte(instance, (byte) prop.getInt());
			}
			
			if (f.getType().equals(Short.TYPE))
			{
				f.setShort(instance, (short) prop.getInt());
			}
			
			if (f.getType().equals(Integer.TYPE))
			{
				f.setInt(instance, prop.getInt());
			}
			
			break;
		}
		
		case DOUBLE:
		{
			if (f.getType().equals(Float.TYPE))
			{
				f.setFloat(instance, (float) prop.getDouble());
			}
			
			if (f.getType().equals(Double.TYPE))
			{
				f.setDouble(instance, prop.getDouble());
			}
			
			if (f.getType().equals(Long.TYPE))
			{
				f.setLong(instance, (long) prop.getDouble());
			}
			
			break;
		}
		
		case BOOLEAN:
		{
			f.setBoolean(instance, prop.getBoolean());
			break;
		}
		
		default:
		{
			f.set(instance, prop.getString());
		}
	}
}
 
開發者ID:V0idWa1k3r,項目名稱:VoidApi,代碼行數:57,代碼來源:SerializableConfig.java

示例10: load

import java.lang.reflect.Field; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void load(Object object, Field field, Property property, Map<String, String> properties)
	throws IllegalAccessException, MalformedURLException
{
	Class type = field.getType();
	String key = property.key();
	String value = properties.get(key);

	if( value != null )
	{
		if( String.class.isAssignableFrom(type) )
		{
			field.set(object, value);
		}
		else if( Integer.TYPE.isAssignableFrom(type) )
		{
			field.setInt(object, Integer.parseInt(value));
		}
		else if( Boolean.TYPE.isAssignableFrom(type) )
		{
			field.setBoolean(object, Boolean.parseBoolean(value));
		}
		else if( Long.TYPE.isAssignableFrom(type) )
		{
			field.setLong(object, Long.parseLong(value));
		}
		else if( URL.class.isAssignableFrom(type) )
		{
			field.set(object, new URL(value));
		}
		else if( Enum.class.isAssignableFrom(type) )
		{
			try
			{
				field.set(object, Enum.valueOf(type, value));
			}
			catch( IllegalArgumentException iae )
			{
				// Ignore if value does not match enum - do not set field
			}
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:45,代碼來源:BasicPropertySerialiser.java

示例11: decodeInternal

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public <T> void decodeInternal(BsonReader reader, T instance, Field field) throws IllegalAccessException {
    field.setLong(instance, reader.readInt64());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:5,代碼來源:MappedField.java

示例12: read

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public void read(Bundle bundle, Object to, StateField field) throws IllegalAccessException {
    Field propertyField = field.getField();

    propertyField.setAccessible(true);

    propertyField.setLong(to,bundle.getLong(field.getBundleKey()));

}
 
開發者ID:leobert-lan,項目名稱:MagicBox,代碼行數:10,代碼來源:LongReader.java


注:本文中的java.lang.reflect.Field.setLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。