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:com.jaliansystems.activeMQLite.impl.ObjectRepository.java
private boolean paramMatches(Method method, Object[] params) { Class<?>[] parameterTypes = method.getParameterTypes(); if (params != null && parameterTypes.length != params.length || params == null && parameterTypes.length != 0) return false; for (int i = 0; i < parameterTypes.length; i++) { Class<?> class1 = parameterTypes[i]; if (!class1.isPrimitive() && params[i] == null) continue; if (params[i] instanceof ObjectHandle) { params[i] = getObject(((ObjectHandle) params[i])); }/*w w w. ja va2 s . c o m*/ if (class1.isPrimitive()) { if (params[i] instanceof Boolean && class1 != Boolean.TYPE) return false; if (params[i] instanceof Integer && class1 != Integer.TYPE) return false; if (params[i] instanceof Long && class1 != Long.TYPE) return false; if (params[i] instanceof Short && class1 != Short.TYPE) return false; if (params[i] instanceof Float && class1 != Float.TYPE) return false; if (params[i] instanceof Double && class1 != Double.TYPE) return false; if (params[i] instanceof Byte && class1 != Byte.TYPE) return false; } else if (!class1.isInstance(params[i])) return false; } return true; }
From source file:com.evolveum.polygon.connector.googleapps.GroupHandler.java
public static ObjectClassInfo getGroupClassInfo() { // @formatter:off /* GROUP from https://devsite.googleplex.com/admin-sdk/directory/v1/reference/groups#resource {/*from ww w. j a v a 2 s . com*/ "kind": "admin#directory#group", "id": string, "etag": etag, "email": string, "name": string, "directMembersCount": long, "description": string, "adminCreated": boolean, "aliases": [ string ], "nonEditableAliases": [ string ] } */ // @formatter:on ObjectClassInfoBuilder builder = new ObjectClassInfoBuilder(); builder.setType(ObjectClass.GROUP_NAME); // email builder.addAttributeInfo(Name.INFO); builder.addAttributeInfo(AttributeInfoBuilder.build(NAME_ATTR)); builder.addAttributeInfo(PredefinedAttributeInfos.DESCRIPTION); // Read-only builder.addAttributeInfo(AttributeInfoBuilder.define(ADMIN_CREATED_ATTR, Boolean.TYPE).setUpdateable(false) .setCreateable(false).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(ALIASES_ATTR).setUpdateable(false).setCreateable(false) .setMultiValued(true).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(NON_EDITABLE_ALIASES_ATTR).setUpdateable(false) .setCreateable(false).setMultiValued(true).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(DIRECT_MEMBERS_COUNT_ATTR, Long.TYPE) .setUpdateable(false).setCreateable(false).build()); // Virtual Attribute builder.addAttributeInfo( AttributeInfoBuilder.define(MEMBERS_ATTR).setMultiValued(true).setReturnedByDefault(false).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_allowExternalMembers).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_allowGoogleCommunication).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_allowWebPosting).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_archiveOnly).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_customFooterText).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_customReplyTo).build()); builder.addAttributeInfo(AttributeInfoBuilder .define(GoogleAppsConnector.SETTING_defaultMessageDenyNotificationText).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_description).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_email).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_includeCustomFooter).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_includeInGlobalAddressList).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_isArchived).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_maxMessageBytes, Integer.TYPE).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_membersCanPostAsTheGroup).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_messageDisplayFont).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_messageModerationLevel).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_name).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_replyTo).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_sendMessageDenyNotification).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_showInGroupDirectory).build());//rizeno builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_spamModerationLevel).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanAdd).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanContactOwner).build());//rizeno builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanInvite).build()); builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanJoin).build());//rizeno builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanLeaveGroup).build()); builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanPostMessage).build());//rizeno builder.addAttributeInfo(AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanViewGroup).build());//rizeno builder.addAttributeInfo( AttributeInfoBuilder.define(GoogleAppsConnector.SETTING_whoCanViewMembership).build());//rizeno return builder.build(); }
From source file:com.google.flatbuffers.Table.java
@SuppressWarnings("unchecked") @Override/*w w w . j a v a2s . c o m*/ public int clone(FlatBufferBuilder builder, Map<String, Object> mutate) throws Exception { int root_table = -1; Class<?> cls = this.getClass(); HashMap<String, Object> v = new HashMap<String, Object>(); try { //b0. phan loai method List<Method> msAdd = new ArrayList<Method>(); List<Method> msGet = new ArrayList<Method>(); HashMap<String, Method> msCreateVector = new HashMap<String, Method>(); Method[] ms = this.getClass().getDeclaredMethods(); for (Method m : ms) { String sMethodName = m.getName(); if (m.getParameterTypes().length == 0 && !sMethodName.endsWith("AsByteBuffer")) msGet.add(m); else if (m.getParameterTypes().length == 2 && sMethodName.startsWith("add")) msAdd.add(m); else if (m.getParameterTypes().length == 2 && sMethodName.startsWith("create") && sMethodName.endsWith("Vector")) msCreateVector.put(sMethodName, m); } //b1. lay ds thuoc tinh va gia tri for (Method m : msGet) { String sMethodName = m.getName(); if (sMethodName.endsWith("Length")) { int ii = sMethodName.lastIndexOf("Length"); String sMethodName1 = sMethodName.substring(0, ii); int iLength = 0; try { iLength = (int) m.invoke(this, new Object[] {}); } catch (Exception e) { } List<Object> l = new ArrayList<>(); for (int i = 0; i < iLength; i++) { Method m1 = this.getClass().getDeclaredMethod(sMethodName1, new Class<?>[] { Integer.TYPE }); Object oKq = m1.invoke(this, new Object[] { i }); l.add(oKq); } v.put(sMethodName1, l); } else { Object oKq = m.invoke(this, new Object[] {}); v.put(sMethodName, oKq); } } //b2. khoi tao gia tri cho builder for (Entry<String, Object> e : v.entrySet()) { String sKey = e.getKey(); Object oValue = e.getValue(); Object oNewValue = mutate != null ? mutate.get(sKey) : null; if (oValue instanceof String || oNewValue instanceof String) { int keyOffset = builder .createString(oNewValue == null ? oValue.toString() : oNewValue.toString()); v.put(sKey, keyOffset); } else if (oValue instanceof List || oNewValue instanceof List) { List<?> oV = (List<?>) (oNewValue == null ? oValue : oNewValue); int iLen = ((List<?>) oV).size(); if (iLen <= 0) v.put(sKey, null); else { Object obj = ((List<?>) oV).get(0); if (obj instanceof Table || obj instanceof Struct) { int[] keyOffsetList = new int[iLen]; boolean isHasValue = false; for (int i = 0; i < iLen; i++) { obj = ((List<?>) oV).get(i); int offset = ((IFlatBuffer) obj).clone(builder, null); if (offset != -1) { keyOffsetList[i] = offset; isHasValue = true; } } if (isHasValue) { int keyOffset = -1; Method m = cls.getDeclaredMethod("create" + WordUtils.capitalize(sKey) + "Vector", new Class<?>[] { FlatBufferBuilder.class, int[].class }); keyOffset = (int) m.invoke(null, new Object[] { builder, keyOffsetList }); if (keyOffset != -1) v.put(sKey, keyOffset); } } else if (obj instanceof String) { int[] keyOffsetList = new int[iLen]; boolean isHasValue = false; for (int i = 0; i < iLen; i++) { obj = ((List<String>) oV).get(i); int offset = builder.createString((CharSequence) obj); if (offset != -1) { keyOffsetList[i] = offset; isHasValue = true; } } if (isHasValue) { int keyOffset = -1; Method m = cls.getDeclaredMethod("create" + WordUtils.capitalize(sKey) + "Vector", new Class<?>[] { FlatBufferBuilder.class, int[].class }); keyOffset = (int) m.invoke(null, new Object[] { builder, keyOffsetList }); if (keyOffset != -1) v.put(sKey, keyOffset); } } else { int keyOffset = -1; Method m = msCreateVector.get("create" + WordUtils.capitalize(sKey) + "Vector"); Class<?> subCls = Class.forName(m.getParameterTypes()[1].getName()); Class<?> objType = subCls.getComponentType(); String objTypeName = objType.getSimpleName(); Method mo = Number.class.getDeclaredMethod(objTypeName + "Value", new Class<?>[] {}); Object aObject = Array.newInstance(objType, iLen); for (int i = 0; i < iLen; i++) Array.set(aObject, i, mo.invoke(((List<Number>) oV).get(i), new Object[] {})); keyOffset = (int) m.invoke(null, new Object[] { builder, aObject }); if (keyOffset != -1) v.put(sKey, keyOffset); } } } else if (oValue instanceof Table || oValue instanceof Struct || oNewValue instanceof Table || oNewValue instanceof Struct) { int keyOffset = -1; if (oNewValue != null) keyOffset = ((IFlatBuffer) oNewValue).clone(builder, mutate); else keyOffset = ((IFlatBuffer) oValue).clone(builder, mutate); if (keyOffset != -1) v.put(sKey, keyOffset); } else { if (oNewValue != null) v.put(sKey, oNewValue); } } //b3. gan gia tri cho clone object Method m = cls.getDeclaredMethod("start" + cls.getSimpleName(), new Class<?>[] { FlatBufferBuilder.class }); m.invoke(null, new Object[] { builder }); for (Method mAdd : msAdd) { String sFieldName = mAdd.getName().replace("add", ""); sFieldName = WordUtils.uncapitalize(sFieldName); Object oFieldValue = v.get(sFieldName); if (oFieldValue != null && !(oFieldValue instanceof Table || oFieldValue instanceof Struct)) { mAdd.invoke(null, new Object[] { builder, oFieldValue }); } } m = cls.getDeclaredMethod("end" + cls.getSimpleName(), new Class<?>[] { FlatBufferBuilder.class }); root_table = (int) m.invoke(null, new Object[] { builder }); } catch (Exception e) { e.printStackTrace(); throw e; } return root_table; }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Tests if obj is a primitive number or wrapper.<br> *//* ww w . j a va 2 s.c o m*/ public static boolean isNumber(Object obj) { if ((obj != null && obj.getClass() == Byte.TYPE) || (obj != null && obj.getClass() == Short.TYPE) || (obj != null && obj.getClass() == Integer.TYPE) || (obj != null && obj.getClass() == Long.TYPE) || (obj != null && obj.getClass() == Float.TYPE) || (obj != null && obj.getClass() == Double.TYPE)) { return true; } return obj instanceof Number; }
From source file:info.guardianproject.netcipher.webkit.WebkitProxy.java
@TargetApi(19) private static boolean setKitKatProxy(String appClass, Context appContext, String host, int port) { //Context appContext = webView.getContext().getApplicationContext(); if (host != null) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", Integer.toString(port)); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", Integer.toString(port)); }/*from w w w .j ava 2 s .c o m*/ try { Class applictionCls = Class.forName(appClass); Field loadedApkField = applictionCls.getField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((ArrayMap) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); if (host != null) { /*********** optional, may be need in future *************/ final String CLASS_NAME = "android.net.ProxyProperties"; Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, null); intent.putExtra("proxy", (Parcelable) proxyProperties); /*********** optional, may be need in future *************/ } onReceiveMethod.invoke(rec, appContext, intent); } } } return true; } catch (ClassNotFoundException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (NoSuchFieldException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (IllegalAccessException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (IllegalArgumentException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (NoSuchMethodException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (InvocationTargetException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (InstantiationException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } return false; }
From source file:catalina.mbeans.MBeanFactory.java
/** * Create a new AjpConnector// ww w . ja va 2 s.c o m * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * * @exception Exception if an MBean cannot be created or registered */ public String createAjpConnector(String parent, String address, int port) throws Exception { Object retobj = null; try { // Create a new CoyoteConnector instance for AJP // use reflection to avoid j-t-c compile-time circular dependencies Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); Constructor ct = cls.getConstructor(null); retobj = ct.newInstance(null); Class partypes1[] = new Class[1]; // Set address String str = new String(); partypes1[0] = str.getClass(); Method meth1 = cls.getMethod("setAddress", partypes1); Object arglist1[] = new Object[1]; arglist1[0] = address; meth1.invoke(retobj, arglist1); // Set port number Class partypes2[] = new Class[1]; partypes2[0] = Integer.TYPE; Method meth2 = cls.getMethod("setPort", partypes2); Object arglist2[] = new Object[1]; arglist2[0] = new Integer(port); meth2.invoke(retobj, arglist2); // set protocolHandlerClassName for AJP Class partypes3[] = new Class[1]; partypes3[0] = str.getClass(); Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3); Object arglist3[] = new Object[1]; arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler"); meth3.invoke(retobj, arglist3); } catch (Exception e) { throw new MBeanException(e); } // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("name")); service.addConnector((Connector) retobj); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("CoyoteConnector"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj); return (oname.toString()); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java
protected Object[] convertPrimitiveArrayToObjectArray(Object array) { Class<?> componentType = array.getClass().getComponentType(); Object[] result = null;//from ww w . j a v a2s.c o m if (componentType == null) { throw new NullPointerException("componentType is null"); } else if (componentType == Character.TYPE) { char[] carray = (char[]) array; result = new Object[carray.length]; for (int i = 0; i < carray.length; i++) { result[i] = new Character(carray[i]); } } else if (componentType == Byte.TYPE) { byte[] barray = (byte[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Byte(barray[i]); } } else if (componentType == Short.TYPE) { short[] sarray = (short[]) array; result = new Object[sarray.length]; for (int i = 0; i < sarray.length; i++) { result[i] = new Short(sarray[i]); } } else if (componentType == Integer.TYPE) { int[] iarray = (int[]) array; result = new Object[iarray.length]; for (int i = 0; i < iarray.length; i++) { result[i] = Integer.valueOf(iarray[i]); } } else if (componentType == Long.TYPE) { long[] larray = (long[]) array; result = new Object[larray.length]; for (int i = 0; i < larray.length; i++) { result[i] = new Long(larray[i]); } } else if (componentType == Double.TYPE) { double[] darray = (double[]) array; result = new Object[darray.length]; for (int i = 0; i < darray.length; i++) { result[i] = new Double(darray[i]); } } else if (componentType == Float.TYPE) { float[] farray = (float[]) array; result = new Object[farray.length]; for (int i = 0; i < farray.length; i++) { result[i] = new Float(farray[i]); } } else if (componentType == Boolean.TYPE) { boolean[] barray = (boolean[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Boolean(barray[i]); } } else { throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName()); } return result; }
From source file:nl.strohalm.cyclos.controls.loans.GrantLoanAction.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private DataBinder<GrantLoanDTO> getDataBinder(final Loan.Type type) { final LocalSettings settings = settingsService.getLocalSettings(); final BeanBinder<PaymentCustomFieldValue> customValueBinder = BeanBinder .instance(PaymentCustomFieldValue.class); customValueBinder.registerBinder("field", PropertyBinder.instance(PaymentCustomField.class, "field", ReferenceConverter.instance(PaymentCustomField.class))); customValueBinder.registerBinder("value", PropertyBinder.instance(String.class, "value", HtmlConverter.instance())); final BeanBinder binder = new BeanBinder(); binder.registerBinder("member", PropertyBinder.instance(Member.class, "member", ReferenceConverter.instance(Member.class))); binder.registerBinder("loanGroup", PropertyBinder.instance(LoanGroup.class, "loanGroup", ReferenceConverter.instance(LoanGroup.class))); binder.registerBinder("amount", PropertyBinder.instance(BigDecimal.class, "amount", settings.getNumberConverter())); binder.registerBinder("date", PropertyBinder.instance(Calendar.class, "date", settings.getRawDateConverter())); binder.registerBinder("description", PropertyBinder.instance(String.class, "description")); binder.registerBinder("transferType", PropertyBinder.instance(TransferType.class, "transferType", ReferenceConverter.instance(TransferType.class))); binder.registerBinder("customValues", BeanCollectionBinder.instance(customValueBinder, "customValues")); switch (type) { case SINGLE_PAYMENT: binder.setType(GrantSinglePaymentLoanDTO.class); binder.registerBinder("repaymentDate", PropertyBinder.instance(Calendar.class, "repaymentDate", settings.getRawDateConverter())); break;//from w ww . j a va2 s .co m case MULTI_PAYMENT: binder.setType(GrantMultiPaymentLoanDTO.class); final BeanBinder<LoanPayment> paymentBinder = BeanBinder.instance(LoanPayment.class); paymentBinder.registerBinder("expirationDate", PropertyBinder.instance(Calendar.class, "expirationDate", settings.getRawDateConverter())); paymentBinder.registerBinder("amount", PropertyBinder.instance(BigDecimal.class, "amount", settings.getNumberConverter())); binder.registerBinder("payments", BeanCollectionBinder.instance(paymentBinder, "payments")); break; case WITH_INTEREST: binder.setType(GrantLoanWithInterestDTO.class); binder.registerBinder("firstRepaymentDate", PropertyBinder.instance(Calendar.class, "firstRepaymentDate", settings.getRawDateConverter())); binder.registerBinder("paymentCount", PropertyBinder.instance(Integer.TYPE, "paymentCount")); break; default: throw new IllegalArgumentException("Invalid loan type: " + type); } return binder; }
From source file:ca.sqlpower.architect.swingui.TestPlayPenComponent.java
/** * Returns a new value that is not equal to oldVal. The * returned object will be a new instance compatible with oldVal. * /*from w w w . j a va2s. c o m*/ * @param property The property that should be modified. * @param oldVal The existing value of the property to modify. The returned value * will not equal this one at the time this method was first called. */ private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) throws SQLObjectException { Object newVal; // don't init here so compiler can warn if the // following code doesn't always give it a value if (property.getPropertyType() == String.class) { newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) { if (oldVal == null) { newVal = new Boolean(false); } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) { if (oldVal == null) { newVal = new Integer(0); } else { newVal = new Integer(((Integer) oldVal).intValue() + 1); } } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) { if (oldVal == null) { newVal = new Double(0); } else { newVal = new Double(((Double) oldVal).doubleValue() + 1); } } else if (property.getPropertyType() == Color.class) { if (oldVal == null) { newVal = new Color(0xFAC157); } else { Color oldColor = (Color) oldVal; newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000); } } else if (property.getPropertyType() == Font.class) { if (oldVal == null) { newVal = FontManager.getDefaultPhysicalFont(); } else { Font oldFont = (Font) oldVal; newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle()); } } else if (property.getPropertyType() == Point.class) { if (oldVal == null) { newVal = new Point(); } else { Point oldPoint = (Point) oldVal; newVal = new Point(oldPoint.x + 10, oldPoint.y + 10); } } else if (property.getPropertyType() == Insets.class) { if (oldVal == null) { newVal = new Insets(0, 0, 0, 0); } else { Insets oldInsets = (Insets) oldVal; newVal = new Insets(oldInsets.top + 10, oldInsets.left + 10, oldInsets.bottom + 10, oldInsets.right + 10); } } else if (property.getPropertyType() == Set.class) { newVal = new HashSet(); if (property.getName().equals("hiddenColumns")) { ((Set) newVal).add(new SQLColumn()); } else { ((Set) newVal).add("Test"); } } else if (property.getPropertyType() == List.class) { newVal = new ArrayList(); if (property.getName().equals("selectedColumns")) { ((List) newVal).add(new SQLColumn()); } else { ((List) newVal).add("Test"); } } else if (property.getPropertyType() == TablePane.class) { SQLTable t = new SQLTable(); t.initFolders(true); newVal = new TablePane(t, pp.getContentPane()); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); ((SQLTable) newVal).initFolders(true); } else if (property.getPropertyType() == Dimension.class) { newVal = new Dimension(); if (oldVal != null) { ((Dimension) newVal).width = ((Dimension) oldVal).width + 1; } } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") in getNewDifferentValue()"); } return newVal; }
From source file:com.ricemap.spateDB.core.RTree.java
/** * Builds the RTree given a serialized list of elements. It uses the given * stockObject to deserialize these elements and build the tree. Also writes * the created tree to the disk directly. * //from ww w . jav a2s.c om * @param elements * - serialization of elements to be written * @param offset * - index of the first element to use in the elements array * @param len * - number of bytes to user from the elements array * @param bytesAvailable * - size available (in bytes) to store the tree structures * @param dataOut * - an output to use for writing the tree to * @param fast_sort * - setting this to <code>true</code> allows the method to run * faster by materializing the offset of each element in the list * which speeds up the comparison. However, this requires an * additional 16 bytes per element. So, for each 1M elements, the * method will require an additional 16 M bytes (approximately). */ public void bulkLoadWrite(final byte[] element_bytes, final int offset, final int len, final int degree, DataOutput dataOut, final boolean fast_sort, final boolean columnarStorage) { try { columnar = columnarStorage; //TODO: the order of fields should be stable under Oracle JVM, but not guaranteed Field[] fields = stockObject.getClass().getDeclaredFields(); // Count number of elements in the given text int i_start = offset; final Text line = new Text(); while (i_start < offset + len) { int i_end = skipToEOL(element_bytes, i_start); // Extract the line without end of line character line.set(element_bytes, i_start, i_end - i_start - 1); stockObject.fromText(line); elementCount++; i_start = i_end; } LOG.info("Bulk loading an RTree with " + elementCount + " elements"); // It turns out the findBestDegree returns the best degree when the // whole // tree is loaded to memory when processed. However, as current // algorithms // process the tree while it's on disk, a higher degree should be // selected // such that a node fits one file block (assumed to be 4K). // final int degree = findBestDegree(bytesAvailable, elementCount); LOG.info("Writing an RTree with degree " + degree); int height = Math.max(1, (int) Math.ceil(Math.log(elementCount) / Math.log(degree))); int leafNodeCount = (int) Math.pow(degree, height - 1); if (elementCount < 2 * leafNodeCount && height > 1) { height--; leafNodeCount = (int) Math.pow(degree, height - 1); } int nodeCount = (int) ((Math.pow(degree, height) - 1) / (degree - 1)); int nonLeafNodeCount = nodeCount - leafNodeCount; // Keep track of the offset of each element in the text final int[] offsets = new int[elementCount]; final int[] ids = new int[elementCount]; final double[] ts = fast_sort ? new double[elementCount] : null; final double[] xs = fast_sort ? new double[elementCount] : null; final double[] ys = fast_sort ? new double[elementCount] : null; //initialize columnar data output ByteArrayOutputStream index_bos = new ByteArrayOutputStream(); DataOutputStream index_dos = new DataOutputStream(index_bos); ByteArrayOutputStream[] bos = new ByteArrayOutputStream[fields.length]; DataOutputStream[] dos = new DataOutputStream[fields.length]; for (int i = 0; i < bos.length; i++) { bos[i] = new ByteArrayOutputStream(); dos[i] = new DataOutputStream(bos[i]); } i_start = offset; line.clear(); for (int i = 0; i < elementCount; i++) { offsets[i] = i_start; ids[i] = i; int i_end = skipToEOL(element_bytes, i_start); if (xs != null) { // Extract the line with end of line character line.set(element_bytes, i_start, i_end - i_start - 1); stockObject.fromText(line); // Sample center of the shape ts[i] = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2; xs[i] = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2; ys[i] = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2; //build columnar storage if (stockObject instanceof Point3d) { index_dos.writeDouble(ts[i]); index_dos.writeDouble(xs[i]); index_dos.writeDouble(ys[i]); } else { throw new RuntimeException("Indexing non-point shape with RTREE is not supported yet"); } for (int j = 0; j < fields.length; j++) { if (fields[j].getType().equals(Integer.TYPE)) { dos[j].writeInt(fields[j].getInt(stockObject)); } else if (fields[j].getType().equals(Double.TYPE)) { dos[j].writeDouble(fields[j].getDouble(stockObject)); } else if (fields[j].getType().equals(Long.TYPE)) { dos[j].writeLong(fields[j].getLong(stockObject)); } else { continue; //throw new RuntimeException("Field type is not supported yet"); } } } i_start = i_end; } index_dos.close(); for (int i = 0; i < dos.length; i++) { dos[i].close(); } /** A struct to store information about a split */ class SplitStruct extends Prism { /** Start and end index for this split */ int index1, index2; /** Direction of this split */ byte direction; /** Index of first element on disk */ int offsetOfFirstElement; static final byte DIRECTION_T = 0; static final byte DIRECTION_X = 1; static final byte DIRECTION_Y = 2; SplitStruct(int index1, int index2, byte direction) { this.index1 = index1; this.index2 = index2; this.direction = direction; } @Override public void write(DataOutput out) throws IOException { // if (columnarStorage) out.writeInt(index1); else out.writeInt(offsetOfFirstElement); super.write(out); } void partition(Queue<SplitStruct> toBePartitioned) { IndexedSortable sortableT; IndexedSortable sortableX; IndexedSortable sortableY; if (fast_sort) { // Use materialized xs[] and ys[] to do the comparisons sortableT = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap ts double tempt = ts[i]; ts[i] = ts[j]; ts[j] = tempt; // Swap xs double tempx = xs[i]; xs[i] = xs[j]; xs[j] = tempx; // Swap ys double tempY = ys[i]; ys[i] = ys[j]; ys[j] = tempY; // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { if (ts[i] < ts[j]) return -1; if (ts[i] > ts[j]) return 1; return 0; } }; sortableX = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap ts double tempt = ts[i]; ts[i] = ts[j]; ts[j] = tempt; // Swap xs double tempx = xs[i]; xs[i] = xs[j]; xs[j] = tempx; // Swap ys double tempY = ys[i]; ys[i] = ys[j]; ys[j] = tempY; // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { if (ts[i] < ts[j]) return -1; if (xs[i] < xs[j]) return -1; if (xs[i] > xs[j]) return 1; return 0; } }; sortableY = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap ts double tempt = ts[i]; ts[i] = ts[j]; ts[j] = tempt; // Swap xs double tempx = xs[i]; xs[i] = xs[j]; xs[j] = tempx; // Swap ys double tempY = ys[i]; ys[i] = ys[j]; ys[j] = tempY; // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { if (ys[i] < ys[j]) return -1; if (ys[i] > ys[j]) return 1; return 0; } }; } else { // No materialized xs and ys. Always deserialize objects // to compare sortableT = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { // Get end of line int eol = skipToEOL(element_bytes, offsets[i]); line.set(element_bytes, offsets[i], eol - offsets[i] - 1); stockObject.fromText(line); double ti = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2; eol = skipToEOL(element_bytes, offsets[j]); line.set(element_bytes, offsets[j], eol - offsets[j] - 1); stockObject.fromText(line); double tj = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2; if (ti < tj) return -1; if (ti > tj) return 1; return 0; } }; sortableX = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { // Get end of line int eol = skipToEOL(element_bytes, offsets[i]); line.set(element_bytes, offsets[i], eol - offsets[i] - 1); stockObject.fromText(line); double xi = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2; eol = skipToEOL(element_bytes, offsets[j]); line.set(element_bytes, offsets[j], eol - offsets[j] - 1); stockObject.fromText(line); double xj = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2; if (xi < xj) return -1; if (xi > xj) return 1; return 0; } }; sortableY = new IndexedSortable() { @Override public void swap(int i, int j) { // Swap id int tempid = offsets[i]; offsets[i] = offsets[j]; offsets[j] = tempid; tempid = ids[i]; ids[i] = ids[j]; ids[j] = tempid; } @Override public int compare(int i, int j) { int eol = skipToEOL(element_bytes, offsets[i]); line.set(element_bytes, offsets[i], eol - offsets[i] - 1); stockObject.fromText(line); double yi = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2; eol = skipToEOL(element_bytes, offsets[j]); line.set(element_bytes, offsets[j], eol - offsets[j] - 1); stockObject.fromText(line); double yj = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2; if (yi < yj) return -1; if (yi > yj) return 1; return 0; } }; } final IndexedSorter sorter = new QuickSort(); final IndexedSortable[] sortables = new IndexedSortable[3]; sortables[SplitStruct.DIRECTION_T] = sortableT; sortables[SplitStruct.DIRECTION_X] = sortableX; sortables[SplitStruct.DIRECTION_Y] = sortableY; sorter.sort(sortables[direction], index1, index2); // Partition into maxEntries partitions (equally) and // create a SplitStruct for each partition int i1 = index1; for (int iSplit = 0; iSplit < degree; iSplit++) { int i2 = index1 + (index2 - index1) * (iSplit + 1) / degree; SplitStruct newSplit; if (direction == 0) { newSplit = new SplitStruct(i1, i2, (byte) 1); } else if (direction == 1) { newSplit = new SplitStruct(i1, i2, (byte) 2); } else { newSplit = new SplitStruct(i1, i2, (byte) 0); } toBePartitioned.add(newSplit); i1 = i2; } } } // All nodes stored in level-order traversal Vector<SplitStruct> nodes = new Vector<SplitStruct>(); final Queue<SplitStruct> toBePartitioned = new LinkedList<SplitStruct>(); toBePartitioned.add(new SplitStruct(0, elementCount, SplitStruct.DIRECTION_X)); while (!toBePartitioned.isEmpty()) { SplitStruct split = toBePartitioned.poll(); if (nodes.size() < nonLeafNodeCount) { // This is a non-leaf split.partition(toBePartitioned); } nodes.add(split); } if (nodes.size() != nodeCount) { throw new RuntimeException( "Expected node count: " + nodeCount + ". Real node count: " + nodes.size()); } // Now we have our data sorted in the required order. Start building // the tree. // Store the offset of each leaf node in the tree FSDataOutputStream fakeOut = new FSDataOutputStream(new java.io.OutputStream() { // Null output stream @Override public void write(int b) throws IOException { // Do nothing } @Override public void write(byte[] b, int off, int len) throws IOException { // Do nothing } @Override public void write(byte[] b) throws IOException { // Do nothing } }, null, TreeHeaderSize + nodes.size() * NodeSize); for (int i_leaf = nonLeafNodeCount, i = 0; i_leaf < nodes.size(); i_leaf++) { nodes.elementAt(i_leaf).offsetOfFirstElement = (int) fakeOut.getPos(); if (i != nodes.elementAt(i_leaf).index1) throw new RuntimeException(); double t1, x1, y1, t2, x2, y2; // Initialize MBR to first object int eol = skipToEOL(element_bytes, offsets[i]); fakeOut.write(element_bytes, offsets[i], eol - offsets[i]); line.set(element_bytes, offsets[i], eol - offsets[i] - 1); stockObject.fromText(line); Prism mbr = stockObject.getMBR(); t1 = mbr.t1; x1 = mbr.x1; y1 = mbr.y1; t2 = mbr.t2; x2 = mbr.x2; y2 = mbr.y2; i++; while (i < nodes.elementAt(i_leaf).index2) { eol = skipToEOL(element_bytes, offsets[i]); fakeOut.write(element_bytes, offsets[i], eol - offsets[i]); line.set(element_bytes, offsets[i], eol - offsets[i] - 1); stockObject.fromText(line); mbr = stockObject.getMBR(); if (mbr.t1 < t1) t1 = mbr.t1; if (mbr.x1 < x1) x1 = mbr.x1; if (mbr.y1 < y1) y1 = mbr.y1; if (mbr.t2 > t2) t2 = mbr.t2; if (mbr.x2 > x2) x2 = mbr.x2; if (mbr.y2 > y2) y2 = mbr.y2; i++; } nodes.elementAt(i_leaf).set(t1, x1, y1, t2, x2, y2); } fakeOut.close(); fakeOut = null; // Calculate MBR and offsetOfFirstElement for non-leaves for (int i_node = nonLeafNodeCount - 1; i_node >= 0; i_node--) { int i_first_child = i_node * degree + 1; nodes.elementAt(i_node).offsetOfFirstElement = nodes.elementAt(i_first_child).offsetOfFirstElement; int i_child = 0; Prism mbr; mbr = nodes.elementAt(i_first_child + i_child); double t1 = mbr.t1; double x1 = mbr.x1; double y1 = mbr.y1; double t2 = mbr.t2; double x2 = mbr.x2; double y2 = mbr.y2; i_child++; while (i_child < degree) { mbr = nodes.elementAt(i_first_child + i_child); if (mbr.t1 < t1) t1 = mbr.t1; if (mbr.x1 < x1) x1 = mbr.x1; if (mbr.y1 < y1) y1 = mbr.y1; if (mbr.t2 > t2) t2 = mbr.t2; if (mbr.x2 > x2) x2 = mbr.x2; if (mbr.y2 > y2) y2 = mbr.y2; i_child++; } nodes.elementAt(i_node).set(t1, x1, y1, t2, x2, y2); } // Start writing the tree // write tree header (including size) // Total tree size. (== Total bytes written - 8 bytes for the size // itself) dataOut.writeInt(TreeHeaderSize + NodeSize * nodeCount + len); // Tree height dataOut.writeInt(height); // Degree dataOut.writeInt(degree); dataOut.writeInt(elementCount); //isColumnar dataOut.writeInt(columnarStorage ? 1 : 0); // write nodes for (SplitStruct node : nodes) { node.write(dataOut); } // write elements if (columnarStorage) { byte[] index_bs = index_bos.toByteArray(); byte[][] bss = new byte[bos.length][]; for (int i = 0; i < bss.length; i++) { bss[i] = bos[i].toByteArray(); } for (int element_i = 0; element_i < elementCount; element_i++) { //int eol = skipToEOL(element_bytes, offsets[element_i]); //dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]); dataOut.write(index_bs, ids[element_i] * IndexUnitSize, IndexUnitSize); } for (int i = 0; i < fields.length; i++) { int fieldSize = 0; if (fields[i].getType().equals(Integer.TYPE)) { fieldSize = 4; } else if (fields[i].getType().equals(Long.TYPE)) { fieldSize = 8; } else if (fields[i].getType().equals(Double.TYPE)) { fieldSize = 8; } else { //throw new RuntimeException("Unsupported field type: " + fields[i].getType().getName()); continue; } for (int element_i = 0; element_i < elementCount; element_i++) { //int eol = skipToEOL(element_bytes, offsets[element_i]); //dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]); dataOut.write(bss[i], ids[element_i] * fieldSize, fieldSize); } } } else { for (int element_i = 0; element_i < elementCount; element_i++) { int eol = skipToEOL(element_bytes, offsets[element_i]); dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]); } } } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }