java.lang.Class.toGenericString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(244)

本文整理了Java中java.lang.Class.toGenericString()方法的一些代码示例,展示了Class.toGenericString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.toGenericString()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:toGenericString

Class.toGenericString介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream()
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass)
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass)
      .collect(toImmutableList());
  checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString()));
  return getOnlyElement(combineFunctions);
}

代码示例来源:origin: prestodb/presto

private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream()
      .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass))
      .collect(toImmutableList());
  if (stateSerializerFactories.isEmpty()) {
    return Optional.empty();
  }
  checkArgument(stateSerializerFactories.size() == 1,
      String.format(
          "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s",
          stateClass.toGenericString(),
          stateSerializerFactories.size(),
          aggregationDefinition.toGenericString()));
  return Optional.of(getOnlyElement(stateSerializerFactories));
}

代码示例来源:origin: stackoverflow.com

import java.util.ArrayList;

class MyClass {
  ArrayList<String> stringList;

  public ArrayList<String> getStringList() {
    return stringList;
  }
}

public class Foo {
  public static void main(String... args) throws NoSuchMethodException {
    ArrayList<Integer> intList = new ArrayList<>();
    System.out.println(intList.getClass().toGenericString());  
    System.out.println(MyClass.class.getMethod("getStringList").toGenericString());
  }
}

代码示例来源:origin: prestosql/presto

public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream()
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass)
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass)
      .collect(toImmutableList());
  checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString()));
  return getOnlyElement(combineFunctions);
}

代码示例来源:origin: in.erail/glue

@Override
public String toString() {
 return MoreObjects
     .toStringHelper(this)
     .add("mFactoryClass", mFactoryClass)
     .add("mFactoryInstance", mFactoryInstance)
     .add("mFactoryMethodName", mFactoryMethodName)
     .add("mFactoryParamValues", mFactoryParamValues != null ? Joiner.on(",").join(mFactoryParamValues) : null)
     .add("mFactoryParamType", mFactoryParamType != null ? Joiner.on(",").join(mFactoryParamType) : null)
     .add("mParamType", mParamType != null ? Joiner.on(",").join(mParamType) : null)
     .add("mComponentPath", mComponentPath)
     .add("mFactoryEnable", mFactoryEnable)
     .add("mMethod", mMethod != null ? mMethod.getName() : null)
     .add("mMethodParam", mMethodParam != null ? Joiner.on(",").join(mMethodParam) : null)
     .add("mMethodClass", mMethodClass != null ? mMethodClass.getCanonicalName() : null)
     .add("mMethodClassInstance", mMethodClassInstance != null ? mMethodClassInstance.getClass().toGenericString() : null)
     .toString();
}

代码示例来源:origin: io.prestosql/presto-main

public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream()
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass)
      .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass)
      .collect(toImmutableList());
  checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString()));
  return getOnlyElement(combineFunctions);
}

代码示例来源:origin: io.prestosql/presto-main

private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream()
      .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass))
      .collect(toImmutableList());
  if (stateSerializerFactories.isEmpty()) {
    return Optional.empty();
  }
  checkArgument(stateSerializerFactories.size() == 1,
      String.format(
          "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s",
          stateClass.toGenericString(),
          stateSerializerFactories.size(),
          aggregationDefinition.toGenericString()));
  return Optional.of(getOnlyElement(stateSerializerFactories));
}

代码示例来源:origin: NyaaCat/RPGItems-reloaded

public static void registerOverride(NamespacedKey origin, NamespacedKey override) {
    if (overrides.containsKey(origin)) {
      throw new IllegalArgumentException("Cannot override a already overridden power: " + origin + " " + override);
    }
    Class<? extends Power> originPower = getPower(origin);
    Class<? extends Power> overridePower = getPower(override);
    if (originPower == null) {
      throw new IllegalArgumentException("Overriding not registered power: " + origin);
    }
    if (overridePower == null) {
      throw new IllegalArgumentException("Override not found: " + override);
    }
    if (!originPower.isAssignableFrom(overridePower)) {
      throw new IllegalArgumentException("Not overrideable: " + origin + "@" + originPower.toGenericString() + " " + override + "@" + overridePower.toGenericString());
    }
    overrides.put(origin, override);
  }
}

代码示例来源:origin: bonitasoft/bonita-engine

public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn,
      final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException {
    final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet);
    final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName());
    final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)});
    if (method != null) {
      final Object o = dataType.cast(objectToInvokeJavaMethodOn);
      method.invoke(o, expressionResultType.cast(valueToSetObjectWith));
      return o;
    } else {
      throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ").");
    }
  }
}

代码示例来源:origin: prestosql/presto

private static Optional<Method> getAggregationStateSerializerFactory(Class<?> aggregationDefinition, Class<?> stateClass)
{
  // Only include methods that match this state class
  List<Method> stateSerializerFactories = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(aggregationDefinition, AggregationStateSerializerFactory.class).stream()
      .filter(method -> ((AggregationStateSerializerFactory) method.getAnnotation(AggregationStateSerializerFactory.class)).value().equals(stateClass))
      .collect(toImmutableList());
  if (stateSerializerFactories.isEmpty()) {
    return Optional.empty();
  }
  checkArgument(stateSerializerFactories.size() == 1,
      String.format(
          "Expect at most 1 @AggregationStateSerializerFactory(%s.class) annotation, found %s in %s",
          stateClass.toGenericString(),
          stateSerializerFactories.size(),
          aggregationDefinition.toGenericString()));
  return Optional.of(getOnlyElement(stateSerializerFactories));
}

代码示例来源:origin: neuhalje/bouncy-gpg

/**
 * The default strategy to search for keys is to *just* search for the email address (the part
 * between &lt; and &gt;).
 *
 * Set this flag to search for any part in the user id.
 *
 * @param strategy instance to use
 *
 * @return next build step
 */
public WithAlgorithmSuite withKeySelectionStrategy(final KeySelectionStrategy strategy) {
 requireNonNull(strategy, "strategy must not be null");
 Preconditions.checkState(
   selectUidByEMailOnly == null && dateOfTimestampVerification == null,
   "selectUidByAnyUidPart/setReferenceDateForKeyValidityTo cannot be used together"
     + " with 'withKeySelectionStrategy' ");
 this.keySelectionStrategy = strategy;
 LOGGER.trace("WithKeySelectionStrategy: override strategy to {}",
   strategy.getClass().toGenericString());
 return this;
}

代码示例来源:origin: bonitasoft/bonita-engine

public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn,
      final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException {
    final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet);
    final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName());
    final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)});
    if (method != null) {
      final Object o = dataType.cast(objectToInvokeJavaMethodOn);
      method.invoke(o, expressionResultType.cast(valueToSetObjectWith));
      return o;
    } else {
      throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ").");
    }
  }
}

代码示例来源:origin: org.jrebirth.af/core

/**
 * Gets the value.
 *
 * @param object the object
 * @param method the method
 * @param cls the cls
 * 
 * @param <T> the generic type
 * 
 * @return the value
 */
@SuppressWarnings("unchecked")
private <T> Optional<T> getValue(Object object, Supplier<Object> method, Class<T> cls) {
  T source = null;
  if (cls.isInstance(method.get())) {
    source = (T) method.get();
  } else {
    if (CoreParameters.DEVELOPER_MODE.get()) {
      throw new CoreRuntimeException("Cannot cast object " + method.get() + " to " + cls.toGenericString());
    }
  }
  return Optional.ofNullable(source);
}

代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.api

@Override
public String getMessage()
{
  String typeNames = typesString();
  String primary = primaryType == null ? "" : "    primary: " + primaryType.toGenericString() + NL;
  String methodName = memberString();
  String message = super.getMessage() == null ? "" : "    message: " + super.getMessage() + NL;
  String fragment = fragmentClass == null ? "" : "    fragmentClass: " + fragmentClass.getName() + NL;
  String valueType = this.valueType == null ? "" : "    valueType: " + this.valueType.getTypeName() + NL;
  String module = this.module == null ? "" : "    layer: " + this.module.layer().name() + NL + "    module: "
                        + this.module.name() + NL;
  return message + module + primary + fragment + methodName + valueType + typeNames;
}

代码示例来源:origin: apache/attic-polygene-java

@Override
public String getMessage()
{
  String typeNames = typesString();
  String primary = primaryType == null ? "" : "    primary: " + primaryType.toGenericString() + NL;
  String methodName = memberString();
  String message = super.getMessage() == null ? "" : "    message: " + super.getMessage() + NL;
  String fragment = fragmentClass == null ? "" : "    fragmentClass: " + fragmentClass.getName() + NL;
  String valueType = this.valueType == null ? "" : "    valueType: " + this.valueType.getTypeName() + NL;
  String module = this.module == null ? "" : "    layer: " + this.module.layer().name() + NL + "    module: "
                        + this.module.name() + NL;
  return message + module + primary + fragment + methodName + valueType + typeNames;
}

代码示例来源:origin: eclipse/kapua

/**
   * Check the exception that was caught. In case the exception was expected the type and message is shown in the cucumber logs.
   * Otherwise the exception is rethrown failing the test and dumping the stack trace to help resolving problems.
   */
  public void verifyException(Exception ex)
      throws Exception {

    boolean exceptionExpected = stepData.contains("ExceptionExpected") ? (boolean)stepData.get("ExceptionExpected") : false;
    String exceptionName = stepData.contains("ExceptionName") ? (String)stepData.get("ExceptionName") : "";
    String exceptionMessage = stepData.contains("ExceptionMessage") ? (String)stepData.get("ExceptionMessage") : "";

    if (!exceptionExpected ||
        (!exceptionName.isEmpty() && !ex.getClass().toGenericString().contains(exceptionName)) ||
        (!exceptionMessage.isEmpty() && !exceptionMessage.trim().contentEquals("*") && !ex.getMessage().contains(exceptionMessage))) {
      scenario.write("An unexpected exception was raised!");
      throw(ex);
    }

    scenario.write("Exception raised as expected: " + ex.getClass().getCanonicalName() + ", " + ex.getMessage());
    stepData.put("ExceptionCaught", true);
    stepData.put("Exception", ex);
  }
}

代码示例来源:origin: waterguo/antsdb

@Override
public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) {
  long addrVal = this.upstream.eval(ctx, heap, params, pRecord);
  Object val = FishObject.get(heap, addrVal);
  if (val == null) {
  }
  else if (val instanceof Float) {
  }
  else if (val instanceof Long) {
    val = ((Long)val).floatValue();
  }
  else if (val instanceof String) {
    val = Float.valueOf((String)val);
  }
  else if (val instanceof BigDecimal) {
    val = ((BigDecimal)val).floatValue();
  }
  else if (val instanceof Double) {
    val = ((Double)val).floatValue();
  }
  else {
    throw new CodingError(val.getClass().toGenericString());
  }
  return FishObject.allocSet(heap, val);
}

代码示例来源:origin: apache/attic-polygene-java

+ method.toGenericString()
+ NL + "Declaring Class:"
+ method.getDeclaringClass().toGenericString()
+ NL + "Types:"
+ mixinsModel.mixinTypes()

代码示例来源:origin: waterguo/antsdb

throw new CodingError(val.getClass().toGenericString());

相关文章

Class类方法