当前位置: 首页>>代码示例>>Java>>正文


Java Param类代码示例

本文整理汇总了Java中org.openjdk.jmh.annotations.Param的典型用法代码示例。如果您正苦于以下问题:Java Param类的具体用法?Java Param怎么用?Java Param使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Param类属于org.openjdk.jmh.annotations包,在下文中一共展示了Param类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toParameterValues

import org.openjdk.jmh.annotations.Param; //导入依赖的package包/类
/**
 * <p>Gets the parameter values to be used for this field. In most cases this will be the values declared
 * in the {@code @Param} annotation.</p>
 *
 * <p>For an enum field type, an empty parameter list will be resolved to be the full list of enum constants
 * of that type.</p>
 *
 * @param fi type of the field for which to find parameters
 * @return string values representing the actual parameters
 */
private static String[] toParameterValues(FieldInfo fi) {
    String[] annotatedValues = fi.getAnnotation(Param.class).value();

    boolean isBlankEnum = (annotatedValues.length == 1)
                            && Param.BLANK_ARGS.equals(annotatedValues[0])
                            && fi.getType().isEnum();

    if (isBlankEnum) {
        Collection<String> enumConstants = fi.getType().getEnumConstants();
        if (enumConstants.isEmpty()) {
            throw new GenerationException("Enum type of field had no constants. "
                    + "Declare some constants or remove the @" + Param.class.getSimpleName() + ".",
                    fi);
        }
        return enumConstants.toArray(new String[enumConstants.size()]);
    } else {
        return annotatedValues;
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:30,代码来源:BenchmarkGeneratorUtils.java

示例2: addParameterValuesToGroup

import org.openjdk.jmh.annotations.Param; //导入依赖的package包/类
/**
 * Compute the parameter space given by {@code @Param} annotations and add all them to the group.
 *
 * @param host type of the state {@code @State} in which to find {@code @Param}s
 * @param group method group
 */
static void addParameterValuesToGroup(ClassInfo host, MethodGroup group) {
    // Add all inherited @Param fields
    for (FieldInfo fi : getAllFields(host)) {
        if (fi.getAnnotation(Param.class) != null) {
            String[] values = toParameterValues(fi);
            group.addParamValues(fi.getName(), values);
        }
    }

    // Add all @Param fields reachable through the dependencies.
    // This recursive approach always converges because @State dependency graph is DAG.
    for (MethodInfo mi : getAllMethods(host)) {
        if (mi.getAnnotation(Setup.class) != null || mi.getAnnotation(TearDown.class) != null) {
            for (ParameterInfo pi : mi.getParameters()) {
                addParameterValuesToGroup(pi.getType(), group);
            }
        }
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:26,代码来源:BenchmarkGeneratorUtils.java

示例3: getParams

import org.openjdk.jmh.annotations.Param; //导入依赖的package包/类
public Optional<Map<String, String[]>> getParams() {
    Map<String, String[]> map = new TreeMap<String, String[]>();

    for (Map.Entry<String, String[]> e : params.entrySet()) {
        String key = e.getKey();
        String[] values = e.getValue();
        if (values.length == 1 && values[0].equalsIgnoreCase(Param.BLANK_ARGS)) {
            map.put(key, new String[0]);
        } else {
            map.put(key, values);
        }
    }

    if (params.isEmpty()) {
        return Optional.none();
    } else {
        return Optional.of(map);
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:20,代码来源:MethodGroup.java

示例4: checkParam

import org.openjdk.jmh.annotations.Param; //导入依赖的package包/类
private void checkParam(FieldInfo fi) {
    if (fi.isStatic()) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " annotation is not acceptable on static fields.",
                fi);
    }

    if (BenchmarkGeneratorUtils.getAnnSyntax(fi.getDeclaringClass(), State.class) == null) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " annotation should be placed in @" + State.class.getSimpleName() +
                        "-annotated class.", fi);
    }

    ClassInfo type = fi.getType();

    if (!isParamTypeAcceptable(type)) {
        throw new GenerationException(
                "@" + Param.class.getSimpleName() + " can only be placed over the annotation-compatible types:" +
                        " primitives, primitive wrappers, Strings, or enums.", fi);
    }

    String[] values = fi.getAnnotation(Param.class).value();

    if (values.length == 1 && values[0].equalsIgnoreCase(Param.BLANK_ARGS)) {
        if (!fi.getType().isEnum()) {
            throw new GenerationException(
                "@" + Param.class.getSimpleName() + " should provide the default parameters.", fi);
        } else {
            // if type is enum then don't need to check conformity
        }
    } else {
        for (String val : values) {
            if (!isParamValueConforming(fi, val, type)) {
                throw new GenerationException(
                        "Some @" + Param.class.getSimpleName() + " values can not be converted to target type: " +
                                "\"" + val + "\" can not be converted to " + type,
                        fi
                );
            }
        }
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:43,代码来源:StateObjectHandler.java


注:本文中的org.openjdk.jmh.annotations.Param类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。