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


Java Array类代码示例

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


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

示例1: resolveClass

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * Use the given ClassLoader rather than using the system class
 */
@Override
protected Class<?> resolveClass(ObjectStreamClass objectstreamclass)
    throws IOException, ClassNotFoundException {

    String s = objectstreamclass.getName();
    if (s.startsWith("[")) {
        int i;
        for (i = 1; s.charAt(i) == '['; i++);
        Class<?> class1;
        if (s.charAt(i) == 'L') {
            class1 = loader.loadClass(s.substring(i + 1, s.length() - 1));
        } else {
            if (s.length() != i + 1)
                throw new ClassNotFoundException(s);
            class1 = primitiveType(s.charAt(i));
        }
        int ai[] = new int[i];
        for (int j = 0; j < i; j++)
            ai[j] = 0;

        return Array.newInstance(class1, ai).getClass();
    } else {
        return loader.loadClass(s);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:MLetObjectInputStream.java

示例2: getValues

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * Returns a typed array containing a snapshot of all values of the Subject.
 * <p>The method follows the conventions of Collection.toArray by setting the array element
 * after the last value to null (if the capacity permits).
 * <p>The method is thread-safe.
 * @param array the target array to copy values into if it fits
 * @return the given array if the values fit into it or a new array containing all values
 */
@SuppressWarnings("unchecked")
public T[] getValues(T[] array) {
    Object o = value.get();
    if (o == null || NotificationLite.isComplete(o) || NotificationLite.isError(o)) {
        if (array.length != 0) {
            array[0] = null;
        }
        return array;
    }
    T v = NotificationLite.getValue(o);
    if (array.length != 0) {
        array[0] = v;
        if (array.length != 1) {
            array[1] = null;
        }
    } else {
        array = (T[])Array.newInstance(array.getClass().getComponentType(), 1);
        array[0] = v;
    }
    return array;
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:30,代码来源:BehaviorProcessor.java

示例3: prepare

import java.lang.reflect.Array; //导入依赖的package包/类
@Override
public Object prepare(Object value) {

  if (!ObjectUtils.isArray(value)) {
    return value;
  }

  int length = Array.getLength(value);
  Collection<Object> result = new ArrayList<Object>(length);

  for (int i = 0; i < length; i++) {
    result.add(Array.get(value, i));
  }

  return result;
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:17,代码来源:StringQuery.java

示例4: update

import java.lang.reflect.Array; //导入依赖的package包/类
private void update() {
	removeAll();
	valid = model.isMatrix();
	if(valid) {
		Object[] array = (Object[]) model.getValues();
		for(Object line : array) {
			int len = Array.getLength(line);
			for(int i = 0; i < len; i++) {
				Object e = Array.get(line, i);
				Label label = new Label(e.toString()); // TODO array deepToString
				label.setForegroundColor(ColorConstants.black);
				add(label);
			}
		}
	}
	getLayoutManager().layout(this);
	repaint();
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:19,代码来源:MatrixWidget.java

示例5: 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();
    in.beginArray();
    while (in.hasNext()) {
        list.add(this.componentTypeAdapter.read(in));
    }
    in.endArray();
    Object array = Array.newInstance(this.componentType, list.size());
    for (int i = 0; i < list.size(); i++) {
        Array.set(array, i, list.get(i));
    }
    return array;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:ArrayTypeAdapter.java

示例6: isEmpty

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * Determine whether the given object is empty.
 * <p>This method supports the following object types.
 * <ul>
 * <li>{@code Optional}: considered empty if {@link Optional#empty()}</li>
 * <li>{@code Array}: considered empty if its length is zero</li>
 * <li>{@link CharSequence}: considered empty if its length is zero</li>
 * <li>{@link Collection}: delegates to {@link Collection#isEmpty()}</li>
 * <li>{@link Map}: delegates to {@link Map#isEmpty()}</li>
 * </ul>
 * <p>If the given object is non-null and not one of the aforementioned
 * supported types, this method returns {@code false}.
 * @param obj the object to check
 * @return {@code true} if the object is {@code null} or <em>empty</em>
 * @since 4.2
 * @see Optional#isPresent()
 * @see ObjectUtils#isEmpty(Object[])
 * @see StringUtils#hasLength(CharSequence)
 * @see StringUtils#isEmpty(Object)
 * @see CollectionUtils#isEmpty(java.util.Collection)
 * @see CollectionUtils#isEmpty(java.util.Map)
 */
@SuppressWarnings("rawtypes")
public static boolean isEmpty( Object obj) {
	if (obj == null) {
		return true;
	}

	if (obj instanceof Optional) {
		return !((Optional) obj).isPresent();
	}
	if (obj.getClass().isArray()) {
		return Array.getLength(obj) == 0;
	}
	if (obj instanceof CharSequence) {
		return ((CharSequence) obj).length() == 0;
	}
	if (obj instanceof Collection) {
		return ((Collection) obj).isEmpty();
	}
	if (obj instanceof Map) {
		return ((Map) obj).isEmpty();
	}

	// else
	return false;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:48,代码来源:ObjectUtils.java

示例7: convert

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * Convert an array of specified values to an array of objects of the
 * specified class (if possible).  If the specified Java class is itself
 * an array class, this class will be the type of the returned value.
 * Otherwise, an array will be constructed whose component type is the
 * specified class.
 *
 * @param values Array of values to be converted
 * @param clazz Java array or element class to be converted to (must not be null)
 * @return The converted value
 *
 * @throws ConversionException if thrown by an underlying Converter
 */
public Object convert(final String[] values, final Class<?> clazz) {

    Class<?> type = clazz;
    if (clazz.isArray()) {
        type = clazz.getComponentType();
    }
    if (log.isDebugEnabled()) {
        log.debug("Convert String[" + values.length + "] to class '" +
                  type.getName() + "[]'");
    }
    Converter converter = lookup(type);
    if (converter == null) {
        converter = lookup(String.class);
    }
    if (log.isTraceEnabled()) {
        log.trace("  Using converter " + converter);
    }
    final Object array = Array.newInstance(type, values.length);
    for (int i = 0; i < values.length; i++) {
        Array.set(array, i, converter.convert(type, values[i]));
    }
    return (array);

}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:38,代码来源:ConvertUtilsBean.java

示例8: hash

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * <code>aObject</code> is a possibly-null object field, and possibly an
 * array.
 * 
 * If <code>aObject</code> is an array, then each element may be a
 * primitive or a possibly-null object.
 */
public static int hash(int aSeed, Object aObject) {
	int result = aSeed;
	if (aObject == null) {
		result = hash(result, 0);
	} else if (!isArray(aObject)) {
		result = hash(result, aObject.hashCode());
	} else {
		int length = Array.getLength(aObject);
		for (int idx = 0; idx < length; ++idx) {
			Object item = Array.get(aObject, idx);
			//recursive call!
			result = hash(result, item);
		}
	}
	return result;
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:24,代码来源:HashCodeUtil.java

示例9: toNonNullOpenValue

import java.lang.reflect.Array; //导入依赖的package包/类
final Object toNonNullOpenValue(Object value) throws OpenDataException {
  final Collection valueCollection = (Collection) value;
  if (valueCollection instanceof SortedSet) {
    Comparator comparator = ((SortedSet) valueCollection).comparator();
    if (comparator != null) {
      final String msg = "Cannot convert SortedSet with non-null comparator: " + comparator;
      throw openDataException(msg, new IllegalArgumentException(msg));
    }
  }
  final Object[] openArray =
      (Object[]) Array.newInstance(getOpenClass().getComponentType(), valueCollection.size());
  int i = 0;
  for (Object o : valueCollection)
    openArray[i++] = elementConverter.toOpenValue(o);
  return openArray;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:CollectionConverter.java

示例10: checkValue

import java.lang.reflect.Array; //导入依赖的package包/类
private static void checkValue(Object o1, Object o2) throws Exception {
    assertEquals(o1.getClass().isAnnotation(), o2.getClass().isAnnotation());
    if (o1.getClass().isAnnotation()) {
        assertEquals(((Annotation) o1).annotationType(), ((Annotation) o2).annotationType());
    } else {
        assertEquals(o1.getClass(), o2.getClass());
    }

    if (o1.getClass().isArray()) {
        assertEquals(Array.getLength(o1), Array.getLength(o2));

        for (int c = 0; c < Array.getLength(o1); c++) {
            checkValue(Array.get(o1, c), Array.get(o2, c));
        }
    } else if (o1.getClass().isAnnotation()) {
        checkAnnotation((Annotation) o1, (Annotation) o2);
    } else {
        assertEquals(o1, o2);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:FSWrapperTest.java

示例11: isEmpty

import java.lang.reflect.Array; //导入依赖的package包/类
/**
 * 检查指定的集合/数组/枚举为空
 * <p>
 * 此方法可以处理如下对象:
 * <ul>
 * <li>Collection
 * <li>Map
 * <li>Array
 * <li>Enumeration
 * </ul>
 * <p>
 *
 * @param object
 * @return true
 * @throws IllegalArgumentException
 * @since 1.0
 */
public static boolean isEmpty(final Object object) {
	if (object == null) {
		return true;
	} else if (object instanceof Collection<?>) {
		return ((Collection<?>) object).isEmpty();
	} else if (object instanceof Map<?, ?>) {
		return ((Map<?, ?>) object).isEmpty();
	} else if (object instanceof Object[]) {
		return ((Object[]) object).length == 0;
	} else if (object instanceof Iterator<?>) {
		return ((Iterator<?>) object).hasNext() == false;
	} else if (object instanceof Enumeration<?>) {
		return ((Enumeration<?>) object).hasMoreElements() == false;
	} else {
		try {
			return Array.getLength(object) == 0;
		} catch (final IllegalArgumentException ex) {
			throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
		}
	}
}
 
开发者ID:smxc,项目名称:garlicts,代码行数:39,代码来源:CollectionUtil.java

示例12: 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

示例13: rangeCheck

import java.lang.reflect.Array; //导入依赖的package包/类
@SuppressWarnings("unused")
private static final boolean rangeCheck(final Object array, final Object index) {
    if(!(index instanceof Number)) {
        return false;
    }
    final Number n = (Number)index;
    final int intIndex = n.intValue();
    final double doubleValue = n.doubleValue();
    if(intIndex != doubleValue && !Double.isInfinite(doubleValue)) { // let infinite trigger IOOBE
        return false;
    }
    if(0 <= intIndex && intIndex < Array.getLength(array)) {
        return true;
    }
    throw new ArrayIndexOutOfBoundsException("Array index out of range: " + n);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:BeanLinker.java

示例14: copyOfRange

import java.lang.reflect.Array; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T[] copyOfRange(T[] original, int start, int end) {
    final int originalLength = original.length; // For exception priority compatibility.
    if (start > end) {
        throw new IllegalArgumentException();
    }
    if (start < 0 || start > originalLength) {
        throw new ArrayIndexOutOfBoundsException();
    }
    final int resultLength = end - start;
    final int copyLength = Math.min(resultLength, originalLength - start);
    final T[] result = (T[]) Array
            .newInstance(original.getClass().getComponentType(), resultLength);
    System.arraycopy(original, start, result, 0, copyLength);
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:DiskLruCache.java

示例15: addToData

import java.lang.reflect.Array; //导入依赖的package包/类
private void addToData(int index, T item) {
    if (index > mSize) {
        throw new IndexOutOfBoundsException(
                "cannot add item to " + index + " because size is " + mSize);
    }
    if (mSize == mData.length) {
        // we are at the limit enlarge
        T[] newData = (T[]) Array.newInstance(mTClass, mData.length + CAPACITY_GROWTH);
        System.arraycopy(mData, 0, newData, 0, index);
        newData[index] = item;
        System.arraycopy(mData, index, newData, index + 1, mSize - index);
        mData = newData;
    } else {
        // just shift, we fit
        System.arraycopy(mData, index, mData, index + 1, mSize - index);
        mData[index] = item;
    }
    mSize++;
}
 
开发者ID:alibaba,项目名称:vlayout,代码行数:20,代码来源:SortedList.java


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