List of usage examples for java.lang.reflect Array get
public static native Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java
public static boolean[] convertToBooleanArray(final Object array) { if (array == null) { return null; }//from w ww. j a v a 2 s . c om if (array instanceof boolean[]) { return (boolean[]) array; } if (array instanceof Boolean[]) { return ArrayUtils.toPrimitive((Boolean[]) array); } final boolean[] newArray = new boolean[Array.getLength(array)]; for (int i = 0; i < newArray.length; i++) { final Object obj = Array.get(array, i); if (obj instanceof Boolean) { newArray[i] = (Boolean) Array.get(array, i); } else { newArray[i] = ((Number) Array.get(array, i)).byteValue() != 0; } } return newArray; }
From source file:org.jolokia.converter.json.ArrayExtractor.java
private List<Object> extractArray(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPath, boolean jsonify, int pLength) throws AttributeNotFoundException { List<Object> ret = new JSONArray(); for (int i = 0; i < pLength; i++) { Stack<String> path = (Stack<String>) pPath.clone(); try {//from w w w . ja va 2 s .c om Object obj = Array.get(pValue, i); ret.add(pConverter.extractObject(obj, path, jsonify)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Filtered ... } } if (ret.isEmpty() && pLength > 0) { throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
From source file:com.app.inventario.logica.ProveedorLogicaImpl.java
@Transactional(readOnly = true) public List<Proveedor> obtenerNombresProveedores() throws HibernateException { try {/*from w w w .j av a2 s .c o m*/ List lista = proveedorDAO.obtenerNombresProveedores(); List<Proveedor> proveedores = new ArrayList<Proveedor>(); Proveedor p; for (Object o : lista.toArray()) { p = new Proveedor(); p.setId(Integer.parseInt(Array.get(o, 0).toString())); p.setNombreProveedor(Array.get(o, 1).toString()); proveedores.add(p); } return proveedores; } catch (HibernateException he) { Logger.getLogger(ProveedorLogicaImpl.class.getName()).log(Level.SEVERE, null, he); throw he; } }
From source file:com.dsj.core.beans.ObjectUtils.java
/** * Convert a primitive array to an object array of primitive wrapper * objects.// w w w .jav a2 s. c o m * * @param primitiveArray * the primitive array * @return the object array * @throws IllegalArgumentException * if the parameter is not a primitive array */ public static Object[] toObjectArray(Object primitiveArray) { if (primitiveArray == null) { return new Object[0]; } Class clazz = primitiveArray.getClass(); if (!clazz.isArray() || !clazz.getComponentType().isPrimitive()) { throw new IllegalArgumentException("The specified parameter is not a primitive array"); } int length = Array.getLength(primitiveArray); if (length == 0) { return new Object[0]; } Class wrapperType = Array.get(primitiveArray, 0).getClass(); Object[] newArray = (Object[]) Array.newInstance(wrapperType, length); for (int i = 0; i < length; i++) { newArray[i] = Array.get(primitiveArray, i); } return newArray; }
From source file:org.apache.axis.utils.BeanPropertyDescriptor.java
/** * Get an indexed property/*from w ww.java 2s.co m*/ * @param obj is the object * @param i the index * @return the object at the indicated index */ public Object get(Object obj, int i) throws InvocationTargetException, IllegalAccessException { if (!isIndexed()) { return Array.get(get(obj), i); } else { IndexedPropertyDescriptor id = (IndexedPropertyDescriptor) myPD; return id.getIndexedReadMethod().invoke(obj, new Object[] { new Integer(i) }); } }
From source file:gda.data.DetectorDataWrapper.java
Object[] calcElements() { Object[] elements = new Object[] { detectorDataVal }; // if( isCounterTimer){ if (detectorDataVal instanceof Object[]) { elements = (Object[]) detectorDataVal; } else if (detectorDataVal instanceof PySequence) { PySequence seq = (PySequence) detectorDataVal; int len = seq.__len__(); elements = new Object[len]; for (int i = 0; i < len; i++) { elements[i] = seq.__finditem__(i); }/*w ww . ja va2 s . co m*/ } else if (detectorDataVal instanceof PyList) { PyList seq = (PyList) detectorDataVal; int len = seq.__len__(); elements = new Object[len]; for (int i = 0; i < len; i++) { elements[i] = seq.__finditem__(i); } } else if (detectorDataVal.getClass().isArray()) { int len = ArrayUtils.getLength(detectorDataVal); elements = new Object[len]; for (int i = 0; i < len; i++) { elements[i] = Array.get(detectorDataVal, i); } } // } return elements; }
From source file:com.example.app.profile.ui.membership.MembershipTypeOperationsEditorUI.java
@Override public void init() { super.init(); MessageContainer messages = new MessageContainer(35_000L); final SearchSupplierImpl searchSupplier = getSearchSupplier(); SearchUIImpl.Options options = new SearchUIImpl.Options("Membership Operation Selector"); options.setSearchOnPageLoad(true);// w w w.ja v a2 s. com options.setSearchActions(Collections.emptyList()); options.addSearchSupplier(searchSupplier); options.setHistory(new HistoryImpl()); options.setRowExtractor(input -> { if (input.getClass().isArray()) return Array.get(input, 0); else return input; }); _searchUI = new SearchUIImpl(options); Label heading = new Label(MEMBERSHIPTYPE_UI_HEADING_FORMAT(MEMBERSHIP_TYPE(), _membershipType.getName())); heading.setHTMLElement(HTMLElement.h3); add(of("search-wrapper membership-operation-search", heading, messages, _searchUI)); }
From source file:org.drools.core.xml.jaxb.util.JaxbUnknownAdapter.java
private Object recursiveMarshal(Object o, Map<Object, Object> seenObjectsMap) { if (o == null) { return o; }//from w w w. j a v a2 s. c om if (seenObjectsMap.put(o, PRESENT) != null) { throw new UnsupportedOperationException("Serialization of recursive data structures is not supported!"); } try { if (o instanceof List) { List list = (List) o; Object[] serializedArr = convertCollectionToSerializedArray(list, seenObjectsMap); return new JaxbListWrapper(serializedArr, JaxbWrapperType.LIST); } else if (o instanceof Set) { Set set = (Set) o; Object[] serializedArr = convertCollectionToSerializedArray(set, seenObjectsMap); return new JaxbListWrapper(serializedArr, JaxbWrapperType.SET); } else if (o instanceof Map) { Map<Object, Object> map = (Map<Object, Object>) o; List<JaxbStringObjectPair> pairList = new ArrayList<JaxbStringObjectPair>(map.size()); if (map == null || map.isEmpty()) { pairList = Collections.EMPTY_LIST; } for (Entry<Object, Object> entry : map.entrySet()) { Object key = entry.getKey(); if (key != null && !(key instanceof String)) { throw new UnsupportedOperationException( "Only String keys for Map structures are supported [key was a " + key.getClass().getName() + "]"); } // There's already a @XmlJavaTypeAdapter(JaxbUnknownAdapter.class) anno on the JaxbStringObjectPair.value field pairList.add(new JaxbStringObjectPair((String) key, entry.getValue())); } return new JaxbListWrapper(pairList.toArray(new JaxbStringObjectPair[pairList.size()]), JaxbWrapperType.MAP); } else if (o.getClass().isArray()) { // convert to serializable types int length = Array.getLength(o); Object[] serializedArr = new Object[length]; for (int i = 0; i < length; ++i) { Object elem = convertObjectToSerializableVariant(Array.get(o, i), seenObjectsMap); serializedArr[i] = elem; } // convert to JaxbListWrapper JaxbListWrapper wrapper = new JaxbListWrapper(serializedArr, JaxbWrapperType.ARRAY); Class componentType = o.getClass().getComponentType(); String componentTypeName = o.getClass().getComponentType().getCanonicalName(); if (componentTypeName == null) { throw new UnsupportedOperationException( "Local or anonymous classes are not supported for serialization: " + componentType.getName()); } wrapper.setComponentType(componentTypeName); return wrapper; } else { return o; } } finally { seenObjectsMap.remove(o); } }
From source file:de.grobmeier.jjson.convert.JSONAnnotationEncoder.java
private void encodeArray(Object result, StringBuilder builder) throws JSONException { builder.append(ARRAY_LEFT);//from www . j a v a 2 s . co m int length = Array.getLength(result); for (int i = 0; i < length; i++) { if (i > 0) { builder.append(COMMA); } encode(Array.get(result, i), builder, null); } builder.append(ARRAY_RIGHT); }
From source file:es.caib.zkib.jxpath.util.ValueUtils.java
/** * Returns an iterator for the supplied collection. If the argument * is null, returns an empty iterator. If the argument is not * a collection, returns an iterator that produces just that one object. * @param collection to iterate//w w w. j a v a2s . co m * @return Iterator */ public static Iterator iterate(Object collection) { if (collection == null) { return Collections.EMPTY_LIST.iterator(); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); if (length == 0) { return Collections.EMPTY_LIST.iterator(); } ArrayList list = new ArrayList(); for (int i = 0; i < length; i++) { list.add(Array.get(collection, i)); } return list.iterator(); } if (collection instanceof Collection) { return ((Collection) collection).iterator(); } return Collections.singletonList(collection).iterator(); }