List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:org.gluu.site.ldap.persistence.LdapEntryManager.java
public <T> void sortListByProperties(Class<T> entryClass, List<T> entries, boolean caseSensetive, String... sortByProperties) { // Check input parameters if (entries == null) { throw new MappingException("Entries list to sort is null"); }/*from w w w .ja v a 2 s . c o m*/ if (entries.size() == 0) { return; } if ((sortByProperties == null) || (sortByProperties.length == 0)) { throw new InvalidArgumentException( "Invalid list of sortBy properties " + Arrays.toString(sortByProperties)); } // Get getters for all properties Getter[][] propertyGetters = new Getter[sortByProperties.length][]; for (int i = 0; i < sortByProperties.length; i++) { String[] tmpProperties = sortByProperties[i].split("\\."); propertyGetters[i] = new Getter[tmpProperties.length]; Class<?> currentEntryClass = entryClass; for (int j = 0; j < tmpProperties.length; j++) { if (j > 0) { currentEntryClass = propertyGetters[i][j - 1].getReturnType(); } propertyGetters[i][j] = getGetter(currentEntryClass, tmpProperties[j]); } if (propertyGetters[i][tmpProperties.length - 1] == null) { throw new MappingException("Entry should has getteres for all properties " + sortByProperties[i]); } Class<?> propertyType = propertyGetters[i][tmpProperties.length - 1].getReturnType(); if (!((propertyType == String.class) || (propertyType == Date.class) || (propertyType == Integer.class) || (propertyType == Integer.TYPE))) { throw new MappingException("Entry properties should has String, Date or Integer type. Property: '" + tmpProperties[tmpProperties.length - 1] + "'"); } } PropertyComparator<T> comparator = new PropertyComparator<T>(propertyGetters, caseSensetive); Collections.sort(entries, comparator); }
From source file:net.sf.morph.reflect.reflectors.BaseReflector.java
/** * {@link BeanReflector#getType(Object, String)} * @param bean//from ww w. ja v a 2s. co m * @param propertyName * @return * @throws ReflectionException */ public final Class getType(Object bean, String propertyName) throws ReflectionException { if (bean == null && ObjectUtils.isEmpty(propertyName)) { throw new ReflectionException( "Please supply non-null arguments to the " + getClass().getName() + ".getType method"); } if (bean == null) { throw new ReflectionException( "Cannot determine type of property '" + propertyName + "' since no bean was specified"); } if (ObjectUtils.isEmpty(propertyName)) { throw new ReflectionException("Please supply a property name of bean " + ObjectUtils.getObjectDescription(bean) + " for which you would like to know the type"); } checkIsReflectable(bean); boolean hasPropertyDefined = ContainerUtils.contains(getPropertyNames(bean), propertyName); if (isStrictlyTyped() && !hasPropertyDefined && !SizableReflector.IMPLICIT_PROPERTY_SIZE.equals(propertyName) && !BeanReflector.IMPLICIT_PROPERTY_CLASS.equals(propertyName) && !BeanReflector.IMPLICIT_PROPERTY_THIS.equals(propertyName) && !BeanReflector.IMPLICIT_PROPERTY_PROPERTY_NAMES.equals(propertyName)) { throw new ReflectionException("Cannot determine type of property '" + propertyName + "' because it is not a property of " + ObjectUtils.getObjectDescription(bean)); } // take care of implicit properties, if applicable Class type = null; if (!hasPropertyDefined) { if (propertyName.equals(BeanReflector.IMPLICIT_PROPERTY_CLASS)) { type = Class.class; } else if (propertyName.equals(BeanReflector.IMPLICIT_PROPERTY_PROPERTY_NAMES)) { type = String[].class; } else if (propertyName.equals(BeanReflector.IMPLICIT_PROPERTY_THIS)) { type = ClassUtils.getClass(bean); } else if (propertyName.equals(SizableReflector.IMPLICIT_PROPERTY_SIZE)) { type = Integer.TYPE; } } // if we aren't retrieving an implicit property, let the subclass handle // the request if (type == null) { try { type = getTypeImpl(bean, propertyName); } catch (ReflectionException e) { throw e; } catch (Exception e) { if (e instanceof RuntimeException && !isWrappingRuntimeExceptions()) { throw (RuntimeException) e; } throw new ReflectionException("Unable to determine type of property '" + propertyName + "' for bean " + ObjectUtils.getObjectDescription(bean), e); } } if (isPerformingLogging() && log.isTraceEnabled()) { log.trace("Property '" + propertyName + "' has type " + ObjectUtils.getObjectDescription(type) + " in bean " + ObjectUtils.getObjectDescription(bean)); } return type; }
From source file:fr.cls.atoll.motu.processor.wps.StringList.java
public static void testBuildChainWPS() { try {//from ww w . j a va 2 s .c o m ServiceMetadata serviceMetadata = new ServiceMetadata(); URL url = null; Set<SVOperationMetadataType> listOperation = new HashSet<SVOperationMetadataType>(); // url = new // URL("file:///c:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/TestServiceMetadataOK.xml"); url = Organizer.findResource("fmpp/out/serviceMetadata_motu-opendap-mercator.xml"); serviceMetadata.getOperations(url, listOperation); ServiceMetadata.dump(listOperation); // DirectedGraph<OperationMetadata, DefaultEdge> directedGraph = new // DefaultDirectedGraph<OperationMetadata, DefaultEdge>(DefaultEdge.class); DirectedGraph<OperationMetadata, OperationRelationshipEdge<String>> directedGraph = ServiceMetadata .createDirectedGraph(); serviceMetadata.getOperations(url, directedGraph); List<OperationMetadata> sourceOperations = new ArrayList<OperationMetadata>(); List<OperationMetadata> sinkOperations = new ArrayList<OperationMetadata>(); EdgeReversedGraph<OperationMetadata, OperationRelationshipEdge<String>> edgeReversedGraph = new EdgeReversedGraph<OperationMetadata, OperationRelationshipEdge<String>>( directedGraph); sourceOperations.clear(); sinkOperations.clear(); ServiceMetadata.getSourceOperations(edgeReversedGraph, sourceOperations); ServiceMetadata.getSinkOperations(edgeReversedGraph, sinkOperations); System.out.println("%%%%%%%% REVERSE GRAPH %%%%%%%%%%%%"); System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%"); System.out.println(sourceOperations); System.out.println("%%%%%%%% SINK %%%%%%%%%%%%"); System.out.println(sinkOperations); for (OperationMetadata source : sourceOperations) { System.out.print("%%%%%%%% PATHS FROM %%%%%%%%%%%%"); System.out.println(source); KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata .getOperationPaths(edgeReversedGraph, source, 10); for (OperationMetadata sink : sinkOperations) { System.out.print(" %%%%%%%%%%%% TO "); System.out.println(sink); List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata .getOperationPaths(paths, sink); for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) { System.out.println(gp.getEdgeList()); } } } sourceOperations.clear(); sinkOperations.clear(); ServiceMetadata.getSourceOperations(directedGraph, sourceOperations); ServiceMetadata.getSinkOperations(directedGraph, sinkOperations); System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%"); System.out.println(sourceOperations); System.out.println("%%%%%%%% SINK %%%%%%%%%%%%"); System.out.println(sinkOperations); Map<String, Map<String, ParameterValue<?>>> operationsInputValues = new HashMap<String, Map<String, ParameterValue<?>>>(); Map<String, ParameterValue<?>> dataInputValues = null; for (OperationMetadata source : sourceOperations) { System.out.print("%%%%%%%% PATHS FROM %%%%%%%%%%%%"); System.out.println(source); // source.dump(); // dataInputValues = source.createParameterValues(); // operationsInputValues.put(source.getOperationName(), dataInputValues); KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata .getOperationPaths(directedGraph, source, 10); for (OperationMetadata sink : sinkOperations) { System.out.print(" %%%%%%%%%%%% TO "); System.out.println(sink); List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata .getOperationPaths(paths, sink); for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) { System.out.println(gp.getEdgeList()); System.out.println("Sink: " + sink.getOperationName()); for (OperationRelationshipEdge<String> edge : gp.getEdgeList()) { OperationMetadata operationMetadata1 = directedGraph.getEdgeSource(edge); OperationMetadata operationMetadata2 = directedGraph.getEdgeTarget(edge); System.out.println("StartVertex: " + operationMetadata1.getOperationName()); System.out.println("EndVertex: " + operationMetadata2.getOperationName()); System.out.println("Parameters Edge: " + edge.getParamOutStartVertex().toString() + " / " + edge.getParamInStartVertex().toString()); dataInputValues = operationMetadata1.createParameterValues(true, false); operationsInputValues.put(operationMetadata1.getOperationName(), dataInputValues); dataInputValues = operationMetadata2.createParameterValues(true, false); operationsInputValues.put(operationMetadata2.getOperationName(), dataInputValues); } } } } for (Map.Entry<String, Map<String, ParameterValue<?>>> pair : operationsInputValues.entrySet()) { System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$"); System.out.println(pair.getKey()); System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$"); for (Map.Entry<String, ParameterValue<?>> pair2 : pair.getValue().entrySet()) { System.out.println(""); System.out.println(pair2.getKey()); System.out.println(""); ParameterValue<?> parameterValue = pair2.getValue(); System.out.print(parameterValue.getDescriptor().getName()); System.out.print(" "); System.out.println(parameterValue.getDescriptor().getValueClass()); final Class<?> type = parameterValue.getDescriptor().getValueClass(); if (Double.class.equals(type) || Double.TYPE.equals(type)) { parameterValue.setValue(1203.36); } if (Long.class.equals(type) || Long.TYPE.equals(type)) { Long v = 120336954L; parameterValue.setValue(v); } if (Integer.class.equals(type) || Integer.TYPE.equals(type)) { int v = 98564; parameterValue.setValue(v); } if (String.class.equals(type)) { parameterValue.setValue("param value as string"); } if (double[].class.equals(type)) { double[] geobbox = new double[] { -10d, -60d, 45d, 120d }; parameterValue.setValue(geobbox); } } } Set<OperationMetadata> setSubGraph = new HashSet<OperationMetadata>(); Set<OperationMetadata> setGraph = directedGraph.vertexSet(); for (OperationMetadata op : setGraph) { if (op.getInvocationName().equalsIgnoreCase("ExtractData")) { setSubGraph.add(op); } if (op.getInvocationName().equalsIgnoreCase("CompressExtraction")) { setSubGraph.add(op); } } DirectedGraph<OperationMetadata, OperationRelationshipEdge<String>> directedSubGraph = ServiceMetadata .createDirectedSubGraph(directedGraph, setSubGraph, null); System.out.println(directedSubGraph.toString()); sourceOperations.clear(); sinkOperations.clear(); ServiceMetadata.getSourceOperations(directedSubGraph, sourceOperations); ServiceMetadata.getSinkOperations(directedSubGraph, sinkOperations); System.out.println("%%%%%%%% SUB GRAPH %%%%%%%%%%%%"); System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%"); System.out.println(sourceOperations); System.out.println("%%%%%%%% SINK %%%%%%%%%%%%"); System.out.println(sinkOperations); for (OperationMetadata source : sourceOperations) { System.out.print("%%%%%%%% PATHS FROM %%%%%%%%%%%%"); System.out.println(source); KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata .getOperationPaths(directedSubGraph, source, 10); for (OperationMetadata sink : sinkOperations) { System.out.print(" %%%%%%%%%%%% TO "); System.out.println(sink); List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata .getOperationPaths(paths, sink); for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) { System.out.println(gp.getEdgeList()); System.out.println(gp.getEdgeList()); System.out.println("Sink: " + sink.getOperationName()); for (OperationRelationshipEdge<String> edge : gp.getEdgeList()) { OperationMetadata operationMetadata1 = directedSubGraph.getEdgeSource(edge); OperationMetadata operationMetadata2 = directedSubGraph.getEdgeTarget(edge); System.out.println("StartVertex: " + operationMetadata1.getOperationName()); System.out.println("EndVertex: " + operationMetadata2.getOperationName()); System.out.println("Parameters Edge: " + edge.getParamInStartVertex().toString() + " / " + edge.getParamOutStartVertex().toString()); System.out.println("operationMetadata1: " + operationMetadata1.getParameterValueMap()); System.out.println("operationMetadata2: " + operationMetadata2.getParameterValueMap()); } } } } String serverURL = "http://atoll-dev.cls.fr:30080/atoll-motuservlet/services"; WPSFactory wpsFactory = new WPSFactory(); Execute execute = wpsFactory.createExecuteProcessRequest(sourceOperations.get(0), directedSubGraph, false); String wpsXml = "WPSExecuteChain.xml"; FileWriter writer = new FileWriter(wpsXml); WPSInfo wpsInfo = WPSFactory.getWpsInfo(serverURL); String schemaLocationKey = String.format("%s%s", wpsInfo.getProcessDescriptions().getService(), wpsInfo.getProcessDescriptions().getVersion()); WPSFactory.marshallExecute(execute, writer, WPSFactory.getSchemaLocations().get(schemaLocationKey)); System.out.println("===============> Validate WPS"); List<String> errors = WPSFactory.validateWPSExecuteRequest("", "file:///c:/tempVFS/OGC_SCHEMA/", "wps/1.0.0/wpsExecute_request.xsd", wpsXml); if (errors.size() > 0) { StringBuffer stringBuffer = new StringBuffer(); for (String str : errors) { stringBuffer.append(str); stringBuffer.append("\n"); } throw new MotuException(String.format("ERROR - XML file '%s' is not valid - See errors below:\n%s", wpsXml, stringBuffer.toString())); } else { System.out.println(String.format("XML file '%s' is valid", wpsXml)); } System.out.println("===============> Execute WPS"); testBodyPost(wpsXml, serverURL); } catch (MotuException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e.notifyException()); } catch (MotuMarshallException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
boolean areAppNotificationsEnabledOnPlatform() { if (android.os.Build.VERSION.SDK_INT < ANDROID_KITKAT) { return true; }//from www . j a v a 2 s. c om final String appOpsServiceName; try { final Field appOpsServiceNameField = Context.class.getDeclaredField(APP_OPS_SERVICE); appOpsServiceName = (String) appOpsServiceNameField.get(String.class); } catch (final NoSuchFieldException e) { log.error(e.getMessage(), e); return true; } catch (final IllegalAccessException e) { log.error(e.getMessage(), e); return true; } final Object mAppOps = pinpointContext.getApplicationContext().getSystemService(appOpsServiceName); if (mAppOps == null) { return true; } final ApplicationInfo appInfo = pinpointContext.getApplicationContext().getApplicationInfo(); final String pkg = pinpointContext.getApplicationContext().getPackageName(); final int uid = appInfo.uid; try { if (appOpsClass == null || checkOpNoThrowMethod == null || opPostNotificationField == null || modeAllowedField == null) { appOpsClass = Class.forName(mAppOps.getClass().getName()); checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); opPostNotificationField = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); modeAllowedField = appOpsClass.getDeclaredField(APP_OPS_MODE_ALLOWED); } final int postNotificationValue = opPostNotificationField.getInt(null); final int opPostNotificationMode = (Integer) checkOpNoThrowMethod.invoke(mAppOps, postNotificationValue, uid, pkg); final int modeAllowed = modeAllowedField.getInt(null); return (modeAllowed == opPostNotificationMode); } catch (final ClassNotFoundException e) { log.error(e.getMessage(), e); } catch (final NoSuchMethodException e) { log.error(e.getMessage(), e); } catch (final NoSuchFieldException e) { log.error(e.getMessage(), e); } catch (final InvocationTargetException e) { log.error(e.getMessage(), e); } catch (final IllegalAccessException e) { log.error(e.getMessage(), e); } return true; }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Returns true if the given class is of an integer type */// w ww . jav a2s . co m public static boolean isIntegerType(Class pClass) { return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE || pClass == Character.class || pClass == Character.TYPE || pClass == Integer.class || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE; }
From source file:org.apache.oodt.cas.cli.util.CmdLineUtils.java
public static List<?> convertToType(List<String> values, Class<?> type) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException { if (type.equals(File.class)) { List<Object> files = new LinkedList<Object>(); for (String value : values) { files.add(new File(value)); }// w ww . j a v a 2 s . c o m return files; } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { List<Object> booleans = new LinkedList<Object>(); for (String value : values) { booleans.add(value.toLowerCase().trim().equals("true")); } return booleans; } else if (type.equals(URL.class)) { List<Object> urls = new LinkedList<Object>(); for (String value : values) { urls.add(new URL(value)); } return urls; } else if (type.equals(Class.class)) { List<Object> classes = new LinkedList<Object>(); for (String value : values) { classes.add(Class.forName(value)); } return classes; } else if (type.equals(List.class)) { List<Object> lists = new LinkedList<Object>(); lists.add(values); return lists; } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { List<Object> ints = new LinkedList<Object>(); for (String value : values) { ints.add(Integer.valueOf(value)); } return ints; } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { List<Object> longs = new LinkedList<Object>(); for (String value : values) { longs.add(Long.valueOf(value)); } return longs; } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { List<Object> doubles = new LinkedList<Object>(); for (String value : values) { doubles.add(new Double(value)); } return doubles; } else if (type.equals(String.class)) { StringBuilder combinedString = new StringBuilder(""); for (String value : values) { combinedString.append(value).append(" "); } return Lists.newArrayList(combinedString.toString().trim()); } else { List<Object> objects = new LinkedList<Object>(); for (String value : values) { Object object = Class.forName(value).newInstance(); if (!type.isAssignableFrom(object.getClass())) { throw new RuntimeException( object.getClass() + " is not a valid" + " type or sub-type of " + type); } objects.add(object); } return objects; } }
From source file:org.apache.sling.models.impl.ModelAdapterFactory.java
private static boolean isAcceptableType(Class<?> type, Type genericType, Object value) { if (type.isInstance(value)) { if ((type == Collection.class || type == List.class) && genericType instanceof ParameterizedType && value instanceof Collection) { Iterator<?> it = ((Collection<?>) value).iterator(); if (!it.hasNext()) { // empty collection, so it doesn't really matter return true; } else { // this is not an ideal way to get the actual component type, but erasure... Class<?> actualComponentType = it.next().getClass(); Class<?> desiredComponentType = (Class<?>) ((ParameterizedType) genericType) .getActualTypeArguments()[0]; return desiredComponentType.isAssignableFrom(actualComponentType); }// w w w. ja v a 2 s. c o m } else { return true; } } if (type == Integer.TYPE) { return Integer.class.isInstance(value); } if (type == Long.TYPE) { return Long.class.isInstance(value); } if (type == Boolean.TYPE) { return Boolean.class.isInstance(value); } if (type == Double.TYPE) { return Double.class.isInstance(value); } if (type == Float.TYPE) { return Float.class.isInstance(value); } if (type == Short.TYPE) { return Short.class.isInstance(value); } if (type == Byte.TYPE) { return Byte.class.isInstance(value); } if (type == Character.TYPE) { return Character.class.isInstance(value); } return false; }
From source file:alice.tuprolog.lib.OOLibrary.java
private boolean parse_arg(Object[] values, Class<?>[] types, int i, PTerm term) { try {//from w w w. ja v a 2s . c o m if (term == null) { values[i] = null; types[i] = null; } else if (term.isAtom()) { String name = alice.util.Tools.removeApices(term.toString()); switch (name) { case "true": values[i] = Boolean.TRUE; types[i] = Boolean.TYPE; break; case "false": values[i] = Boolean.FALSE; types[i] = Boolean.TYPE; break; default: Object obj = currentObjects.get(name); values[i] = obj == null ? name : obj; types[i] = values[i].getClass(); break; } } else if (term instanceof Number) { Number t = (Number) term; if (t instanceof Int) { values[i] = t.intValue(); types[i] = java.lang.Integer.TYPE; } else if (t instanceof alice.tuprolog.Double) { values[i] = t.doubleValue(); types[i] = java.lang.Double.TYPE; } else if (t instanceof alice.tuprolog.Long) { values[i] = t.longValue(); types[i] = java.lang.Long.TYPE; } else if (t instanceof alice.tuprolog.Float) { values[i] = t.floatValue(); types[i] = java.lang.Float.TYPE; } } else if (term instanceof Struct) { // argument descriptors Struct tc = (Struct) term; if (tc.getName().equals("as")) { return parse_as(values, types, i, tc.getTerm(0), tc.getTerm(1)); } else { Object obj = currentObjects.get(alice.util.Tools.removeApices(tc.toString())); values[i] = obj == null ? alice.util.Tools.removeApices(tc.toString()) : obj; types[i] = values[i].getClass(); } } else if (term instanceof Var && !((Var) term).isBound()) { values[i] = null; types[i] = Object.class; } else { return false; } } catch (Exception ex) { return false; } return true; }
From source file:com.ricemap.spateDB.core.RTree.java
/** * Searches the RTree starting from the given start position. This is either * a node number or offset of an element. If it's a node number, it performs * the search in the subtree rooted at this node. If it's an offset number, * it searches only the object found there. It is assumed that the * openQuery() has been called before this function and that endQuery() will * be called afterwards./* w ww . j av a 2 s . c o m*/ * * @param query_mbr * @param output * @param start * - where to start searching * @param end * - where to end searching. Only used when start is an offset of * an object. * @return * @throws IOException */ protected int searchColumnar(Shape query_shape, ResultCollector<Writable> output, int start, int end, String field) throws IOException { if (output == null) { throw new RuntimeException("Output is NULL"); } //build search field int fieldOffset = 0; int fieldSize = -1; FIELD_TYPE fieldType = FIELD_TYPE.NULL; //get fields Field[] fields = stockObject.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(field)) { if (fields[i].getType().equals(Integer.TYPE)) { fieldSize = 4; fieldType = FIELD_TYPE.Integer; } else if (fields[i].getType().equals(Long.TYPE)) { fieldSize = 8; fieldType = FIELD_TYPE.Long; } else if (fields[i].getType().equals(Double.TYPE)) { fieldSize = 8; fieldType = FIELD_TYPE.Double; } else { //throw new RuntimeException("Unsupported type: " + fields[i].getType()); } break; } else { if (fields[i].getType().equals(Integer.TYPE)) { fieldOffset += elementCount * 4; } else if (fields[i].getType().equals(Long.TYPE) || fields[i].getType().equals(Double.TYPE)) { fieldOffset += elementCount * 8; } else { //throw new RuntimeException("Unsupported type: " + fields[i].getType()); } } } Prism query_mbr = query_shape.getMBR(); int resultSize = 0; // Special case for an empty tree if (height == 0) return 0; Stack<Integer> toBeSearched = new Stack<Integer>(); // Start from the given node toBeSearched.push(start); if (start >= nodeCount) { toBeSearched.push(end); } Prism node_mbr = new Prism(); // Holds one data line from tree data Text line = new Text2(); while (!toBeSearched.isEmpty()) { int searchNumber = toBeSearched.pop(); int mbrsToTest = searchNumber == 0 ? 1 : degree; if (searchNumber < nodeCount) { long nodeOffset = NodeSize * searchNumber; structure.seek(nodeOffset); int dataOffset = structure.readInt(); for (int i = 0; i < mbrsToTest; i++) { node_mbr.readFields(structure); int lastOffset = (searchNumber + i) == nodeCount - 1 ? elementCount - 1 : structure.readInt(); if (query_mbr.contains(node_mbr)) { // The node is full contained in the query range. // Save the time and do full scan for this node // Checks if this node is the last node in its level // This can be easily detected because the next node in // the level // order traversal will be the first node in the next // level // which means it will have an offset less than this // node if (lastOffset <= dataOffset) lastOffset = elementCount; data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + elementCount * IndexUnitSize + fieldOffset + dataOffset * fieldSize); for (int j = 0; j < lastOffset - dataOffset; j++) { switch (fieldType) { case Integer: output.collect(new IntWritable(data.readInt())); break; case Long: output.collect(new LongWritable(data.readLong())); break; case Double: output.collect(new DoubleWritable(data.readDouble())); break; default: output.collect( new Point3d(data.readDouble(), data.readDouble(), data.readDouble())); break; } resultSize++; } } else if (query_mbr.isIntersected(node_mbr)) { // Node partially overlaps with query. Go deep under // this node if (searchNumber < nonLeafNodeCount) { // Search child nodes toBeSearched.push((searchNumber + i) * degree + 1); } else { // Search all elements in this node //toBeSearched.push(dataOffset); // Checks if this node is the last node in its level // This can be easily detected because the next node // in the level // order traversal will be the first node in the // next level // which means it will have an offset less than this // node if (lastOffset <= dataOffset) lastOffset = elementCount; //toBeSearched.push(lastOffset); data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + dataOffset * IndexUnitSize); boolean report[] = new boolean[lastOffset - dataOffset]; Point3d point = new Point3d(); for (int j = 0; j < lastOffset - dataOffset; j++) { point.t = data.readDouble(); point.x = data.readDouble(); point.y = data.readDouble(); if (point.isIntersected(query_shape)) { report[j] = true; } else report[j] = false; } data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + elementCount * IndexUnitSize + fieldOffset + dataOffset * fieldSize); for (int j = 0; j < lastOffset - dataOffset; j++) { if (report[j]) { switch (fieldType) { case Integer: output.collect(new IntWritable(data.readInt())); break; case Long: output.collect(new LongWritable(data.readLong())); break; case Double: output.collect(new DoubleWritable(data.readDouble())); break; default: output.collect(new Point3d(data.readDouble(), data.readDouble(), data.readDouble())); break; } resultSize++; } } } } dataOffset = lastOffset; } } else { LOG.error("searchNumber > nodeCount, something is wrong"); int firstOffset, lastOffset; // Search for data items (records) lastOffset = searchNumber; firstOffset = toBeSearched.pop(); data.seek(firstOffset + treeStartOffset); LineReader lineReader = new LineReader(data); while (firstOffset < lastOffset) { firstOffset += lineReader.readLine(line); stockObject.fromText(line); if (stockObject.isIntersected(query_shape)) { resultSize++; if (output != null) output.collect(stockObject); } } } } return resultSize; }
From source file:net.sf.json.TestJSONArray.java
public void testToArray_StringToInt() { int[] expected = new int[] { 1, 2, 3, 4, 5, 6 }; String[] input = new String[] { "1", "2", "3", "4", "5", "6" }; JSONArray jsonArray = JSONArray.fromObject(input); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setRootClass(Integer.TYPE); Object actual = JSONArray.toArray(jsonArray, jsonConfig); Assertions.assertEquals(expected, actual); }