本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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++;
}