本文整理汇总了Java中java.lang.reflect.Array.set方法的典型用法代码示例。如果您正苦于以下问题:Java Array.set方法的具体用法?Java Array.set怎么用?Java Array.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Array
的用法示例。
在下文中一共展示了Array.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import java.lang.reflect.Array; //导入方法依赖的package包/类
public Object read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
List<E> list = new ArrayList<E>();
in.beginArray();
while (in.hasNext()) {
E instance = componentTypeAdapter.read(in);
list.add(instance);
}
in.endArray();
Object array = Array.newInstance(componentType, list.size());
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
return array;
}
示例2: convertArgs
import java.lang.reflect.Array; //导入方法依赖的package包/类
private static Object[] convertArgs (Member function, Class<?>[] formals, Object[] actuals) {
Object[] results = actuals;
if (isVarArgs(function)) {
results = new Object[formals.length];
int idx = 0;
for (; idx < formals.length - 1; idx++) {
// simply copy the basic parameters
results[idx] = actuals[idx];
}
Class<?> type = formals[idx].getComponentType();
Object varArgs = Array.newInstance(type, actuals.length - formals.length + 1);
for (; idx < actuals.length; idx++) {
// fill the varArg array with the remaining parameters
Array.set(varArgs, idx - formals.length + 1, actuals[idx]);
}
results[results.length - 1] = varArgs;
}
return results;
}
示例3: a
import java.lang.reflect.Array; //导入方法依赖的package包/类
public final Object a(com.google.gson.jpush.b.a aVar) {
if (aVar.f() == c.i) {
aVar.j();
return null;
}
List arrayList = new ArrayList();
aVar.a();
while (aVar.e()) {
arrayList.add(this.c.a(aVar));
}
aVar.b();
Object newInstance = Array.newInstance(this.b, arrayList.size());
for (int i = 0; i < arrayList.size(); i++) {
Array.set(newInstance, i, arrayList.get(i));
}
return newInstance;
}
示例4: read
import java.lang.reflect.Array; //导入方法依赖的package包/类
@Override
public void read(JsonReader in, GsonProperty property, Object t) throws IOException {
final Class<?> simpleType = property.getType();
List list = new ArrayList();
in.beginArray();
if (simpleType.isPrimitive() || isBoxedClass(simpleType)) {
while (in.hasNext()){
list.add(SupportUtils.readPrimitiveOrItsBox(in, property));
}
}else{
TypeAdapter adapter = getTypeAdapter(simpleType);
while (in.hasNext()){
list.add(adapter.read(in));
}
}
//copy to array
Object array = Array.newInstance(simpleType, list.size());
for(int i = 0, size = list.size() ; i < size ; i ++){
Array.set(array, i, list.get(i));
}
setValue(property, t, array);
in.endArray();
}
示例5: isValidParameter
import java.lang.reflect.Array; //导入方法依赖的package包/类
static boolean isValidParameter(Method m, Object value, int paramNo) {
Class<?> c = m.getParameterTypes()[paramNo];
try {
// Following is expensive but we only call this method to determine
// if an exception is due to an incompatible parameter type.
// Plain old c.isInstance doesn't work for primitive types.
Object a = Array.newInstance(c, 1);
Array.set(a, 0, value);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
示例6: setValue
import java.lang.reflect.Array; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void setValue(Object object, Object value) {
if (map != null) {
map.put(key, value);
return;
}
if (collection != null) {
collection.add(value);
return;
}
list.set(index, value);
if (list instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) list;
Object array = jsonArray.getRelatedArray();
if (array != null) {
int arrayLength = Array.getLength(array);
if (arrayLength > index) {
Object item;
if (jsonArray.getComponentType() != null) {
item = TypeUtils.cast(value, jsonArray.getComponentType(), parser.getConfig());
} else {
item = value;
}
Array.set(array, index, item);
}
}
}
}
示例7: setTextCursorDrawable
import java.lang.reflect.Array; //导入方法依赖的package包/类
private void setTextCursorDrawable() {
try {
Method method = TextView.class.getDeclaredMethod("createEditorIfNeeded");
method.setAccessible(true);
method.invoke(this);
Field field1 = TextView.class.getDeclaredField("mEditor");
Field field2 = Class.forName("android.widget.Editor").getDeclaredField("mCursorDrawable");
field1.setAccessible(true);
field2.setAccessible(true);
Object arr = field2.get(field1.get(this));
Array.set(arr, 0, new LineSpaceCursorDrawable(getCursorColor(), getCursorWidth(), getCursorHeight()));
Array.set(arr, 1, new LineSpaceCursorDrawable(getCursorColor(), getCursorWidth(), getCursorHeight()));
} catch (Exception ignored) {
}
}
示例8: newValue
import java.lang.reflect.Array; //导入方法依赖的package包/类
private Object newValue(Class<?> type, String name) {
try {
if (type.isArray()) {
Class<?> componentType = type.getComponentType();
// TODO - only handles 2-dimensional arrays
if (componentType.isArray()) {
Object array = Array.newInstance(componentType, 1);
Array.set(array, 0, Array.newInstance(componentType.getComponentType(), 0));
return array;
}
else {
return Array.newInstance(componentType, 0);
}
}
else if (Collection.class.isAssignableFrom(type)) {
return CollectionFactory.createCollection(type, 16);
}
else if (Map.class.isAssignableFrom(type)) {
return CollectionFactory.createMap(type, 16);
}
else {
return type.newInstance();
}
}
catch (Exception ex) {
// TODO Root cause exception context is lost here... should we throw another exception type that preserves context instead?
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,
"Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path: " + ex);
}
}
示例9: combineArray
import java.lang.reflect.Array; //导入方法依赖的package包/类
private static Object combineArray(Object firstArray, Object secondArray) {
Class<?> localClass = firstArray.getClass().getComponentType();
int firstArrayLength = Array.getLength(firstArray);
int allLength = firstArrayLength + Array.getLength(secondArray);
Object result = Array.newInstance(localClass, allLength);
for (int k = 0; k < allLength; ++k) {
if (k < firstArrayLength) {
Array.set(result, k, Array.get(firstArray, k));
} else {
Array.set(result, k, Array.get(secondArray, k - firstArrayLength));
}
}
return result;
}
示例10: getProperty
import java.lang.reflect.Array; //导入方法依赖的package包/类
protected synchronized Object getProperty(String property, Class<?> clazz)
{
Object o;
try
{
o = getPropertySpi(property, clazz);
if (o == null)
{
o = zero(clazz);
}
else if (clazz.isArray() && (o instanceof String[]) && !clazz.equals(String[].class))
{
String[] str = (String[]) o;
o = Array.newInstance(clazz.getComponentType(), str.length);
for (int i = 0; i < str.length; i++)
{
Array.set(o, i, parse(str[i], clazz.getComponentType()));
}
}
else if ((o instanceof String) && !clazz.equals(String.class))
{
o = parse((String) o, clazz);
}
}
catch (Exception x)
{
o = zero(clazz);
}
return o;
}
示例11: doCopyArray
import java.lang.reflect.Array; //导入方法依赖的package包/类
private Object doCopyArray(Object array,Class baseInterface) throws Exception {
Class elementClass = array.getClass().getComponentType();
int length = Array.getLength(array);
Object newArray = Array.newInstance(elementClass,length);
for (int i=0;i<length;i++) {
Object element = doCopy(Array.get(array,i),baseInterface);
Array.set(newArray,i,element);
}
return newArray;
}
示例12: rehydrateInstance
import java.lang.reflect.Array; //导入方法依赖的package包/类
@Override
public Object rehydrateInstance(Instance ii) {
ObjectArrayInstance oai = (ObjectArrayInstance) ii;
int len = oai.getLength();
Object a = Array.newInstance(ctype, len);
rehydrationCache.put(ii.getInstanceId(), a);
List<Instance> values = oai.getValues();
for(int i = 0; i != len; ++i) {
Array.set(a, i, rehydrate(values.get(i)));
}
return a;
}
示例13: setArray
import java.lang.reflect.Array; //导入方法依赖的package包/类
private static void setArray(Object array, String arrayType, int index, Object value) throws ValueParseException {
if ("int".equals(arrayType)) {
Array.setInt(array, index, (Integer) parse(value, arrayType));
} else if ("boolean".equals(arrayType)) {
Array.setBoolean(array, index, (Boolean) parse(value, arrayType));
} else if ("long".equals(arrayType)) {
Array.setLong(array, index, (Long) parse(value, arrayType));
} else if ("double".equals(arrayType)) {
Array.setDouble(array, index, (Double) parse(value, arrayType));
} else if ("float".equals(arrayType)) {
Array.setFloat(array, index, (Float) parse(value, arrayType));
} else {
Array.set(array, index, parse(value, arrayType));
}
}
示例14: setValue
import java.lang.reflect.Array; //导入方法依赖的package包/类
@Override
public void setValue(Object obj, Object value, Map<String, Object> args, InstanceFactory instanceFactory) {
Object array = obj;
if (INTERNAL_NODE != null) {
array = INTERNAL_NODE.getValue(obj, args);
if (array == null) {
Class<?> nodeClass = INTERNAL_NODE.getNodeClass(obj, args);
array = instanceFactory.getInstance(nodeClass, args);
INTERNAL_NODE.setValue(obj, array, args);
}
}
if (array != null) {
Array.set(array, INDEX, value);
}
}
示例15: endRead
import java.lang.reflect.Array; //导入方法依赖的package包/类
public boolean endRead() {
setInitialized();
array = Array.newInstance( elementClass, tempList.size() );
for ( int i=0; i<tempList.size(); i++) {
Array.set(array, i, tempList.get(i) );
}
tempList=null;
return true;
}