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.cloudata.core.common.io.CObjectWritable.java
/** Write a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *///from w w w . ja v a 2 s.c o m public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf, boolean arrayComponent) throws IOException { if (instance == null) { // null instance = new NullInstance(declaredClass, conf); declaredClass = CWritable.class; arrayComponent = false; } if (!arrayComponent) { CUTF8.writeString(out, declaredClass.getName()); // always write declared //System.out.println("Write:declaredClass.getName():" + declaredClass.getName()); } if (declaredClass.isArray()) { // array int length = Array.getLength(instance); out.writeInt(length); //System.out.println("Write:length:" + length); if (declaredClass.getComponentType() == Byte.TYPE) { out.write((byte[]) instance); } else if (declaredClass.getComponentType() == ColumnValue.class) { //ColumnValue? Deserialize? ?? ? ?? ? . writeColumnValue(out, instance, declaredClass, conf, length); } else { for (int i = 0; i < length; i++) { writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf, !declaredClass.getComponentType().isArray()); } } } else if (declaredClass == String.class) { // String CUTF8.writeString(out, (String) instance); } else if (declaredClass.isPrimitive()) { // primitive type if (declaredClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instance).booleanValue()); } else if (declaredClass == Character.TYPE) { // char out.writeChar(((Character) instance).charValue()); } else if (declaredClass == Byte.TYPE) { // byte out.writeByte(((Byte) instance).byteValue()); } else if (declaredClass == Short.TYPE) { // short out.writeShort(((Short) instance).shortValue()); } else if (declaredClass == Integer.TYPE) { // int out.writeInt(((Integer) instance).intValue()); } else if (declaredClass == Long.TYPE) { // long out.writeLong(((Long) instance).longValue()); } else if (declaredClass == Float.TYPE) { // float out.writeFloat(((Float) instance).floatValue()); } else if (declaredClass == Double.TYPE) { // double out.writeDouble(((Double) instance).doubleValue()); } else if (declaredClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isEnum()) { // enum CUTF8.writeString(out, ((Enum) instance).name()); } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable if (instance.getClass() == declaredClass) { out.writeShort(TYPE_SAME); // ? ?? ? ?? //System.out.println("Write:TYPE_SAME:" + TYPE_SAME); } else { out.writeShort(TYPE_DIFF); //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF); CUTF8.writeString(out, instance.getClass().getName()); //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName()); } ((CWritable) instance).write(out); //System.out.println("Write:instance value"); } else { throw new IOException("Can't write: " + instance + " as " + declaredClass); } }
From source file:au.com.addstar.cellblock.configuration.AutoConfig.java
@SuppressWarnings("unchecked") public boolean load() { FileConfiguration yml = new YamlConfiguration(); try {/*from w w w .j a va 2 s .c om*/ if (mFile.getParentFile().exists() || mFile.getParentFile().mkdirs()) {// Make sure the file exists if (mFile.exists() || mFile.createNewFile()) { // Parse the config yml.load(mFile); for (Field field : getClass().getDeclaredFields()) { ConfigField configField = field.getAnnotation(ConfigField.class); if (configField == null) continue; String optionName = configField.name(); if (optionName.isEmpty()) optionName = field.getName(); field.setAccessible(true); String path = (configField.category().isEmpty() ? "" : configField.category() + ".") //$NON-NLS-2$ + optionName; if (!yml.contains(path)) { if (field.get(this) == null) throw new InvalidConfigurationException( path + " is required to be set! Info:\n" + configField.comment()); } else { // Parse the value if (field.getType().isArray()) { // Integer if (field.getType().getComponentType().equals(Integer.TYPE)) field.set(this, yml.getIntegerList(path).toArray(new Integer[0])); // Float else if (field.getType().getComponentType().equals(Float.TYPE)) field.set(this, yml.getFloatList(path).toArray(new Float[0])); // Double else if (field.getType().getComponentType().equals(Double.TYPE)) field.set(this, yml.getDoubleList(path).toArray(new Double[0])); // Long else if (field.getType().getComponentType().equals(Long.TYPE)) field.set(this, yml.getLongList(path).toArray(new Long[0])); // Short else if (field.getType().getComponentType().equals(Short.TYPE)) field.set(this, yml.getShortList(path).toArray(new Short[0])); // Boolean else if (field.getType().getComponentType().equals(Boolean.TYPE)) field.set(this, yml.getBooleanList(path).toArray(new Boolean[0])); // String else if (field.getType().getComponentType().equals(String.class)) { field.set(this, yml.getStringList(path).toArray(new String[0])); } else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$ } else if (List.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type List without specifying generic type for AutoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; if (type.equals(Integer.class)) field.set(this, newList((Class<? extends List<Integer>>) field.getType(), yml.getIntegerList(path))); else if (type.equals(Float.class)) field.set(this, newList((Class<? extends List<Float>>) field.getType(), yml.getFloatList(path))); else if (type.equals(Double.class)) field.set(this, newList((Class<? extends List<Double>>) field.getType(), yml.getDoubleList(path))); else if (type.equals(Long.class)) field.set(this, newList((Class<? extends List<Long>>) field.getType(), yml.getLongList(path))); else if (type.equals(Short.class)) field.set(this, newList((Class<? extends List<Short>>) field.getType(), yml.getShortList(path))); else if (type.equals(Boolean.class)) field.set(this, newList((Class<? extends List<Boolean>>) field.getType(), yml.getBooleanList(path))); else if (type.equals(String.class)) field.set(this, newList((Class<? extends List<String>>) field.getType(), yml.getStringList(path))); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$ + type.toString() + "> for AutoConfiguration"); } else if (Set.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type set without specifying generic type for AytoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; if (type.equals(Integer.class)) field.set(this, newSet((Class<? extends Set<Integer>>) field.getType(), yml.getIntegerList(path))); else if (type.equals(Float.class)) field.set(this, newSet((Class<? extends Set<Float>>) field.getType(), yml.getFloatList(path))); else if (type.equals(Double.class)) field.set(this, newSet((Class<? extends Set<Double>>) field.getType(), yml.getDoubleList(path))); else if (type.equals(Long.class)) field.set(this, newSet((Class<? extends Set<Long>>) field.getType(), yml.getLongList(path))); else if (type.equals(Short.class)) field.set(this, newSet((Class<? extends Set<Short>>) field.getType(), yml.getShortList(path))); else if (type.equals(Boolean.class)) field.set(this, newSet((Class<? extends Set<Boolean>>) field.getType(), yml.getBooleanList(path))); else if (type.equals(String.class)) field.set(this, newSet((Class<? extends Set<String>>) field.getType(), yml.getStringList(path))); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$ + type.toString() + "> for AutoConfiguration"); } else { // Integer if (field.getType().equals(Integer.TYPE)) field.setInt(this, yml.getInt(path)); // Float else if (field.getType().equals(Float.TYPE)) field.setFloat(this, (float) yml.getDouble(path)); // Double else if (field.getType().equals(Double.TYPE)) field.setDouble(this, yml.getDouble(path)); // Long else if (field.getType().equals(Long.TYPE)) field.setLong(this, yml.getLong(path)); // Short else if (field.getType().equals(Short.TYPE)) field.setShort(this, (short) yml.getInt(path)); // Boolean else if (field.getType().equals(Boolean.TYPE)) field.setBoolean(this, yml.getBoolean(path)); // ItemStack else if (field.getType().equals(ItemStack.class)) field.set(this, yml.getItemStack(path)); // String else if (field.getType().equals(String.class)) field.set(this, yml.getString(path)); else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$ } } } onPostLoad(); } else { Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.toString()); } } else { Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.getParentFile().toString()); } return true; } catch (IOException | InvalidConfigurationException | IllegalAccessException | IllegalArgumentException e) { e.printStackTrace(); return false; } }
From source file:org.cocoa4android.util.sbjson.SBJsonWriter.java
/** * /*ww w . j a v a 2 s . c o m*/ * @param clazz * @return */ public static boolean isNumber(Class<?> clazz) { return (clazz != null) && ((Byte.TYPE.isAssignableFrom(clazz)) || (Short.TYPE.isAssignableFrom(clazz)) || (Integer.TYPE.isAssignableFrom(clazz)) || (Long.TYPE.isAssignableFrom(clazz)) || (Float.TYPE.isAssignableFrom(clazz)) || (Double.TYPE.isAssignableFrom(clazz)) || (Number.class.isAssignableFrom(clazz))); }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Object getPrimitiveTypeForNull(Class<?> clazz) { if (clazz.equals(Long.TYPE)) { return 0L; } else if (clazz.equals(Integer.TYPE)) { return 0; } else if (clazz.equals(Float.TYPE)) { return 0.0F; } else if (clazz.equals(Double.TYPE)) { return 0.0D; } else if (clazz.equals(Boolean.TYPE)) { return false; }//w w w . ja v a2 s.c om return null; }
From source file:com.microsoft.tfs.client.common.ui.browser.BrowserFacade.java
private static void launchWithWorkbenchBrowserSupport(final URI uri, final String title, final String tooltip, final String browserId, final LaunchMode launchMode) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { URL url;//from w w w . jav a 2 s. c om try { url = uri.toURL(); } catch (final MalformedURLException e) { throw new RuntimeException(e); } /* * compute style int for IWorkbenchBrowserSupport.createBrowser */ int style = 0; if (launchMode == LaunchMode.EXTERNAL) { style |= (1 << 7); // IWorkbenchBrowserSupport.AS_EXTERNAL } else if (launchMode == LaunchMode.INTERNAL) { style |= (1 << 5); // IWorkbenchBrowserSupport.AS_EDITOR } /* * Method: IWorkbench#getBrowserSupport */ final Method getBrowserSupportMethod = IWorkbench.class.getDeclaredMethod("getBrowserSupport", //$NON-NLS-1$ new Class[] {}); /* * Interface: IWorkbenchBrowserSupport */ final Class iWorkbenchBrowserSupportInterface = getBrowserSupportMethod.getReturnType(); /* * Object: workbench browser support object */ final Object workbenchBrowserSupport = getBrowserSupportMethod.invoke(PlatformUI.getWorkbench(), (Object[]) null); /* * Method: IWorkbenchBrowserSupport#createBrowser(int, String, String, * String) */ final Method createBrowserMethod = iWorkbenchBrowserSupportInterface.getDeclaredMethod("createBrowser", //$NON-NLS-1$ new Class[] { Integer.TYPE, String.class, String.class, String.class }); /* * Interface: IWebBrowser */ final Class iWebBrowserInterface = createBrowserMethod.getReturnType(); /* * Object: web browser object */ final Object webBrowser = createBrowserMethod.invoke(workbenchBrowserSupport, new Object[] { new Integer(style), browserId, title, tooltip }); /* * Launch the browser: IWebBrowser#openURL */ iWebBrowserInterface.getDeclaredMethod("openURL", new Class[] //$NON-NLS-1$ { URL.class }).invoke(webBrowser, new Object[] { url }); }
From source file:net.jetrix.servlets.SettingsAction.java
/** * Update the settings field with the value in the request. The field is * set only if the value in the request is different from the current value. * If the value is empty the field is reset to the default value. * * @param settings the Settings object to update * @param field the name of the field to update * @param request the request containing the field value *//*w ww . j av a 2s. com*/ private void updateSettingsField(Settings settings, String field, HttpServletRequest request) { String value = request.getParameter(field); field = field.substring(0, 1).toUpperCase() + field.substring(1); try { if (value == null || "".equals(value.trim())) { // reset the field to the default value Method method = Settings.class.getMethod("setDefault" + field, Boolean.TYPE); method.invoke(settings, Boolean.TRUE); } else { // update the field if necessary Method getter = Settings.class.getMethod("get" + field); Object oldValue = getter.invoke(settings); // find the type of the field Class type = null; Object newValue = null; if (oldValue instanceof String) { newValue = value.trim(); type = String.class; } else if (oldValue instanceof Integer) { newValue = Integer.parseInt(value.trim()); type = Integer.TYPE; } else if (oldValue instanceof Boolean) { newValue = Boolean.valueOf(value); type = Boolean.TYPE; } if (!oldValue.equals(newValue)) { // set the new value Method setter = Settings.class.getMethod("set" + field, type); setter.invoke(settings, newValue); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:backup.namenode.NameNodeBackupServicePlugin.java
@Override public void start(Object service) { UserGroupInformation ugi;//from w w w. ja v a2s . c o m try { ugi = UserGroupInformation.getCurrentUser(); LOG.info("Starting NameNodeBackupServicePlugin with ugi {}", ugi); } catch (IOException e) { throw new RuntimeException(e); } Configuration conf = getConf(); NameNode namenode = (NameNode) service; BlockManager blockManager = namenode.getNamesystem().getBlockManager(); // This object is created here so that it's lifecycle follows the namenode try { restoreProcessor = SingletonManager.getManager(NameNodeRestoreProcessor.class).getInstance(namenode, () -> new NameNodeRestoreProcessor(getConf(), namenode, ugi)); LOG.info("NameNode Backup plugin setup using UGI {}", ugi); NameNodeBackupRPCImpl backupRPCImpl = new NameNodeBackupRPCImpl(blockManager); InetSocketAddress listenerAddress = namenode.getServiceRpcAddress(); int ipcPort = listenerAddress.getPort(); String bindAddress = listenerAddress.getAddress().getHostAddress(); int port = conf.getInt(DFS_BACKUP_NAMENODE_RPC_PORT_KEY, DFS_BACKUP_NAMENODE_RPC_PORT_DEFAULT); if (port == 0) { port = ipcPort + 1; } server = new RPC.Builder(conf).setBindAddress(bindAddress).setPort(port).setInstance(backupRPCImpl) .setProtocol(NameNodeBackupRPC.class).build(); ServiceAuthorizationManager serviceAuthorizationManager = server.getServiceAuthorizationManager(); serviceAuthorizationManager.refresh(conf, new BackupPolicyProvider()); server.start(); LOG.info("NameNode Backup RPC listening on {}", port); int httpPort = getConf().getInt(DFS_BACKUP_NAMENODE_HTTP_PORT_KEY, DFS_BACKUP_NAMENODE_HTTP_PORT_DEFAULT); if (httpPort != 0) { ClassLoader classLoader = getClassLoader(); if (classLoader != null) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { BackupWebService<Stats> stats = getBackupWebService(ugi, blockManager, restoreProcessor); // Have to setup classloader in thread context to get the static // files in the http server tp be setup correctly. Thread.currentThread().setContextClassLoader(classLoader); Class<?> backupStatusServerClass = classLoader.loadClass(BACKUP_WEB_BACKUP_WEB_SERVER); Object server = DuckTypeUtil.newInstance(backupStatusServerClass, new Class[] { Integer.TYPE, BackupWebService.class }, new Object[] { httpPort, stats }); httpServer = DuckTypeUtil.wrap(HttpServer.class, server); httpServer.start(); LOG.info("NameNode Backup HTTP listening on {}", httpPort); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } } else { LOG.info("NameNode Backup HTTP classes not found."); } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.excalibur.core.util.SystemUtils2.java
public static int chmod(String filename, int mode) { try {/* ww w .ja va 2 s.c o m*/ Class<?> fspClass = Class.forName("java.util.prefs.FileSystemPreferences"); Method chmodMethod = fspClass.getDeclaredMethod("chmod", String.class, Integer.TYPE); chmodMethod.setAccessible(true); return (Integer) chmodMethod.invoke(null, filename, mode); } catch (Throwable ex) { return -1; } }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
private static void initCompatibility() { try {/*from w ww .j av a 2s. c om*/ mActivity_overridePendingTransition = Activity.class.getMethod("overridePendingTransition", new Class[] { Integer.TYPE, Integer.TYPE }); /* success, this is a newer device */ } catch (NoSuchMethodException nsme) { /* failure, must be older device */ } }
From source file:org.gradle.internal.reflect.JavaReflectionUtil.java
public static Class<?> getWrapperTypeForPrimitiveType(Class<?> type) { if (type == Character.TYPE) { return Character.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Integer.TYPE) { return Integer.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Double.TYPE) { return Double.class; }/*from w w w. j a v a 2s . com*/ throw new IllegalArgumentException( String.format("Don't know the wrapper type for primitive type %s.", type)); }