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


Java Array.set方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:ArrayTypeAdapter.java

示例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;
}
 
開發者ID:tomrom95,項目名稱:GameAuthoringEnvironment,代碼行數:20,代碼來源:Reflection.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:a.java

示例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();
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:25,代碼來源:TypeHandler.java

示例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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:MBeanIntrospector.java

示例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);
            }
        }
    }
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:34,代碼來源:ResolveFieldDeserializer.java

示例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) {
    }
}
 
開發者ID:hanks-zyh,項目名稱:LineHeightEditText,代碼行數:16,代碼來源:LineHeightEditText.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:BeanWrapperImpl.java

示例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;
}
 
開發者ID:didi,項目名稱:VirtualAPK,代碼行數:15,代碼來源:DexUtil.java

示例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;
}
 
開發者ID:JetBrains,項目名稱:intellij-deps-ini4j,代碼行數:34,代碼來源:AbstractBeanInvocationHandler.java

示例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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:11,代碼來源:CopyFromHelper.java

示例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;
}
 
開發者ID:aragozin,項目名稱:heapunit,代碼行數:13,代碼來源:SimpleHeapImage.java

示例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));
    }
}
 
開發者ID:TangXiaoLv,項目名稱:Android-Router,代碼行數:16,代碼來源:ValueParser.java

示例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);
	}
}
 
開發者ID:InfinityRefactoring,項目名稱:8R-Reflections,代碼行數:16,代碼來源:ArrayNode.java

示例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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:10,代碼來源:ArrayHolder.java


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