_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q167300
ListBuddiesLayout.toogleListView
validation
private void toogleListView(View v) { if (mLastViewTouchId != v.getId()) { if (mLastViewTouchId == mListViewLeft.getId()) { isLeftListEnabled = true; isRightListEnabled = false; } else { isLeftListEnabled = false; isRightListEnabled = true; } } }
java
{ "resource": "" }
q167301
ListBuddiesLayout.onListScroll
validation
@Override public void onListScroll(View view, float deltaY) { int speed; if (view.getId() == mListViewLeft.getId() && !isLeftListEnabled) { speed = getSpeed(false, deltaY); mListViewRight.smoothScrollBy(speed, 0); } else if (view.getId() == mListViewRight.getId() && !isRightListEnabled) { speed = getSpeed(true, deltaY); mListViewLeft.smoothScrollBy(speed, 0); } }
java
{ "resource": "" }
q167302
SafeUrls.toProto
validation
public static SafeUrlProto toProto(SafeUrl url) { return SafeUrlProto.newBuilder() .setPrivateDoNotAccessOrElseSafeUrlWrappedValue(url.getSafeUrlString()) .build(); }
java
{ "resource": "" }
q167303
SafeStyles.toProto
validation
public static SafeStyleProto toProto(SafeStyle style) { return SafeStyleProto.newBuilder() .setPrivateDoNotAccessOrElseSafeStyleWrappedValue(style.getSafeStyleString()).build(); }
java
{ "resource": "" }
q167304
SafeScripts.toProto
validation
public static SafeScriptProto toProto(SafeScript script) { return SafeScriptProto.newBuilder() .setPrivateDoNotAccessOrElseSafeScriptWrappedValue(script.getSafeScriptString()).build(); }
java
{ "resource": "" }
q167305
SafeStyleSheets.toProto
validation
public static SafeStyleSheetProto toProto(SafeStyleSheet style) { return SafeStyleSheetProto.newBuilder() .setPrivateDoNotAccessOrElseSafeStyleSheetWrappedValue( style.getSafeStyleSheetString()) .build(); }
java
{ "resource": "" }
q167306
TrustedResourceUrls.toProto
validation
public static TrustedResourceUrlProto toProto(TrustedResourceUrl url) { return TrustedResourceUrlProto.newBuilder() .setPrivateDoNotAccessOrElseTrustedResourceUrlWrappedValue( url.getTrustedResourceUrlString()) .build(); }
java
{ "resource": "" }
q167307
SafeHtmls.toProto
validation
public static SafeHtmlProto toProto(SafeHtml safeHtml) { return SafeHtmlProto.newBuilder().setPrivateDoNotAccessOrElseSafeHtmlWrappedValue( safeHtml.getSafeHtmlString()).build(); }
java
{ "resource": "" }
q167308
GenericMath.wrapAngleRad
validation
public static double wrapAngleRad(double angle) { angle %= TrigMath.TWO_PI; if (angle <= -TrigMath.PI) { return angle + TrigMath.TWO_PI; } if (angle > TrigMath.PI) { return angle - TrigMath.TWO_PI; } return angle; }
java
{ "resource": "" }
q167309
GenericMath.round
validation
public static double round(double input, int decimals) { final double p = Math.pow(10, decimals); return Math.round(input * p) / p; }
java
{ "resource": "" }
q167310
GenericMath.lerp
validation
public static double lerp(double x, double x1, double x2, double q0, double q1) { return ((x2 - x) / (x2 - x1)) * q0 + ((x - x1) / (x2 - x1)) * q1; }
java
{ "resource": "" }
q167311
GenericMath.slerp
validation
public static Quaternionf slerp(Quaternionf a, Quaternionf b, float percent) { final float inverted; float cosineTheta = a.dot(b); if (cosineTheta < 0) { cosineTheta = -cosineTheta; inverted = -1; } else { inverted = 1; } if (1 - cosineTheta < GenericMath.FLT_EPSILON) { return a.mul(1 - percent).add(b.mul(percent * inverted)); } final float theta = (float) TrigMath.acos(cosineTheta); final float sineTheta = TrigMath.sin(theta); final float coefficient1 = TrigMath.sin((1 - percent) * theta) / sineTheta; final float coefficient2 = TrigMath.sin(percent * theta) / sineTheta * inverted; return a.mul(coefficient1).add(b.mul(coefficient2)); }
java
{ "resource": "" }
q167312
GenericMath.biLerp
validation
public static double biLerp(double x, double y, double q00, double q01, double q10, double q11, double x1, double x2, double y1, double y2) { double q0 = lerp(x, x1, x2, q00, q10); double q1 = lerp(x, x1, x2, q01, q11); return lerp(y, y1, y2, q0, q1); }
java
{ "resource": "" }
q167313
GenericMath.triLerp
validation
public static double triLerp(double x, double y, double z, double q000, double q001, double q010, double q011, double q100, double q101, double q110, double q111, double x1, double x2, double y1, double y2, double z1, double z2) { double q00 = lerp(x, x1, x2, q000, q100); double q01 = lerp(x, x1, x2, q010, q110); double q10 = lerp(x, x1, x2, q001, q101); double q11 = lerp(x, x1, x2, q011, q111); double q0 = lerp(y, y1, y2, q00, q10); double q1 = lerp(y, y1, y2, q01, q11); return lerp(z, z1, z2, q0, q1); }
java
{ "resource": "" }
q167314
GenericMath.blend
validation
public static Color blend(Color a, Color b) { return lerp(a, b, a.getAlpha() / 255f); }
java
{ "resource": "" }
q167315
GenericMath.clamp
validation
public static double clamp(double value, double low, double high) { if (value < low) { return low; } if (value > high) { return high; } return value; }
java
{ "resource": "" }
q167316
GenericMath.inverseSqrt
validation
public static double inverseSqrt(double a) { final double halfA = 0.5d * a; a = Double.longBitsToDouble(0x5FE6EB50C7B537AAl - (Double.doubleToRawLongBits(a) >> 1)); return a * (1.5d - halfA * a * a); }
java
{ "resource": "" }
q167317
GenericMath.castFloat
validation
public static Float castFloat(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).floatValue(); } try { return Float.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167318
GenericMath.castByte
validation
public static Byte castByte(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).byteValue(); } try { return Byte.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167319
GenericMath.castShort
validation
public static Short castShort(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).shortValue(); } try { return Short.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167320
GenericMath.castInt
validation
public static Integer castInt(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).intValue(); } try { return Integer.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167321
GenericMath.castDouble
validation
public static Double castDouble(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).doubleValue(); } try { return Double.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167322
GenericMath.castLong
validation
public static Long castLong(Object o) { if (o == null) { return null; } if (o instanceof Number) { return ((Number) o).longValue(); } try { return Long.valueOf(o.toString()); } catch (NumberFormatException e) { return null; } }
java
{ "resource": "" }
q167323
GenericMath.castBoolean
validation
public static Boolean castBoolean(Object o) { if (o == null) { return null; } if (o instanceof Boolean) { return (Boolean) o; } else if (o instanceof String) { try { return Boolean.parseBoolean((String) o); } catch (IllegalArgumentException e) { return null; } } return null; }
java
{ "resource": "" }
q167324
GenericMath.mean
validation
public static int mean(int... values) { int sum = 0; for (int v : values) { sum += v; } return sum / values.length; }
java
{ "resource": "" }
q167325
GenericMath.mod
validation
public static double mod(double a, double div) { final double remainder = a % div; return remainder < 0 ? remainder + div : remainder; }
java
{ "resource": "" }
q167326
GenericMath.multiplyToShift
validation
public static int multiplyToShift(int a) { if (a < 1) { throw new IllegalArgumentException("Multiplicand must be at least 1"); } int shift = 31 - Integer.numberOfLeadingZeros(a); if ((1 << shift) != a) { throw new IllegalArgumentException("Multiplicand must be a power of 2"); } return shift; }
java
{ "resource": "" }
q167327
Quaterniond.mul
validation
@Override public Quaterniond mul(double a) { return new Quaterniond(x * a, y * a, z * a, w * a); }
java
{ "resource": "" }
q167328
Quaterniond.div
validation
@Override public Quaterniond div(double a) { return new Quaterniond(x / a, y / a, z / a, w / a); }
java
{ "resource": "" }
q167329
Quaterniond.rotate
validation
public Vector3d rotate(double x, double y, double z) { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot rotate by the zero quaternion"); } final double nx = this.x / length; final double ny = this.y / length; final double nz = this.z / length; final double nw = this.w / length; final double px = nw * x + ny * z - nz * y; final double py = nw * y + nz * x - nx * z; final double pz = nw * z + nx * y - ny * x; final double pw = -nx * x - ny * y - nz * z; return new Vector3d( pw * -nx + px * nw - py * nz + pz * ny, pw * -ny + py * nw - pz * nx + px * nz, pw * -nz + pz * nw - px * ny + py * nx); }
java
{ "resource": "" }
q167330
Quaterniond.lengthSquared
validation
@Override public double lengthSquared() { return x * x + y * y + z * z + w * w; }
java
{ "resource": "" }
q167331
Quaterniond.normalize
validation
@Override public Quaterniond normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero quaternion"); } return new Quaterniond(x / length, y / length, z / length, w / length); }
java
{ "resource": "" }
q167332
Quaterniond.fromImaginary
validation
public static Quaterniond fromImaginary(double x, double y, double z) { return x == 0 && y == 0 && z == 0 ? ZERO : new Quaterniond(x, y, z, 0); }
java
{ "resource": "" }
q167333
Quaterniond.from
validation
public static Quaterniond from(double x, double y, double z, double w) { return x == 0 && y == 0 && z == 0 && w == 0 ? ZERO : new Quaterniond(x, y, z, w); }
java
{ "resource": "" }
q167334
Quaterniond.fromAxesAnglesDeg
validation
public static Quaterniond fromAxesAnglesDeg(double pitch, double yaw, double roll) { return Quaterniond.fromAngleDegAxis(yaw, Vector3d.UNIT_Y). mul(Quaterniond.fromAngleDegAxis(pitch, Vector3d.UNIT_X)). mul(Quaterniond.fromAngleDegAxis(roll, Vector3d.UNIT_Z)); }
java
{ "resource": "" }
q167335
Quaterniond.fromAxesAnglesRad
validation
public static Quaterniond fromAxesAnglesRad(double pitch, double yaw, double roll) { return Quaterniond.fromAngleRadAxis(yaw, Vector3d.UNIT_Y). mul(Quaterniond.fromAngleRadAxis(pitch, Vector3d.UNIT_X)). mul(Quaterniond.fromAngleRadAxis(roll, Vector3d.UNIT_Z)); }
java
{ "resource": "" }
q167336
Quaterniond.fromAngleRadAxis
validation
public static Quaterniond fromAngleRadAxis(double angle, Vector3d axis) { return fromAngleRadAxis(angle, axis.getX(), axis.getY(), axis.getZ()); }
java
{ "resource": "" }
q167337
Quaterniond.fromAngleDegAxis
validation
public static Quaterniond fromAngleDegAxis(float angle, float x, float y, float z) { return fromAngleRadAxis(Math.toRadians(angle), x, y, z); }
java
{ "resource": "" }
q167338
Vector4i.getMinAxis
validation
@Override public int getMinAxis() { int value = x; int axis = 0; if (y < value) { value = y; axis = 1; } if (z < value) { value = z; axis = 2; } if (w < value) { axis = 3; } return axis; }
java
{ "resource": "" }
q167339
Complexf.mul
validation
public Complexf mul(float x, float y) { return new Complexf( this.x * x - this.y * y, this.x * y + this.y * x); }
java
{ "resource": "" }
q167340
Complexf.div
validation
public Complexf div(float x, float y) { final float d = x * x + y * y; return new Complexf( (this.x * x + this.y * y) / d, (this.y * x - this.x * y) / d); }
java
{ "resource": "" }
q167341
Complexf.rotate
validation
public Vector2f rotate(float x, float y) { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot rotate by the zero complex"); } final float nx = this.x / length; final float ny = this.y / length; return new Vector2f(x * nx - y * ny, y * nx + x * ny); }
java
{ "resource": "" }
q167342
Complexf.normalize
validation
@Override public Complexf normalize() { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot normalize the zero complex"); } return new Complexf(x / length, y / length); }
java
{ "resource": "" }
q167343
Complexf.toQuaternion
validation
public Quaternionf toQuaternion(float x, float y, float z) { return Quaternionf.fromAngleRadAxis(getAngleRad(), x, y, z); }
java
{ "resource": "" }
q167344
Complexf.from
validation
public static Complexf from(float x, float y) { return x == 0 && y == 0 ? ZERO : new Complexf(x, y); }
java
{ "resource": "" }
q167345
Complexf.fromAngleRad
validation
public static Complexf fromAngleRad(float angle) { return new Complexf(TrigMath.cos(angle), TrigMath.sin(angle)); }
java
{ "resource": "" }
q167346
Vector4l.getMaxAxis
validation
@Override public int getMaxAxis() { long value = x; int axis = 0; if (y > value) { value = y; axis = 1; } if (z > value) { value = z; axis = 2; } if (w > value) { axis = 3; } return axis; }
java
{ "resource": "" }
q167347
HashFunctions.hash
validation
public static int hash(double value) { assert !Double.isNaN(value) : "Values of NaN are not supported."; long bits = Double.doubleToLongBits(value); return (int) (bits ^ (bits >>> 32)); //return (int) Double.doubleToLongBits(value*663608941.737); // This avoids excessive hashCollisions in the case values are of the form (1.0, 2.0, 3.0, ...) }
java
{ "resource": "" }
q167348
Quaternionf.add
validation
public Quaternionf add(float x, float y, float z, float w) { return new Quaternionf(this.x + x, this.y + y, this.z + z, this.w + w); }
java
{ "resource": "" }
q167349
Quaternionf.mul
validation
@Override public Quaternionf mul(float a) { return new Quaternionf(x * a, y * a, z * a, w * a); }
java
{ "resource": "" }
q167350
Quaternionf.div
validation
@Override public Quaternionf div(float a) { return new Quaternionf(x / a, y / a, z / a, w / a); }
java
{ "resource": "" }
q167351
Quaternionf.getAxis
validation
public Vector3f getAxis() { final float q = (float) Math.sqrt(1 - w * w); return new Vector3f(x / q, y / q, z / q); }
java
{ "resource": "" }
q167352
Quaternionf.getAxesAnglesRad
validation
public Vector3f getAxesAnglesRad() { final double roll; final double pitch; double yaw; final double test = w * x - y * z; if (Math.abs(test) < 0.4999) { roll = TrigMath.atan2(2 * (w * z + x * y), 1 - 2 * (x * x + z * z)); pitch = TrigMath.asin(2 * test); yaw = TrigMath.atan2(2 * (w * y + z * x), 1 - 2 * (x * x + y * y)); } else { final int sign = (test < 0) ? -1 : 1; roll = 0; pitch = sign * Math.PI / 2; yaw = -sign * 2 * TrigMath.atan2(z, w); } return new Vector3f(pitch, yaw, roll); }
java
{ "resource": "" }
q167353
Quaternionf.fromImaginary
validation
public static Quaternionf fromImaginary(float x, float y, float z) { return x == 0 && y == 0 && z == 0 ? ZERO : new Quaternionf(x, y, z, 0); }
java
{ "resource": "" }
q167354
Quaternionf.from
validation
public static Quaternionf from(float x, float y, float z, float w) { return x == 0 && y == 0 && z == 0 && w == 0 ? ZERO : new Quaternionf(x, y, z, w); }
java
{ "resource": "" }
q167355
Quaternionf.fromAxesAnglesDeg
validation
public static Quaternionf fromAxesAnglesDeg(float pitch, float yaw, float roll) { return Quaternionf.fromAngleDegAxis(yaw, Vector3f.UNIT_Y). mul(Quaternionf.fromAngleDegAxis(pitch, Vector3f.UNIT_X)). mul(Quaternionf.fromAngleDegAxis(roll, Vector3f.UNIT_Z)); }
java
{ "resource": "" }
q167356
Quaternionf.fromAxesAnglesRad
validation
public static Quaternionf fromAxesAnglesRad(float pitch, float yaw, float roll) { return Quaternionf.fromAngleRadAxis(yaw, Vector3f.UNIT_Y). mul(Quaternionf.fromAngleRadAxis(pitch, Vector3f.UNIT_X)). mul(Quaternionf.fromAngleRadAxis(roll, Vector3f.UNIT_Z)); }
java
{ "resource": "" }
q167357
Quaternionf.fromAngleRadAxis
validation
public static Quaternionf fromAngleRadAxis(float angle, Vector3f axis) { return fromAngleRadAxis(angle, axis.getX(), axis.getY(), axis.getZ()); }
java
{ "resource": "" }
q167358
Quaternionf.fromAngleRadAxis
validation
public static Quaternionf fromAngleRadAxis(double angle, double x, double y, double z) { return fromAngleRadAxis((float) angle, (float) x, (float) y, (float) z); }
java
{ "resource": "" }
q167359
Complexd.mul
validation
public Complexd mul(double x, double y) { return new Complexd( this.x * x - this.y * y, this.x * y + this.y * x); }
java
{ "resource": "" }
q167360
Complexd.div
validation
public Complexd div(double x, double y) { final double d = x * x + y * y; return new Complexd( (this.x * x + this.y * y) / d, (this.y * x - this.x * y) / d); }
java
{ "resource": "" }
q167361
Complexd.rotate
validation
public Vector2d rotate(double x, double y) { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot rotate by the zero complex"); } final double nx = this.x / length; final double ny = this.y / length; return new Vector2d(x * nx - y * ny, y * nx + x * ny); }
java
{ "resource": "" }
q167362
Complexd.toQuaternion
validation
public Quaterniond toQuaternion(double x, double y, double z) { return Quaterniond.fromAngleRadAxis(getAngleRad(), x, y, z); }
java
{ "resource": "" }
q167363
Complexd.from
validation
public static Complexd from(double x, double y) { return x == 0 && y == 0 ? ZERO : new Complexd(x, y); }
java
{ "resource": "" }
q167364
Complexd.fromAngleRad
validation
public static Complexd fromAngleRad(double angle) { return new Complexd(TrigMath.cos(angle), TrigMath.sin(angle)); }
java
{ "resource": "" }
q167365
ScalableLayout.moveChildView
validation
public void moveChildView(View pChildView, float pScale_Left, float pScale_Top) { ScalableLayout.LayoutParams lSLLP = getChildLayoutParams(pChildView); lSLLP.mScale_Left = pScale_Left; lSLLP.mScale_Top = pScale_Top; postInvalidate(); }
java
{ "resource": "" }
q167366
ScalableLayout.moveChildView
validation
public void moveChildView(View pChildView, float pScale_Left, float pScale_Top, float pScale_Width, float pScale_Height) { ScalableLayout.LayoutParams lSLLP = getChildLayoutParams(pChildView); lSLLP.mScale_Left = pScale_Left; lSLLP.mScale_Top = pScale_Top; lSLLP.mScale_Width = pScale_Width; lSLLP.mScale_Height = pScale_Height; postInvalidate(); }
java
{ "resource": "" }
q167367
Bypass.setBlockSpan
validation
private static void setBlockSpan(SpannableStringBuilder builder, Object what) { int length = Math.max(0, builder.length() - 1); builder.setSpan(what, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
java
{ "resource": "" }
q167368
ConstraintFormulaSet.reduce
validation
public BoundSet reduce(TypeSolver typeSolver) { List<ConstraintFormula> constraints = new LinkedList<>(constraintFormulas); BoundSet boundSet = BoundSet.empty(); while (constraints.size() > 0) { ConstraintFormula constraintFormula = constraints.remove(0); ConstraintFormula.ReductionResult reductionResult = constraintFormula.reduce(boundSet); constraints.addAll(reductionResult.getConstraintFormulas()); boundSet.incorporate(reductionResult.getBoundSet(), typeSolver); } return boundSet; }
java
{ "resource": "" }
q167369
ReferenceTypeImpl.transformTypeParameters
validation
@Override public ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer) { ResolvedType result = this; int i = 0; for (ResolvedType tp : this.typeParametersValues()) { ResolvedType transformedTp = transformer.transform(tp); // Identity comparison on purpose if (transformedTp != tp) { List<ResolvedType> typeParametersCorrected = result.asReferenceType().typeParametersValues(); typeParametersCorrected.set(i, transformedTp); result = create(typeDeclaration, typeParametersCorrected); } i++; } return result; }
java
{ "resource": "" }
q167370
SymbolReference.solved
validation
public static <S extends ResolvedDeclaration, S2 extends S> SymbolReference<S> solved(S2 symbolDeclaration) { return new SymbolReference<S>(Optional.of(symbolDeclaration)); }
java
{ "resource": "" }
q167371
SymbolReference.unsolved
validation
public static <S extends ResolvedDeclaration, S2 extends S> SymbolReference<S> unsolved(Class<S2> clazz) { return new SymbolReference<>(Optional.empty()); }
java
{ "resource": "" }
q167372
TypeHelper.isProperType
validation
public static boolean isProperType(ResolvedType type) { if (type instanceof InferenceVariable) { return false; } if (type instanceof ResolvedReferenceType) { ResolvedReferenceType referenceType = (ResolvedReferenceType) type; return referenceType.typeParametersValues().stream().allMatch(it -> isProperType(it)); } if (type instanceof ResolvedWildcard) { ResolvedWildcard wildcard = (ResolvedWildcard)type; if (wildcard.isBounded()) { return isProperType(wildcard.getBoundedType()); } else { return true; } } if (type.isPrimitive()) { return true; } if (type.isTypeVariable()) { // FIXME I am not sure... return false; } if (type.isArray()) { return isProperType(type.asArrayType().getComponentType()); } throw new UnsupportedOperationException(type.toString()); }
java
{ "resource": "" }
q167373
TypeHelper.leastUpperBound
validation
public static ResolvedType leastUpperBound(Set<ResolvedType> types) { if (types.size() == 0) { throw new IllegalArgumentException(); } // The least upper bound, or "lub", of a set of reference types is a shared supertype that is more specific than // any other shared supertype (that is, no other shared supertype is a subtype of the least upper bound). // This type, lub(U1, ..., Uk), is determined as follows. // // If k = 1, then the lub is the type itself: lub(U) = U. if (types.size() == 1) { return types.stream().findFirst().get(); } // //Otherwise: // //For each Ui (1 ≤ i ≤ k): // //Let ST(Ui) be the set of supertypes of Ui. // //Let EST(Ui), the set of erased supertypes of Ui, be: // //EST(Ui) = { |W| | W in ST(Ui) } where |W| is the erasure of W. // //The reason for computing the set of erased supertypes is to deal with situations where the set of types includes several distinct parameterizations of a generic type. // //For example, given List<String> and List<Object>, simply intersecting the sets ST(List<String>) = { List<String>, Collection<String>, Object } and ST(List<Object>) = { List<Object>, Collection<Object>, Object } would yield a set { Object }, and we would have lost track of the fact that the upper bound can safely be assumed to be a List. // //In contrast, intersecting EST(List<String>) = { List, Collection, Object } and EST(List<Object>) = { List, Collection, Object } yields { List, Collection, Object }, which will eventually enable us to produce List<?>. // //Let EC, the erased candidate set for U1 ... Uk, be the intersection of all the sets EST(Ui) (1 ≤ i ≤ k). // //Let MEC, the minimal erased candidate set for U1 ... Uk, be: // //MEC = { V | V in EC, and for all W ≠ V in EC, it is not the case that W <: V } // //Because we are seeking to infer more precise types, we wish to filter out any candidates that are supertypes of other candidates. This is what computing MEC accomplishes. In our running example, we had EC = { List, Collection, Object }, so MEC = { List }. The next step is to recover type arguments for the erased types in MEC. // //For any element G of MEC that is a generic type: // //Let the "relevant" parameterizations of G, Relevant(G), be: // //Relevant(G) = { V | 1 ≤ i ≤ k: V in ST(Ui) and V = G<...> } // //In our running example, the only generic element of MEC is List, and Relevant(List) = { List<String>, List<Object> }. We will now seek to find a type argument for List that contains (§4.5.1) both String and Object. // //This is done by means of the least containing parameterization (lcp) operation defined below. The first line defines lcp() on a set, such as Relevant(List), as an operation on a list of the elements of the set. The next line defines the operation on such lists, as a pairwise reduction on the elements of the list. The third line is the definition of lcp() on pairs of parameterized types, which in turn relies on the notion of least containing type argument (lcta). lcta() is defined for all possible cases. // //Let the "candidate" parameterization of G, Candidate(G), be the most specific parameterization of the generic type G that contains all the relevant parameterizations of G: // //Candidate(G) = lcp(Relevant(G)) // //where lcp(), the least containing invocation, is: // //lcp(S) = lcp(e1, ..., en) where ei (1 ≤ i ≤ n) in S // //lcp(e1, ..., en) = lcp(lcp(e1, e2), e3, ..., en) // //lcp(G<X1, ..., Xn>, G<Y1, ..., Yn>) = G<lcta(X1, Y1), ..., lcta(Xn, Yn)> // //lcp(G<X1, ..., Xn>) = G<lcta(X1), ..., lcta(Xn)> // //and where lcta(), the least containing type argument, is: (assuming U and V are types) // //lcta(U, V) = U if U = V, otherwise ? extends lub(U, V) // //lcta(U, ? extends V) = ? extends lub(U, V) // //lcta(U, ? super V) = ? super glb(U, V) // //lcta(? extends U, ? extends V) = ? extends lub(U, V) // //lcta(? extends U, ? super V) = U if U = V, otherwise ? // //lcta(? super U, ? super V) = ? super glb(U, V) // //lcta(U) = ? if U's upper bound is Object, otherwise ? extends lub(U,Object) // //and where glb() is as defined in §5.1.10. // //Let lub(U1 ... Uk) be: // //Best(W1) & ... & Best(Wr) // //where Wi (1 ≤ i ≤ r) are the elements of MEC, the minimal erased candidate set of U1 ... Uk; // //and where, if any of these elements are generic, we use the candidate parameterization (so as to recover type arguments): // //Best(X) = Candidate(X) if X is generic; X otherwise. // //Strictly speaking, this lub() function only approximates a least upper bound. Formally, there may exist some other type T such that all of U1 ... Uk are subtypes of T and T is a subtype of lub(U1, ..., Uk). However, a compiler for the Java programming language must implement lub() as specified above. // //It is possible that the lub() function yields an infinite type. This is permissible, and a compiler for the Java programming language must recognize such situations and represent them appropriately using cyclic data structures. // //The possibility of an infinite type stems from the recursive calls to lub(). Readers familiar with recursive types should note that an infinite type is not the same as a recursive type throw new UnsupportedOperationException(); }
java
{ "resource": "" }
q167374
TypeHelper.groundTargetTypeOfLambda
validation
public static Pair<ResolvedType, Boolean> groundTargetTypeOfLambda(LambdaExpr lambdaExpr, ResolvedType T, TypeSolver typeSolver) { // The ground target type is derived from T as follows: // boolean used18_5_3 = false; boolean wildcardParameterized = T.asReferenceType().typeParametersValues().stream() .anyMatch(tp -> tp.isWildcard()); if (wildcardParameterized) { // - If T is a wildcard-parameterized functional interface type and the lambda expression is explicitly typed, // then the ground target type is inferred as described in §18.5.3. if (ExpressionHelper.isExplicitlyTyped(lambdaExpr)) { used18_5_3 = true; throw new UnsupportedOperationException(); } // - If T is a wildcard-parameterized functional interface type and the lambda expression is implicitly typed, // then the ground target type is the non-wildcard parameterization (§9.9) of T. else { return new Pair<>(nonWildcardParameterizationOf(T.asReferenceType(), typeSolver), used18_5_3); } } // - Otherwise, the ground target type is T. return new Pair<>(T, used18_5_3); }
java
{ "resource": "" }
q167375
TypeHelper.nonWildcardParameterizationOf
validation
private static ResolvedReferenceType nonWildcardParameterizationOf(ResolvedReferenceType originalType, TypeSolver typeSolver) { List<ResolvedType> TIs = new LinkedList<>(); List<ResolvedType> AIs = originalType.typeParametersValues(); List<ResolvedTypeParameterDeclaration> TPs = originalType.getTypeDeclaration().getTypeParameters(); // Let P1...Pn be the type parameters of I with corresponding bounds B1...Bn. For all i (1 ≤ i ≤ n), // Ti is derived according to the form of Ai: ResolvedReferenceType object = new ReferenceTypeImpl(typeSolver.solveType(Object.class.getCanonicalName()), typeSolver); for (int i=0;i<AIs.size();i++) { ResolvedType Ai = AIs.get(i); ResolvedType Ti = null; // - If Ai is a type, then Ti = Ai. if (!Ai.isWildcard()) { Ti = Ai; } // - If Ai is a wildcard, and the corresponding type parameter's bound, Bi, mentions one of P1...Pn, then // Ti is undefined and there is no function type. if (Ti == null && Ai.isWildcard() && Ai.asWildcard().mention(originalType.getTypeDeclaration().getTypeParameters())) { throw new IllegalArgumentException(); } // - Otherwise: if (Ti == null) { ResolvedType Bi = TPs.get(i).hasLowerBound() ? TPs.get(i).getLowerBound() : object; // - If Ai is an unbound wildcard ?, then Ti = Bi. if (Ai.isWildcard() && !Ai.asWildcard().isBounded()) { Ti = Bi; } // - If Ai is a upper-bounded wildcard ? extends Ui, then Ti = glb(Ui, Bi) (§5.1.10). else if (Ai.isWildcard() && Ai.asWildcard().isUpperBounded()) { ResolvedType Ui = Ai.asWildcard().getBoundedType(); Ti = glb(new HashSet<>(Arrays.asList(Ui, Bi))); } // - If Ai is a lower-bounded wildcard ? super Li, then Ti = Li. else if (Ai.isWildcard() && Ai.asWildcard().isLowerBounded()) { Ti = Ai.asWildcard().getBoundedType(); } else throw new RuntimeException("This should not happen"); } TIs.add(Ti); } return new ReferenceTypeImpl(originalType.getTypeDeclaration(), TIs, typeSolver); }
java
{ "resource": "" }
q167376
TypeHelper.glb
validation
public static ResolvedType glb(Set<ResolvedType> types) { if (types.size() == 0) { throw new IllegalArgumentException(); } if (types.size() == 1) { return types.iterator().next(); } return new ResolvedIntersectionType(types); }
java
{ "resource": "" }
q167377
TypeExtractor.solveDotExpressionType
validation
private ResolvedType solveDotExpressionType(ResolvedReferenceTypeDeclaration parentType, FieldAccessExpr node) { // Fields and internal type declarations cannot have the same name. // Thus, these checks will always be mutually exclusive. if (parentType.hasField(node.getName().getId())) { return parentType.getField(node.getName().getId()).getType(); } else if (parentType.hasInternalType(node.getName().getId())) { return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId()), typeSolver); } else { throw new UnsolvedSymbolException(node.getName().getId()); } }
java
{ "resource": "" }
q167378
JavaParserFacade.solve
validation
public SymbolReference<ResolvedConstructorDeclaration> solve(ObjectCreationExpr objectCreationExpr, boolean solveLambdas) { List<ResolvedType> argumentTypes = new LinkedList<>(); List<LambdaArgumentTypePlaceholder> placeholders = new LinkedList<>(); solveArguments(objectCreationExpr, objectCreationExpr.getArguments(), solveLambdas, argumentTypes, placeholders); ResolvedType classDecl = JavaParserFacade.get(typeSolver).convert(objectCreationExpr.getType(), objectCreationExpr); if (!classDecl.isReferenceType()) { return SymbolReference.unsolved(ResolvedConstructorDeclaration.class); } SymbolReference<ResolvedConstructorDeclaration> res = ConstructorResolutionLogic.findMostApplicable(((ResolvedClassDeclaration) classDecl.asReferenceType().getTypeDeclaration()).getConstructors(), argumentTypes, typeSolver); for (LambdaArgumentTypePlaceholder placeholder : placeholders) { placeholder.setMethod(res); } return res; }
java
{ "resource": "" }
q167379
JavaParserFacade.solve
validation
public SymbolReference<ResolvedMethodDeclaration> solve(MethodCallExpr methodCallExpr, boolean solveLambdas) { List<ResolvedType> argumentTypes = new LinkedList<>(); List<LambdaArgumentTypePlaceholder> placeholders = new LinkedList<>(); solveArguments(methodCallExpr, methodCallExpr.getArguments(), solveLambdas, argumentTypes, placeholders); SymbolReference<ResolvedMethodDeclaration> res = JavaParserFactory.getContext(methodCallExpr, typeSolver).solveMethod(methodCallExpr.getName().getId(), argumentTypes, false, typeSolver); for (LambdaArgumentTypePlaceholder placeholder : placeholders) { placeholder.setMethod(res); } return res; }
java
{ "resource": "" }
q167380
JavaParserFacade.find
validation
private Optional<ResolvedType> find(Map<Node, ResolvedType> map, LambdaExpr lambdaExpr) { for (Node key : map.keySet()) { if (key instanceof LambdaExpr) { LambdaExpr keyLambdaExpr = (LambdaExpr) key; if (keyLambdaExpr.toString().equals(lambdaExpr.toString()) && getParentNode(keyLambdaExpr) == getParentNode(lambdaExpr)) { return Optional.of(map.get(keyLambdaExpr)); } } } return Optional.empty(); }
java
{ "resource": "" }
q167381
JavaParserFacade.qName
validation
private String qName(ClassOrInterfaceType classOrInterfaceType) { String name = classOrInterfaceType.getName().getId(); if (classOrInterfaceType.getScope().isPresent()) { return qName(classOrInterfaceType.getScope().get()) + "." + name; } else { return name; } }
java
{ "resource": "" }
q167382
JavaParserFacade.getTypeOfThisIn
validation
public ResolvedType getTypeOfThisIn(Node node) { // TODO consider static methods if (node instanceof ClassOrInterfaceDeclaration) { return new ReferenceTypeImpl(getTypeDeclaration((ClassOrInterfaceDeclaration) node), typeSolver); } else if (node instanceof EnumDeclaration) { JavaParserEnumDeclaration enumDeclaration = new JavaParserEnumDeclaration((EnumDeclaration) node, typeSolver); return new ReferenceTypeImpl(enumDeclaration, typeSolver); } else if (node instanceof ObjectCreationExpr && ((ObjectCreationExpr) node).getAnonymousClassBody().isPresent()) { JavaParserAnonymousClassDeclaration anonymousDeclaration = new JavaParserAnonymousClassDeclaration((ObjectCreationExpr) node, typeSolver); return new ReferenceTypeImpl(anonymousDeclaration, typeSolver); } else { return getTypeOfThisIn(getParentNode(node)); } }
java
{ "resource": "" }
q167383
ControlFlowLogic.exitTheStatement
validation
public boolean exitTheStatement(BreakStmt breakStmt) { if (!isReachable(breakStmt)) { return false; } Statement breakTarget = breakTarget(breakStmt); for (TryStmt tryStmt : containedTryStmts(breakTarget)) { if (contains(tryStmt.getTryBlock(), breakStmt)) { if (!tryStmt.getFinallyBlock().isPresent() && !canCompleteNormally(tryStmt.getFinallyBlock().get())) { return false; } } } return true; }
java
{ "resource": "" }
q167384
ControlFlowLogic.canCompleteNormally
validation
public boolean canCompleteNormally(Statement statement) { if (!isReachable(statement)) { return false; } GenericVisitor<Boolean, Void> visitor = new GenericVisitorAdapter<Boolean, Void>(){ @Override public Boolean visit(BlockStmt n, Void arg) { // An empty block that is not a switch block can complete normally iff it is reachable if (n.isEmpty() && !parentIs(statement, SwitchStmt.class)) { return isReachable(statement); } // A non-empty block that is not a switch block can complete normally iff the last statement in // it can complete normally. if (!n.isEmpty() && !parentIs(statement, SwitchStmt.class)) { return canCompleteNormally(n.getStatement(n.getStatements().size() - 1)); } throw new UnsupportedOperationException(); } @Override public Boolean visit(LabeledStmt n, Void arg) { // A labeled statement can complete normally if at least one of the following is true: // – The contained statement can complete normally. // – There is a reachable break statement that exits the labeled statement. throw new UnsupportedOperationException(); } @Override public Boolean visit(EmptyStmt n, Void arg) { // An empty statement can complete normally iff it is reachable. return isReachable(n); } @Override public Boolean visit(LocalClassDeclarationStmt n, Void arg) { // A local class declaration statement can complete normally iff it is reachable. return isReachable(n); } @Override public Boolean visit(IfStmt n, Void arg) { if (n.getElseStmt().isPresent()) { // An if-then-else statement can complete normally iff the then-statement can // complete normally or the else-statement can complete normally. return canCompleteNormally(n.getThenStmt()) || canCompleteNormally(n.getElseStmt().get()); } else { // An if-then statement can complete normally iff it is reachable. return isReachable(n); } } @Override public Boolean visit(AssertStmt n, Void arg) { // An assert statement can complete normally iff it is reachable. return isReachable(n); } @Override public Boolean visit(ExpressionStmt n, Void arg) { // A local variable declaration statement can complete normally iff it is reachable. if (n.getExpression() instanceof VariableDeclarationExpr) { VariableDeclarationExpr expr = (VariableDeclarationExpr) n.getExpression(); return isReachable(n); } // An expression statement can complete normally iff it is reachable. return isReachable(n); } }; return statement.accept(visitor, null); }
java
{ "resource": "" }
q167385
SymbolSolver.solveTypeInType
validation
@Deprecated public SymbolReference<ResolvedTypeDeclaration> solveTypeInType(ResolvedTypeDeclaration typeDeclaration, String name) { if (typeDeclaration instanceof JavaParserClassDeclaration) { return ((JavaParserClassDeclaration) typeDeclaration).solveType(name, typeSolver); } if (typeDeclaration instanceof JavaParserInterfaceDeclaration) { return ((JavaParserInterfaceDeclaration) typeDeclaration).solveType(name, typeSolver); } return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); }
java
{ "resource": "" }
q167386
MethodResolutionLogic.solveMethodInType
validation
public static SymbolReference<ResolvedMethodDeclaration> solveMethodInType(ResolvedTypeDeclaration typeDeclaration, String name, List<ResolvedType> argumentsTypes, boolean staticOnly, TypeSolver typeSolver) { if (typeDeclaration instanceof JavaParserClassDeclaration) { Context ctx = ((JavaParserClassDeclaration) typeDeclaration).getContext(); return ctx.solveMethod(name, argumentsTypes, staticOnly, typeSolver); } if (typeDeclaration instanceof JavaParserInterfaceDeclaration) { Context ctx = ((JavaParserInterfaceDeclaration) typeDeclaration).getContext(); return ctx.solveMethod(name, argumentsTypes, staticOnly, typeSolver); } if (typeDeclaration instanceof JavaParserEnumDeclaration) { if (name.equals("values") && argumentsTypes.isEmpty()) { return SymbolReference.solved(new JavaParserEnumDeclaration.ValuesMethod((JavaParserEnumDeclaration) typeDeclaration, typeSolver)); } Context ctx = ((JavaParserEnumDeclaration) typeDeclaration).getContext(); return ctx.solveMethod(name, argumentsTypes, staticOnly, typeSolver); } if (typeDeclaration instanceof JavaParserAnonymousClassDeclaration) { Context ctx = ((JavaParserAnonymousClassDeclaration) typeDeclaration).getContext(); return ctx.solveMethod(name, argumentsTypes, staticOnly, typeSolver); } if (typeDeclaration instanceof ReflectionClassDeclaration) { return ((ReflectionClassDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } if (typeDeclaration instanceof ReflectionInterfaceDeclaration) { return ((ReflectionInterfaceDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } if (typeDeclaration instanceof ReflectionEnumDeclaration) { return ((ReflectionEnumDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } if (typeDeclaration instanceof JavassistInterfaceDeclaration) { return ((JavassistInterfaceDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } if (typeDeclaration instanceof JavassistClassDeclaration) { return ((JavassistClassDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } if (typeDeclaration instanceof JavassistEnumDeclaration) { return ((JavassistEnumDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly); } throw new UnsupportedOperationException(typeDeclaration.getClass().getCanonicalName()); }
java
{ "resource": "" }
q167387
Value.from
validation
public static Value from(ResolvedValueDeclaration decl) { ResolvedType type = decl.getType(); return new Value(type, decl.getName()); }
java
{ "resource": "" }
q167388
TypeInference.invocationApplicabilityInference
validation
public boolean invocationApplicabilityInference(MethodCallExpr methodCallExpr, ResolvedMethodDeclaration methodDeclaration) { if (!methodCallExpr.getNameAsString().equals(methodDeclaration.getName())) { throw new IllegalArgumentException(); } Optional<InstantiationSet> partial = instantiationInference(methodCallExpr, methodDeclaration); if (!partial.isPresent()) { return false; } int nActualParams = methodCallExpr.getArguments().size(); int nFormalParams = methodDeclaration.getNumberOfParams(); if (nActualParams != nFormalParams) { if (methodDeclaration.hasVariadicParameter()) { if (nActualParams < (nFormalParams - 1)) { return false; } } else { return false; } } //MethodUsage methodUsage = instantiationSetToMethodUsage(methodDeclaration, partial.get()); // for (int i=0;i<nActualParams;i++) { // int formalIndex = i >= nFormalParams ? nFormalParams - 1 : i; // Type formalType = methodDeclaration.getParam(formalIndex).getType(); // Type actualType = JavaParserFacade.get(typeSolver).getType(methodCallExpr.getArgument(i)); // //if (!formalType.isAssignableBy(actualType)) { // // return false; // //} // } return true; }
java
{ "resource": "" }
q167389
TypeInference.moreSpecificMethodInference
validation
public boolean moreSpecificMethodInference(MethodCallExpr methodCall, ResolvedMethodDeclaration m1, ResolvedMethodDeclaration m2) { // When testing that one applicable method is more specific than another (§15.12.2.5), where the second method // is generic, it is necessary to test whether some instantiation of the second method's type parameters can be // inferred to make the first method more specific than the second. if (!m2.isGeneric()) { throw new IllegalArgumentException("M2 is not generic (m2: " + m2 + ")"); } // Let m1 be the first method and m2 be the second method. Where m2 has type parameters P1, ..., Pp, // let α1, ..., αp be inference variables, and let θ be the substitution [P1:=α1, ..., Pp:=αp]. // // Let e1, ..., ek be the argument expressions of the corresponding invocation. Then: // // - If m1 and m2 are applicable by strict or loose invocation (§15.12.2.2, §15.12.2.3), then let S1, ..., Sk be the formal parameter types of m1, and let T1, ..., Tk be the result of θ applied to the formal parameter types of m2. // // - If m1 and m2 are applicable by variable arity invocation (§15.12.2.4), then let S1, ..., Sk be the first k variable arity parameter types of m1, and let T1, ..., Tk be the result of θ applied to the first k variable arity parameter types of m2. // // Note that no substitution is applied to S1, ..., Sk; even if m1 is generic, the type parameters of m1 are treated as type variables, not inference variables. // // The process to determine if m1 is more specific than m2 is as follows: // // - First, an initial bound set, B, is constructed from the declared bounds of P1, ..., Pp, as specified in §18.1.3. // // - Second, for all i (1 ≤ i ≤ k), a set of constraint formulas or bounds is generated. // // If Ti is a proper type, the result is true if Si is more specific than Ti for ei (§15.12.2.5), and false otherwise. (Note that Si is always a proper type.) // // Otherwise, if Ti is not a functional interface type, the constraint formula ‹Si <: Ti› is generated. // // Otherwise, Ti is a parameterization of a functional interface, I. It must be determined whether Si satisfies the following five conditions: // // 1. Si is a functional interface type. // // 2. Si is not a superinterface of I, nor a parameterization of a superinterface of I. // // 3. Si is not a subinterface of I, nor a parameterization of a subinterface of I. // // 4. If Si is an intersection type, at least one element of the intersection is not a superinterface of I, nor a parameterization of a superinterface of I. // // 5. If Si is an intersection type, no element of the intersection is a subinterface of I, nor a parameterization of a subinterface of I. // // If all five conditions are true, then the following constraint formulas or bounds are generated (where U1 ... Uk and R1 are the parameter types and return type of the function type of the capture of Si, and V1 ... Vk and R2 are the parameter types and return type of the function type of Ti): // // - If ei is an explicitly typed lambda expression: // // - For all j (1 ≤ j ≤ k), ‹Uj = Vj›. // // - If R2 is void, true. // // - Otherwise, if R1 and R2 are functional interface types, and neither interface is a subinterface of the other, and ei has at least one result expression, then these rules are applied recursively to R1 and R2, for each result expression in ei. // // - Otherwise, if R1 is a primitive type and R2 is not, and ei has at least one result expression, and each result expression of ei is a standalone expression (§15.2) of a primitive type, true. // // - Otherwise, if R2 is a primitive type and R1 is not, and ei has at least one result expression, and each result expression of ei is either a standalone expression of a reference type or a poly expression, true. // // - Otherwise, ‹R1 <: R2›. // // - If ei is an exact method reference: // // - For all j (1 ≤ j ≤ k), ‹Uj = Vj›. // // - If R2 is void, true. // // - Otherwise, if R1 is a primitive type and R2 is not, and the compile-time declaration for ei has a primitive return type, true. // // - Otherwise if R2 is a primitive type and R1 is not, and the compile-time declaration for ei has a reference return type, true. // // - Otherwise, ‹R1 <: R2›. // // - If ei is a parenthesized expression, these rules are applied recursively to the contained expression. // // - If ei is a conditional expression, these rules are applied recursively to each of the second and third operands. // // - Otherwise, false. // // If the five constraints on Si are not satisfied, the constraint formula ‹Si <: Ti› is generated instead. // // - Third, if m2 is applicable by variable arity invocation and has k+1 parameters, then where Sk+1 is the k+1'th variable arity parameter type of m1 and Tk+1 is the result of θ applied to the k+1'th variable arity parameter type of m2, the constraint ‹Sk+1 <: Tk+1› is generated. // // - Fourth, the generated bounds and constraint formulas are reduced and incorporated with B to produce a bound set B'. // // If B' does not contain the bound false, and resolution of all the inference variables in B' succeeds, then m1 is more specific than m2. // // Otherwise, m1 is not more specific than m2. throw new UnsupportedOperationException(); }
java
{ "resource": "" }
q167390
ExpressionHelper.appearsInAssignmentContext
validation
private static boolean appearsInAssignmentContext(Expression expression) { if (expression.getParentNode().isPresent()) { Node parent = expression.getParentNode().get(); if (parent instanceof ExpressionStmt) { return false; } if (parent instanceof MethodCallExpr) { return false; } if (parent instanceof ReturnStmt) { return false; } throw new UnsupportedOperationException(parent.getClass().getCanonicalName()); } return false; }
java
{ "resource": "" }
q167391
Predictor.predict
validation
public float[] predict(FVec feat, boolean output_margin, int ntree_limit) { float[] preds = predictRaw(feat, ntree_limit); if (! output_margin) { preds = obj.predTransform(preds); } return preds; }
java
{ "resource": "" }
q167392
RegTreeImpl.loadModel
validation
public void loadModel(ModelReader reader) throws IOException { param = new Param(reader); nodes = new Node[param.num_nodes]; for (int i = 0; i < param.num_nodes; i++) { nodes[i] = new Node(reader); } stats = new RTreeNodeStat[param.num_nodes]; for (int i = 0; i < param.num_nodes; i++) { stats[i] = new RTreeNodeStat(reader); } }
java
{ "resource": "" }
q167393
RegTreeImpl.getLeafIndex
validation
@Override public int getLeafIndex(FVec feat, int root_id) { int pid = root_id; Node n; while (!(n = nodes[pid])._isLeaf) { pid = n.next(feat); } return pid; }
java
{ "resource": "" }
q167394
RegTreeImpl.getLeafValue
validation
@Override public float getLeafValue(FVec feat, int root_id) { Node n = nodes[root_id]; while (!n._isLeaf) { n = nodes[n.next(feat)]; } return n.leaf_value; }
java
{ "resource": "" }
q167395
JsonUnflattener.unflatten
validation
public String unflatten() { StringWriter sw = new StringWriter(); if (root.isArray()) { try { unflattenArray(root.asArray()).writeTo(sw, getWriterConfig()); } catch (IOException e) {} return sw.toString(); } if (!root.isObject()) { return root.toString(); } JsonObject flattened = root.asObject(); JsonValue unflattened = flattened.names().isEmpty() ? Json.object() : null; for (String key : flattened.names()) { JsonValue currentVal = unflattened; String objKey = null; Integer aryIdx = null; Matcher matcher = keyPartPattern().matcher(key); while (matcher.find()) { String keyPart = matcher.group(); if (objKey != null ^ aryIdx != null) { if (isJsonArray(keyPart)) { currentVal = findOrCreateJsonArray(currentVal, objKey, aryIdx); objKey = null; aryIdx = extractIndex(keyPart); } else { // JSON object if (flattened.get(key).isArray()) { // KEEP_ARRAYS mode flattened.set(key, unflattenArray(flattened.get(key).asArray())); } currentVal = findOrCreateJsonObject(currentVal, objKey, aryIdx); objKey = extractKey(keyPart); aryIdx = null; } } if (objKey == null && aryIdx == null) { if (isJsonArray(keyPart)) { aryIdx = extractIndex(keyPart); if (currentVal == null) currentVal = Json.array(); } else { // JSON object objKey = extractKey(keyPart); if (currentVal == null) currentVal = Json.object(); } } if (unflattened == null) unflattened = currentVal; } setUnflattenedValue(flattened, key, currentVal, objKey, aryIdx); } try { unflattened.writeTo(sw, getWriterConfig()); } catch (IOException e) {} return sw.toString(); }
java
{ "resource": "" }
q167396
JsonFlattener.flatten
validation
public String flatten() { flattenAsMap(); if (source.isObject() || isObjectifiableArray()) return flattenedMap.toString(printMode); else return javaObj2Json(flattenedMap.get(ROOT)); }
java
{ "resource": "" }
q167397
JsonFlattener.flattenAsMap
validation
public Map<String, Object> flattenAsMap() { if (flattenedMap != null) return flattenedMap; flattenedMap = newJsonifyLinkedHashMap(); reduce(source); while (!elementIters.isEmpty()) { IndexedPeekIterator<?> deepestIter = elementIters.getLast(); if (!deepestIter.hasNext()) { elementIters.removeLast(); } else if (deepestIter.peek() instanceof Member) { Member mem = (Member) deepestIter.next(); reduce(mem.getValue()); } else { // JsonValue JsonValue val = (JsonValue) deepestIter.next(); reduce(val); } } return flattenedMap; }
java
{ "resource": "" }
q167398
Lists.concatView
validation
public static <E> List<E> concatView(List<List<? extends E>> lists) { if(lists.isEmpty()) { return Collections.emptyList(); } else { return ConcatView.create(lists); } }
java
{ "resource": "" }
q167399
EventStreams.invalidationsOf
validation
public static EventStream<Void> invalidationsOf(Observable observable) { return new EventStreamBase<Void>() { @Override protected Subscription observeInputs() { InvalidationListener listener = obs -> emit(null); observable.addListener(listener); return () -> observable.removeListener(listener); } }; }
java
{ "resource": "" }