Example usage for java.lang Double TYPE

List of usage examples for java.lang Double TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type double .

Usage

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

private void loadGeneralParameters(final Element gaSettingsElement) throws WizardLoadingException {
    NodeList nl = gaSettingsElement.getElementsByTagName(POPULATION_SIZE);
    if (nl != null && nl.getLength() > 0) {
        final Element element = (Element) nl.item(0);
        final NodeList content = element.getChildNodes();
        if (content == null || content.getLength() == 0) {
            throw new WizardLoadingException(true, "missing content at node: " + POPULATION_SIZE);
        }/*from   w w  w  .  j ava  2 s  .c o m*/

        final String populationSizeStr = ((Text) content.item(0)).getNodeValue().trim();
        try {
            populationSize = Integer.parseInt(populationSizeStr);
        } catch (final NumberFormatException e) {
            throw new WizardLoadingException(true, "invalid content (" + populationSizeStr + ") at node: "
                    + POPULATION_SIZE + " (expected: integer number)");
        }
    } else {
        throw new WizardLoadingException(true, "missing node: " + POPULATION_SIZE);
    }

    nl = gaSettingsElement.getElementsByTagName(POPULATION_RANDOM_SEED);
    if (nl != null && nl.getLength() > 0) {
        final Element element = (Element) nl.item(0);
        final NodeList content = element.getChildNodes();
        if (content == null || content.getLength() == 0) {
            throw new WizardLoadingException(true, "missing content at node: " + POPULATION_RANDOM_SEED);
        }

        final String populationGenerationSeedStr = ((Text) content.item(0)).getNodeValue().trim();
        try {
            populationGenerationSeed = Integer.parseInt(populationGenerationSeedStr);
        } catch (final NumberFormatException e) {
            throw new WizardLoadingException(true, "invalid content (" + populationGenerationSeedStr
                    + ") at node: " + POPULATION_RANDOM_SEED + " (expected: integer number)");
        }
    } else {
        throw new WizardLoadingException(true, "missing node: " + POPULATION_RANDOM_SEED);
    }

    nl = gaSettingsElement.getElementsByTagName(FIX_NUMBER_OF_GENERATIONS);
    if (nl != null && nl.getLength() > 0) {
        final Element element = (Element) nl.item(0);
        final NodeList content = element.getChildNodes();
        if (content == null || content.getLength() == 0) {
            throw new WizardLoadingException(true, "missing content at node: " + FIX_NUMBER_OF_GENERATIONS);
        }

        final String fixNumberOfGenerationsStr = ((Text) content.item(0)).getNodeValue().trim();
        fixNumberOfGenerations = Boolean.parseBoolean(fixNumberOfGenerationsStr);
    } else {
        throw new WizardLoadingException(true, "missing node: " + FIX_NUMBER_OF_GENERATIONS);
    }

    if (fixNumberOfGenerations) {
        nl = gaSettingsElement.getElementsByTagName(NUMBER_OF_GENERATIONS);
        if (nl != null && nl.getLength() > 0) {
            final Element element = (Element) nl.item(0);
            final NodeList content = element.getChildNodes();
            if (content == null || content.getLength() == 0) {
                throw new WizardLoadingException(true, "missing content at node: " + NUMBER_OF_GENERATIONS);
            }

            final String numberOfGenerationsStr = ((Text) content.item(0)).getNodeValue().trim();
            try {
                numberOfGenerations = Integer.parseInt(numberOfGenerationsStr);
            } catch (final NumberFormatException e) {
                throw new WizardLoadingException(true, "invalid content (" + numberOfGenerationsStr
                        + ") at node: " + NUMBER_OF_GENERATIONS + " (expected: integer number)");
            }
        } else {
            throw new WizardLoadingException(true, "missing node: " + NUMBER_OF_GENERATIONS);
        }
    } else {
        nl = gaSettingsElement.getElementsByTagName(FITNESS_LIMIT_CRITERION);
        if (nl != null && nl.getLength() > 0) {
            final Element element = (Element) nl.item(0);
            final NodeList content = element.getChildNodes();
            if (content == null || content.getLength() == 0) {
                throw new WizardLoadingException(true, "missing content at node: " + FITNESS_LIMIT_CRITERION);
            }

            final String fitnessLimitCriterionStr = ((Text) content.item(0)).getNodeValue().trim();
            try {
                fitnessLimitCriterion = Double.parseDouble(fitnessLimitCriterionStr);
            } catch (final NumberFormatException e) {
                throw new WizardLoadingException(true, "invalid content (" + fitnessLimitCriterionStr
                        + ") at node: " + FITNESS_LIMIT_CRITERION + " (expected: real number)");
            }
        } else {
            throw new WizardLoadingException(true, "missing node: " + FITNESS_LIMIT_CRITERION);
        }
    }

    nl = gaSettingsElement.getElementsByTagName(OPTIMIZATION_DIRECTION);
    if (nl != null && nl.getLength() > 0) {
        final Element element = (Element) nl.item(0);
        final NodeList content = element.getChildNodes();
        if (content == null || content.getLength() == 0) {
            throw new WizardLoadingException(true, "missing content at node: " + OPTIMIZATION_DIRECTION);
        }

        final String optimizationDirectionStr = ((Text) content.item(0)).getNodeValue().trim();
        try {
            optimizationDirection = FitnessFunctionDirection.valueOf(optimizationDirectionStr);
        } catch (final IllegalArgumentException e) {
            throw new WizardLoadingException(true, "invalid content (" + optimizationDirectionStr
                    + ") at node: " + OPTIMIZATION_DIRECTION + " (expected: MINIMIZE or MAXIMIZE)");
        }
    } else {
        throw new WizardLoadingException(true, "missing node: " + OPTIMIZATION_DIRECTION);
    }

    nl = gaSettingsElement.getElementsByTagName(FITNESS_FUNCTION);
    if (nl != null && nl.getLength() > 0) {
        final Element element = (Element) nl.item(0);

        String fitnessFunctionAlias = element.getAttribute(WizardSettingsManager.ALIAS);

        final NodeList content = element.getChildNodes();
        if (content == null || content.getLength() == 0) {
            throw new WizardLoadingException(true, "missing content at node: " + FITNESS_FUNCTION);
        }

        final String fitnessFunctionStr = ((Text) content.item(0)).getNodeValue().trim();
        fitnessFunctionAlias = (fitnessFunctionAlias != null && !fitnessFunctionAlias.trim().isEmpty())
                ? fitnessFunctionAlias.trim()
                : fitnessFunctionStr;
        selectedFunction = new RecordableInfo(fitnessFunctionAlias, Double.TYPE, fitnessFunctionStr); // dummy object to store accessible name
    } else {
        throw new WizardLoadingException(true, "missing node: " + FITNESS_FUNCTION);
    }
}

From source file:org.apache.openjpa.meta.FieldMetaData.java

/**
 * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.8 
 *//* ww  w  .  j  a v a 2 s . c  o  m*/
private Class<?> unbox(Class<?> sourceType) {
    if (sourceType == java.lang.Boolean.class) {
        return java.lang.Boolean.TYPE;
    } else if (sourceType == java.lang.Byte.class) {
        return java.lang.Byte.TYPE;
    } else if (sourceType == java.lang.Short.class) {
        return java.lang.Short.TYPE;
    } else if (sourceType == java.lang.Character.class) {
        return java.lang.Character.TYPE;
    } else if (sourceType == java.lang.Integer.class) {
        return java.lang.Integer.TYPE;
    } else if (sourceType == java.lang.Long.class) {
        return java.lang.Long.TYPE;
    } else if (sourceType == java.lang.Float.class) {
        return java.lang.Float.TYPE;
    } else if (sourceType == java.lang.Double.class) {
        return java.lang.Double.TYPE;
    } else {
        return null;
    }
}

From source file:org.apache.openjpa.meta.FieldMetaData.java

/**
 * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.7 
 *///from w ww.j  av  a 2s .co  m
private Class<?> box(Class<?> sourceType) {
    if (sourceType.isPrimitive()) {
        if (sourceType == java.lang.Boolean.TYPE) {
            return java.lang.Boolean.class;
        } else if (sourceType == java.lang.Byte.TYPE) {
            return java.lang.Byte.class;
        } else if (sourceType == java.lang.Short.TYPE) {
            return java.lang.Short.class;
        } else if (sourceType == java.lang.Character.TYPE) {
            return java.lang.Character.class;
        } else if (sourceType == java.lang.Integer.TYPE) {
            return java.lang.Integer.class;
        } else if (sourceType == java.lang.Long.TYPE) {
            return java.lang.Long.class;
        } else if (sourceType == java.lang.Float.TYPE) {
            return java.lang.Float.class;
        } else if (sourceType == java.lang.Double.TYPE) {
            return java.lang.Double.class;
        }
        return null; // Should never be reached because all primitives are accounted for above.
    } else {
        throw new IllegalArgumentException("Cannot box a type that is not a primitive.");
    }
}

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.FileHarvester.java

private void initializeTika(HarvestContext context, SourcePojo source) {
    AutoDetectParser autoDetectParser = new AutoDetectParser();

    if (null != source.getFileConfig().XmlRootLevelValues) {
        for (String s : source.getFileConfig().XmlRootLevelValues) {
            int separator = s.indexOf(':');
            String jsonStr = s.substring(separator + 1);

            if (separator > 0) {
                String mediaType = s.substring(0, separator);
                if (mediaType.equalsIgnoreCase("output")) { //special case, just going to configure output
                    if (jsonStr.equalsIgnoreCase("xml") || jsonStr.equalsIgnoreCase("xhtml")) {
                        _tikaXmlFormatWriter = new StringWriter();
                        _tikaOutputFormat = getTransformerHandler("xml", _tikaXmlFormatWriter);
                        _tikaOutputParseContext = new ParseContext();
                    }//from  ww  w  .  j  a v  a  2  s  . co m
                    if (jsonStr.equalsIgnoreCase("html")) {
                        _tikaXmlFormatWriter = new StringWriter();
                        _tikaOutputFormat = getTransformerHandler("html", _tikaXmlFormatWriter);
                        _tikaOutputParseContext = new ParseContext();
                    }
                    continue;
                } //TESTED
                else if (mediaType.equalsIgnoreCase("bypass")) {
                    Map<MediaType, Parser> parsers = autoDetectParser.getParsers();
                    parsers.put(MediaType.parse(jsonStr), new TXTParser());
                    autoDetectParser.setParsers(parsers);
                    continue;
                }
                // Try to get media type parser:

                Parser p = autoDetectParser.getParsers().get(MediaType.parse(mediaType));
                while (p instanceof CompositeParser) {
                    p = ((CompositeParser) p).getParsers().get(MediaType.parse(mediaType));
                }
                if (null == p) {
                    context.getHarvestStatus().logMessage(
                            "Failed to find application type " + mediaType + " in tika option: " + s, true);
                    continue;
                } //TESTED

                // Get JSON objects and try to apply

                try {
                    JsonElement jsonObj = new JsonParser().parse(jsonStr);
                    for (Map.Entry<String, JsonElement> keyVal : jsonObj.getAsJsonObject().entrySet()) {
                        if (keyVal.getValue().getAsJsonPrimitive().isBoolean()) { //boolean
                            try {
                                Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.class);
                                method.invoke(p,
                                        (Boolean) keyVal.getValue().getAsJsonPrimitive().getAsBoolean());
                            } catch (Exception e) {
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsBoolean());
                                } catch (Exception e2) {
                                    context.getHarvestStatus().logMessage(
                                            "Failed to invoke " + keyVal.getKey() + " in tika option: " + s,
                                            true);
                                    continue;
                                } //TESTED
                            }
                        } //TESTED
                        if (keyVal.getValue().getAsJsonPrimitive().isString()) { //string
                            try {
                                Method method = p.getClass().getMethod(keyVal.getKey(), String.class);
                                method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsString());
                            } catch (Exception e) {
                                context.getHarvestStatus().logMessage(
                                        "Failed to invoke " + keyVal.getKey() + " in tika option: " + s, true);
                                continue;
                            }
                        } //TESTED (cut and paste)
                        if (keyVal.getValue().getAsJsonPrimitive().isNumber()) { // number: int/long/double
                            // Loads of options: Integer.class, Integer.TYPE, Long.class, Long.TYPE, Double.long, Double.TYPE
                            boolean invoked = false;
                            if (!invoked) { // Int.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Integer.class);
                                    method.invoke(p,
                                            (Integer) keyVal.getValue().getAsJsonPrimitive().getAsInt());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Int.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Integer.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsInt());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Long.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Long.class);
                                    method.invoke(p, (Long) keyVal.getValue().getAsJsonPrimitive().getAsLong());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Long.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Long.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsLong());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Double.class
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Double.class);
                                    method.invoke(p,
                                            (Double) keyVal.getValue().getAsJsonPrimitive().getAsDouble());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                            if (!invoked) { // Double.type
                                try {
                                    Method method = p.getClass().getMethod(keyVal.getKey(), Double.TYPE);
                                    method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsDouble());
                                    invoked = true;
                                } catch (Exception e) {
                                }
                            }
                        } //TOTEST (all the different options)

                    } //(end loop over options)
                } catch (Exception e) {
                    context.getHarvestStatus().logMessage("Failed to parse JSON in tika option: " + s, true);
                } //TESTED
            } else {
                context.getHarvestStatus().logMessage("Failed to parse tika option: " + s, true);
            } //TESTED

        } //TESTED
    } //(end if has options)

    _tika = new Tika(TikaConfig.getDefaultConfig().getDetector(), autoDetectParser);

}

From source file:org.apache.openjpa.meta.FieldMetaData.java

/**
 * @return true iff {@sourceType} can be converted by a widening primitive conversion
 *  following Java Language Specification, 3rd Ed, s5.1.2 
 *//*from w  ww.j  a  v  a2s.c  om*/
private boolean isConvertibleToByWideningPrimitive(Class<?> sourceType, Class<?> destType) {
    // Widening conversion following Java Language Specification, s5.1.2.
    if (sourceType == java.lang.Byte.TYPE) {
        return destType == java.lang.Short.TYPE || destType == java.lang.Integer.TYPE
                || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE
                || destType == java.lang.Double.TYPE;
    } else if (sourceType == java.lang.Short.TYPE) {
        return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE
                || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE;
    } else if (sourceType == java.lang.Character.TYPE) {
        return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE
                || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE;
    } else if (sourceType == java.lang.Integer.TYPE) {
        return destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE
                || destType == java.lang.Double.TYPE;
    } else if (sourceType == java.lang.Long.TYPE) {
        return destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE;
    } else if (sourceType == java.lang.Float.TYPE) {
        return destType == java.lang.Double.TYPE;
    }
    return false;
}

From source file:org.apache.myfaces.ov2021.application.ApplicationImpl.java

@SuppressWarnings("unchecked")
private Converter internalCreateConverter(final Class<?> targetClass) {
    // Locate a Converter registered for the target class itself.
    Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass);

    // Locate a Converter registered for interfaces that are
    // implemented by the target class (directly or indirectly).
    // Skip if class is String, for performance reasons 
    // (save 3 additional lookups over a concurrent map per request). 
    if (converterClassOrClassName == null && !String.class.equals(targetClass)) {
        final Class<?> interfaces[] = targetClass.getInterfaces();
        if (interfaces != null) {
            for (int i = 0, len = interfaces.length; i < len; i++) {
                // search all superinterfaces for a matching converter,
                // create it
                final Converter converter = internalCreateConverter(interfaces[i]);
                if (converter != null) {
                    return converter;
                }/*ww w .ja v a  2 s .  c o  m*/
            }
        }
    }

    // Get EnumConverter for enum classes with no special converter, check
    // here as recursive call with java.lang.Enum will not work
    if (converterClassOrClassName == null && targetClass.isEnum()) {
        converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class);
    }

    if (converterClassOrClassName != null) {
        try {
            Class<? extends Converter> converterClass = null;
            if (converterClassOrClassName instanceof Class<?>) {
                converterClass = (Class<? extends Converter>) converterClassOrClassName;
            } else if (converterClassOrClassName instanceof String) {
                converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName);
                _converterTargetClassToConverterClassMap.put(targetClass, converterClass);
            } else {
                //object stored in the map for this id is an invalid type.  remove it and return null
                _converterTargetClassToConverterClassMap.remove(targetClass);
            }

            Converter converter = null;

            // check cached constructor information
            if (!_noArgConstructorConverterClasses.contains(converterClass)) {
                // the converter class either supports the one-arg constructor
                // or has never been processed before
                try {
                    // look for a constructor that takes a single Class object
                    // See JSF 1.2 javadoc for Converter
                    Constructor<? extends Converter> constructor = converterClass
                            .getConstructor(new Class[] { Class.class });

                    converter = constructor.newInstance(new Object[] { targetClass });
                } catch (Exception e) {
                    // the constructor does not exist
                    // add the class to the no-arg constructor classes cache
                    _noArgConstructorConverterClasses.add(converterClass);

                    // use no-arg constructor
                    converter = converterClass.newInstance();
                }
            } else {
                // use no-arg constructor
                converter = converterClass.newInstance();
            }

            setConverterProperties(converterClass, converter);

            return converter;
        } catch (Exception e) {
            log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e);
            throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(),
                    e);
        }
    }

    // locate converter for primitive types
    if (targetClass == Long.TYPE) {
        return internalCreateConverter(Long.class);
    } else if (targetClass == Boolean.TYPE) {
        return internalCreateConverter(Boolean.class);
    } else if (targetClass == Double.TYPE) {
        return internalCreateConverter(Double.class);
    } else if (targetClass == Byte.TYPE) {
        return internalCreateConverter(Byte.class);
    } else if (targetClass == Short.TYPE) {
        return internalCreateConverter(Short.class);
    } else if (targetClass == Integer.TYPE) {
        return internalCreateConverter(Integer.class);
    } else if (targetClass == Float.TYPE) {
        return internalCreateConverter(Float.class);
    } else if (targetClass == Character.TYPE) {
        return internalCreateConverter(Character.class);
    }

    // Locate a Converter registered for the superclass (if any) of the
    // target class,
    // recursively working up the inheritance hierarchy.
    Class<?> superClazz = targetClass.getSuperclass();

    return superClazz != null ? internalCreateConverter(superClazz) : null;

}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@SuppressWarnings("unchecked")
private Converter internalCreateConverter(final Class<?> targetClass) {
    // Locate a Converter registered for the target class itself.
    Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass);

    // Locate a Converter registered for interfaces that are
    // implemented by the target class (directly or indirectly).
    // Skip if class is String, for performance reasons 
    // (save 3 additional lookups over a concurrent map per request). 
    if (converterClassOrClassName == null && !String.class.equals(targetClass)) {
        final Class<?> interfaces[] = targetClass.getInterfaces();
        if (interfaces != null) {
            for (int i = 0, len = interfaces.length; i < len; i++) {
                // search all superinterfaces for a matching converter,
                // create it
                final Converter converter = internalCreateConverter(interfaces[i]);
                if (converter != null) {
                    return converter;
                }//from   w  w w.j av a  2s  . co  m
            }
        }
    }

    // Get EnumConverter for enum classes with no special converter, check
    // here as recursive call with java.lang.Enum will not work
    if (converterClassOrClassName == null && targetClass.isEnum()) {
        converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class);
    }

    if (converterClassOrClassName != null) {
        try {
            Class<? extends Converter> converterClass = null;
            if (converterClassOrClassName instanceof Class<?>) {
                converterClass = (Class<? extends Converter>) converterClassOrClassName;
            } else if (converterClassOrClassName instanceof String) {
                converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName);
                _converterTargetClassToConverterClassMap.put(targetClass, converterClass);
            } else {
                //object stored in the map for this id is an invalid type.  remove it and return null
                _converterTargetClassToConverterClassMap.remove(targetClass);
            }

            Converter converter = null;

            // check cached constructor information
            if (!_noArgConstructorConverterClasses.contains(converterClass)) {
                // the converter class either supports the one-arg constructor
                // or has never been processed before
                try {
                    // look for a constructor that takes a single Class object
                    // See JSF 1.2 javadoc for Converter
                    Constructor<? extends Converter> constructor = converterClass
                            .getConstructor(new Class[] { Class.class });

                    converter = constructor.newInstance(new Object[] { targetClass });
                } catch (Exception e) {
                    // the constructor does not exist
                    // add the class to the no-arg constructor classes cache
                    _noArgConstructorConverterClasses.add(converterClass);

                    // use no-arg constructor
                    converter = createConverterInstance(converterClass);
                }
            } else {
                // use no-arg constructor
                converter = createConverterInstance(converterClass);
            }

            setConverterProperties(converterClass, converter);

            return converter;
        } catch (Exception e) {
            log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e);
            throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(),
                    e);
        }
    }

    // locate converter for primitive types
    if (targetClass == Long.TYPE) {
        return internalCreateConverter(Long.class);
    } else if (targetClass == Boolean.TYPE) {
        return internalCreateConverter(Boolean.class);
    } else if (targetClass == Double.TYPE) {
        return internalCreateConverter(Double.class);
    } else if (targetClass == Byte.TYPE) {
        return internalCreateConverter(Byte.class);
    } else if (targetClass == Short.TYPE) {
        return internalCreateConverter(Short.class);
    } else if (targetClass == Integer.TYPE) {
        return internalCreateConverter(Integer.class);
    } else if (targetClass == Float.TYPE) {
        return internalCreateConverter(Float.class);
    } else if (targetClass == Character.TYPE) {
        return internalCreateConverter(Character.class);
    }

    // Locate a Converter registered for the superclass (if any) of the
    // target class,
    // recursively working up the inheritance hierarchy.
    Class<?> superClazz = targetClass.getSuperclass();

    return superClazz != null ? internalCreateConverter(superClazz) : null;

}

From source file:org.evosuite.testcase.TestFactory.java

private List<VariableReference> getCandidatesForReuse(TestCase test, Type parameterType, int position,
        VariableReference exclude, boolean allowNull, boolean canUseMocks) {

    //look at all vars defined before pos
    List<VariableReference> objects = test.getObjects(parameterType, position);

    //if an exclude var was specified, then remove it
    if (exclude != null) {
        objects.remove(exclude);/*w  ww .j a va 2s .  c o  m*/
        if (exclude.getAdditionalVariableReference() != null)
            objects.remove(exclude.getAdditionalVariableReference());

        Iterator<VariableReference> it = objects.iterator();
        while (it.hasNext()) {
            VariableReference v = it.next();
            if (exclude.equals(v.getAdditionalVariableReference()))
                it.remove();
        }
    }

    List<VariableReference> additionalToRemove = new ArrayList<>();

    //no mock should be used more than once
    Iterator<VariableReference> iter = objects.iterator();
    while (iter.hasNext()) {
        VariableReference ref = iter.next();
        if (!(test.getStatement(ref.getStPosition()) instanceof FunctionalMockStatement)) {
            continue;
        }

        //check if current mock var is used anywhere: if so, then we cannot choose it
        for (int i = ref.getStPosition() + 1; i < test.size(); i++) {
            Statement st = test.getStatement(i);
            if (st.getVariableReferences().contains(ref)) {
                iter.remove();
                additionalToRemove.add(ref);
                break;
            }
        }
    }

    //check for null
    if (!allowNull) {
        iter = objects.iterator();
        while (iter.hasNext()) {
            VariableReference ref = iter.next();

            if (ConstraintHelper.isNull(ref, test)) {
                iter.remove();
                additionalToRemove.add(ref);
            }
        }
    }

    //check for mocks
    if (!canUseMocks) {
        iter = objects.iterator();
        while (iter.hasNext()) {
            VariableReference ref = iter.next();

            if (test.getStatement(ref.getStPosition()) instanceof FunctionalMockStatement) {
                iter.remove();
                additionalToRemove.add(ref);
            }
        }
    }

    //check for bounded variables
    if (Properties.JEE) {
        iter = objects.iterator();
        while (iter.hasNext()) {
            VariableReference ref = iter.next();

            if (ConstraintHelper.getLastPositionOfBounded(ref, test) >= position) {
                iter.remove();
                additionalToRemove.add(ref);
            }
        }
    }

    //further remove all other vars that have the deleted ones as additionals
    iter = objects.iterator();
    while (iter.hasNext()) {
        VariableReference ref = iter.next();
        VariableReference additional = ref.getAdditionalVariableReference();
        if (additional == null) {
            continue;
        }
        if (additionalToRemove.contains(additional)) {
            iter.remove();
        }
    }

    //avoid using characters as values for numeric types arguments
    iter = objects.iterator();
    String parCls = parameterType.getTypeName();
    if (Integer.TYPE.getTypeName().equals(parCls) || Long.TYPE.getTypeName().equals(parCls)
            || Float.TYPE.getTypeName().equals(parCls) || Double.TYPE.getTypeName().equals(parCls)) {
        while (iter.hasNext()) {
            VariableReference ref = iter.next();
            String cls = ref.getType().getTypeName();
            if ((Character.TYPE.getTypeName().equals(cls)))
                iter.remove();
        }
    }

    return objects;
}

From source file:com.netspective.commons.xdm.XmlDataModelSchema.java

/**
 * Create a proper implementation of AttributeSetter for the given
 * attribute type./* www  . j a  va 2 s  .c  o  m*/
 */
private AttributeSetter createAttributeSetter(final Method m, final String attrName, final Class arg) {
    if (java.lang.String[].class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Object[] { TextUtils.getInstance().split(value, ",", true) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.String.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new String[] { value });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Character.class.equals(arg) || java.lang.Character.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Character[] { new Character(value.charAt(0)) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Byte.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Byte[] { new Byte(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Short.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Short[] { new Short(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Integer.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Integer[] { new Integer(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Long.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Long[] { new Long(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Float.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Float[] { new Float(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.lang.Double.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Double[] { new Double(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    }
    // boolean gets an extra treatment, because we have a nice method
    else if (java.lang.Boolean.class.equals(arg) || java.lang.Boolean.TYPE.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                m.invoke(parent, new Boolean[] { new Boolean(TextUtils.getInstance().toBoolean(value)) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    }
    // Class doesn't have a String constructor but a decent factory method
    else if (java.lang.Class.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    m.invoke(parent, new Class[] { Class.forName(value) });
                } catch (ClassNotFoundException ce) {
                    if (pc != null) {
                        DataModelException dme = new DataModelException(pc, ce);
                        pc.addError(dme);
                        if (pc.isThrowErrorException())
                            throw dme;
                    } else
                        log.error(ce);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (java.io.File.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                // resolve relative paths through DataModel
                m.invoke(parent, new File[] { pc != null ? pc.resolveFile(value) : new File(value) });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (RedirectValueSource.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                TextUtils textUtils = TextUtils.getInstance();
                ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value);
                if (vs == null) {
                    // better to throw an error here since if there are objects which are based on null/non-null
                    // value of the value source, it is easier to debug
                    pc.addError("Unable to find ValueSource '" + value + "' to wrap in RedirectValueSource at "
                            + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                            + ". Valid value sources are: "
                            + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                }
                try {
                    RedirectValueSource redirectValueSource = (RedirectValueSource) arg.newInstance();
                    redirectValueSource.setValueSource(vs);
                    m.invoke(parent, new RedirectValueSource[] { redirectValueSource });
                } catch (InstantiationException e) {
                    pc.addError("Unable to create RedirectValueSource for '" + value + "' at "
                            + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                            + ". Valid value sources are: "
                            + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (ValueSource.class.equals(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException {
                TextUtils textUtils = TextUtils.getInstance();
                ValueSource vs = ValueSources.getInstance().getValueSourceOrStatic(value);
                if (vs == null) {
                    // better to throw an error here since if there are objects which are based on null/non-null
                    // value of the value source, it is easier to debug
                    if (pc != null)
                        pc.addError("Unable to create ValueSource for '" + value + "' at "
                                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                                + ". Valid value sources are: " + textUtils
                                        .join(ValueSources.getInstance().getAllValueSourceIdentifiers(), ", "));
                    else
                        log.error("Unable to create ValueSource for '" + value + ". Valid value sources are: "
                                + textUtils.join(ValueSources.getInstance().getAllValueSourceIdentifiers(),
                                        ", "));
                }
                m.invoke(parent, new ValueSource[] { vs });
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Command.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    m.invoke(parent, new Command[] { Commands.getInstance().getCommand(value) });
                } catch (CommandNotFoundException e) {
                    if (pc != null) {
                        pc.addError("Unable to create Command for '" + value + "' at "
                                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber()
                                + ".");
                        if (pc.isThrowErrorException())
                            throw new DataModelException(pc, e);
                    } else
                        log.error("Unable to create Command for '" + value + "'", e);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (XdmEnumeratedAttribute.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    XdmEnumeratedAttribute ea = (XdmEnumeratedAttribute) arg.newInstance();
                    ea.setValue(pc, parent, attrName, value);
                    m.invoke(parent, new XdmEnumeratedAttribute[] { ea });
                } catch (InstantiationException ie) {
                    pc.addError(ie);
                    if (pc.isThrowErrorException())
                        throw new DataModelException(pc, ie);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (XdmBitmaskedFlagsAttribute.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                try {
                    XdmBitmaskedFlagsAttribute bfa;
                    NestedCreator creator = (NestedCreator) nestedCreators.get(attrName);
                    if (creator != null)
                        bfa = (XdmBitmaskedFlagsAttribute) creator.create(parent);
                    else
                        bfa = (XdmBitmaskedFlagsAttribute) arg.newInstance();
                    bfa.setValue(pc, parent, attrName, value);
                    m.invoke(parent, new XdmBitmaskedFlagsAttribute[] { bfa });
                } catch (InstantiationException ie) {
                    pc.addError(ie);
                    if (pc.isThrowErrorException())
                        throw new DataModelException(pc, ie);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Locale.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                String[] items = TextUtils.getInstance().split(value, ",", true);
                switch (items.length) {
                case 1:
                    m.invoke(parent, new Locale[] { new Locale(items[0], "") });
                    break;

                case 2:
                    m.invoke(parent, new Locale[] { new Locale(items[1], items[2]) });
                    break;

                case 3:
                    m.invoke(parent, new Locale[] { new Locale(items[1], items[2], items[3]) });
                    break;

                case 4:
                    if (pc != null)
                        throw new DataModelException(pc, "Too many items in Locale constructor.");
                    else
                        log.error("Too many items in Locale constructor: " + value);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (ResourceBundle.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                String[] items = TextUtils.getInstance().split(value, ",", true);
                switch (items.length) {
                case 1:
                    m.invoke(parent, new ResourceBundle[] { ResourceBundle.getBundle(items[0]) });
                    break;

                case 2:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], Locale.US.getCountry())) });
                    break;

                case 3:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], items[2])) });
                    break;

                case 4:
                    m.invoke(parent, new ResourceBundle[] {
                            ResourceBundle.getBundle(items[0], new Locale(items[1], items[2], items[3])) });

                default:
                    if (pc != null)
                        throw new DataModelException(pc, "Too many items in ResourceBundle constructor.");
                    else
                        log.error("Too many items in Locale constructor: " + value);

                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else if (Properties.class.isAssignableFrom(arg)) {
        return new AttributeSetter() {
            public void set(XdmParseContext pc, Object parent, String value)
                    throws InvocationTargetException, IllegalAccessException, DataModelException {
                // when specifying properties the following are valid
                // <xxx properties="abc.properties">  <!-- load this property file, throw exception if not found -->
                // <xxx properties="abc.properties:optional">  <!-- load this property file, no exception if not found -->
                // <xxx properties="/a/b/abc.properties,/x/y/def.properties"> <!-- load the first property file found, throw exception if none found -->
                // <xxx properties="/a/b/abc.properties,/x/y/def.properties:optional"> <!-- load the first property file found, no exception if none found -->

                final TextUtils textUtils = TextUtils.getInstance();
                final String[] options = textUtils.split(value, ":", true);
                final String[] fileNames = textUtils.split(value, ",", true);
                final Properties properties;
                switch (options.length) {
                case 1:
                    properties = PropertiesLoader.loadProperties(fileNames, true, false);
                    m.invoke(parent, new Properties[] { properties });
                    break;

                case 2:
                    properties = PropertiesLoader.loadProperties(fileNames,
                            options[1].equals("optional") ? false : true, false);
                    if (properties != null)
                        m.invoke(parent, new Properties[] { properties });
                    break;

                default:
                    if (pc != null)
                        throw new DataModelException(pc,
                                "Don't know how to get properties from PropertiesLoader: " + value);
                    else
                        log.error("Don't know how to get properties from PropertiesLoader:" + value);
                }
            }

            public boolean isInherited() {
                return !m.getDeclaringClass().equals(bean);
            }

            public Class getDeclaringClass() {
                return m.getDeclaringClass();
            }
        };
    } else {
        // worst case. look for a public String constructor and use it
        try {
            final Constructor c = arg.getConstructor(new Class[] { java.lang.String.class });
            return new AttributeSetter() {
                public void set(XdmParseContext pc, Object parent, String value)
                        throws InvocationTargetException, IllegalAccessException, DataModelException {
                    try {
                        Object attribute = c.newInstance(new String[] { value });
                        m.invoke(parent, new Object[] { attribute });
                    } catch (InstantiationException ie) {
                        if (pc != null) {
                            pc.addError(ie);
                            if (pc.isThrowErrorException())
                                throw new DataModelException(pc, ie);
                        } else
                            log.error(ie);
                    }
                }

                public boolean isInherited() {
                    return !m.getDeclaringClass().equals(bean);
                }

                public Class getDeclaringClass() {
                    return m.getDeclaringClass();
                }
            };
        } catch (NoSuchMethodException nme) {
        }
    }

    return null;
}

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private Object parseListElement(final Class<?> type, final String strValue) throws WizardLoadingException {
    if (String.class.equals(type)) {
        return strValue;
    }/*  ww  w  .  j  a v  a  2  s.  c  o m*/

    if (Enum.class.isAssignableFrom(type)) {
        final Class<? extends Enum> clazz = (Class<? extends Enum>) type;
        return Enum.valueOf(clazz, strValue);
    }

    if (type.equals(Double.class) || type.equals(Float.class) || type.equals(Double.TYPE)
            || type.equals(Float.TYPE)) {
        try {
            return Double.parseDouble(strValue);
        } catch (final NumberFormatException e) {
            throw new WizardLoadingException(true,
                    "invalid content (" + strValue + ") at node: " + LIST_VALUE + " (expected: real number)");
        }
    }

    try {
        return Long.parseLong(strValue);
    } catch (final NumberFormatException e) {
        throw new WizardLoadingException(true,
                "invalid content (" + strValue + ") at node: " + LIST_VALUE + " (expected: integer number)");
    }
}