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.ocelotds.dashboard.services.ServiceToolsTest.java
/** * Test of getInstanceOfClass method, of class ServiceTools. * * @throws com.fasterxml.jackson.core.JsonProcessingException *//*from w w w .j a v a 2 s .co m*/ @Test public void testGetInstanceOfClass() throws JsonProcessingException { System.out.println("getTemplateOfClass"); ObjectMapper om = new ObjectMapper(); Result r = new Result(); String expResult = om.writeValueAsString(r); Class cls = Boolean.class; Object result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Boolean.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Integer.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Integer.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Long.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0L); cls = Long.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0l); cls = Float.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Float.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Double.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Double.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Float[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(new Float[] { 0.1f, 0.1f }); cls = Result.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(r); cls = Result[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(new Result[] { r, r }); cls = Locale.class; result = instance.getInstanceOfClass(cls); assertThat(result).isInstanceOf(Locale.class); cls = Serializable.class; result = instance.getInstanceOfClass(cls); assertThat(result).isNull(); }
From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Gets default value. * @return default value.// w w w . jav a 2s . c om */ public Object getDefaultValue() { if (defaultValue != null) return this.defaultValue; Class cls = getType(); if (primitiveWrapperClass != null) { if (cls.equals(Boolean.TYPE)) return new Boolean(false); else if (cls.equals(Byte.TYPE)) return new Byte((byte) 0); else if (cls.equals(Character.TYPE)) return new Character((char) 0); else if (cls.equals(Double.TYPE)) return new Double((double) 0); else if (cls.equals(Float.TYPE)) return new Float((float) 0); else if (cls.equals(Integer.TYPE)) return new Integer((int) 0); else if (cls.equals(Long.TYPE)) return new Long((long) 0); else if (cls.equals(Short.TYPE)) return new Short((short) 0); else return null; } else return null; }
From source file:de.iew.imageread.Main.java
protected static Options setupOptions() { Options options = new Options(); Option imageOutputDirOption = new Option("o", "outputDir", true, "The base directory to write the images to (Default: system temp directory)"); imageOutputDirOption.setArgName("outputDir"); Option imageFilenamePrefixOption = new Option("p", "filenamePrefix", true, "The basename/prefix for each image (Default: image-)"); imageFilenamePrefixOption.setArgName("filenamePrefix"); Option groupingOutputOption = new Option("g", "groupingOutput", true, "Grouping option for the images; valid values are ALL, GROUP_BY_DAY (Default: ALL)"); groupingOutputOption.setArgName("groupingOutput"); groupingOutputOption.setType(OUTPUT_OPTION.class); Option queryOption = new Option("q", "query", true, "Query filters for the mongo db queries; valid values for 'query' are FROM, TO and EXACT (Default: no specific query)"); queryOption.setArgs(2);//w ww.j a va 2 s . com queryOption.setArgName("query=date"); queryOption.setValueSeparator('='); Option databaseOption = new Option("md", "database", true, "The mongo db database (Default: test)"); databaseOption.setArgName("database"); Option mongodbHostOption = new Option("mh", "hostname", true, "The hostname of the mongo db instance (Default: localhost)"); mongodbHostOption.setArgName("hostname"); Option mongodbPortOption = new Option("mp", "port", true, "The port of the mongo db instance (Default: 27017)"); mongodbPortOption.setArgName("port"); mongodbPortOption.setType(Integer.TYPE); Option printHelpOption = new Option("h", "help", false, "Print help"); options.addOption(imageOutputDirOption); options.addOption(imageFilenamePrefixOption); options.addOption(groupingOutputOption); options.addOption(queryOption); options.addOption(databaseOption); options.addOption(mongodbHostOption); options.addOption(mongodbPortOption); options.addOption(printHelpOption); return options; }
From source file:net.dmulloy2.ultimatearena.types.ArenaZone.java
/** * {@inheritDoc}//w w w . j a va2 s .co m */ @Override public Map<String, Object> serialize() { Map<String, Object> data = new LinkedHashMap<>(); for (java.lang.reflect.Field field : ArenaZone.class.getDeclaredFields()) { if (Modifier.isTransient(field.getModifiers())) continue; try { boolean accessible = field.isAccessible(); field.setAccessible(true); if (field.getType().equals(Integer.TYPE)) { if (field.getInt(this) != 0) data.put(field.getName(), field.getInt(this)); } else if (field.getType().equals(Long.TYPE)) { if (field.getLong(this) != 0) data.put(field.getName(), field.getLong(this)); } else if (field.getType().equals(Boolean.TYPE)) { if (field.getBoolean(this)) data.put(field.getName(), field.getBoolean(this)); } else if (field.getType().isAssignableFrom(Collection.class)) { if (!((Collection<?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(String.class)) { if ((String) field.get(this) != null) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(Map.class)) { if (!((Map<?, ?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else { if (field.get(this) != null) data.put(field.getName(), field.get(this)); } field.setAccessible(accessible); } catch (Throwable ex) { } } data.put("version", CURRENT_VERSION); return data; }
From source file:catalina.startup.WebRuleSet.java
/** * <p>Add the set of Rule instances defined in this RuleSet to the * specified <code>Digester</code> instance, associating them with * our namespace URI (if any). This method should only be called * by a Digester instance.</p>/*from ww w .ja va 2 s. c o m*/ * * @param digester Digester instance to which the new Rule instances * should be added. */ public void addRuleInstances(Digester digester) { digester.addRule(prefix + "web-app", new SetPublicIdRule(digester, "setPublicId")); digester.addCallMethod(prefix + "web-app/context-param", "addParameter", 2); digester.addCallParam(prefix + "web-app/context-param/param-name", 0); digester.addCallParam(prefix + "web-app/context-param/param-value", 1); digester.addCallMethod(prefix + "web-app/display-name", "setDisplayName", 0); digester.addRule(prefix + "web-app/distributable", new SetDistributableRule(digester)); digester.addObjectCreate(prefix + "web-app/ejb-local-ref", "org.apache.catalina.deploy.ContextLocalEjb"); digester.addSetNext(prefix + "web-app/ejb-local-ref", "addLocalEjb", "org.apache.catalina.deploy.ContextLocalEjb"); digester.addCallMethod(prefix + "web-app/ejb-local-ref/description", "setDescription", 0); digester.addCallMethod(prefix + "web-app/ejb-local-ref/ejb-link", "setLink", 0); digester.addCallMethod(prefix + "web-app/ejb-local-ref/ejb-ref-name", "setName", 0); digester.addCallMethod(prefix + "web-app/ejb-local-ref/ejb-ref-type", "setType", 0); digester.addCallMethod(prefix + "web-app/ejb-local-ref/local", "setLocal", 0); digester.addCallMethod(prefix + "web-app/ejb-local-ref/local-home", "setHome", 0); digester.addObjectCreate(prefix + "web-app/ejb-ref", "org.apache.catalina.deploy.ContextEjb"); digester.addSetNext(prefix + "web-app/ejb-ref", "addEjb", "org.apache.catalina.deploy.ContextEjb"); digester.addCallMethod(prefix + "web-app/ejb-ref/description", "setDescription", 0); digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-link", "setLink", 0); digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-ref-name", "setName", 0); digester.addCallMethod(prefix + "web-app/ejb-ref/ejb-ref-type", "setType", 0); digester.addCallMethod(prefix + "web-app/ejb-ref/home", "setHome", 0); digester.addCallMethod(prefix + "web-app/ejb-ref/remote", "setRemote", 0); digester.addObjectCreate(prefix + "web-app/env-entry", "org.apache.catalina.deploy.ContextEnvironment"); digester.addSetNext(prefix + "web-app/env-entry", "addEnvironment", "org.apache.catalina.deploy.ContextEnvironment"); digester.addCallMethod(prefix + "web-app/env-entry/description", "setDescription", 0); digester.addCallMethod(prefix + "web-app/env-entry/env-entry-name", "setName", 0); digester.addCallMethod(prefix + "web-app/env-entry/env-entry-type", "setType", 0); digester.addCallMethod(prefix + "web-app/env-entry/env-entry-value", "setValue", 0); digester.addObjectCreate(prefix + "web-app/error-page", "org.apache.catalina.deploy.ErrorPage"); digester.addSetNext(prefix + "web-app/error-page", "addErrorPage", "org.apache.catalina.deploy.ErrorPage"); digester.addCallMethod(prefix + "web-app/error-page/error-code", "setErrorCode", 0); digester.addCallMethod(prefix + "web-app/error-page/exception-type", "setExceptionType", 0); digester.addCallMethod(prefix + "web-app/error-page/location", "setLocation", 0); digester.addObjectCreate(prefix + "web-app/filter", "org.apache.catalina.deploy.FilterDef"); digester.addSetNext(prefix + "web-app/filter", "addFilterDef", "org.apache.catalina.deploy.FilterDef"); digester.addCallMethod(prefix + "web-app/filter/description", "setDescription", 0); digester.addCallMethod(prefix + "web-app/filter/display-name", "setDisplayName", 0); digester.addCallMethod(prefix + "web-app/filter/filter-class", "setFilterClass", 0); digester.addCallMethod(prefix + "web-app/filter/filter-name", "setFilterName", 0); digester.addCallMethod(prefix + "web-app/filter/large-icon", "setLargeIcon", 0); digester.addCallMethod(prefix + "web-app/filter/small-icon", "setSmallIcon", 0); digester.addCallMethod(prefix + "web-app/filter/init-param", "addInitParameter", 2); digester.addCallParam(prefix + "web-app/filter/init-param/param-name", 0); digester.addCallParam(prefix + "web-app/filter/init-param/param-value", 1); digester.addObjectCreate(prefix + "web-app/filter-mapping", "org.apache.catalina.deploy.FilterMap"); digester.addSetNext(prefix + "web-app/filter-mapping", "addFilterMap", "org.apache.catalina.deploy.FilterMap"); digester.addCallMethod(prefix + "web-app/filter-mapping/filter-name", "setFilterName", 0); digester.addCallMethod(prefix + "web-app/filter-mapping/servlet-name", "setServletName", 0); digester.addCallMethod(prefix + "web-app/filter-mapping/url-pattern", "setURLPattern", 0); digester.addCallMethod(prefix + "web-app/listener/listener-class", "addApplicationListener", 0); digester.addObjectCreate(prefix + "web-app/login-config", "org.apache.catalina.deploy.LoginConfig"); digester.addSetNext(prefix + "web-app/login-config", "setLoginConfig", "org.apache.catalina.deploy.LoginConfig"); digester.addCallMethod(prefix + "web-app/login-config/auth-method", "setAuthMethod", 0); digester.addCallMethod(prefix + "web-app/login-config/realm-name", "setRealmName", 0); digester.addCallMethod(prefix + "web-app/login-config/form-login-config/form-error-page", "setErrorPage", 0); digester.addCallMethod(prefix + "web-app/login-config/form-login-config/form-login-page", "setLoginPage", 0); digester.addCallMethod(prefix + "web-app/mime-mapping", "addMimeMapping", 2); digester.addCallParam(prefix + "web-app/mime-mapping/extension", 0); digester.addCallParam(prefix + "web-app/mime-mapping/mime-type", 1); digester.addCallMethod(prefix + "web-app/resource-env-ref", "addResourceEnvRef", 2); digester.addCallParam(prefix + "web-app/resource-env-ref/resource-env-ref-name", 0); digester.addCallParam(prefix + "web-app/resource-env-ref/resource-env-ref-type", 1); digester.addObjectCreate(prefix + "web-app/resource-ref", "org.apache.catalina.deploy.ContextResource"); digester.addSetNext(prefix + "web-app/resource-ref", "addResource", "org.apache.catalina.deploy.ContextResource"); digester.addCallMethod(prefix + "web-app/resource-ref/description", "setDescription", 0); digester.addCallMethod(prefix + "web-app/resource-ref/res-auth", "setAuth", 0); digester.addCallMethod(prefix + "web-app/resource-ref/res-ref-name", "setName", 0); digester.addCallMethod(prefix + "web-app/resource-ref/res-sharing-scope", "setScope", 0); digester.addCallMethod(prefix + "web-app/resource-ref/res-type", "setType", 0); digester.addObjectCreate(prefix + "web-app/security-constraint", "org.apache.catalina.deploy.SecurityConstraint"); digester.addSetNext(prefix + "web-app/security-constraint", "addConstraint", "org.apache.catalina.deploy.SecurityConstraint"); digester.addRule(prefix + "web-app/security-constraint/auth-constraint", new SetAuthConstraintRule(digester)); digester.addCallMethod(prefix + "web-app/security-constraint/auth-constraint/role-name", "addAuthRole", 0); digester.addCallMethod(prefix + "web-app/security-constraint/display-name", "setDisplayName", 0); digester.addCallMethod(prefix + "web-app/security-constraint/user-data-constraint/transport-guarantee", "setUserConstraint", 0); digester.addObjectCreate(prefix + "web-app/security-constraint/web-resource-collection", "org.apache.catalina.deploy.SecurityCollection"); digester.addSetNext(prefix + "web-app/security-constraint/web-resource-collection", "addCollection", "org.apache.catalina.deploy.SecurityCollection"); digester.addCallMethod(prefix + "web-app/security-constraint/web-resource-collection/http-method", "addMethod", 0); digester.addCallMethod(prefix + "web-app/security-constraint/web-resource-collection/url-pattern", "addPattern", 0); digester.addCallMethod(prefix + "web-app/security-constraint/web-resource-collection/web-resource-name", "setName", 0); digester.addCallMethod(prefix + "web-app/security-role/role-name", "addSecurityRole", 0); digester.addRule(prefix + "web-app/servlet", new WrapperCreateRule(digester)); digester.addSetNext(prefix + "web-app/servlet", "addChild", "org.apache.catalina.Container"); digester.addCallMethod(prefix + "web-app/servlet/init-param", "addInitParameter", 2); digester.addCallParam(prefix + "web-app/servlet/init-param/param-name", 0); digester.addCallParam(prefix + "web-app/servlet/init-param/param-value", 1); digester.addCallMethod(prefix + "web-app/servlet/jsp-file", "setJspFile", 0); digester.addCallMethod(prefix + "web-app/servlet/load-on-startup", "setLoadOnStartupString", 0); digester.addCallMethod(prefix + "web-app/servlet/run-as/role-name", "setRunAs", 0); digester.addCallMethod(prefix + "web-app/servlet/security-role-ref", "addSecurityReference", 2); digester.addCallParam(prefix + "web-app/servlet/security-role-ref/role-link", 1); digester.addCallParam(prefix + "web-app/servlet/security-role-ref/role-name", 0); digester.addCallMethod(prefix + "web-app/servlet/servlet-class", "setServletClass", 0); digester.addCallMethod(prefix + "web-app/servlet/servlet-name", "setName", 0); digester.addCallMethod(prefix + "web-app/servlet-mapping", "addServletMapping", 2); digester.addCallParam(prefix + "web-app/servlet-mapping/servlet-name", 1); digester.addCallParam(prefix + "web-app/servlet-mapping/url-pattern", 0); digester.addCallMethod(prefix + "web-app/session-config/session-timeout", "setSessionTimeout", 1, new Class[] { Integer.TYPE }); digester.addCallParam(prefix + "web-app/session-config/session-timeout", 0); digester.addCallMethod(prefix + "web-app/taglib", "addTaglib", 2); digester.addCallParam(prefix + "web-app/taglib/taglib-location", 1); digester.addCallParam(prefix + "web-app/taglib/taglib-uri", 0); digester.addCallMethod(prefix + "web-app/welcome-file-list/welcome-file", "addWelcomeFile", 0); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.LogListenerTest.java
@Test public void testMonitoringStatusWithNoChildsFiltered() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { MultiStatus multi = new MultiStatus("org.eclipse.ui.monitoring", 0, "UI freeze of 6,0s at 11:24:59.108", new RuntimeException("stand-in-stacktrace")); Method method = Status.class.getDeclaredMethod("setSeverity", Integer.TYPE); method.setAccessible(true);/*from ww w. ja va 2 s.c om*/ method.invoke(multi, IStatus.ERROR); sut.logging(multi, ""); verifyNoErrorReportLogged(); }
From source file:com.liferay.tool.datamanipulator.handler.BaseHandler.java
private Object[] _getArgs(String[] argNames, Class<?>[] argClazzs, RequestContext requestContext, Map<String, Object> entrySpecifiedArgs) throws Exception { long companyId = requestContext.getCompanyId(); long groupId = requestContext.getGroupId(); long userId = requestContext.getUserId(); Date now = new Date(); ServiceContext serviceContext = HandlerUtil.getServiceContext(groupId, userId); Map<String, Calendar> dateMap = new HashMap<String, Calendar>(entryDateFields.size()); for (String entryDateField : entryDateFields) { String dateVarName = entryDateField + "Date"; String dateKeyName = entryDateField + "-date"; Date serviceContextDate = (Date) BeanUtil.getPropertySilently(serviceContext, dateVarName); Calendar dateVarValue;//w ww .j a v a 2s .c o m if (requestContext.contains(dateKeyName + "-from") && requestContext.contains(dateKeyName + "-to")) { dateVarValue = requestContext.getBetweenCalendar(dateKeyName); } else if (Validator.isNotNull(serviceContextDate)) { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(serviceContextDate); } else { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(now); } dateMap.put(dateVarName, dateVarValue); } StringBuilder sb = new StringBuilder(); sb.append(_entryName); sb.append(requestContext.getString("entryCount")); sb.append(" ${fieldName} "); if (requestContext.contains("editCount")) { sb.append("Edited "); sb.append(requestContext.getString("editCount")); sb.append(" times "); } sb.append(requestContext.getRandomString()); String entryTemplate = sb.toString(); User user = UserLocalServiceUtil.fetchUser(userId); List<Object> argValues = new ArrayList<Object>(argNames.length); for (int i = 0; i < argNames.length; i++) { String argName = argNames[i]; Class<?> argClazz = argClazzs[i]; if (entrySpecifiedArgs.containsKey(argName)) { argValues.add(entrySpecifiedArgs.get(argName)); } else if (argName.equals(Field.COMPANY_ID)) { argValues.add(companyId); } else if (argName.matches(".*Date.*")) { int x = argName.indexOf("Date") + 4; String dateKey = argName.substring(0, x); Calendar calendar = dateMap.get(dateKey); String calendarFieldName = argName.substring(x).toUpperCase(); if (calendarFieldName.equals("DAY")) { calendarFieldName = "DATE"; } int calendarFieldValue = (Integer) GetterUtil.getFieldValue(Calendar.class.getName(), calendarFieldName); argValues.add(calendar.get(calendarFieldValue)); } else if (entryStringFields.contains(argName)) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(content); } else if (entryMapFields.contains(argName)) { argName = argName.substring(0, (argName.length() - 3)); Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(StringUtil.getLocalizationMap(content)); } else if (argName.equals("friendlyURL")) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", "name"); String friendlyURL = StringUtil.getStringFieldValue(argName, context, entryTemplate); friendlyURL = StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(friendlyURL); argValues.add(friendlyURL); } else if (argName.equals(Field.GROUP_ID)) { argValues.add(groupId); } else if (argName.equals(getParentClassPKName())) { argValues.add(Long.valueOf(_getParentClassPK(requestContext))); } else if (argName.equals("locale")) { argValues.add(LocaleUtil.getDefault()); } else if (argName.equals("serviceContext")) { argValues.add(serviceContext); } else if (argName.equals(Field.USER_ID)) { argValues.add(userId); } else if (argName.equals(Field.USER_NAME)) { argValues.add(user.getFullName()); } else if (requestContext.contains(argName)) { argValues.add(requestContext.get(argName)); } else { Object argValue = null; try { Object object = argClazz.newInstance(); if (object instanceof String) { argValue = StringPool.BLANK; } } catch (InstantiationException e) { Type type = argClazz; if (type.equals(Boolean.TYPE)) { argValue = false; } else if (type.equals(Integer.TYPE)) { argValue = (int) 0; } else if (type.equals(List.class)) { argValue = new ArrayList<Object>(0); } else if (type.equals(Long.TYPE)) { argValue = (long) 0; } } argValues.add(argValue); } } return (Object[]) argValues.toArray(new Object[argValues.size()]); }
From source file:com.flexive.faces.renderer.FxSelectRenderer.java
/** * Convert select many values to given array class * * @param context faces context//from w w w . j a v a2 s.com * @param uiSelectMany select many component * @param arrayClass the array class * @param newValues new values to convert * @return converted values * @throws ConverterException on errors */ protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result; Converter converter; int len = (null != newValues ? newValues.length : 0); Class elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) return newValues; try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) return result; // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) return newValues; StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) valueStr.append(newValues[i]); else valueStr.append(' ').append(newValues[i]); } throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr)); } } if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } return result; }
From source file:rb.app.RBSystem.java
/** * @param output_index The index of the output we are interested in * @return the number of terms in the affine expansion of the specified output *//* w w w. ja va2s . c om*/ protected int get_Q_l(int output_index) { Method meth; try { // Get a reference to get_Q_l, which takes an int argument Class partypes[] = new Class[1]; partypes[0] = Integer.TYPE; meth = mAffineFnsClass.getMethod("get_Q_l", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for get_Q_l failed", nsme); } Integer Q_l; try { Object arglist[] = new Object[1]; arglist[0] = new Integer(output_index); Object Q_l_obj = meth.invoke(mTheta, arglist); Q_l = (Integer) Q_l_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return Q_l.intValue(); }
From source file:iing.uabc.edu.mx.persistencia.util.JSON.java
public static void stringifyArray(JsonGenerator generator, CollectionManager manager) { //Get size of the array to start stringifying elements //Note that the elements of this array has to be of the same class Collection collection = manager.getCollection(); Class elementType = manager.getElementClass(); System.out.println("Coleccion de tamanio " + collection.size()); int i = 0;//from w ww .j av a 2 s. c om //Read every element and transform it to a json array element string for (Iterator it = collection.iterator(); it.hasNext();) { Object element = it.next(); System.out.println("Elemento: [" + i + "], Valor: " + element); if (element == null) { //Set to null the property generator.writeNull(); continue; } //Is a String if (elementType == String.class) { generator.write(String.valueOf(element)); } //Is a Date else if (elementType == Date.class) { String date = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(element); generator.write(date); } //Is a integer else if (elementType == Integer.class || elementType == Integer.TYPE) { generator.write((int) element); } //Is a double else if (elementType == Double.class || elementType == Double.TYPE) { generator.write((double) element); } //Is boolean else if (elementType == Boolean.class || elementType == Boolean.TYPE) { generator.write((boolean) element); } //Is a collection (Not implemented) else if (element instanceof Collection) { // Class elementClass = manager.getCollectionElementType(keyName); // // System.out.println("Nueva Colleccion [] de clase: " // + elementClass.getSimpleName()); // // generator.writeStartArray(keyName); // // //Create new collection manager with the given class // CollectionManager collectionManager // = new CollectionManager((Collection) value, elementClass); // // generator.writeEnd(); } else { //Is a object... probably BeanManager objectManager = new BeanManager(element); System.out.println("Nuevo Objecto {}: " + element.getClass().getSimpleName()); generator.writeStartObject(); stringifyObject(generator, objectManager); generator.writeEnd(); } } }