java.lang.Number类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(136)

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

Number介绍

[英]The abstract superclass of the classes which represent numeric base types (that is Byte, Short, Integer, Long, Float, and Double.
[中]表示数字基类型(即字节、短、整数、长、浮点和双精度)的类的抽象超类。

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).doubleValue();
    }
    return (double) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).longValue();
    }
    return (long) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).floatValue();
    }
    return (float) 0;
  }
};

代码示例来源:origin: google/guava

@Override
 public Integer apply(Number x) {
  return x.intValue();
 }
};

代码示例来源:origin: google/guava

public void testForMapWildCardWithDefault() {
 Map<String, Integer> map = Maps.newHashMap();
 map.put("One", 1);
 map.put("Three", 3);
 Number number = Double.valueOf(42);
 Function<String, Number> function = Functions.forMap(map, number);
 assertEquals(1, function.apply("One").intValue());
 assertEquals(number, function.apply("Two"));
 assertEquals(3L, function.apply("Three").longValue());
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).shortValue();
    }
    return (short) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).byteValue();
    }
    return (byte) 0;
  }
};

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

/**
 * Set the misfire instruction via the name of the corresponding
 * constant in the {@link org.quartz.CronTrigger} class.
 * Default is {@code MISFIRE_INSTRUCTION_SMART_POLICY}.
 * @see org.quartz.CronTrigger#MISFIRE_INSTRUCTION_FIRE_ONCE_NOW
 * @see org.quartz.CronTrigger#MISFIRE_INSTRUCTION_DO_NOTHING
 * @see org.quartz.Trigger#MISFIRE_INSTRUCTION_SMART_POLICY
 */
public void setMisfireInstructionName(String constantName) {
  this.misfireInstruction = constants.asNumber(constantName).intValue();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).shortValue();
    }
    return (short) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).byteValue();
    }
    return (byte) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).doubleValue();
    }
    return (double) 0;
  }
};

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

/**
 * Set the system property mode by the name of the corresponding constant,
 * e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".
 * @param constantName name of the constant
 * @see #setSystemPropertiesMode
 */
public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException {
  this.systemPropertiesMode = constants.asNumber(constantName).intValue();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).longValue();
    }
    return (long) 0;
  }
};

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return ((Number) jv).floatValue();
    }
    return (float) 0;
  }
};

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

@Override
public Character convert(Number source) {
  return (char) source.shortValue();
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Subtracts a value from the value of this instance.
 *
 * @param operand  the value to subtract, not null
 * @throws NullPointerException if the object is null
 * @since 2.2
 */
public void subtract(final Number operand) {
  this.value -= operand.byteValue();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) throws IOException {
    if (jv instanceof Number) {
      return BigDecimal.valueOf(((Number) jv).doubleValue());
    }
    return (BigDecimal) null;
  }
};

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

/**
 * Specify the level of caching that this listener container is allowed to apply,
 * in the form of the name of the corresponding constant: e.g. "CACHE_CONNECTION".
 * @see #setCacheLevel
 */
public void setCacheLevelName(String constantName) throws IllegalArgumentException {
  if (!constantName.startsWith("CACHE_")) {
    throw new IllegalArgumentException("Only cache constants allowed");
  }
  setCacheLevel(constants.asNumber(constantName).intValue());
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * get long value.
 *
 * @param key key.
 * @param def default value.
 * @return value or default value.
 */
public long getLong(String key, long def) {
  Object tmp = mMap.get(key);
  return tmp != null && tmp instanceof Number ? ((Number) tmp).longValue() : def;
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * get float value.
 *
 * @param index index.
 * @param def   default value.
 * @return value or default value.
 */
public float getFloat(int index, float def) {
  Object tmp = mArray.get(index);
  return tmp != null && tmp instanceof Number ? ((Number) tmp).floatValue() : def;
}

相关文章