|
Java example source code file (RealFunctionValidation.java)
The RealFunctionValidation.java Java example source code
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.util.FastMath;
/*
* plot 'logGamma.dat' binary format="%double%double" endian=big u 1:2 w l
*/
public class RealFunctionValidation {
public static class MissingRequiredPropertyException
extends IllegalArgumentException {
private static final long serialVersionUID = 20121017L;
public MissingRequiredPropertyException(final String key) {
super("missing required property " + key);
}
}
public static class ApplicationProperties {
private static final int DOT = '.';
private static final String METHOD_KEY = "method";
private static final String SIGNATURE_KEY = "signature";
private static final String INPUT_FILE_MASK = "inputFileMask";
private static final String OUTPUT_FILE_MASK = "outputFileMask";
private static final String FROM_KEY = "from";
private static final String TO_KEY = "to";
private static final String BY_KEY = "by";
final Method method;
final String inputFileMask;
final String outputFileMask;
final int from;
final int to;
final int by;
/**
* Returns a {@link Method} with specified signature.
*
* @param className The fully qualified name of the class to which the
* method belongs.
* @param methodName The name of the method.
* @param signature The signature of the method, as a list of parameter
* types.
* @return the method
* @throws SecurityException
* @throws ClassNotFoundException
*/
public static Method findStaticMethod(final String className,
final String methodName,
final List<Class>> signature)
throws SecurityException, ClassNotFoundException {
final int n = signature.size();
final Method[] methods = Class.forName(className).getMethods();
for (Method method : methods) {
if (method.getName().equals(methodName)) {
final Class<?>[] parameters = method.getParameterTypes();
boolean sameSignature = true;
if (parameters.length == n) {
for (int i = 0; i < n; i++) {
sameSignature &= signature.get(i)
.equals(parameters[i]);
}
if (sameSignature) {
final int modifiers = method.getModifiers();
if ((modifiers & Modifier.STATIC) != 0) {
return method;
} else {
final String msg = "method must be static";
throw new IllegalArgumentException(msg);
}
}
}
}
}
throw new IllegalArgumentException("method not found");
}
public static Class<?> parsePrimitiveType(final String type) {
if (type.equals("boolean")) {
return Boolean.TYPE;
} else if (type.equals("byte")) {
return Byte.TYPE;
} else if (type.equals("char")) {
return Character.TYPE;
} else if (type.equals("double")) {
return Double.TYPE;
} else if (type.equals("float")) {
return Float.TYPE;
} else if (type.equals("int")) {
return Integer.TYPE;
} else if (type.equals("long")) {
return Long.TYPE;
} else if (type.equals("short")) {
return Short.TYPE;
} else {
final StringBuilder builder = new StringBuilder();
builder.append(type).append(" is not a primitive type");
throw new IllegalArgumentException(builder.toString());
}
}
private static String getPropertyAsString(final Properties properties,
final String key) {
final String value = properties.getProperty(key);
if (value == null) {
throw new MissingRequiredPropertyException(key);
} else {
return value;
}
}
private static int getPropertyAsInteger(final Properties properties,
final String key) {
final String value = properties.getProperty(key);
if (value == null) {
throw new MissingRequiredPropertyException(key);
} else {
return Integer.parseInt(value);
}
}
private ApplicationProperties(final String fullyQualifiedName,
final String signature,
final String inputFileMask,
final String outputFileMask,
final int from, final int to, final int by) {
this.inputFileMask = inputFileMask;
this.outputFileMask = outputFileMask;
this.from = from;
this.to = to;
this.by = by;
final String[] types = signature.split(",");
final List<Class>> parameterTypes = new ArrayList
Other Java examples (source code examples)Here is a short list of links related to this Java RealFunctionValidation.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.