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()); }
@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"); }
@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"); }
/** * * @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; }
@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"); }
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)); } } }
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; }
public void methods(){ List<HashMap<Integer, Set<String>>> localComplexList = complexListField; Integer smallNum = new Integer(2); Number number = smallNum; java.lang.Comparable<?> comparable = smallNum; }
/** * * @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; }
/** * * @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(); }
@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"); }
/** * @see ExtensionWithType#asInteger(RequestBuilder) */ public GlideRequest<Number> asInteger() { GlideRequest<Number> requestBuilder = this.as(Number.class); ExtensionWithType.asInteger(requestBuilder); return requestBuilder; }
/** * @see ExtensionWithType#asNumber(RequestBuilder) */ public GlideRequest<Number> asNumber() { return (GlideRequest<Number>) ExtensionWithType.asNumber(this.as(Number.class)); }
@Override public final void updateAutoIncrement(WeatherData.Weather model, Number id) { model.setWId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Weather model) { return model.getWId(); }
@Override public final void updateAutoIncrement(WeatherData.Sys model, Number id) { model.setSysId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Sys model) { return model.getSysId(); }
@Override public final void updateAutoIncrement(WeatherData.Main model, Number id) { model.setId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Main model) { return model.getId(); }
@Override public final void updateAutoIncrement(WeatherForecastData.Rain model, Number id) { model.setId(id.longValue()); }
@Override public final Number getAutoIncrementingId(WeatherForecastData.Rain model) { return model.getId(); }
@Override public final void updateAutoIncrement(WeatherForecastData.ForecastList model, Number id) { model.setId(id.longValue()); }
@Override public final Number getAutoIncrementingId(WeatherForecastData.ForecastList model) { return model.getId(); }
@Override public final void updateAutoIncrement(WeatherData.Wind model, Number id) { model.setId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Wind model) { return model.getId(); }
@Override public final void updateAutoIncrement(WeatherData.Clouds model, Number id) { model.setId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Clouds model) { return model.getId(); }
@Override public final void updateAutoIncrement(WeatherData.Coord model, Number id) { model.setId(id.intValue()); }
@Override public final Number getAutoIncrementingId(WeatherData.Coord model) { return model.getId(); }
public static void main(String[] args) { Number[] list = {11.5, 2, 7.6}; count(list); }
/** * 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); }
/** * 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); }