_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q14400
SubProgressionModel.disconnect
train
void disconnect() { final DefaultProgression parentInstance = getParent(); if (parentInstance != null) { parentInstance.disconnectSubTask(this, this.maxValueInParent, this.overwriteCommentWhenDisconnect); } this.parent = null; }
java
{ "resource": "" }
q14401
VomsProxyDestroy.initOptions
train
private void initOptions() { List<CLIOption> options = new ArrayList<CLIOption>(); options.addAll(Arrays.asList(ProxyDestroyOptions.values())); initOptions(options); }
java
{ "resource": "" }
q14402
DBaseFileField.updateSizes
train
@SuppressWarnings("checkstyle:cyclomaticcomplexity") void updateSizes(int fieldLength, int decimalPointPosition) { switch (this.type) { case STRING: if (fieldLength > this.length) { this.length = fieldLength; } break; case FLOATING_NUMBER: case NUMBER: if (decimalPointPosition > this.decimal) { final int intPart = this.length - this.decimal; this.decimal = decimalPointPosition; this.length = intPart + this.decimal; } if (fieldLength > this.length) { this.length = fieldLength; } break; //$CASES-OMITTED$ default: // Do nothing } }
java
{ "resource": "" }
q14403
DssatSortHelper.compare
train
@Override public int compare(HashMap m1, HashMap m2) { double val1; double val2; for (String sortId : sortIds) { val1 = getValue(m1, sortId); val2 = getValue(m2, sortId); if (val1 > val2) { return decVal; } else if (val1 < val2) { return ascVal; } } return 0; }
java
{ "resource": "" }
q14404
DssatSortHelper.getValue
train
private double getValue(HashMap m, String key) { try { return Double.parseDouble(getValueOr(m, key, "")); } catch (Exception e) { return Double.MIN_VALUE; } }
java
{ "resource": "" }
q14405
AbstractWizardPanel.onNext
train
protected void onNext() { stateMachine.next(); updateButtonState(); final String name = getStateMachine().getCurrentState().getName(); final CardLayout cardLayout = getWizardContentPanel().getCardLayout(); cardLayout.show(getWizardContentPanel(), name); }
java
{ "resource": "" }
q14406
AbstractWizardPanel.onPrevious
train
protected void onPrevious() { stateMachine.previous(); updateButtonState(); final String name = getStateMachine().getCurrentState().getName(); final CardLayout cardLayout = getWizardContentPanel().getCardLayout(); cardLayout.show(getWizardContentPanel(), name); }
java
{ "resource": "" }
q14407
AbstractWizardPanel.updateButtonState
train
protected void updateButtonState() { getNavigationPanel().getBtnPrevious() .setEnabled(getStateMachine().getCurrentState().hasPrevious()); getNavigationPanel().getBtnNext().setEnabled(getStateMachine().getCurrentState().hasNext()); }
java
{ "resource": "" }
q14408
Quaternion.conjugate
train
public final void conjugate(Quaternion q1) { this.x = -q1.x; this.y = -q1.y; this.z = -q1.z; this.w = q1.w; }
java
{ "resource": "" }
q14409
Quaternion.inverse
train
public final void inverse(Quaternion q1) { double norm; norm = 1f/(q1.w*q1.w + q1.x*q1.x + q1.y*q1.y + q1.z*q1.z); this.w = norm*q1.w; this.x = -norm*q1.x; this.y = -norm*q1.y; this.z = -norm*q1.z; }
java
{ "resource": "" }
q14410
Quaternion.inverse
train
public final void inverse() { double norm; norm = 1f/(this.w*this.w + this.x*this.x + this.y*this.y + this.z*this.z); this.w *= norm; this.x *= -norm; this.y *= -norm; this.z *= -norm; }
java
{ "resource": "" }
q14411
Quaternion.normalize
train
public final void normalize(Quaternion q1) { double norm; norm = (q1.x*q1.x + q1.y*q1.y + q1.z*q1.z + q1.w*q1.w); if (norm > 0f) { norm = 1f/Math.sqrt(norm); this.x = norm*q1.x; this.y = norm*q1.y; this.z = norm*q1.z; this.w = norm*q1.w; } else { this.x = 0f; this.y = 0f; this.z = 0f; this.w = 0f; } }
java
{ "resource": "" }
q14412
Quaternion.normalize
train
public final void normalize() { double norm; norm = (this.x*this.x + this.y*this.y + this.z*this.z + this.w*this.w); if (norm > 0f) { norm = 1f / Math.sqrt(norm); this.x *= norm; this.y *= norm; this.z *= norm; this.w *= norm; } else { this.x = 0f; this.y = 0f; this.z = 0f; this.w = 0f; } }
java
{ "resource": "" }
q14413
Quaternion.setFromMatrix
train
public final void setFromMatrix(Matrix4f m1) { double ww = 0.25f*(m1.m00 + m1.m11 + m1.m22 + m1.m33); if (ww >= 0) { if (ww >= EPS2) { this.w = Math.sqrt(ww); ww = 0.25f/this.w; this.x = (m1.m21 - m1.m12)*ww; this.y = (m1.m02 - m1.m20)*ww; this.z = (m1.m10 - m1.m01)*ww; return; } } else { this.w = 0; this.x = 0; this.y = 0; this.z = 1; return; } this.w = 0; ww = -0.5f*(m1.m11 + m1.m22); if (ww >= 0) { if (ww >= EPS2) { this.x = Math.sqrt(ww); ww = 1.0f/(2.0f*this.x); this.y = m1.m10*ww; this.z = m1.m20*ww; return; } } else { this.x = 0; this.y = 0; this.z = 1; return; } this.x = 0; ww = 0.5f*(1.0f - m1.m22); if (ww >= EPS2) { this.y = Math.sqrt(ww); this.z = m1.m21/(2.0f*this.y); return; } this.y = 0; this.z = 1; }
java
{ "resource": "" }
q14414
Quaternion.getAxis
train
@Pure public final Vector3f getAxis() { double mag = this.x*this.x + this.y*this.y + this.z*this.z; if ( mag > EPS ) { mag = Math.sqrt(mag); double invMag = 1f/mag; return new Vector3f( this.x*invMag, this.y*invMag, this.z*invMag); } return new Vector3f(0f, 0f, 1f); }
java
{ "resource": "" }
q14415
Quaternion.getAngle
train
@Pure public final double getAngle() { double mag = this.x*this.x + this.y*this.y + this.z*this.z; if ( mag > EPS ) { mag = Math.sqrt(mag); return (2.f*Math.atan2(mag, this.w)); } return 0f; }
java
{ "resource": "" }
q14416
Quaternion.getAxisAngle
train
@SuppressWarnings("synthetic-access") @Pure public final AxisAngle getAxisAngle() { double mag = this.x*this.x + this.y*this.y + this.z*this.z; if ( mag > EPS ) { mag = Math.sqrt(mag); double invMag = 1f/mag; return new AxisAngle( this.x*invMag, this.y*invMag, this.z*invMag, (2.*Math.atan2(mag, this.w))); } return new AxisAngle(0, 0, 1, 0); }
java
{ "resource": "" }
q14417
Quaternion.interpolate
train
public final void interpolate(Quaternion q1, double alpha) { // From "Advanced Animation and Rendering Techniques" // by Watt and Watt pg. 364, function as implemented appeared to be // incorrect. Fails to choose the same quaternion for the double // covering. Resulting in change of direction for rotations. // Fixed function to negate the first quaternion in the case that the // dot product of q1 and this is negative. Second case was not needed. double dot,s1,s2,om,sinom; dot = this.x*q1.x + this.y*q1.y + this.z*q1.z + this.w*q1.w; if ( dot < 0 ) { // negate quaternion q1.x = -q1.x; q1.y = -q1.y; q1.z = -q1.z; q1.w = -q1.w; dot = -dot; } if ( (1.0 - dot) > EPS ) { om = Math.acos(dot); sinom = Math.sin(om); s1 = Math.sin((1.0-alpha)*om)/sinom; s2 = Math.sin( alpha*om)/sinom; } else{ s1 = 1.0 - alpha; s2 = alpha; } this.w = (s1*this.w + s2*q1.w); this.x = (s1*this.x + s2*q1.x); this.y = (s1*this.y + s2*q1.y); this.z = (s1*this.z + s2*q1.z); }
java
{ "resource": "" }
q14418
Quaternion.getEulerAngles
train
@SuppressWarnings("synthetic-access") @Pure public EulerAngles getEulerAngles(CoordinateSystem3D system) { // See http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm // Standard used: XZY_RIGHT_HAND Quaternion q = new Quaternion(this); system.toSystem(q, CoordinateSystem3D.XZY_RIGHT_HAND); double sqw = q.w * q.w; double sqx = q.x * q.x; double sqy = q.y * q.y; double sqz = q.z * q.z; double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor double test = q.x * q.y + q.z * q.w; if (MathUtil.compareEpsilon(test, .5 * unit) >= 0) { // singularity at north pole return new EulerAngles( 2. * Math.atan2(q.x, q.w), // heading MathConstants.DEMI_PI, // attitude 0., system); } if (MathUtil.compareEpsilon(test, -.5 * unit) <= 0) { // singularity at south pole return new EulerAngles( -2. * Math.atan2(q.x, q.w), // heading -MathConstants.DEMI_PI, // attitude 0., system); } return new EulerAngles( Math.atan2(2. * q.y * q.w - 2. * q.x * q.z, sqx - sqy - sqz + sqw), Math.asin(2. * test / unit), Math.atan2(2. * q.x * q.w - 2. * q.y * q.z, -sqx + sqy - sqz + sqw), system); }
java
{ "resource": "" }
q14419
XMLRoadUtil.writeRoadNetwork
train
public static void writeRoadNetwork(Element xmlNode, RoadNetwork primitive, URL geometryURL, MapMetricProjection mapProjection, URL attributeURL, XMLBuilder builder, PathBuilder pathBuilder, XMLResources resources) throws IOException { final ContainerWrapper w = new ContainerWrapper(primitive); w.setElementGeometrySource(geometryURL, mapProjection); w.setElementAttributeSourceURL(attributeURL); writeGISElementContainer(xmlNode, w, NODE_ROAD, builder, pathBuilder, resources); final Rectangle2d bounds = primitive.getBoundingBox(); if (bounds != null) { xmlNode.setAttribute(ATTR_X, Double.toString(bounds.getMinX())); xmlNode.setAttribute(ATTR_Y, Double.toString(bounds.getMinY())); xmlNode.setAttribute(ATTR_WIDTH, Double.toString(bounds.getWidth())); xmlNode.setAttribute(ATTR_HEIGHT, Double.toString(bounds.getHeight())); } }
java
{ "resource": "" }
q14420
SynopsisHelpGenerator.printSynopsis
train
@SuppressWarnings("static-method") protected void printSynopsis(HelpAppender out, String name, String argumentSynopsis) { out.printSectionName(SYNOPSIS); assert name != null; if (Strings.isNullOrEmpty(argumentSynopsis)) { out.printText(name, OPTION_SYNOPSIS); } else { out.printText(name, OPTION_SYNOPSIS, argumentSynopsis); } }
java
{ "resource": "" }
q14421
SynopsisHelpGenerator.printDetailedDescription
train
@SuppressWarnings("static-method") protected void printDetailedDescription(SynopsisHelpAppender out, String detailedDescription) { if (!Strings.isNullOrEmpty(detailedDescription)) { out.printSectionName(DETAILED_DESCRIPTION); out.printLongDescription(detailedDescription.split("[\r\n\f]+")); //$NON-NLS-1$ } }
java
{ "resource": "" }
q14422
GisElementContainerDrawer.draw
train
protected Drawer<? super T> draw(ZoomableGraphicsContext gc, GISElementContainer<T> primitive, Drawer<? super T> drawer) { Drawer<? super T> drw = drawer; final Iterator<T> iterator = primitive.iterator(gc.getVisibleArea()); while (iterator.hasNext()) { final T mapelement = iterator.next(); if (drw == null) { drw = Drawers.getDrawerFor(mapelement.getClass()); if (drw != null) { gc.save(); drw.draw(gc, mapelement); gc.restore(); } } else { gc.save(); drw.draw(gc, mapelement); gc.restore(); } } return drw; }
java
{ "resource": "" }
q14423
AbstractSphere3F.intersectsSolidSphereOrientedBox
train
@Pure public static boolean intersectsSolidSphereOrientedBox( double sphereCenterx, double sphereCentery, double sphereCenterz, double sphereRadius, double boxCenterx, double boxCentery, double boxCenterz, double boxAxis1x, double boxAxis1y, double boxAxis1z, double boxAxis2x, double boxAxis2y, double boxAxis2z, double boxAxis3x, double boxAxis3y, double boxAxis3z, double boxExtentAxis1, double boxExtentAxis2, double boxExtentAxis3) { // Find points on OBB closest and farest to sphere center Point3f closest = new Point3f(); Point3f farest = new Point3f(); AbstractOrientedBox3F.computeClosestFarestOBBPoints( sphereCenterx, sphereCentery, sphereCenterz, boxCenterx, boxCentery, boxCenterz, boxAxis1x, boxAxis1y, boxAxis1z, boxAxis2x, boxAxis2y, boxAxis2z, boxAxis3x, boxAxis3y, boxAxis3z, boxExtentAxis1, boxExtentAxis2, boxExtentAxis3, closest, farest); // Sphere and OBB intersect if the (squared) distance from sphere // center to point p is less than the (squared) sphere radius double squaredRadius = sphereRadius * sphereRadius; return (FunctionalPoint3D.distanceSquaredPointPoint( sphereCenterx, sphereCentery, sphereCenterz, closest.getX(), closest.getY(), closest.getZ()) < squaredRadius); }
java
{ "resource": "" }
q14424
AbstractSphere3F.intersectsSphereCapsule
train
@Pure public static boolean intersectsSphereCapsule( double sphereCenterx, double sphereCentery, double sphereCenterz, double sphereRadius, double capsuleAx, double capsuleAy, double capsuleAz, double capsuleBx, double capsuleBy, double capsuleBz, double capsuleRadius) { // Compute (squared) distance between sphere center and capsule line segment double dist2 = AbstractSegment3F.distanceSquaredSegmentPoint( capsuleAx, capsuleAy, capsuleAz, capsuleBx, capsuleBy, capsuleBz, sphereCenterx, sphereCentery, sphereCenterz); // If (squared) distance smaller than (squared) sum of radii, they collide double radius = sphereRadius + capsuleRadius; return dist2 < radius * radius; }
java
{ "resource": "" }
q14425
AbstractSphere3F.containsSpherePoint
train
@Pure public static boolean containsSpherePoint(double cx, double cy, double cz, double radius, double px, double py, double pz) { return FunctionalPoint3D.distanceSquaredPointPoint( px, py, pz, cx, cy, cz) <= (radius * radius); }
java
{ "resource": "" }
q14426
AbstractSphere3F.containsSphereAlignedBox
train
@Pure public static boolean containsSphereAlignedBox( double cx, double cy, double cz, double radius, double bx, double by, double bz, double bsx, double bsy, double bsz) { double rcx = (bx + bsx/2f); double rcy = (by + bsy/2f); double rcz = (bz + bsz/2f); double farX; if (cx<=rcx) farX = bx + bsx; else farX = bx; double farY; if (cy<=rcy) farY = by + bsy; else farY = by; double farZ; if (cz<=rcz) farZ = bz + bsz; else farZ = bz; return containsSpherePoint(cx, cy, cz, radius, farX, farY, farZ); }
java
{ "resource": "" }
q14427
AbstractSphere3F.intersectsSphereSphere
train
@Pure public static boolean intersectsSphereSphere( double x1, double y1, double z1, double radius1, double x2, double y2, double z2, double radius2) { double r = radius1+radius2; return FunctionalPoint3D.distanceSquaredPointPoint(x1, y1, z1, x2, y2, z2) < (r*r); }
java
{ "resource": "" }
q14428
AbstractSphere3F.intersectsSphereLine
train
@Pure public static boolean intersectsSphereLine( double x1, double y1, double z1, double radius, double x2, double y2, double z2, double x3, double y3, double z3) { double d = AbstractSegment3F.distanceSquaredLinePoint(x2, y2, z2, x3, y3, z3, x1, y1, z1); return d<(radius*radius); }
java
{ "resource": "" }
q14429
AbstractSphere3F.intersectsSphereSegment
train
@Pure public static boolean intersectsSphereSegment( double x1, double y1, double z1, double radius, double x2, double y2, double z2, double x3, double y3, double z3) { double d = AbstractSegment3F.distanceSquaredSegmentPoint(x2, y2, z2, x3, y3, z3, x1, y1, z1); return d<(radius*radius); }
java
{ "resource": "" }
q14430
PersistentCookieStore.encodeCookie
train
protected String encodeCookie(SerializableHttpCookie cookie) { if (cookie == null) return null; ByteArrayOutputStream os = new ByteArrayOutputStream(); try { ObjectOutputStream outputStream = new ObjectOutputStream(os); outputStream.writeObject(cookie); } catch (IOException e) { Util.log("IOException in encodeCookie", e); return null; } return byteArrayToHexString(os.toByteArray()); }
java
{ "resource": "" }
q14431
PersistentCookieStore.decodeCookie
train
protected Cookie decodeCookie(String cookieString) { byte[] bytes = hexStringToByteArray(cookieString); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); Cookie cookie = null; try { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie(); } catch (IOException e) { Util.log("IOException in decodeCookie", e); } catch (ClassNotFoundException e) { Util.log("ClassNotFoundException in decodeCookie", e); } return cookie; }
java
{ "resource": "" }
q14432
ReflectionUtil.getSuperClasses
train
@Pure public static <T> Collection<Class<? super T>> getSuperClasses(Class<T> className) { assert className != null; final Collection<Class<? super T>> list = new ArrayList<>(); Class<? super T> type = className.getSuperclass(); while (type != null && !Object.class.equals(type)) { list.add(type); type = type.getSuperclass(); } return list; }
java
{ "resource": "" }
q14433
ReflectionUtil.getCommonType
train
public static Class<?> getCommonType(Class<?> type1, Class<?> type2) { if (type1 == null) { return type2; } if (type2 == null) { return type1; } Class<?> top = type1; while (!top.isAssignableFrom(type2)) { top = top.getSuperclass(); assert top != null; } return top; }
java
{ "resource": "" }
q14434
ReflectionUtil.getCommonType
train
@Pure public static Class<?> getCommonType(Object instance1, Object instance2) { if (instance1 == null) { return instance2 == null ? null : instance2.getClass(); } if (instance2 == null) { return instance1.getClass(); } Class<?> top = instance1.getClass(); while (!top.isInstance(instance2)) { top = top.getSuperclass(); assert top != null; } return top; }
java
{ "resource": "" }
q14435
ReflectionUtil.getOutboxingType
train
@Pure @SuppressWarnings({"checkstyle:returncount", "npathcomplexity"}) public static Class<?> getOutboxingType(Class<?> type) { if (void.class.equals(type)) { return Void.class; } if (boolean.class.equals(type)) { return Boolean.class; } if (byte.class.equals(type)) { return Byte.class; } if (char.class.equals(type)) { return Character.class; } if (double.class.equals(type)) { return Double.class; } if (float.class.equals(type)) { return Float.class; } if (int.class.equals(type)) { return Integer.class; } if (long.class.equals(type)) { return Long.class; } if (short.class.equals(type)) { return Short.class; } return type; }
java
{ "resource": "" }
q14436
ReflectionUtil.matchesParameters
train
@Pure public static boolean matchesParameters(Class<?>[] formalParameters, Object... parameterValues) { if (formalParameters == null) { return parameterValues == null; } if (parameterValues != null && formalParameters.length == parameterValues.length) { for (int i = 0; i < formalParameters.length; ++i) { if (!isInstance(formalParameters[i], parameterValues[i])) { return false; } } return true; } return false; }
java
{ "resource": "" }
q14437
ReflectionUtil.matchesParameters
train
@Pure @Inline(value = "ReflectionUtil.matchesParameters(($1).getParameterTypes(), ($2))", imported = {ReflectionUtil.class}) public static boolean matchesParameters(Method method, Object... parameters) { return matchesParameters(method.getParameterTypes(), parameters); }
java
{ "resource": "" }
q14438
ReflectionUtil.toJson
train
public static void toJson(Object object, JsonBuffer output) { if (object == null) { return; } for (final Method method : object.getClass().getMethods()) { try { if (!method.isSynthetic() && !Modifier.isStatic(method.getModifiers()) && method.getParameterCount() == 0 && (method.getReturnType().isPrimitive() || String.class.equals(method.getReturnType()) || method.getReturnType().isEnum())) { final String name = method.getName(); if (name.startsWith("get") && name.length() > 3) { //$NON-NLS-1$ output.add(makeName(name, 3), method.invoke(object)); } else if (name.startsWith("is") && name.length() > 2) { //$NON-NLS-1$ output.add(makeName(name, 2), method.invoke(object)); } } } catch (Exception e) { // } } }
java
{ "resource": "" }
q14439
Capsule3d.getCenter
train
@Pure @Override public Point3d getCenter() { return new Point3d( (this.medial1.getX() + this.medial2.getX()) / 2., (this.medial1.getY() + this.medial2.getY()) / 2., (this.medial1.getZ() + this.medial2.getZ()) / 2.); }
java
{ "resource": "" }
q14440
GenericTableColumnsModel.onSetColumnNames
train
protected void onSetColumnNames() { columnNames = ReflectionExtensions.getDeclaredFieldNames(getType(), "serialVersionUID"); for(int i = 0; i < columnNames.length; i++){ columnNames[i] = StringUtils.capitalize(columnNames[i]); } }
java
{ "resource": "" }
q14441
GenericTableColumnsModel.onSetCanEdit
train
protected void onSetCanEdit() { Field[] fields = ReflectionExtensions.getDeclaredFields(getType(), "serialVersionUID"); canEdit = new boolean[fields.length]; for (int i = 0; i < fields.length; i++) { canEdit[i] = false; } }
java
{ "resource": "" }
q14442
ConstantNaryTreeNode.setChildAt
train
@Override public boolean setChildAt(int index, N newChild) throws IndexOutOfBoundsException { final N oldChild = (index < this.children.length) ? this.children[index] : null; if (oldChild == newChild) { return false; } if (oldChild != null) { oldChild.setParentNodeReference(null, true); --this.notNullChildCount; firePropertyChildRemoved(index, oldChild); } if (newChild != null) { final N oldParent = newChild.getParentNode(); if (oldParent != this) { newChild.removeFromParent(); } } // set the element this.children[index] = newChild; if (newChild != null) { newChild.setParentNodeReference(toN(), true); ++this.notNullChildCount; firePropertyChildAdded(index, newChild); } return true; }
java
{ "resource": "" }
q14443
MultiSizedIterator.addIterator
train
public void addIterator(SizedIterator<? extends M> iterator) { if (this.iterators.add(iterator)) { this.total += iterator.totalSize(); this.update = true; } }
java
{ "resource": "" }
q14444
GISLayerWriter.write
train
public void write(Collection<? extends MapLayer> layers) throws IOException { if (this.progression != null) { this.progression.setProperties(0, 0, layers.size() + 1, false); } // Write the header if (!this.isHeaderWritten) { this.isHeaderWritten = true; writeHeader(); } if (this.progression != null) { this.progression.increment(); } final ObjectOutputStream oos = new ObjectOutputStream(this.tmpOutput); for (final MapLayer layer : layers) { oos.writeObject(layer); ++this.length; if (this.progression != null) { this.progression.increment(); } } if (this.progression != null) { this.progression.end(); } }
java
{ "resource": "" }
q14445
GISLayerWriter.writeHeader
train
protected void writeHeader() throws IOException { this.tmpOutput.write(HEADER_KEY.getBytes()); this.tmpOutput.write(new byte[]{MAJOR_SPEC_NUMBER, MINOR_SPEC_NUMBER}); this.tmpOutput.write(new byte[] {0, 0, 0, 0}); }
java
{ "resource": "" }
q14446
AbstractOperatingSystemWrapper.runCommand
train
protected static String runCommand(String... command) { try { final Process p = Runtime.getRuntime().exec(command); if (p == null) { return null; } final StringBuilder bStr = new StringBuilder(); try (InputStream standardOutput = p.getInputStream()) { final byte[] buffer = new byte[BUFFER_SIZE]; int len; while ((len = standardOutput.read(buffer)) > 0) { bStr.append(new String(buffer, 0, len)); } p.waitFor(); return bStr.toString(); } } catch (Exception e) { return null; } }
java
{ "resource": "" }
q14447
AbstractOperatingSystemWrapper.grep
train
protected static String grep(String selector, String text) { if (text == null || text.isEmpty()) { return null; } final StringBuilder line = new StringBuilder(); final int textLength = text.length(); char c; String string; for (int i = 0; i < textLength; ++i) { c = text.charAt(i); if (c == '\n' || c == '\r') { string = line.toString(); if (string.contains(selector)) { return string; } line.setLength(0); } else { line.append(c); } } if (line.length() > 0) { string = line.toString(); if (string.contains(selector)) { return string; } } return null; }
java
{ "resource": "" }
q14448
AbstractOperatingSystemWrapper.cut
train
protected static String cut(String delimiter, int column, String lineText) { if (lineText == null || lineText.isEmpty()) { return null; } final String[] columns = lineText.split(Pattern.quote(delimiter)); if (columns != null && column >= 0 && column < columns.length) { return columns[column].trim(); } return null; }
java
{ "resource": "" }
q14449
AbstractTriangle3F.toPlane
train
@Pure protected static Plane3D<?> toPlane( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3) { Vector3f norm = new Vector3f(); FunctionalVector3D.crossProduct( tx2 - tx1, ty2 - ty1, tz2 - tz1, tx3 - tx1, ty3 - ty1, tz3 - tz1, norm); assert(norm!=null); if (norm.getY()==0. && norm.getZ()==0.) return new PlaneYZ4f(tx1); if (norm.getX()==0. && norm.getZ()==0.) return new PlaneXZ4f(ty1); if (norm.getX()==0. && norm.getY()==0.) return new PlaneXY4f(tz1); return new Plane4f(tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3); }
java
{ "resource": "" }
q14450
AbstractTriangle3F.computeClosestPointTrianglePoint
train
@Unefficient public static void computeClosestPointTrianglePoint( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3, double px, double py, double pz, Point3D closestPoint) { if (containsTrianglePoint( tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3, px, py, pz, false, MathConstants.EPSILON)) { closestPoint.set(toPlane( tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3).getProjection(px, py, pz)); return; } double f; f = AbstractSegment3F.getPointProjectionFactorOnSegmentLine( px, py, pz, tx1, ty1, tz1, tx2, ty2, tz2); double p1x = tx1 + f * (tx2 - tx1); double p1y = ty1 + f * (ty2 - ty1); double p1z = tz1 + f * (tz2 - tz1); f = AbstractSegment3F.getPointProjectionFactorOnSegmentLine( px, py, pz, tx2, ty2, tz2, tx3, ty3, tz3); double p2x = tx2 + f * (tx3 - tx2); double p2y = ty2 + f * (ty3 - ty2); double p2z = tz2 + f * (tz3 - tz2); f = AbstractSegment3F.getPointProjectionFactorOnSegmentLine( px, py, pz, tx3, ty3, tz3, tx1, ty1, tz1); double p3x = tx3 + f * (tx1 - tx3); double p3y = ty3 + f * (ty1 - ty3); double p3z = tz3 + f * (tz1 - tz3); double d1 = FunctionalPoint3D.distanceSquaredPointPoint(px, py, pz, p1x, p1y, p1z); double d2 = FunctionalPoint3D.distanceSquaredPointPoint(px, py, pz, p2x, p2y, p3z); double d3 = FunctionalPoint3D.distanceSquaredPointPoint(px, py, pz, p3x, p3y, p3z); if (d1 <= d2) { if (d1 <= d3) { closestPoint.set(p1x, p1y, p1z); } else { closestPoint.set(p3x, p3y, p3z); } } if (d2 <= d3) { closestPoint.set(p2x, p2y, p2z); } else { closestPoint.set(p3x, p3y, p3z); } }
java
{ "resource": "" }
q14451
AbstractTriangle3F.distanceSquaredTriangleSegment
train
@Pure @Unefficient public static double distanceSquaredTriangleSegment( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3, double sx1, double sy1, double sz1, double sx2, double sy2, double sz2) { double t = getTriangleSegmentIntersectionFactorWithJimenezAlgorithm( tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3, sx1, sy1, sz1, sx2, sy2, sz2); if (Double.isInfinite(t) || (!Double.isNaN(t) && t >= 0. && t <= 1.)) { return 0.; } double d1 = AbstractSegment3F.distanceSquaredSegmentSegment( tx1, ty1, tz1, tx2, ty2, tz2, sx1, sy1, sz1, sx2, sy2, sz2); double d2 = AbstractSegment3F.distanceSquaredSegmentSegment( tx1, ty1, tz1, tx3, ty3, tz3, sx1, sy1, sz1, sx2, sy2, sz2); double d3 = AbstractSegment3F.distanceSquaredSegmentSegment( tx2, ty2, tz2, tx3, ty3, tz3, sx1, sy1, sz1, sx2, sy2, sz2); return MathUtil.min(d1, d2, d3); }
java
{ "resource": "" }
q14452
AbstractTriangle3F.intersectsTriangleCapsule
train
@Pure @Unefficient public static boolean intersectsTriangleCapsule( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3, double cx1, double cy1, double cz1, double cx2, double cy2, double cz2, double radius) { double d = distanceSquaredTriangleSegment( tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3, cx1, cy1, cz1, cx2, cy2, cz2); return d < (radius * radius); }
java
{ "resource": "" }
q14453
AbstractTriangle3F.intersectsTriangleOrientedBox
train
@Pure public static boolean intersectsTriangleOrientedBox( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3, double cx, double cy, double cz, double ax1, double ay1, double az1, double ax2, double ay2, double az2, double ax3, double ay3, double az3, double ae1, double ae2, double ae3) { double nx, ny, nz; // Translate the triangle into the oriented box frame. nx = tx1 - cx; ny = ty1 - cy; nz = tz1 - cz; double ntx1 = FunctionalVector3D.dotProduct(nx, ny, nz, ax1, ay1, az1); double nty1 = FunctionalVector3D.dotProduct(nx, ny, nz, ax2, ay2, az2); double ntz1 = FunctionalVector3D.dotProduct(nx, ny, nz, ax3, ay3, az3); nx = tx2 - cx; ny = ty2 - cy; nz = tz2 - cz; double ntx2 = FunctionalVector3D.dotProduct(nx, ny, nz, ax1, ay1, az1); double nty2 = FunctionalVector3D.dotProduct(nx, ny, nz, ax2, ay2, az2); double ntz2 = FunctionalVector3D.dotProduct(nx, ny, nz, ax3, ay3, az3); nx = tx3 - cx; ny = ty3 - cy; nz = tz3 - cz; double ntx3 = FunctionalVector3D.dotProduct(nx, ny, nz, ax1, ay1, az1); double nty3 = FunctionalVector3D.dotProduct(nx, ny, nz, ax2, ay2, az2); double ntz3 = FunctionalVector3D.dotProduct(nx, ny, nz, ax3, ay3, az3); // Test intersection return intersectsTriangleAlignedBox( ntx1, nty1, ntz1, ntx2, nty2, ntz2, ntx3, nty3, ntz3, -ae1, -ae2, -ae3, ae1, ae2, ae3); }
java
{ "resource": "" }
q14454
AbstractTriangle3F.intersectsTriangleSegment
train
@Pure public static boolean intersectsTriangleSegment( double tx1, double ty1, double tz1, double tx2, double ty2, double tz2, double tx3, double ty3, double tz3, double sx1, double sy1, double sz1, double sx2, double sy2, double sz2) { double factor = getTriangleSegmentIntersectionFactorWithJimenezAlgorithm( tx1, ty1, tz1, tx2, ty2, tz2, tx3, ty3, tz3, sx1, sy1, sz1, sx2, sy2, sz2); return !Double.isNaN(factor); }
java
{ "resource": "" }
q14455
AbstractTriangle3F.containsTrianglePoint
train
@Pure private static boolean containsTrianglePoint( int i0, int i1, double[] v, double[] u1, double[] u2, double[] u3) { // is T1 completly inside T2? // check if V0 is inside tri(U0,U1,U2) double a = u2[i1] - u1[i1]; double b = -(u2[i0] - u1[i0]); double c = -a * u1[i0] - b * u1[i1]; double d0 = a * v[i0] + b * v[i1] + c; a = u3[i1] - u2[i1]; b = -(u3[i0] - u2[i0]); c = -a * u2[i0] - b * u2[i1]; double d1 = a * v[i0] + b * v[i1] + c; a = u1[i1] - u2[i1]; b = -(u1[i0] - u3[i0]); c = -a * u3[i0] - b * u3[i1]; double d2 = a * v[i0] + b * v[i1] + c; return ((d0*d1>0.)&&(d0*d2>0.0)); }
java
{ "resource": "" }
q14456
AbstractTriangle3F.intersectsCoplanarTriangle
train
@Pure private static boolean intersectsCoplanarTriangle( int i0, int i1, int con, double[] s1, double[] s2, double[] u1, double[] u2, double[] u3) { double Ax,Ay; Ax = s2[i0] - s1[i0]; Ay = s2[i1] - s1[i1]; // test edge U0,U1 against V0,V1 if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u1, u2)) return true; // test edge U1,U2 against V0,V1 if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u2, u3)) return true; // test edge U2,U1 against V0,V1 if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u3, u1)) return true; return false; }
java
{ "resource": "" }
q14457
AbstractTriangle3F.contains
train
@Pure public boolean contains(FunctionalPoint3D point) { return containsTrianglePoint( this.getP1().getX(), this.getP1().getY(), this.getP1().getZ(), this.getP2().getX(), this.getP2().getY(), this.getP2().getZ(), this.getP3().getX(), this.getP3().getY(), this.getP3().getZ(), point.getX(), point.getY(), point.getZ(), true, 0.); }
java
{ "resource": "" }
q14458
AbstractTriangle3F.getPlane
train
@Pure public Plane3D<?> getPlane() { return toPlane( getX1(), getY1(), getZ1(), getX1(), getY1(), getZ1(), getX1(), getY1(), getZ1()); }
java
{ "resource": "" }
q14459
WriterOutputStream.writeln
train
public void writeln(String text) throws IOException { this.writer.write(text); if (text != null && text.length() > 0) { this.writer.write("\n"); //$NON-NLS-1$ } }
java
{ "resource": "" }
q14460
IterableUtils.zip
train
public static <X, Y> Iterable<ZipPair<X, Y>> zip(final Iterable<X> iter1, final Iterable<Y> iter2) { return new ZipIterable<X, Y>(iter1, iter2); }
java
{ "resource": "" }
q14461
IterableUtils.reduce
train
public static <A, B> B reduce(final Iterable<A> iterable, final B initial, final Function2<A, B> func) { B b = initial; for (final A item : iterable) { b = func.apply(b, item); } return b; }
java
{ "resource": "" }
q14462
IterableUtils.mapFromPairedKeyValueSequences
train
public static <K, V> ImmutableMap<K, V> mapFromPairedKeyValueSequences( final Iterable<K> keys, final Iterable<V> values) { final ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); for (final ZipPair<K, V> pair : zip(keys, values)) { builder.put(pair.first(), pair.second()); } return builder.build(); }
java
{ "resource": "" }
q14463
IterableUtils.allTheSame
train
@Deprecated public static <T> boolean allTheSame(final Iterable<T> iterable) { if (Iterables.isEmpty(iterable)) { return true; } final T reference = Iterables.getFirst(iterable, null); for (final T x : iterable) { if (!x.equals(reference)) { return false; } } return true; }
java
{ "resource": "" }
q14464
Vector1dfx.convert
train
public static Vector1dfx convert(Tuple1dfx<?> tuple) { if (tuple instanceof Vector1dfx) { return (Vector1dfx) tuple; } return new Vector1dfx(tuple.getSegment(), tuple.getX(), tuple.getY()); }
java
{ "resource": "" }
q14465
RequestCallBuilder.buildGetParams
train
protected boolean buildGetParams(StringBuilder sb, boolean isFirst) { BuilderListener listener = mListener; if (listener != null) { return listener.onBuildGetParams(sb, isFirst); } else { return isFirst; } }
java
{ "resource": "" }
q14466
DefaultVOMSProxyInitBehaviour.extendedProxyTypeAsProxyType
train
private ProxyType extendedProxyTypeAsProxyType(ExtendedProxyType pt) { switch (pt) { case DRAFT_RFC: return ProxyType.DRAFT_RFC; case LEGACY: return ProxyType.LEGACY; case RFC3820: return ProxyType.RFC3820; default: return null; } }
java
{ "resource": "" }
q14467
TextUtil.encodeBase26
train
@Pure @SuppressWarnings("checkstyle:magicnumber") public static String encodeBase26(int number) { final StringBuilder value = new StringBuilder(); int code = number; do { final int rest = code % 26; value.insert(0, (char) ('A' + rest)); code = code / 26 - 1; } while (code >= 0); return value.toString(); }
java
{ "resource": "" }
q14468
TextUtil.getJavaToHTMLTranslationTable
train
@Pure @SuppressWarnings("checkstyle:npathcomplexity") public static Map<Character, String> getJavaToHTMLTranslationTable() { Map<Character, String> map = null; try { LOCK.lock(); if (javaToHtmlTransTbl != null) { map = javaToHtmlTransTbl.get(); } } finally { LOCK.unlock(); } if (map != null) { return map; } // Get the resource file ResourceBundle resource = null; try { resource = ResourceBundle.getBundle( TextUtil.class.getCanonicalName(), java.util.Locale.getDefault()); } catch (MissingResourceException exep) { return null; } // get the resource string final String result; try { result = resource.getString("HTML_TRANS_TBL"); //$NON-NLS-1$ } catch (Exception e) { return null; } map = new TreeMap<>(); final String[] pairs = result.split("(\\}\\{)|\\{|\\}"); //$NON-NLS-1$ Integer isoCode; String entity; String code; for (int i = 1; (i + 1) < pairs.length; i += 2) { try { entity = pairs[i]; code = pairs[i + 1]; isoCode = Integer.valueOf(code); if (isoCode != null) { map.put((char) isoCode.intValue(), entity); } } catch (Throwable exception) { // } } try { LOCK.lock(); javaToHtmlTransTbl = new SoftReference<>(map); } finally { LOCK.unlock(); } return map; }
java
{ "resource": "" }
q14469
TextUtil.parseHTML
train
@Pure @SuppressWarnings("checkstyle:magicnumber") public static String parseHTML(String html) { if (html == null) { return null; } final Map<String, Integer> transTbl = getHtmlToJavaTranslationTable(); assert transTbl != null; if (transTbl.isEmpty()) { return html; } final Pattern pattern = Pattern.compile("[&](([a-zA-Z]+)|(#x?[0-9]+))[;]"); //$NON-NLS-1$ final Matcher matcher = pattern.matcher(html); final StringBuilder result = new StringBuilder(); String entity; Integer isoCode; int lastIndex = 0; while (matcher.find()) { final int idx = matcher.start(); result.append(html.substring(lastIndex, idx)); lastIndex = matcher.end(); entity = matcher.group(1); if (entity.startsWith("#x")) { //$NON-NLS-1$ try { isoCode = Integer.valueOf(entity.substring(2), 16); } catch (Throwable exception) { isoCode = null; } } else if (entity.startsWith("#")) { //$NON-NLS-1$ try { isoCode = Integer.valueOf(entity.substring(1)); } catch (Throwable exception) { isoCode = null; } } else { isoCode = transTbl.get(entity); } if (isoCode == null) { result.append(matcher.group()); } else { result.append((char) isoCode.intValue()); } } if (lastIndex < html.length()) { result.append(html.substring(lastIndex)); } return result.toString(); }
java
{ "resource": "" }
q14470
TextUtil.toHTML
train
@Pure public static String toHTML(String text) { if (text == null) { return null; } final Map<Character, String> transTbl = getJavaToHTMLTranslationTable(); assert transTbl != null; if (transTbl.isEmpty()) { return text; } final StringBuilder patternStr = new StringBuilder(); for (final Character c : transTbl.keySet()) { if (patternStr.length() > 0) { patternStr.append("|"); //$NON-NLS-1$ } patternStr.append(Pattern.quote(c.toString())); } final Pattern pattern = Pattern.compile(patternStr.toString()); final Matcher matcher = pattern.matcher(text); final StringBuilder result = new StringBuilder(); String character; String entity; int lastIndex = 0; while (matcher.find()) { final int idx = matcher.start(); result.append(text.substring(lastIndex, idx)); lastIndex = matcher.end(); character = matcher.group(); if (character.length() == 1) { entity = transTbl.get(Character.valueOf(character.charAt(0))); if (entity != null) { entity = "&" + entity + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } else { entity = character; } } else { entity = character; } result.append(entity); } if (lastIndex < text.length()) { result.append(text.substring(lastIndex)); } return result.toString(); }
java
{ "resource": "" }
q14471
TextUtil.cutStringAsArray
train
public static void cutStringAsArray(String text, CutStringCritera critera, List<String> output) { cutStringAlgo(text, critera, new CutStringToArray(output)); }
java
{ "resource": "" }
q14472
TextUtil.getMnemonicChar
train
@Pure public static char getMnemonicChar(String text) { if (text != null) { final int pos = text.indexOf('&'); if ((pos != -1) && (pos < text.length() - 1)) { return text.charAt(pos + 1); } } return '\0'; }
java
{ "resource": "" }
q14473
TextUtil.removeMnemonicChar
train
@Pure public static String removeMnemonicChar(String text) { if (text == null) { return text; } return text.replaceFirst("&", ""); //$NON-NLS-1$ //$NON-NLS-2$ }
java
{ "resource": "" }
q14474
TextUtil.getAccentTranslationTable
train
@Pure @SuppressWarnings("checkstyle:npathcomplexity") public static Map<Character, String> getAccentTranslationTable() { Map<Character, String> map = null; try { LOCK.lock(); if (accentTransTbl != null) { map = accentTransTbl.get(); } } finally { LOCK.unlock(); } if (map != null) { return map; } // Get the resource file ResourceBundle resource = null; try { resource = ResourceBundle.getBundle( TextUtil.class.getCanonicalName(), java.util.Locale.getDefault()); } catch (MissingResourceException exep) { return null; } // get the resource string final String result; try { result = resource.getString("ACCENT_TRANS_TBL"); //$NON-NLS-1$ } catch (Exception e) { return null; } map = new TreeMap<>(); final String[] pairs = result.split("(\\}\\{)|\\{|\\}"); //$NON-NLS-1$ for (final String pair : pairs) { if (pair.length() > 1) { map.put(pair.charAt(0), pair.substring(1)); } } try { LOCK.lock(); accentTransTbl = new SoftReference<>(map); } finally { LOCK.unlock(); } return map; }
java
{ "resource": "" }
q14475
TextUtil.removeAccents
train
@Pure public static String removeAccents(String text) { final Map<Character, String> map = getAccentTranslationTable(); if ((map == null) || (map.isEmpty())) { return text; } return removeAccents(text, map); }
java
{ "resource": "" }
q14476
TextUtil.split
train
@Pure public static String[] split(char leftSeparator, char rightSeparator, String str) { final SplitSeparatorToArrayAlgorithm algo = new SplitSeparatorToArrayAlgorithm(); splitSeparatorAlgorithm(leftSeparator, rightSeparator, str, algo); return algo.toArray(); }
java
{ "resource": "" }
q14477
TextUtil.join
train
@Pure public static <T> String join(char leftSeparator, char rightSeparator, @SuppressWarnings("unchecked") T... strs) { final StringBuilder buffer = new StringBuilder(); for (final Object s : strs) { buffer.append(leftSeparator); if (s != null) { buffer.append(s.toString()); } buffer.append(rightSeparator); } return buffer.toString(); }
java
{ "resource": "" }
q14478
TextUtil.toUpperCaseWithoutAccent
train
@Pure public static String toUpperCaseWithoutAccent(String text, Map<Character, String> map) { final StringBuilder buffer = new StringBuilder(); for (final char c : text.toCharArray()) { final String trans = map.get(c); if (trans != null) { buffer.append(trans.toUpperCase()); } else { buffer.append(Character.toUpperCase(c)); } } return buffer.toString(); }
java
{ "resource": "" }
q14479
TextUtil.formatDouble
train
@Pure public static String formatDouble(double amount, int decimalCount) { final int dc = (decimalCount < 0) ? 0 : decimalCount; final StringBuilder str = new StringBuilder("#0"); //$NON-NLS-1$ if (dc > 0) { str.append('.'); for (int i = 0; i < dc; ++i) { str.append('0'); } } final DecimalFormat fmt = new DecimalFormat(str.toString()); return fmt.format(amount); }
java
{ "resource": "" }
q14480
TextUtil.getLevenshteinDistance
train
public static int getLevenshteinDistance(String firstString, String secondString) { final String s0 = firstString == null ? "" : firstString; //$NON-NLS-1$ final String s1 = secondString == null ? "" : secondString; //$NON-NLS-1$ final int len0 = s0.length() + 1; final int len1 = s1.length() + 1; // the array of distances int[] cost = new int[len0]; int[] newcost = new int[len0]; // initial cost of skipping prefix in String s0 for (int i = 0; i < len0; ++i) { cost[i] = i; } // dynamically computing the array of distances // transformation cost for each letter in s1 for (int j = 1; j < len1; ++j) { // initial cost of skipping prefix in String s1 newcost[0] = j; // transformation cost for each letter in s0 for (int i = 1; i < len0; ++i) { // matching current letters in both strings final int match = (s0.charAt(i - 1) == s1.charAt(j - 1)) ? 0 : 1; // computing cost for each transformation final int costReplace = cost[i - 1] + match; final int costInsert = cost[i] + 1; final int costDelete = newcost[i - 1] + 1; // keep minimum cost newcost[i] = Math.min(Math.min(costInsert, costDelete), costReplace); } // swap cost/newcost arrays final int[] swap = cost; cost = newcost; newcost = swap; } // the distance is the cost for transforming all letters in both strings return cost[len0 - 1]; }
java
{ "resource": "" }
q14481
TextUtil.toJavaString
train
@Pure public static String toJavaString(String text) { final StringEscaper escaper = new StringEscaper(); return escaper.escape(text); }
java
{ "resource": "" }
q14482
TextUtil.toJsonString
train
@Pure public static String toJsonString(String text) { final StringEscaper escaper = new StringEscaper( StringEscaper.JAVA_ESCAPE_CHAR, StringEscaper.JAVA_STRING_CHAR, StringEscaper.JAVA_ESCAPE_CHAR, StringEscaper.JSON_SPECIAL_ESCAPED_CHAR); return escaper.escape(text); }
java
{ "resource": "" }
q14483
VariableDecls.extend
train
public static VariableDecls extend(Binder binder) { return new VariableDecls(io.bootique.BQCoreModule.extend(binder)); }
java
{ "resource": "" }
q14484
VariableDecls.declareVar
train
public VariableDecls declareVar(String bootiqueVariable) { this.extender.declareVar(bootiqueVariable, VariableNames.toEnvironmentVariableName(bootiqueVariable)); return this; }
java
{ "resource": "" }
q14485
BusItineraryLayer.initializeElements
train
protected void initializeElements() { final BusItinerary itinerary = getBusItinerary(); if (itinerary != null) { int i = 0; for (final BusItineraryHalt halt : itinerary.busHalts()) { onBusItineraryHaltAdded(halt, i, null); ++i; } } }
java
{ "resource": "" }
q14486
AbstractReferencedValueMap.maskNull
train
@Pure @SuppressWarnings("unchecked") protected static <VALUET> VALUET maskNull(VALUET value) { return (value == null) ? (VALUET) NULL_VALUE : value; }
java
{ "resource": "" }
q14487
AbstractReferencedValueMap.unmaskNull
train
@Pure protected static <VALUET> VALUET unmaskNull(VALUET value) { return (value == NULL_VALUE) ? null : value; }
java
{ "resource": "" }
q14488
AbstractReferencedValueMap.finishToArray
train
@SuppressWarnings("unchecked") static <T> T[] finishToArray(T[] array, Iterator<?> it) { T[] rp = array; int i = rp.length; while (it.hasNext()) { final int cap = rp.length; if (i == cap) { int newCap = ((cap / 2) + 1) * 3; if (newCap <= cap) { // integer overflow if (cap == Integer.MAX_VALUE) { throw new OutOfMemoryError(); } newCap = Integer.MAX_VALUE; } rp = Arrays.copyOf(rp, newCap); } rp[++i] = (T) it.next(); } // trim if overallocated return (i == rp.length) ? rp : Arrays.copyOf(rp, i); }
java
{ "resource": "" }
q14489
AbstractReferencedValueMap.makeValue
train
protected final ReferencableValue<K, V> makeValue(K key, V value) { return makeValue(key, value, this.queue); }
java
{ "resource": "" }
q14490
BusItinerary.getFirstFreeBusItineraryName
train
@Pure public static String getFirstFreeBusItineraryName(BusLine busline) { if (busline == null) { return null; } int nb = busline.getBusItineraryCount(); String name; do { ++nb; name = Locale.getString("NAME_TEMPLATE", Integer.toString(nb)); //$NON-NLS-1$ } while (busline.getBusItinerary(name) != null); return name; }
java
{ "resource": "" }
q14491
BusItinerary.invert
train
public void invert() { final boolean isEventFirable = isEventFirable(); setEventFirable(false); try { final int count = this.roadSegments.getRoadSegmentCount(); // Invert the segments this.roadSegments.invert(); // Invert the bus halts and their indexes. final int middle = this.validHalts.size() / 2; for (int i = 0, j = this.validHalts.size() - 1; i < middle; ++i, --j) { final BusItineraryHalt h1 = this.validHalts.get(i); final BusItineraryHalt h2 = this.validHalts.get(j); this.validHalts.set(i, h2); this.validHalts.set(j, h1); int idx = h1.getRoadSegmentIndex(); idx = count - idx - 1; h1.setRoadSegmentIndex(idx); idx = h2.getRoadSegmentIndex(); idx = count - idx - 1; h2.setRoadSegmentIndex(idx); } if (middle * 2 != this.validHalts.size()) { final BusItineraryHalt h1 = this.validHalts.get(middle); int idx = h1.getRoadSegmentIndex(); idx = count - idx - 1; h1.setRoadSegmentIndex(idx); } } finally { setEventFirable(isEventFirable); } fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ITINERARY_INVERTED, this, indexInParent(), "busHalts", //$NON-NLS-1$ null, null)); }
java
{ "resource": "" }
q14492
BusItinerary.hasBusHaltOnSegment
train
@Pure public boolean hasBusHaltOnSegment(RoadSegment segment) { if (this.roadSegments.isEmpty() || this.validHalts.isEmpty()) { return false; } int cIdxSegment; int lIdxSegment = -1; RoadSegment cSegment; for (final BusItineraryHalt bushalt : this.validHalts) { cIdxSegment = bushalt.getRoadSegmentIndex(); if (cIdxSegment >= 0 && cIdxSegment < this.roadSegments.getRoadSegmentCount() && cIdxSegment != lIdxSegment) { cSegment = this.roadSegments.getRoadSegmentAt(cIdxSegment); lIdxSegment = cIdxSegment; if (segment == cSegment) { return true; } } } return false; }
java
{ "resource": "" }
q14493
BusItinerary.getBusHaltsOnSegment
train
@Pure public List<BusItineraryHalt> getBusHaltsOnSegment(RoadSegment segment) { if (this.roadSegments.isEmpty() || this.validHalts.isEmpty()) { return Collections.emptyList(); } int cIdxSegment; int lIdxSegment = -1; int sIdxSegment = -1; RoadSegment cSegment; final List<BusItineraryHalt> halts = new ArrayList<>(); for (final BusItineraryHalt bushalt : this.validHalts) { cIdxSegment = bushalt.getRoadSegmentIndex(); if (cIdxSegment >= 0 && cIdxSegment < this.roadSegments.getRoadSegmentCount() && cIdxSegment != lIdxSegment) { cSegment = this.roadSegments.getRoadSegmentAt(cIdxSegment); lIdxSegment = cIdxSegment; if (segment == cSegment) { sIdxSegment = cIdxSegment; } else if (sIdxSegment != -1) { // halt loop now because I'm sure there has no more bus halt break; } } if (sIdxSegment != -1) { halts.add(bushalt); } } return halts; }
java
{ "resource": "" }
q14494
BusItinerary.getBusHaltBinding
train
@Pure public Map<BusItineraryHalt, Pair<Integer, Double>> getBusHaltBinding() { final Comparator<BusItineraryHalt> comp = (elt1, elt2) -> { if (elt1 == elt2) { return 0; } if (elt1 == null) { return -1; } if (elt2 == null) { return 1; } return elt1.getName().compareTo(elt2.getName()); }; final Map<BusItineraryHalt, Pair<Integer, Double>> haltBinding = new TreeMap<>(comp); for (final BusItineraryHalt halt : busHalts()) { haltBinding.put(halt, new Pair<>( halt.getRoadSegmentIndex(), halt.getPositionOnSegment())); } return haltBinding; }
java
{ "resource": "" }
q14495
BusItinerary.setBusHaltBinding
train
public void setBusHaltBinding(Map<BusItineraryHalt, Pair<Integer, Float>> binding) { if (binding != null) { BusItineraryHalt halt; boolean shapeChanged = false; for (final Entry<BusItineraryHalt, Pair<Integer, Float>> entry : binding.entrySet()) { halt = entry.getKey(); halt.setRoadSegmentIndex(entry.getValue().getKey()); halt.setPositionOnSegment(entry.getValue().getValue()); halt.checkPrimitiveValidity(); shapeChanged = true; } if (shapeChanged) { fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ITINERARY_CHANGED, null, -1, "shape", //$NON-NLS-1$ null, null)); } checkPrimitiveValidity(); } }
java
{ "resource": "" }
q14496
BusItinerary.getLength
train
@Pure public double getLength() { double length = this.roadSegments.getLength(); if (isValidPrimitive()) { BusItineraryHalt halt = this.validHalts.get(0); assert halt != null; RoadSegment sgmt = halt.getRoadSegment(); assert sgmt != null; Direction1D dir = this.roadSegments.getRoadSegmentDirectionAt(halt.getRoadSegmentIndex()); assert dir != null; if (dir == Direction1D.SEGMENT_DIRECTION) { length -= halt.getPositionOnSegment(); } else { length -= sgmt.getLength() - halt.getPositionOnSegment(); } halt = this.validHalts.get(this.validHalts.size() - 1); assert halt != null; sgmt = halt.getRoadSegment(); assert sgmt != null; dir = this.roadSegments.getRoadSegmentDirectionAt(halt.getRoadSegmentIndex()); assert dir != null; if (dir == Direction1D.SEGMENT_DIRECTION) { length -= sgmt.getLength() - halt.getPositionOnSegment(); } else { length -= halt.getPositionOnSegment(); } if (length < 0.) { length = 0.; } } return length; }
java
{ "resource": "" }
q14497
BusItinerary.getDistanceBetweenBusHalts
train
@Pure public double getDistanceBetweenBusHalts(int firsthaltIndex, int lasthaltIndex) { if (firsthaltIndex < 0 || firsthaltIndex >= this.validHalts.size() - 1) { throw new ArrayIndexOutOfBoundsException(firsthaltIndex); } if (lasthaltIndex <= firsthaltIndex || lasthaltIndex >= this.validHalts.size()) { throw new ArrayIndexOutOfBoundsException(lasthaltIndex); } double length = 0; final BusItineraryHalt b1 = this.validHalts.get(firsthaltIndex); final BusItineraryHalt b2 = this.validHalts.get(lasthaltIndex); final int firstSegment = b1.getRoadSegmentIndex(); final int lastSegment = b2.getRoadSegmentIndex(); for (int i = firstSegment + 1; i < lastSegment; ++i) { final RoadSegment segment = this.roadSegments.getRoadSegmentAt(i); length += segment.getLength(); } Direction1D direction = getRoadSegmentDirection(firstSegment); if (direction.isRevertedSegmentDirection()) { length += b1.getPositionOnSegment(); } else { length += this.roadSegments.getRoadSegmentAt(firstSegment).getLength() - b1.getPositionOnSegment(); } direction = getRoadSegmentDirection(lastSegment); if (direction.isSegmentDirection()) { length += b2.getPositionOnSegment(); } else { length += this.roadSegments.getRoadSegmentAt(firstSegment).getLength() - b2.getPositionOnSegment(); } return length; }
java
{ "resource": "" }
q14498
BusItinerary.addBusHalt
train
boolean addBusHalt(BusItineraryHalt halt, int insertToIndex) { //set index for right ordering when add to invalid list ! if (insertToIndex < 0) { halt.setInvalidListIndex(this.insertionIndex); } else { halt.setInvalidListIndex(insertToIndex); } if (halt.isValidPrimitive()) { ListUtil.addIfAbsent(this.validHalts, VALID_HALT_COMPARATOR, halt); } else { ListUtil.addIfAbsent(this.invalidHalts, INVALID_HALT_COMPARATOR, halt); } halt.setEventFirable(isEventFirable()); ++this.insertionIndex; if (isEventFirable()) { fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ITINERARY_HALT_ADDED, halt, halt.indexInParent(), "shape", null, null)); //$NON-NLS-1$ checkPrimitiveValidity(); } return true; }
java
{ "resource": "" }
q14499
BusItinerary.removeAllBusHalts
train
public void removeAllBusHalts() { for (final BusItineraryHalt bushalt : this.invalidHalts) { bushalt.setContainer(null); bushalt.setRoadSegmentIndex(-1); bushalt.setPositionOnSegment(Float.NaN); bushalt.checkPrimitiveValidity(); } final BusItineraryHalt[] halts = new BusItineraryHalt[this.validHalts.size()]; this.validHalts.toArray(halts); this.validHalts.clear(); this.invalidHalts.clear(); for (final BusItineraryHalt bushalt : halts) { bushalt.setContainer(null); bushalt.setRoadSegmentIndex(-1); bushalt.setPositionOnSegment(Float.NaN); bushalt.checkPrimitiveValidity(); } fireShapeChanged(new BusChangeEvent(this, BusChangeEventType.ALL_ITINERARY_HALTS_REMOVED, null, -1, "shape", //$NON-NLS-1$ null, null)); checkPrimitiveValidity(); }
java
{ "resource": "" }