Java 类java.lang.Number 实例源码

项目:fsharpadvent2016    文件:LispReader.java   
public Object invoke(Object reader, Object pct, Object opts, Object pendingForms) {
    PushbackReader r = (PushbackReader) reader;
    if(ARG_ENV.deref() == null)
        {
        return interpretToken(readToken(r, '%'));
        }
    int ch = read1(r);
    unread(r, ch);
    //% alone is first arg
    if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch))
        {
        return registerArg(1);
        }
    Object n = read(r, true, null, true, opts, ensurePending(pendingForms));
    if(n.equals(Compiler._AMP_))
        return registerArg(-1);
    if(!(n instanceof Number))
        throw new IllegalStateException("arg literal must be %, %& or %integer");
    return registerArg(((Number) n).intValue());
}
项目:eclojure    文件:LispReader.java   
public Object invoke(Object reader, Object pct, Object opts, Object pendingForms) {
    PushbackReader r = (PushbackReader) reader;
    if(ARG_ENV.deref() == null)
        {
        return interpretToken(readToken(r, '%'));
        }
    int ch = read1(r);
    unread(r, ch);
    //% alone is first arg
    if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch))
        {
        return registerArg(1);
        }
    Object n = read(r, true, null, true, opts, ensurePending(pendingForms));
    if(n.equals(Compiler._AMP_))
        return registerArg(-1);
    if(!(n instanceof Number))
        throw new IllegalStateException("arg literal must be %, %& or %integer");
    return registerArg(((Number) n).intValue());
}
项目:wava    文件:TestTypeSpec.java   
@Test
public void typeVariableWithBounds()
{
    AnnotationSpec a = AnnotationSpec.builder(ClassName.get("com.squareup.tacos", "A")).build();
    TypeVariableName p = TypeVariableName.get("P", Number.class);
    TypeVariableName q = (TypeVariableName) TypeVariableName.get("Q", Number.class).annotated(a);
    TypeSpec typeSpec = TypeSpec.classBuilder("Location")
            .addTypeVariable(p.withBounds(Comparable.class))
            .addTypeVariable(q.withBounds(Comparable.class))
            .addField(p, "x")
            .addField(q, "y")
            .build();
    assertThat(toString(typeSpec)).isEqualTo(""
            + "package com.squareup.tacos;\n"
            + "\n"
            + "import java.lang.Comparable;\n"
            + "import java.lang.Number;\n"
            + "\n"
            + "class Location<P extends Number & Comparable, Q extends Number & Comparable> {\n"
            + "  P x;\n"
            + "\n"
            + "  @A Q y;\n"
            + "}\n");
}
项目:wava    文件:TestTypeSpec.java   
@Test
public void multipleTypeVariableAddition()
{
    TypeSpec location = TypeSpec.classBuilder("Location")
            .addTypeVariables(Arrays.asList(
                    TypeVariableName.get("T"),
                    TypeVariableName.get("P", Number.class)))
            .build();
    assertThat(toString(location)).isEqualTo(""
            + "package com.squareup.tacos;\n"
            + "\n"
            + "import java.lang.Number;\n"
            + "\n"
            + "class Location<T, P extends Number> {\n"
            + "}\n");
}
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param key
 * @return
 */
public Long getLongNull(Object key) {
    if (key == null)
        return null;
    if (key instanceof Number)
        return new Long(((Number) key).longValue());
    if (key instanceof String) {
        if ( ((String)key).length() < 1 ) return new Long(-1);
        try {
            return new Long((String) key);
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param key
 * @return
 */
public Long getLongNull(Object key) {
    if (key == null)
        return null;
    if (key instanceof Number)
        return new Long(((Number) key).longValue());
    if (key instanceof String) {
        if ( ((String)key).length() < 1 ) return new Long(-1);
        try {
            return new Long((String) key);
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
项目:javapoet    文件:TypeSpecTest.java   
@Test public void typeVariableWithBounds() {
  AnnotationSpec a = AnnotationSpec.builder(ClassName.get("com.squareup.tacos", "A")).build();
  TypeVariableName p = TypeVariableName.get("P", Number.class);
  TypeVariableName q = (TypeVariableName) TypeVariableName.get("Q", Number.class).annotated(a);
  TypeSpec typeSpec = TypeSpec.classBuilder("Location")
      .addTypeVariable(p.withBounds(Comparable.class))
      .addTypeVariable(q.withBounds(Comparable.class))
      .addField(p, "x")
      .addField(q, "y")
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Comparable;\n"
      + "import java.lang.Number;\n"
      + "\n"
      + "class Location<P extends Number & Comparable, @A Q extends Number & Comparable> {\n"
      + "  P x;\n"
      + "\n"
      + "  @A Q y;\n"
      + "}\n");
}
项目:AvI    文件:SQLiteAndroidDatabase.java   
private void bindArgsToStatement(SQLiteStatement myStatement, JSONArray sqlArgs) throws JSONException {
    for (int i = 0; i < sqlArgs.length(); i++) {
        if (sqlArgs.get(i) instanceof Float || sqlArgs.get(i) instanceof Double) {
            myStatement.bindDouble(i + 1, sqlArgs.getDouble(i));
        } else if (sqlArgs.get(i) instanceof Number) {
            myStatement.bindLong(i + 1, sqlArgs.getLong(i));
        } else if (sqlArgs.isNull(i)) {
            myStatement.bindNull(i + 1);
        } else {
            myStatement.bindString(i + 1, sqlArgs.getString(i));
        }
    }
}
项目:biomedicus    文件:MeasuresAnnotationTool.java   
private List<Integer> collectIds(Scanner scanner) {
  String tokens = scanner.nextLine();

  if (tokens.length() == 0) {
    return Collections.emptyList();
  }

  if ("u".equals(tokens)) {
    retry = true;
    return null;
  }

  if (!NON_NUMBER.matcher(tokens).matches()) {
    return null;
  }

  String[] numbers = SPACE_SPLIT.split(tokens);
  List<Integer> results = new ArrayList<>(numbers.length);
  for (String number : numbers) {
    try {
      Number parse = numberFormat.parse(number);
      int i = parse.intValue();
      if (i > 0 && i < tokenCount) {
        results.add(i);
      } else {
        return null;
      }
    } catch (ParseException e) {
      return null;
    }
  }
  return results;
}
项目:thesis-disassembler    文件:ComplexVariableNames.java   
public void methods(){
    List<HashMap<Integer, Set<String>>> localComplexList = complexListField;
    Integer smallNum = new Integer(2);
    Number number = smallNum;
    java.lang.Comparable<?> comparable = smallNum;
}
项目:react-native-sqlite-storage    文件:SQLiteAndroidDatabase.java   
private void bindArgsToStatement(SQLiteStatement myStatement, JSONArray sqlArgs) throws JSONException {
    for (int i = 0; i < sqlArgs.length(); i++) {
        if (sqlArgs.get(i) instanceof Float || sqlArgs.get(i) instanceof Double) {
            myStatement.bindDouble(i + 1, sqlArgs.getDouble(i));
        } else if (sqlArgs.get(i) instanceof Number) {
            myStatement.bindLong(i + 1, sqlArgs.getLong(i));
        } else if (sqlArgs.isNull(i)) {
            myStatement.bindNull(i + 1);
        } else {
            myStatement.bindString(i + 1, sqlArgs.getString(i));
        }
    }
}
项目:react-native-sqlite-storage    文件:SQLitePlugin.java   
private void bindArgsToStatement(SQLiteStatement myStatement, JSONArray sqlArgs) throws JSONException {
    for (int i = 0; i < sqlArgs.length(); i++) {
        if (sqlArgs.get(i) instanceof Float || sqlArgs.get(i) instanceof Double) {
            myStatement.bindDouble(i + 1, sqlArgs.getDouble(i));
        } else if (sqlArgs.get(i) instanceof Number) {
            myStatement.bindLong(i + 1, sqlArgs.getLong(i));
        } else if (sqlArgs.isNull(i)) {
            myStatement.bindNull(i + 1);
        } else {
            myStatement.bindString(i + 1, sqlArgs.getString(i));
        }
    }
}
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param o
 * @return
 */
public static int getInt(Object o) {
    if (o instanceof String) {
        try {
            return (new Integer((String) o)).intValue();
        } catch (Exception e) {
            return -1;
        }
    }
    if (o instanceof Number)
        return ((Number) o).intValue();
    return -1;
}
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param value
 * @param field
 * @param label
 * @param required
 * @param choices
 * @param loader
 * @return
 */
public String formInputRadio(Object value, String field, String label,
        boolean required, String[] choices, Object loader) {
    StringBuffer sb = new StringBuffer();
    // formInputStart(sb, field, "radio", label, required, loader);
    sb.append(formInputHeader(field, label, loader));
    int val = 0;
    if (value != null && value instanceof Number)
        val = ((Number) value).intValue();
    if (value != null && value instanceof String) {
        Integer ival = new Integer((String) value);
        val = ival.intValue();
    }
    if (val < 0)
        val = 0;
    if (choices == null || val >= choices.length)
        val = 0;
    int i = 0;
    sb.append("<ol style=\"list-style-type:none\">\n");
    for (String choice : choices) {
        String checked = "";
        if (i == val)
            checked = " checked=\"checked\"";
        sb.append("<li style=\"border:padding:3px;;margin:7px 3px;\">\n");
        sb.append("<input type=\"radio\" name=\"");
        sb.append(field);
        sb.append("\" value=\"" + i + "\" id=\"");
        String id = field + "_" + choice;
        sb.append(id + "\"");
        sb.append(checked);
        sb.append("/> <label for=\"");
        sb.append(id);
        sb.append("\">");
        sb.append(getI18N(label + "_" + choice, loader));
        sb.append("</label></li>\n");
        i++;
    }
    sb.append("</ol>\n");
    formInputEnd(sb, field, "radio", label, required, loader);
    return sb.toString();
}
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param o
 * @return
 */
public static int getInt(Object o) {
    if (o instanceof String) {
        try {
            return (new Integer((String) o)).intValue();
        } catch (Exception e) {
            return -1;
        }
    }
    if (o instanceof Number)
        return ((Number) o).intValue();
    return -1;
}
项目:javapoet    文件:TypeSpecTest.java   
@Test public void typeVariables() throws Exception {
  TypeVariableName t = TypeVariableName.get("T");
  TypeVariableName p = TypeVariableName.get("P", Number.class);
  ClassName location = ClassName.get(tacosPackage, "Location");
  TypeSpec typeSpec = TypeSpec.classBuilder("Location")
      .addTypeVariable(t)
      .addTypeVariable(p)
      .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), p))
      .addField(t, "label")
      .addField(p, "x")
      .addField(p, "y")
      .addMethod(MethodSpec.methodBuilder("compareTo")
          .addAnnotation(Override.class)
          .addModifiers(Modifier.PUBLIC)
          .returns(int.class)
          .addParameter(p, "p")
          .addCode("return 0;\n")
          .build())
      .addMethod(MethodSpec.methodBuilder("of")
          .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
          .addTypeVariable(t)
          .addTypeVariable(p)
          .returns(ParameterizedTypeName.get(location, t, p))
          .addParameter(t, "label")
          .addParameter(p, "x")
          .addParameter(p, "y")
          .addCode("throw new $T($S);\n", UnsupportedOperationException.class, "TODO")
          .build())
      .build();
  assertThat(toString(typeSpec)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Comparable;\n"
      + "import java.lang.Number;\n"
      + "import java.lang.Override;\n"
      + "import java.lang.UnsupportedOperationException;\n"
      + "\n"
      + "class Location<T, P extends Number> implements Comparable<P> {\n"
      + "  T label;\n"
      + "\n"
      + "  P x;\n"
      + "\n"
      + "  P y;\n"
      + "\n"
      + "  @Override\n"
      + "  public int compareTo(P p) {\n"
      + "    return 0;\n"
      + "  }\n"
      + "\n"
      + "  public static <T, P extends Number> Location<T, P> of(T label, P x, P y) {\n"
      + "    throw new UnsupportedOperationException(\"TODO\");\n"
      + "  }\n"
      + "}\n");
}
项目:javapoet    文件:TypeSpecTest.java   
@Test public void multipleTypeVariableAddition() {
  TypeSpec location = TypeSpec.classBuilder("Location")
      .addTypeVariables(Arrays.asList(
          TypeVariableName.get("T"),
          TypeVariableName.get("P", Number.class)))
      .build();
  assertThat(toString(location)).isEqualTo(""
      + "package com.squareup.tacos;\n"
      + "\n"
      + "import java.lang.Number;\n"
      + "\n"
      + "class Location<T, P extends Number> {\n"
      + "}\n");
}
项目:GitHub    文件:GlideRequests.java   
/**
 * @see ExtensionWithType#asInteger(RequestBuilder)
 */
public GlideRequest<Number> asInteger() {
  GlideRequest<Number> requestBuilder = this.as(Number.class);
  ExtensionWithType.asInteger(requestBuilder);
  return requestBuilder;
}
项目:GitHub    文件:GlideRequests.java   
/**
 * @see ExtensionWithType#asNumber(RequestBuilder)
 */
public GlideRequest<Number> asNumber() {
  return (GlideRequest<Number>) ExtensionWithType.asNumber(this.as(Number.class));
}
项目:WeatherStream    文件:Weather_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Weather model, Number id) {
  model.setWId(id.intValue());
}
项目:WeatherStream    文件:Weather_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Weather model) {
  return model.getWId();
}
项目:WeatherStream    文件:Sys_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Sys model, Number id) {
  model.setSysId(id.intValue());
}
项目:WeatherStream    文件:Sys_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Sys model) {
  return model.getSysId();
}
项目:WeatherStream    文件:Main_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Main model, Number id) {
  model.setId(id.intValue());
}
项目:WeatherStream    文件:Main_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Main model) {
  return model.getId();
}
项目:WeatherStream    文件:Rain_Table.java   
@Override
public final void updateAutoIncrement(WeatherForecastData.Rain model, Number id) {
  model.setId(id.longValue());
}
项目:WeatherStream    文件:Rain_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherForecastData.Rain model) {
  return model.getId();
}
项目:WeatherStream    文件:ForecastList_Table.java   
@Override
public final void updateAutoIncrement(WeatherForecastData.ForecastList model, Number id) {
  model.setId(id.longValue());
}
项目:WeatherStream    文件:ForecastList_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherForecastData.ForecastList model) {
  return model.getId();
}
项目:WeatherStream    文件:Wind_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Wind model, Number id) {
  model.setId(id.intValue());
}
项目:WeatherStream    文件:Wind_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Wind model) {
  return model.getId();
}
项目:WeatherStream    文件:Clouds_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Clouds model, Number id) {
  model.setId(id.intValue());
}
项目:WeatherStream    文件:Clouds_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Clouds model) {
  return model.getId();
}
项目:WeatherStream    文件:Coord_Table.java   
@Override
public final void updateAutoIncrement(WeatherData.Coord model, Number id) {
  model.setId(id.intValue());
}
项目:WeatherStream    文件:Coord_Table.java   
@Override
public final Number getAutoIncrementingId(WeatherData.Coord model) {
  return model.getId();
}
项目:wava    文件:TestTypeSpec.java   
@Test
public void typeVariables()
        throws Exception
{
    TypeVariableName t = TypeVariableName.get("T");
    TypeVariableName p = TypeVariableName.get("P", Number.class);
    ClassName location = ClassName.get(tacosPackage, "Location");
    TypeSpec typeSpec = TypeSpec.classBuilder("Location")
            .addTypeVariable(t)
            .addTypeVariable(p)
            .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), p))
            .addField(t, "label")
            .addField(p, "x")
            .addField(p, "y")
            .addMethod(MethodSpec.methodBuilder("compareTo")
                    .addAnnotation(Override.class)
                    .addModifiers(Modifier.PUBLIC)
                    .returns(int.class)
                    .addParameter(p, "p")
                    .addCode("return 0;\n")
                    .build())
            .addMethod(MethodSpec.methodBuilder("of")
                    .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                    .addTypeVariable(t)
                    .addTypeVariable(p)
                    .returns(ParameterizedTypeName.get(location, t, p))
                    .addParameter(t, "label")
                    .addParameter(p, "x")
                    .addParameter(p, "y")
                    .addCode("throw new $T($S);\n", UnsupportedOperationException.class, "TODO")
                    .build())
            .build();
    assertThat(toString(typeSpec)).isEqualTo(""
            + "package com.squareup.tacos;\n"
            + "\n"
            + "import java.lang.Comparable;\n"
            + "import java.lang.Number;\n"
            + "import java.lang.Override;\n"
            + "import java.lang.UnsupportedOperationException;\n"
            + "\n"
            + "class Location<T, P extends Number> implements Comparable<P> {\n"
            + "  T label;\n"
            + "\n"
            + "  P x;\n"
            + "\n"
            + "  P y;\n"
            + "\n"
            + "  @Override\n"
            + "  public int compareTo(P p) {\n"
            + "    return 0;\n"
            + "  }\n"
            + "\n"
            + "  public static <T, P extends Number> Location<T, P> of(T label, P x, P y) {\n"
            + "    throw new UnsupportedOperationException(\"TODO\");\n"
            + "  }\n"
            + "}\n");
}
项目:Casper    文件:InstanceOfCount.java   
public static void main(String[] args) {

        Number[] list = {11.5, 2, 7.6};
        count(list);
    }
项目:sakai    文件:Foorm.java   
/**
 * 
 * @param value
 * @param field
 * @param label
 * @param required
 * @param choices
 * @param loader
 * @return
 */
public String formInputRadio(Object value, String field, String label,
        boolean required, String[] choices, Object loader) {
    StringBuffer sb = new StringBuffer();
    // formInputStart(sb, field, "radio", label, required, loader);
    sb.append(formInputHeader(field, label, loader));
    int val = 0;
    if (value != null && value instanceof Number)
        val = ((Number) value).intValue();
    if (value != null && value instanceof String) {
        Integer ival = new Integer((String) value);
        val = ival.intValue();
    }
    if (val < 0)
        val = 0;
    if (choices == null || val >= choices.length)
        val = 0;
    int i = 0;
    sb.append("<ol style=\"list-style-type:none\">\n");
    for (String choice : choices) {
        String checked = "";
        if (i == val)
            checked = " checked=\"checked\"";
        sb.append("<li style=\"border:padding:3px;;margin:7px 3px;\">\n");
        sb.append("<input type=\"radio\" name=\"");
        sb.append(field);
        sb.append("\" value=\"" + i + "\" id=\"");
        String id = field + "_" + choice;
        sb.append(id + "\"");
        sb.append(checked);
        sb.append("/> <label for=\"");
        sb.append(id);
        sb.append("\">");
        sb.append(getI18N(label + "_" + choice, loader));
        sb.append("</label></li>\n");
        i++;
    }
    sb.append("</ol>\n");
    formInputEnd(sb, field, "radio", label, required, loader);
    return sb.toString();
}
项目:xpresso    文件:x.java   
/**
 * Sums the elements of the input {@link Iterable} and returs the sum. 
 * 
 * @param iterable      an Iterable of Numbers
 * @param <T>           a type that extends a {@link Number}
 * @return the sum of elements of the input {@link Iterable}
 * 
 */
public static <T extends Number> T sum(Iterable<T> iterable){
    return x.<T>reduce(x.<T>add(), iterable);
}
项目:xpresso    文件:x.java   
/**
 * Averages the elements of the input {@link Iterable} and returs the average. 
 * 
 * @param iterable      an Iterable of Numbers
 * @param <T>           a type that extends a {@link Number}
 * @return the average of elemets of the Iterable
 * 
 */
public static <T extends Number> T avg(Iterable<T> iterable){
    return XUtils.avg(iterable);
}