本文整理汇总了Java中com.esotericsoftware.reflectasm.FieldAccess.get方法的典型用法代码示例。如果您正苦于以下问题:Java FieldAccess.get方法的具体用法?Java FieldAccess.get怎么用?Java FieldAccess.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.esotericsoftware.reflectasm.FieldAccess
的用法示例。
在下文中一共展示了FieldAccess.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFieldAccess
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
private FieldAccess getFieldAccess(String fieldName) {
FieldAccess fieldAccess = clsFieldPool.get(cls);
if (fieldAccess == null) {
fieldAccess = FieldAccess.get(cls);
clsFieldPool.put(cls, fieldAccess);
}
return fieldAccess;
}
示例2: PacketImpl
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
/**
* Constructs a new packet wrapper with the data provided
*
* @param data the data
*/
private PacketImpl(PacketData data) {
this.packet = TridentServer
.instance()
.protocol()
.getPacket(data.getId(), Protocol.ClientStage.PLAY, PacketDirection.IN);
this.access = FieldAccess.get(packet.getClass());
this.packet.decode(data.getData());
data.getData().resetReaderIndex();
}
示例3: setClass
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
@Override
public void setClass(Class<?> clazz) {
super.setClass(clazz);
// Setup ReflectASM stuff
try {
access = FieldAccess.get(clazz);
index = access.getIndex(name);
} catch(Exception ex) {
MyTown.instance.LOG.debug(name + " - Falling back to reflection based field caller", ex);
index = -1;
}
}
示例4: load
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
@Override public FieldAccess load(Class beanClass) {
return FieldAccess.get(beanClass);
}
示例5: get
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
public <V> V get(String fieldName) {
final FieldAccess fieldAccess = getFieldAccess(fieldName);
return (V) fieldAccess.get(target, fieldName);
}
示例6: test4
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
@Test
public void test4() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Person person = new Person("xxx");
int count = 10000;
String name;
// direct invoke
long startTime = System.nanoTime();
for (int i = 0; i < count; i++) {
name = person.getName();
}
System.out.println("total = " + (System.nanoTime() - startTime));
// field invoke
startTime = System.nanoTime();
Field field = person.getClass().getDeclaredField("name");
field.setAccessible(true);
for (int i = 0; i < count; i++) {
name = (String) field.get(person);
}
System.out.println("total = " + (System.nanoTime() - startTime));
// field invoke
startTime = System.nanoTime();
FieldAccess fieldAccess = FieldAccess.get(Person.class);
for (int i = 0; i < count; i++) {
name = (String) fieldAccess.get(person, "name");
}
System.out.println("total = " + (System.nanoTime() - startTime));
// method invoke - 1
startTime = System.nanoTime();
Method method = person.getClass().getDeclaredMethod("getName");
for (int i = 0; i < count; i++) {
name = (String) method.invoke(person);
}
System.out.println("total = " + (System.nanoTime() - startTime));
// method invoke - 2
startTime = System.nanoTime();
MethodAccess access = MethodAccess.get(Person.class);
for (int i = 0; i < count; i++) {
name = (String) access.invoke(person, "getName");
}
System.out.println("total = " + (System.nanoTime() - startTime));
}
示例7: getAttribute
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
private Object getAttribute(Object container, Object index) {
if (container instanceof Map) {
if (index == null) {
warn("attr is null");
return null;
}
// TODO: remove SuppressWarnigns
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) container;
Object value = map.get(index.toString());
return value;
} else if (container instanceof List) {
if (index == null) {
warn("null index for list index");
return null;
} else if (!(index instanceof Integer)) {
warn("array index must be Integer but " + index.getClass());
return null;
}
// TODO: remove SuppressWarnigns
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>) container;
return list.get((Integer) index);
} else if (container == null) {
warn("container is null");
return null;
} else {
FieldAccess access;
Class<? extends Object> klass = container.getClass();
if (fieldAccessCache.containsKey(klass)) {
access = fieldAccessCache.get(klass);
} else {
access = FieldAccess.get(container.getClass());
fieldAccessCache.put(klass, access);
}
if (index instanceof String) {
try {
Object result = access.get(container, (String) index);
return result;
} catch (IllegalArgumentException e) {
warn(e.toString());
return null;
}
} else if (index == null) {
warn("null index for accessor name");
return null;
} else {
warn("Index is not a string: " + index.getClass());
return null;
}
}
}
示例8: ReflectasmObjectExtractor
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
public ReflectasmObjectExtractor(Class<T> clazz, String field) {
fieldAccess = FieldAccess.get(clazz);
fieldIndex = fieldAccess.getIndex(field);
}
示例9: FieldAccessBenchmark
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
public FieldAccessBenchmark () throws Exception {
int count = 1000000;
Object[] dontCompileMeAway = new Object[count];
FieldAccess access = FieldAccess.get(SomeClass.class);
SomeClass someObject = new SomeClass();
int index = access.getIndex("name");
Field field = SomeClass.class.getField("name");
for (int i = 0; i < 100; i++) {
for (int ii = 0; ii < count; ii++) {
access.set(someObject, index, "first");
dontCompileMeAway[ii] = access.get(someObject, index);
}
for (int ii = 0; ii < count; ii++) {
field.set(someObject, "first");
dontCompileMeAway[ii] = field.get(someObject);
}
}
warmup = false;
for (int i = 0; i < 100; i++) {
start();
for (int ii = 0; ii < count; ii++) {
access.set(someObject, index, "first");
dontCompileMeAway[ii] = access.get(someObject, index);
}
end("FieldAccess");
}
for (int i = 0; i < 100; i++) {
start();
for (int ii = 0; ii < count; ii++) {
field.set(someObject, "first");
dontCompileMeAway[ii] = field.get(someObject);
}
end("Reflection");
}
chart("Field Set/Get");
}
示例10: setLocal
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
@Override
protected void setLocal(String property, Object content) {
FieldAccess access = FieldAccess.get(getClass());
access.set(this, property, content);
}
示例11: getLocal
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
@Override
protected <T> T getLocal(String property) {
FieldAccess access = FieldAccess.get(getClass());
return (T) access.get(this, property);
}
示例12: rebuildCachedFields
import com.esotericsoftware.reflectasm.FieldAccess; //导入方法依赖的package包/类
/** Called when the list of cached fields must be rebuilt. This is done any time settings are changed that affect which fields
* will be used. It is called from the constructor for FieldSerializer, but not for subclasses. Subclasses must call this from
* their constructor. */
protected void rebuildCachedFields () {
if (TRACE && generics != null) trace("kryo", "generic type parameters are: " + Arrays.toString(generics));
if (type.isInterface()) {
fields = new CachedField[0]; // No fields to serialize.
return;
}
hasObjectFields = false;
// For generic classes, generate a mapping from type variable names to the concrete types
// This mapping is the same for the whole class.
Generics genScope = buildGenericsScope(type, generics);
genericsScope = genScope;
// Push proper scopes at serializer construction time
if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
// Collect all fields.
List<Field> allFields = new ArrayList();
Class nextClass = type;
while (nextClass != Object.class) {
Field[] declaredFields = nextClass.getDeclaredFields();
if (declaredFields != null) {
for (Field f : declaredFields) {
if (Modifier.isStatic(f.getModifiers())) continue;
allFields.add(f);
}
}
nextClass = nextClass.getSuperclass();
}
ObjectMap context = kryo.getContext();
IntArray useAsm = new IntArray();
// Sort fields by their offsets
if (useMemRegions && !useAsmEnabled && unsafe() != null) {
Field[] allFieldsArray = softFieldsByOffset(allFields);
allFields = Arrays.asList(allFieldsArray);
}
// TODO: useAsm is modified as a side effect, this should be pulled out of buildValidFields
List<Field> validFields = buildValidFields(false, allFields, context, useAsm);
List<Field> validTransientFields = buildValidFields(true, allFields, context, useAsm);
// Use ReflectASM for any public fields.
if (useAsmEnabled && !Util.isAndroid && Modifier.isPublic(type.getModifiers()) && useAsm.indexOf(1) != -1) {
try {
access = FieldAccess.get(type);
} catch (RuntimeException ignored) {
}
}
List<CachedField> cachedFields = new ArrayList(validFields.size());
List<CachedField> cachedTransientFields = new ArrayList(validTransientFields.size());
createCachedFields(useAsm, validFields, cachedFields, 0);
createCachedFields(useAsm, validTransientFields, cachedTransientFields, validFields.size());
Collections.sort(cachedFields, this);
fields = cachedFields.toArray(new CachedField[cachedFields.size()]);
Collections.sort(cachedTransientFields, this);
transientFields = cachedTransientFields.toArray(new CachedField[cachedTransientFields.size()]);
initializeCachedFields();
if (genericsScope != null) kryo.popGenericsScope();
}