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:nz.co.senanque.validationengine.ConvertUtils.java
public static Object convertToObject(Class<?> clazz) { if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { return new Long(0L); } else if (clazz.equals(Integer.TYPE)) { return new Integer(0); } else if (clazz.equals(Float.TYPE)) { return new Float(0F); } else if (clazz.equals(Double.TYPE)) { return new Double(0D); } else if (clazz.equals(Boolean.TYPE)) { return new Boolean(false); }/*from w w w. j a va 2s . c o m*/ } return null; }
From source file:org.piraso.server.spring.remoting.HttpInvokerReflectionHelper.java
public void prepareConnection(HttpURLConnection con, int contentLength) throws IOException { invokeMethod("prepareConnection", new Class<?>[] { HttpURLConnection.class, Integer.TYPE }, new Object[] { con, contentLength }); }
From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java
/** * ???????/*from w ww. ja v a 2 s . c o m*/ * @param klass ???klass?Class * @param filepath ? * @param sizeThreshold ?? * @param isFileNameBaseTime ???? * @return bean */ public static <T> Object upload(HttpServletRequest request, Class<T> klass, String filepath, int sizeThreshold, boolean isFileNameBaseTime) throws Exception { FileItemFactory fileItemFactory = null; if (sizeThreshold > 0) { File repository = new File(filepath); fileItemFactory = new DiskFileItemFactory(sizeThreshold, repository); } else { fileItemFactory = new DiskFileItemFactory(); } ServletFileUpload upload = new ServletFileUpload(fileItemFactory); ServletRequestContext requestContext = new ServletRequestContext(request); T bean = null; if (klass != null) { bean = klass.newInstance(); } // if (ServletFileUpload.isMultipartContent(requestContext)) { File parentDir = new File(filepath); List<FileItem> fileItemList = upload.parseRequest(requestContext); for (int i = 0; i < fileItemList.size(); i++) { FileItem item = fileItemList.get(i); // ?? if (item.isFormField()) { String paramName = item.getFieldName(); String paramValue = item.getString("UTF-8"); log.info("?" + paramName + "=" + paramValue); request.setAttribute(paramName, paramValue); // ?bean if (klass != null) { Field field = null; try { field = klass.getDeclaredField(paramName); if (field != null) { field.setAccessible(true); Class type = field.getType(); if (type == Integer.TYPE) { field.setInt(bean, Integer.valueOf(paramValue)); } else if (type == Double.TYPE) { field.setDouble(bean, Double.valueOf(paramValue)); } else if (type == Float.TYPE) { field.setFloat(bean, Float.valueOf(paramValue)); } else if (type == Boolean.TYPE) { field.setBoolean(bean, Boolean.valueOf(paramValue)); } else if (type == Character.TYPE) { field.setChar(bean, paramValue.charAt(0)); } else if (type == Long.TYPE) { field.setLong(bean, Long.valueOf(paramValue)); } else if (type == Short.TYPE) { field.setShort(bean, Short.valueOf(paramValue)); } else { field.set(bean, paramValue); } } } catch (NoSuchFieldException e) { log.info("" + klass.getName() + "?" + paramName); } } } // else { // <input type='file' name='xxx'> xxx String paramName = item.getFieldName(); log.info("?" + item.getSize()); if (sizeThreshold > 0) { if (item.getSize() > sizeThreshold) continue; } String clientFileName = item.getName(); int index = -1; // ?IE? if ((index = clientFileName.lastIndexOf("\\")) != -1) { clientFileName = clientFileName.substring(index + 1); } if (clientFileName == null || "".equals(clientFileName)) continue; String filename = null; log.info("" + paramName + "\t??" + clientFileName); if (isFileNameBaseTime) { filename = buildFileName(clientFileName); } else filename = clientFileName; request.setAttribute(paramName, filename); // ?bean if (klass != null) { Field field = null; try { field = klass.getDeclaredField(paramName); if (field != null) { field.setAccessible(true); field.set(bean, filename); } } catch (NoSuchFieldException e) { log.info("" + klass.getName() + "? " + paramName); continue; } } if (!parentDir.exists()) { parentDir.mkdirs(); } File newfile = new File(parentDir, filename); item.write(newfile); String serverPath = newfile.getPath(); log.info("?" + serverPath); } } } return bean; }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?://from w ww .j a va 2s .co m * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java
@Override public void injectMembers(T instance) { NuunProperty injectConfigAnnotation = null; // The annotation is actual NuunProperty.class if (clonedAnno.annotationType() == NuunProperty.class) { injectConfigAnnotation = field.getAnnotation(NuunProperty.class); } else { // The annotation has the NuunProperty annotation on it we proxy it injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno); }// ww w . ja va 2 s . c o m String configurationParameterName = injectConfigAnnotation.value(); // Pre verification // if (StringUtils.isEmpty(configurationParameterName)) { log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); throw new PluginException("Value for annotation %s on field %s can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); } if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) { throw new PluginException("\"%s\" must be in one properties file for field %s.", configurationParameterName, field.toGenericString()); } try { this.field.setAccessible(true); Class<?> type = field.getType(); if (type == Integer.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setInt(instance, configuration.getInt(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setInt(instance, injectConfigAnnotation.defaultIntValue()); } } else if (type == Integer.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Integer(configuration.getInt(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue())); } } else if (type == Boolean.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setBoolean(instance, configuration.getBoolean(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue()); } } else if (type == Boolean.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue())); } } else if (type == Short.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setShort(instance, configuration.getShort(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setShort(instance, injectConfigAnnotation.defaultShortValue()); } } else if (type == Short.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Short(configuration.getShort(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Short(injectConfigAnnotation.defaultShortValue())); } } else if (type == Byte.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setByte(instance, configuration.getByte(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setByte(instance, injectConfigAnnotation.defaultByteValue()); } } else if (type == Byte.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Byte(configuration.getByte(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue())); } } else if (type == Long.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setLong(instance, configuration.getLong(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setLong(instance, injectConfigAnnotation.defaultLongValue()); } } else if (type == Long.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Long(configuration.getLong(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Long(injectConfigAnnotation.defaultLongValue())); } } else if (type == Float.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setFloat(instance, configuration.getFloat(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setFloat(instance, injectConfigAnnotation.defaultFloatValue()); } } else if (type == Float.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Float(configuration.getFloat(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue())); } } else if (type == Double.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setDouble(instance, configuration.getDouble(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue()); } } else if (type == Double.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Double(configuration.getDouble(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue())); } } else if (type == Character.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setChar(instance, configuration.getString(configurationParameterName).charAt(0)); } } else if (type == Character.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Character(configuration.getString(configurationParameterName).charAt(0))); } } else { Object property = getProperty(configurationParameterName, injectConfigAnnotation); field.set(instance, property); } } catch (IllegalArgumentException ex) { log.error("Wrong argument or argument type during configuration injection", ex); } catch (IllegalAccessException ex) { log.error("Illegal access during configuration injection", ex); } catch (InstantiationException ex) { log.error("Impossible to instantiate value converter", ex); } finally { this.field.setAccessible(false); } }
From source file:net.yck.wkrdb.common.shared.PropertyConverter.java
/** * Performs a data type conversion from the specified value object to the * given target data class. If additional information is required for this * conversion, it is obtained from {@code DefaultConversionHandler.INSTANCE} * object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE, * etc), the value returned will use the wrapper type (Integer.class, * Boolean.class, etc).// w ww .j a v a2 s. c o m * * @param cls * the target class of the converted value * @param value * the value to convert * @return the converted value * @throws ConversionException * if the value is not compatible with the requested type */ public static Object to(Class<?> cls, Object value) throws ConversionException { if (cls.isInstance(value)) { return value; // no conversion needed } if (String.class.equals(cls)) { return String.valueOf(value); } if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) { return toBoolean(value); } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) { return toCharacter(value); } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) { if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) { return toInteger(value); } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) { return toLong(value); } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) { return toByte(value); } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) { return toShort(value); } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) { return toFloat(value); } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) { return toDouble(value); } else if (BigInteger.class.equals(cls)) { return toBigInteger(value); } else if (BigDecimal.class.equals(cls)) { return toBigDecimal(value); } } else if (Date.class.equals(cls)) { return toDate(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (Calendar.class.equals(cls)) { return toCalendar(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (URL.class.equals(cls)) { return toURL(value); } else if (Locale.class.equals(cls)) { return toLocale(value); } else if (isEnum(cls)) { return convertToEnum(cls, value); } else if (Color.class.equals(cls)) { return toColor(value); } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) { return toInternetAddress(value); } else if (InetAddress.class.isAssignableFrom(cls)) { return toInetAddress(value); } throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")" + " can't be converted to a " + cls.getName() + " object"); }
From source file:ch.rasc.wampspring.method.MethodParameterConverterTest.java
@Test(expected = ConversionFailedException.class) public void testTointException() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("intParam", Integer.TYPE); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.converter.convert(param, "str")).isEqualTo("str"); }
From source file:org.eclim.plugin.cdt.command.complete.CodeCompleteCommand.java
/** * {@inheritDoc}// w w w . j a va 2 s .c o m * @see AbstractCodeCompleteCommand#getCompletionProposals(CommandLine,String,String,int) */ @Override protected ICompletionProposal[] getCompletionProposals(CommandLine commandLine, String projectName, String file, int offset) throws Exception { IProject project = ProjectUtils.getProject(projectName); CEditor editor = new CEditor(); IEditorInput input = new FileEditorInput(ProjectUtils.getFile(project, file)); editor.init(new EclimEditorSite(), input); editor.setInput(input); CTextTools textTools = CUIPlugin.getDefault().getTextTools(); IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); CSourceViewerConfiguration config = new CSourceViewerConfiguration(textTools.getColorManager(), store, editor, textTools.getDocumentPartitioning()); CSourceViewer viewer = new CSourceViewer(EclimPlugin.getShell(), null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, CUIPlugin.getDefault().getPreferenceStore()); viewer.setDocument(ProjectUtils.getDocument(project, file)); ContentAssistant ca = (ContentAssistant) config.getContentAssistant(viewer); Method computeCompletionProposals = ContentAssistant.class.getDeclaredMethod("computeCompletionProposals", ITextViewer.class, Integer.TYPE); computeCompletionProposals.setAccessible(true); return (ICompletionProposal[]) computeCompletionProposals.invoke(ca, viewer, offset); }
From source file:com.github.jknack.handlebars.helper.MethodHelper.java
/** * Wrap (if possible) a primitive type to their wrapper. * * @param type The candidate type./*from w w w .j a va 2s . c o m*/ * @return A wrapper for the primitive type or the original type. */ private static Class<?> wrap(final Class<?> type) { if (type.isPrimitive()) { if (type == Integer.TYPE) { return Integer.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Character.TYPE) { return Character.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } } return type; }
From source file:org.evosuite.testcase.fm.MethodDescriptor.java
private String initMatchers(GenericMethod method, GenericClass retvalType) { String matchers = ""; Type[] types = method.getParameterTypes(); List<GenericClass> parameterClasses = method.getParameterClasses(); for (int i = 0; i < types.length; i++) { if (i > 0) { matchers += " , "; }/*from w w w .ja v a2 s. c om*/ Type type = types[i]; GenericClass genericParameter = parameterClasses.get(i); if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { matchers += "anyInt()"; } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { matchers += "anyLong()"; } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { matchers += "anyBoolean()"; } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { matchers += "anyDouble()"; } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { matchers += "anyFloat()"; } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { matchers += "anyShort()"; } else if (type.equals(Character.TYPE) || type.equals(Character.class)) { matchers += "anyChar()"; } else if (type.equals(String.class)) { matchers += "anyString()"; } else { if (type.getTypeName().equals(Object.class.getName())) { /* Ideally here we should use retvalType to understand if the target class is using generics and if this method parameters would need to be handled accordingly. However, doing it does not seem so trivial... so a current workaround is that, when a method takes an Object as input (which is that would happen in case of Generics T), we use the undetermined "any()" */ matchers += "any()"; } else { if (type instanceof Class) { matchers += "any(" + ((Class) type).getCanonicalName() + ".class)"; } else { //what to do here? is it even possible? matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)"; // matchers += "any(" + type.getTypeName() + ".class)"; } } } } return matchers; }