当前位置: 首页>>代码示例>>Java>>正文


Java Array.getLength方法代码示例

本文整理汇总了Java中java.lang.reflect.Array.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java Array.getLength方法的具体用法?Java Array.getLength怎么用?Java Array.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Array的用法示例。


在下文中一共展示了Array.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toString

import java.lang.reflect.Array; //导入方法依赖的package包/类
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:XMBeanNotifications.java

示例2: toObjectArray

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * Convert the given array (which may be a primitive array) to an
 * object array (if necessary of primitive wrapper objects).
 * <p>A {@code null} source value will be converted to an
 * empty Object array.
 * @param source the (potentially primitive) array
 * @return the corresponding object array (never {@code null})
 * @throws IllegalArgumentException if the parameter is not an array
 */
public static Object[] toObjectArray(Object source) {
	if (source instanceof Object[]) {
		return (Object[]) source;
	}
	if (source == null) {
		return new Object[0];
	}
	if (!source.getClass().isArray()) {
		throw new IllegalArgumentException("Source is not an array: " + source);
	}
	int length = Array.getLength(source);
	if (length == 0) {
		return new Object[0];
	}
	Class<?> wrapperType = Array.get(source, 0).getClass();
	Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);
	for (int i = 0; i < length; i++) {
		newArray[i] = Array.get(source, i);
	}
	return newArray;
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:31,代码来源:ObjectUtils.java

示例3: print

import java.lang.reflect.Array; //导入方法依赖的package包/类
private static void print(FeatureDescriptor descriptor) {
    String name = descriptor.getName();
    String display = descriptor.getDisplayName();
    String description = descriptor.getShortDescription();
    System.out.println("name: " + name);
    if (!Objects.equals(name, display)) {
        System.out.println("display name: " + display);
    }
    if (!Objects.equals(display, description)) {
        System.out.println("description: " + description.trim());
    }
    print("expert", descriptor.isExpert());
    print("hidden", descriptor.isHidden());
    print("preferred", descriptor.isPreferred());
    TreeMap<String,Object> map = new TreeMap<>();
    Enumeration<String> enumeration = descriptor.attributeNames();
    while (enumeration.hasMoreElements()) {
        String id = enumeration.nextElement();
        Object value = descriptor.getValue(id);
        if (value.getClass().isArray()) {
            TreeSet<String> set = new TreeSet<>();
            int index = 0;
            int length = Array.getLength(value);
            while (index < length) {
                set.add(Array.get(value, index++) + ", " +
                        Array.get(value, index++) + ", " +
                        Array.get(value, index++));
            }
            value = set.toString();
        }
        map.put(id, value);
    }
    for (Entry<String,Object> entry : map.entrySet()) {
        System.out.println(entry.getKey() + ": " + entry.getValue());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:Test4058433.java

示例4: bindArray

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * 配列の値をIN句として加工してバインドする
 *
 * @param transformContext transformコンテキスト
 * @param values バインドする値の配列
 */
private void bindArray(final TransformContext transformContext, final Object values) {
	int length = Array.getLength(values);
	if (length == 0) {
		throw new ParameterNotFoundRuntimeException("Parameter is not set. [" + expression + "]");
	}

	transformContext.addSqlPart("(?");
	transformContext.addBindVariable(Array.get(values, 0));
	for (int i = 1; i < length; i++) {
		transformContext.addSqlPart(", ?");
		transformContext.addBindVariable(Array.get(values, i));
	}
	transformContext.addSqlPart(")/*").addSqlPart(expression).addSqlPart("*/");
	transformContext.addBindName(expression);
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:22,代码来源:ParenBindVariableNode.java

示例5: disassemble

import java.lang.reflect.Array; //导入方法依赖的package包/类
@Override
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
	final int length = Array.getLength( array );
	final Serializable[] result = new Serializable[length];
	for ( int i=0; i<length; i++ ) {
		result[i] = persister.getElementType().disassemble( Array.get( array,i ), getSession(), null );
	}

	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:PersistentArrayHolder.java

示例6: getArrayItem

import java.lang.reflect.Array; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
protected Object getArrayItem(final Object currentObject, int index) {
    if (currentObject == null) {
        return null;
    }

    if (currentObject instanceof List) {
        List list = (List) currentObject;

        if (index >= 0) {
            if (index < list.size()) {
                return list.get(index);
            }
            return null;
        } else {
            if (Math.abs(index) <= list.size()) {
                return list.get(list.size() + index);
            }
            return null;
        }
    }

    if (currentObject.getClass().isArray()) {
        int arrayLenth = Array.getLength(currentObject);

        if (index >= 0) {
            if (index < arrayLenth) {
                return Array.get(currentObject, index);
            }
            return null;
        } else {
            if (Math.abs(index) <= arrayLenth) {
                return Array.get(currentObject, arrayLenth + index);
            }
            return null;
        }
    }

    throw new UnsupportedOperationException();
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:41,代码来源:JSONPath.java

示例7: create

import java.lang.reflect.Array; //导入方法依赖的package包/类
public static MethodCall create(String method, Object param) {
    MethodCall methodCall = new MethodCall();
    methodCall.methodName = method;

    if (param.getClass() == byte[].class) {
        methodCall.params = Collections.singletonList(Param.from(param));
    } else if (param.getClass().isArray()) {
        // Treat param as array of individual parameters
        int length = Array.getLength(param);
        methodCall.params = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            methodCall.params.add(Param.from(Array.get(param, i)));
        }
    } else if (param instanceof Iterable) {
        // Treat param as collection of individual parameters
        Iterator iter = ((Iterable) param).iterator();
        methodCall.params = new ArrayList<>();
        while (iter.hasNext()) {
            methodCall.params.add(Param.from(iter.next()));
        }
    } else if (param instanceof Boolean || param instanceof Integer || param instanceof Long || param
            instanceof Double || param instanceof String) {
        methodCall.params = Collections.singletonList(Param.from(param));
    } else {
        // Treat param a an input object of which the fields represent the parameters
        Field[] fields = param.getClass().getDeclaredFields();
        methodCall.params = new ArrayList<>(fields.length);
        for (Field field : fields) {
            if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
                continue;
            }
            try {
                methodCall.params.add(Param.from(field.get(param)));
            } catch (IllegalAccessException e) {
                throw new RuntimeException(field.getName() + " could not be accessed to read XML-RPC param");
            }
        }
    }
    return methodCall;
}
 
开发者ID:erickok,项目名称:retrofit-xmlrpc,代码行数:41,代码来源:MethodCall.java

示例8: echoResult

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * @param name context of result
 * @param result
 */
protected void echoResult(String name, Object result) {
    if (isEcho()) {
        if (result.getClass().isArray()) {
            for (int i = 0; i < Array.getLength(result); i++) {
                handleOutput(name + "." + i + "=" + Array.get(result, i));
            }
        } else
            handleOutput(name + "=" + result);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:JMXAccessorTask.java

示例9: assertEQ

import java.lang.reflect.Array; //导入方法依赖的package包/类
private void assertEQ(T t, Object returned) {
    if (rtype.isArray()) {
        Asserts.assertEQ(t.getClass(), returned.getClass());
        int n = Array.getLength(t);
        Asserts.assertEQ(n, Array.getLength(returned));
        for (int i = 0; i < n; ++i) {
            Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
        }
    } else {
        Asserts.assertEQ(t, returned);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:CatchExceptionTest.java

示例10: writeObject

import java.lang.reflect.Array; //导入方法依赖的package包/类
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:JMXJsonServlet.java

示例11: arrayToString

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * {@link Arrays#toString(Object[])} with {@link Arrays#toString(Object[])} for array elements.
 */
public static Object arrayToString(final Object obj) {
    if (obj != null && obj.getClass().isArray()) {
        final int len = Array.getLength(obj);
        final String[] strings = new String[len];
        for (int i = 0; i < len; i++) {
            strings[i] = String.valueOf(Array.get(obj, i));
        }
        return Arrays.toString(strings);
    } else {
        return obj;
    }
}
 
开发者ID:allure-framework,项目名称:allure-java,代码行数:16,代码来源:Allure1Utils.java

示例12: elements

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * @see PersistentCollection#entries
 */
public Iterator elements() {
	//if (array==null) return tempList.iterator();
	int length = Array.getLength(array);
	java.util.List list = new ArrayList(length);
	for (int i=0; i<length; i++) {
		list.add( Array.get(array, i) );
	}
	return list.iterator();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:13,代码来源:ArrayHolder.java

示例13: isEmptyObject

import java.lang.reflect.Array; //导入方法依赖的package包/类
private static boolean isEmptyObject(Object object){
	if(object == null){
		return true;
	}else if(object instanceof String){
		return ((String)object).trim().equals("") || ((String)object).trim().equals("null");
	}else if(object instanceof Collection<?>){
		return ((Collection<?>)object).isEmpty();
	}else if(object instanceof Map<?,?>){
		return ((Map<?,?>)object).isEmpty();
	}else if(object.getClass().isArray()){
		return Array.getLength(object) == 0;
	}else{
		return false;
	}
}
 
开发者ID:penggle,项目名称:xproject,代码行数:16,代码来源:ValidationAssert.java

示例14: testOK

import java.lang.reflect.Array; //导入方法依赖的package包/类
public static void testOK(Class<?> expectClass, int expectLen, Callable<Object> test) throws Exception {
    for (int c = 0; c < ITERS; c++) {
        Object res = test.call();
        Class<?> actualClass = res.getClass();
        if (!actualClass.equals(expectClass)) {
            throw new IllegalStateException("Wrong class: expected = " + expectClass + ", but got " + actualClass);
        }
        int actualLen = Array.getLength(res);
        if (actualLen != expectLen) {
            throw new IllegalStateException("Wrong length: expected = " + expectLen + ", but got " + actualLen);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AllocateUninitializedArray.java

示例15: JSONArray

import java.lang.reflect.Array; //导入方法依赖的package包/类
/**
 * Construct a JSONArray from an array
 *
 * @throws JSONException
 *             If not an array.
 */
public JSONArray(Object array) throws JSONException {
    this();
    if (array.getClass().isArray()) {
        int length = Array.getLength(array);
        for (int i = 0; i < length; i += 1) {
            this.put(JSONObject.wrap(Array.get(array, i)));
        }
    } else {
        throw new JSONException(
                "JSONArray initial value should be a string or collection or array.");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:JSONArray.java


注:本文中的java.lang.reflect.Array.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。