Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

In this page you can find the example usage for java.lang Boolean TYPE.

Prototype

Class TYPE

To view the source code for java.lang Boolean TYPE.

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!/*  w w  w  .j a  v a 2 s. co  m*/
 *
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public Object get(String name) {
    Object value = dynaValues.get(name);

    if (value != null) {
        return value;
    }

    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }

    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

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  .  j  a va  2  s .  c o m*/

        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;
}

From source file:org.primeframework.mvc.parameter.convert.converters.BooleanConverterTest.java

@Test
public void toStrings() {
    GlobalConverter converter = new BooleanConverter(new MockConfiguration());
    String str = converter.convertToString(Boolean.class, null, "testExpr", null);
    assertNull(str);//from w ww  .ja  va 2 s  .c  o m

    str = converter.convertToString(Boolean.class, null, "testExpr", Boolean.TRUE);
    assertEquals(str, "true");

    str = converter.convertToString(Boolean.TYPE, null, "testExpr", Boolean.TRUE);
    assertEquals(str, "true");

    str = converter.convertToString(Boolean.class, null, "testExpr", Boolean.FALSE);
    assertEquals(str, "false");

    str = converter.convertToString(Boolean.TYPE, null, "testExpr", Boolean.FALSE);
    assertEquals(str, "false");
}

From source file:com.superyu.slidingmenu.SlidingMenu02.java

/**
 **??//from   w  w  w .ja  va 2  s  .  c o m
 **/

@Override
public boolean onMenuOpened(int featureId, Menu menu) {

    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    return super.onMenuOpened(featureId, menu);
}

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

private OpenType detectType(final Class type) {
    if ((Long.class == type) || (Long.TYPE == type)) {
        return SimpleType.LONG;
    } else if ((Integer.class == type) || (Integer.TYPE == type)) {
        return SimpleType.INTEGER;
    } else if ((Double.class == type) || (Double.TYPE == type)) {
        return SimpleType.DOUBLE;
    } else if ((Float.class == type) || (Float.TYPE == type)) {
        return SimpleType.FLOAT;
    } else if ((Byte.class == type) || (Byte.TYPE == type)) {
        return SimpleType.BYTE;
    } else if ((Short.class == type) || (Short.TYPE == type)) {
        return SimpleType.SHORT;
    } else if ((Boolean.class == type) || (Boolean.TYPE == type)) {
        return SimpleType.BOOLEAN;
    } else if (BigDecimal.class == type) {
        return SimpleType.BIGDECIMAL;
    } else if (BigInteger.class == type) {
        return SimpleType.BIGINTEGER;
    } else if ((Character.class == type) || (Character.TYPE == type)) {
        return SimpleType.CHARACTER;
    }/*from  ww w.  j  a v  a 2 s .  c  o m*/

    // last fallback to strings
    if (isConvertibleToString(type)) {
        return SimpleType.STRING;
    }

    // give up
    return null;
}

From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java

/**
 * ???????/*from   w w w  .  jav  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:org.openTwoFactor.clientExt.net.sf.ezmorph.primitive.BooleanMorpher.java

public Class morphsTo() {
    return Boolean.TYPE;
}

From source file:org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogWriter.java

@Override
public void init(FileSystem fs, Path path, Configuration conf, boolean overwritable) throws IOException {
    super.init(fs, path, conf, overwritable);
    boolean compress = initializeCompressionContext(conf, path);
    // Create a SF.Writer instance.
    try {//from  ww w . j  a va 2 s.  c  o m
        // reflection for a version of SequenceFile.createWriter that doesn't
        // automatically create the parent directory (see HBASE-2312)
        this.writer = (SequenceFile.Writer) SequenceFile.class
                .getMethod("createWriter",
                        new Class[] { FileSystem.class, Configuration.class, Path.class, Class.class,
                                Class.class, Integer.TYPE, Short.TYPE, Long.TYPE, Boolean.TYPE,
                                CompressionType.class, CompressionCodec.class, Metadata.class })
                .invoke(null,
                        new Object[] { fs, conf, path, HLogKey.class, WALEdit.class,
                                Integer.valueOf(FSUtils.getDefaultBufferSize(fs)),
                                Short.valueOf((short) conf.getInt("hbase.regionserver.hlog.replication",
                                        FSUtils.getDefaultReplication(fs, path))),
                                Long.valueOf(conf.getLong("hbase.regionserver.hlog.blocksize",
                                        FSUtils.getDefaultBlockSize(fs, path))),
                                Boolean.valueOf(false) /*createParent*/, SequenceFile.CompressionType.NONE,
                                new DefaultCodec(), createMetadata(conf, compress) });
    } catch (InvocationTargetException ite) {
        // function was properly called, but threw it's own exception
        throw new IOException(ite.getCause());
    } catch (Exception e) {
        // ignore all other exceptions. related to reflection failure
    }

    // if reflection failed, use the old createWriter
    if (this.writer == null) {
        LOG.debug("new createWriter -- HADOOP-6840 -- not available");
        this.writer = SequenceFile.createWriter(fs, conf, path, HLogKey.class, WALEdit.class,
                FSUtils.getDefaultBufferSize(fs),
                (short) conf.getInt("hbase.regionserver.hlog.replication",
                        FSUtils.getDefaultReplication(fs, path)),
                conf.getLong("hbase.regionserver.hlog.blocksize", FSUtils.getDefaultBlockSize(fs, path)),
                SequenceFile.CompressionType.NONE, new DefaultCodec(), null, createMetadata(conf, compress));
    } else {
        if (LOG.isTraceEnabled())
            LOG.trace("Using new createWriter -- HADOOP-6840");
    }

    this.writer_out = getSequenceFilePrivateFSDataOutputStreamAccessible();
    if (LOG.isTraceEnabled())
        LOG.trace("Path=" + path + ", compression=" + compress);
}

From source file:org.wrml.runtime.syntax.DefaultSyntaxLoader.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public final <T> T parseSyntacticText(final String text, final java.lang.reflect.Type targetType) {

    if (text == null) {
        return null;
    }//from  w  ww.ja  va  2  s  .  c  o m

    if (targetType == null || targetType.equals(String.class)) {
        return (T) text;
    }

    if (targetType.equals(Integer.TYPE) || targetType.equals(Integer.class)) {
        return (T) new Integer(text);
    }

    if (targetType.equals(Boolean.TYPE) || targetType.equals(Boolean.class)) {
        return (T) (text.equals("true") ? Boolean.TRUE : Boolean.FALSE);
    }

    if (targetType.equals(Long.TYPE) || targetType.equals(Long.class)) {
        return (T) new Long(text);
    }

    if (targetType.equals(Double.TYPE) || targetType.equals(Double.class)) {
        return (T) new Double(text);
    }

    if (TypeUtils.isAssignable(targetType, Enum.class)) {
        return (T) Enum.valueOf((Class<Enum>) targetType, text);
    }

    if (targetType instanceof Class<?>) {

        final SyntaxHandler<?> syntaxHandler = getSyntaxHandler((Class<?>) targetType);

        if (syntaxHandler != null) {
            return (T) syntaxHandler.parseSyntacticText(text);
        }
    }

    throw new SyntaxRegistryException(
            "Failed to transform text: \"" + text + "\" value to target type: " + targetType, null, this);

}

From source file:org.openmrs.module.webservices.helper.ModuleFactoryWrapper.java

/**
 * It's hacky method to workaround the fact that before 2.x platform
 * {@link WebModuleUtil#stopModule(Module, ServletContext, boolean)} was private. It is
 * essential to support uploading modules 1.x platform via REST api
 *//*from   w w w . j a  v a2  s.  c  o  m*/
public void stopModuleSkipRefresh(Module module, ServletContext servletContext) {
    ModuleFactory.stopModule(module);
    try {
        Method stopModule = WebModuleUtil.class.getDeclaredMethod("stopModule", Module.class,
                ServletContext.class, Boolean.TYPE);
        stopModule.setAccessible(true);
        stopModule.invoke(null, module, servletContext, true);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(STOP_MODULE_SKIP_REFRESH_EXCEPTION_MESSAGE, e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(STOP_MODULE_SKIP_REFRESH_EXCEPTION_MESSAGE, e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(STOP_MODULE_SKIP_REFRESH_EXCEPTION_MESSAGE, e);
    }
}