Example usage for java.lang Void TYPE

List of usage examples for java.lang Void TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class object representing the pseudo-type corresponding to the keyword void .

Usage

From source file:com.github.gekoh.yagen.util.MappingUtils.java

public static Class determineTargetEntity(AccessibleObject ao, Class<?> specifiedTargetEntity) {
    String errorMessage = "targetEntity not present and not determinable (need generic declaration)";
    try {// w w  w  .ja  v a2  s  .c om
        if (specifiedTargetEntity != null && specifiedTargetEntity != Void.TYPE) {
            return specifiedTargetEntity;
        } else {
            if (ao instanceof Field) {
                Field f = (Field) ao;
                if (Collection.class.isAssignableFrom(f.getType())) {
                    // this has to work, because otherwise the target entity must be valid
                    ParameterizedType type = (ParameterizedType) f.getGenericType();
                    return (Class<?>) type.getActualTypeArguments()[0];
                }
                return f.getType();
            } else if (ao instanceof Method) {
                Method m = (Method) ao;
                if (Collection.class.isAssignableFrom(m.getReturnType())) {
                    // this has to work, because otherwise the target entity must be valid
                    ParameterizedType type = (ParameterizedType) m.getGenericReturnType();
                    return (Class<?>) type.getActualTypeArguments()[0];
                }
                return m.getReturnType();
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException(errorMessage, e);
    }
    throw new IllegalStateException(errorMessage);
}

From source file:org.apache.hadoop.io.retry.RetryInvocationHandler.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    RetryPolicy policy = methodNameToPolicyMap.get(method.getName());
    if (policy == null) {
        policy = defaultPolicy;/* w ww .j  av  a 2  s  .co  m*/
    }

    int retries = 0;
    while (true) {
        try {
            return invokeMethod(method, args);
        } catch (Exception e) {
            if (!policy.shouldRetry(e, retries++)) {
                LOG.info("Exception while invoking " + method.getName() + " of " + implementation.getClass()
                        + ". Not retrying." + StringUtils.stringifyException(e));
                if (!method.getReturnType().equals(Void.TYPE)) {
                    throw e; // non-void methods can't fail without an exception
                }
                return null;
            }
            LOG.debug("Exception while invoking " + method.getName() + " of " + implementation.getClass()
                    + ". Retrying." + StringUtils.stringifyException(e));
        }
    }
}

From source file:org.grouplens.lenskit.eval.traintest.OutputPredictMetric.java

public OutputPredictMetric(ExperimentOutputLayout layout, File file, List<Pair<Symbol, String>> chans)
        throws IOException {
    super(Void.TYPE, Void.TYPE);
    outputLayout = layout;//from  w w w .  j a  v a  2s  . c o m
    channels = chans;

    TableLayoutBuilder lb = TableLayoutBuilder.copy(layout.getCommonLayout()).addColumn("User")
            .addColumn("Item").addColumn("Rating").addColumn("Prediction");
    for (Pair<Symbol, String> chan : channels) {
        lb.addColumn(chan.getRight());
    }

    tableWriter = CSVWriter.open(file, lb.build());
}

From source file:org.gradle.api.internal.tasks.options.FieldOptionElement.java

public void apply(Object object, List<String> parameterValues) {
    if (getOptionType() == Void.TYPE && parameterValues.size() == 0) {
        setFieldValue(object, true);/*w  w  w  .j a va 2s . co  m*/
    } else if (parameterValues.size() > 1) {
        throw new IllegalArgumentException(String.format("Lists not supported for option"));
    } else {
        Object arg = getNotationParser().parseNotation(parameterValues.get(0));
        setFieldValue(object, arg);
    }
}

From source file:org.pentaho.di.ui.core.dialog.DisplayInvocationHandler.java

@Override
public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
    if (display.getThread() == Thread.currentThread()) {
        try {/*from w  w  w  .j  ava 2  s .  com*/
            return method.invoke(delegate, args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }
    if (asyncForVoid && method.getReturnType().equals(Void.TYPE)) {
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    method.invoke(delegate, args);
                } catch (Throwable e) {
                    if (e instanceof InvocationTargetException) {
                        e = e.getCause();
                    }
                    log.logError(e.getMessage(), e);
                }
            }
        });
        return null;
    }
    final ResultHolder resultHolder = new ResultHolder();
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            try {
                resultHolder.result = method.invoke(delegate, args);
            } catch (InvocationTargetException e) {
                resultHolder.throwable = e.getCause();
            } catch (Exception e) {
                resultHolder.throwable = e;
            }
        }
    });
    if (resultHolder.result != null) {
        return resultHolder.result;
    } else {
        throw resultHolder.throwable;
    }
}

From source file:com.javaforge.tapestry.acegi.enhance.SecuredMethodEnhancementWorker.java

@SuppressWarnings("unused")
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method,
        Location location) {//from  www .  j  av  a2 s  .co m
    getLog().debug("Securing method " + method + "...");
    final String securityUtilsField = op.addInjectedField("_$securityUtils", SecurityUtils.class,
            securityUtils);
    final Collection<ConfigAttribute> configAttributeDefinition = securityUtils
            .createConfigAttributeDefinition(method);
    final String configAttributeDefinitionField = op.addInjectedField("_$configAttributeDefinition",
            Collection.class, configAttributeDefinition);
    final StringBuffer methodBody = new StringBuffer("{\n");
    methodBody.append(securityUtilsField + ".checkSecurity(this," + configAttributeDefinitionField + ");\n");
    if (!method.getReturnType().equals(Void.TYPE)) {
        methodBody.append("return ");
    }
    methodBody.append("super." + method.getName() + "($$);\n}");
    op.addMethod(method.getModifiers(), new MethodSignature(method), methodBody.toString(), location);
}

From source file:org.nuxeo.ecm.automation.core.impl.InvokableMethod.java

public InvokableMethod(OperationType op, Method method, OperationMethod anno) {
    produce = method.getReturnType();//from www .ja v a2  s .  co m
    Class<?>[] p = method.getParameterTypes();
    if (p.length > 1) {
        throw new IllegalArgumentException("Operation method must accept at most one argument: " + method);
    }
    // if produce is Void => a control operation
    // if (produce == Void.TYPE) {
    // throw new IllegalArgumentException("Operation method must return a
    // value: "+method);
    // }
    this.op = op;
    this.method = method;
    priority = anno.priority();
    if (priority > 0) {
        priority += USER_PRIORITY;
    }
    consume = p.length == 0 ? Void.TYPE : p[0];
}

From source file:org.apache.camel.component.exec.ExecResultConverter.java

/**
 * Converts <code>ExecResult</code> to the type <code>T</code>.
 * /*from   w  w  w .j  ava 2s  . co m*/
 * @param <T> The type to convert to
 * @param type Class instance of the type to which to convert
 * @param exchange a Camel exchange. If exchange is <code>null</code>, no
 *            conversion will be made
 * @param result the exec result
 * @return the converted {@link ExecResult}
 * @throws FileNotFoundException if there is a file in the execResult, and
 *             the file can not be found
 */
@SuppressWarnings("unchecked")
private static <T> T convertTo(Class<T> type, Exchange exchange, ExecResult result)
        throws FileNotFoundException {
    InputStream is = toInputStream(result);
    if (is != null) {
        return exchange.getContext().getTypeConverter().convertTo(type, exchange, is);
    } else {
        // use Void to indicate we cannot convert it
        // (prevents Camel from using a fallback converter which may convert a String from the instance name)  
        return (T) Void.TYPE;
    }
}

From source file:com.jredrain.dao.BeanResultTransFormer.java

/**
 * Setter//from   w w w .  j a  va 2s. c o  m
 *
 * @param method
 * @return
 */
boolean filter(Method method) {
    if (method.getReturnType() == Void.TYPE && method.getParameterTypes().length == 1) {
        String methodName = method.getName();
        return methodName.startsWith("set") && methodName.length() > 3;
    }
    return false;
}

From source file:org.seasar.mayaa.impl.util.ObjectUtil.java

protected static Class loadPrimitiveClass(String className) {
    if (StringUtil.isEmpty(className)) {
        throw new IllegalArgumentException();
    }/* www.  j a va  2  s.c  om*/
    if ("short".equals(className)) {
        return Short.TYPE;
    } else if ("int".equals(className)) {
        return Integer.TYPE;
    } else if ("long".equals(className)) {
        return Long.TYPE;
    } else if ("float".equals(className)) {
        return Float.TYPE;
    } else if ("double".equals(className)) {
        return Double.TYPE;
    } else if ("byte".equals(className)) {
        return Byte.TYPE;
    } else if ("char".equals(className)) {
        return Character.TYPE;
    } else if ("boolean".equals(className)) {
        return Boolean.TYPE;
    } else if ("void".equals(className)) {
        return Void.TYPE;
    }
    return null;
}