org.springframework.core.Constants.asObject()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(128)

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

Constants.asObject介绍

[英]Parse the given String (upper or lower case accepted) and return the appropriate value if it's the name of a constant field in the class that we're analysing.
[中]解析给定的字符串(接受大写或小写),如果它是我们正在分析的类中常量字段的名称,则返回相应的值。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return a constant value as a String.
 * @param code the name of the field (never {@code null})
 * @return the String value
 * Works even if it's not a string (invokes {@code toString()}).
 * @throws ConstantException if the field name wasn't found
 * @see #asObject
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Return a constant value as a String.
 * @param code the name of the field (never {@code null})
 * @return the String value
 * Works even if it's not a string (invokes {@code toString()}).
 * @throws ConstantException if the field name wasn't found
 * @see #asObject
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return a constant value cast to a Number.
 * @param code the name of the field (never {@code null})
 * @return the Number value
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 * @see #asObject
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Return a constant value cast to a Number.
 * @param code the name of the field (never {@code null})
 * @return the Number value
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 * @see #asObject
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Return a constant value as a String.
 * @param code the name of the field (never <code>null</code>)
 * @return the String value
 * Works even if it's not a string (invokes <code>toString()</code>).
 * @see #asObject
 * @throws ConstantException if the field name wasn't found
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Return a constant value cast to a Number.
 * @param code the name of the field (never <code>null</code>)
 * @return the Number value
 * @see #asObject
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Return a constant value as a String.
 * @param code the name of the field (never {@code null})
 * @return the String value
 * Works even if it's not a string (invokes {@code toString()}).
 * @throws ConstantException if the field name wasn't found
 * @see #asObject
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: springframework/spring-core

/**
 * Return a constant value as a String.
 * @param code name of the field
 * @return String string value if successful.
 * Works even if it's not a string (invokes toString()).
 * @see #asObject
 * @throws ConstantException if the field name wasn't found
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Return a constant value as a String.
 * @param code the name of the field (never {@code null})
 * @return the String value
 * Works even if it's not a string (invokes {@code toString()}).
 * @throws ConstantException if the field name wasn't found
 * @see #asObject
 */
public String asString(String code) throws ConstantException {
  return asObject(code).toString();
}

代码示例来源:origin: e-biz/spring-dbunit

/**
   * Convert this enum into {@link DatabaseOperation operation database}.
   * 
   * @return The DatabaseOperation for this enum
   */
  public DatabaseOperation getDatabaseOperation() {
    return DatabaseOperation.class.cast(operations.asObject(name()));
  }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Return a constant value cast to a Number.
 * @param code the name of the field (never {@code null})
 * @return the Number value
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 * @see #asObject
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

代码示例来源:origin: org.springframework.data/spring-data-gemfire

/**
 * Sets the initial {@link InterestResultPolicy} used when interest is first registered and determines whether KEYS,
 * KEYS_VALUE or nothing (NONE) is initially fetched.
 *
 * The argument is set as an {@link Object} to be able to accept both {@link InterestResultPolicy}
 * and {@link String Strings}, used in XML configuration meta-data.
 *
 * @param policy initial {@link InterestResultPolicy} to set.
 * @throws IllegalArgumentException if the given {@code policy} is not a valid type.
 * @see org.apache.geode.cache.InterestResultPolicy
 */
public void setPolicy(Object policy) {
  if (policy instanceof InterestResultPolicy) {
    this.policy = (InterestResultPolicy) policy;
  }
  else if (policy instanceof String) {
    this.policy = (InterestResultPolicy) constants.asObject(String.valueOf(policy));
  }
  else {
    throw new IllegalArgumentException(String.format(
      "Unknown argument type [%s] for property 'policy'", policy));
  }
}

代码示例来源:origin: org.springframework.data/spring-data-geode

/**
 * Sets the initial {@link InterestResultPolicy} used when interest is first registered and determines whether KEYS,
 * KEYS_VALUE or nothing (NONE) is initially fetched.
 *
 * The argument is set as an {@link Object} to be able to accept both {@link InterestResultPolicy}
 * and {@link String Strings}, used in XML configuration meta-data.
 *
 * @param policy initial {@link InterestResultPolicy} to set.
 * @throws IllegalArgumentException if the given {@code policy} is not a valid type.
 * @see org.apache.geode.cache.InterestResultPolicy
 */
public void setPolicy(Object policy) {
  if (policy instanceof InterestResultPolicy) {
    this.policy = (InterestResultPolicy) policy;
  }
  else if (policy instanceof String) {
    this.policy = (InterestResultPolicy) constants.asObject(String.valueOf(policy));
  }
  else {
    throw new IllegalArgumentException(String.format(
      "Unknown argument type [%s] for property 'policy'", policy));
  }
}

代码示例来源:origin: springframework/spring-core

/**
 * Return a constant value cast to a Number.
 * @param code name of the field
 * @return long value if successful
 * @see #asObject
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Return a constant value cast to a Number.
 * @param code the name of the field (never {@code null})
 * @return the Number value
 * @throws ConstantException if the field name wasn't found
 * or if the type wasn't compatible with Number
 * @see #asObject
 */
public Number asNumber(String code) throws ConstantException {
  Object obj = asObject(code);
  if (!(obj instanceof Number)) {
    throw new ConstantException(this.className, code, "not a Number");
  }
  return (Number) obj;
}

相关文章