code
stringlengths
73
34.1k
label
stringclasses
1 value
public static Function<File, Iterable<String>> toLinesFunction(final Charset charset) { return new Function<File, Iterable<String>>() { @Override public Iterable<String> apply(final File input) { try { return Files.readLines(input, charset); } catch (IOException e) { ...
java
public static void recursivelyDeleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; } checkArgument(directory.isDirectory(), "Cannot recursively delete a non-directory"); walkFileTree(directory.toPath(), new DeletionFileVisitor()); }
java
public static void recursivelyCopyDirectory(final File sourceDir, final File destDir, final StandardCopyOption copyOption) throws IOException { checkNotNull(sourceDir); checkNotNull(destDir); checkArgument(sourceDir.isDirectory(), "Source directory does not exist"); java.nio.file.Files.creat...
java
@Deprecated public static ImmutableMultimap<Symbol, Symbol> loadSymbolMultimap(File multimapFile) throws IOException { return loadSymbolMultimap(Files.asCharSource(multimapFile, Charsets.UTF_8)); }
java
@Pure public static double toESRI_x(double x) throws IOException { if (Double.isInfinite(x) || Double.isNaN(x)) { throw new InvalidNumericValueException(x); } return x; }
java
@Pure public static double fromESRI_x(double x) throws IOException { if (Double.isInfinite(x) || Double.isNaN(x)) { throw new InvalidNumericValueException(x); } return x; }
java
@Pure public static double toESRI_y(double y) throws IOException { if (Double.isInfinite(y) || Double.isNaN(y)) { throw new InvalidNumericValueException(y); } return y; }
java
@Pure public static double fromESRI_y(double y) throws IOException { if (Double.isInfinite(y) || Double.isNaN(y)) { throw new InvalidNumericValueException(y); } return y; }
java
@Pure public static double toESRI_z(double z) { if (Double.isInfinite(z) || Double.isNaN(z)) { return ESRI_NAN; } return z; }
java
@Pure public static double toESRI_m(double measure) { if (Double.isInfinite(measure) || Double.isNaN(measure)) { return ESRI_NAN; } return measure; }
java
public static void setAccelerator(final JMenuItem jmi, final Character keyChar, final int modifiers) { jmi.setAccelerator(KeyStroke.getKeyStroke(keyChar, modifiers)); }
java
public static void setAccelerator(final JMenuItem jmi, final int keyCode, final int modifiers) { jmi.setAccelerator(KeyStroke.getKeyStroke(keyCode, modifiers)); }
java
public static void setAccelerator(final JMenuItem jmi, final String parsableKeystrokeString) { jmi.setAccelerator(KeyStroke.getKeyStroke(parsableKeystrokeString)); }
java
@Pure @Inline(value = "Base64Coder.decode(($1).toCharArray())", imported = {Base64Coder.class}) public static byte[] decode(String string) { return decode(string.toCharArray()); }
java
public static void setPreferredClassLoader(ClassLoader classLoader) { if (classLoader != dynamicLoader) { dynamicLoader = classLoader; final Thread[] threads = new Thread[Thread.activeCount()]; Thread.enumerate(threads); for (final Thread t : threads) { if (t != null) { t.setContextClassLoader(cl...
java
public static void popPreferredClassLoader() { final ClassLoader sysLoader = ClassLoaderFinder.class.getClassLoader(); if ((dynamicLoader == null) || (dynamicLoader == sysLoader)) { dynamicLoader = null; final Thread[] threads = new Thread[Thread.activeCount()]; Thread.enumerate(threads); for (final Th...
java
public static boolean isMinValue(Progression model) { if (model != null) { return model.getValue() <= model.getMinimum(); } return true; }
java
protected void defineSmallRectangles(ZoomableGraphicsContext gc, T element) { final double ptsSize = element.getPointSize() / 2.; final Rectangle2afp<?, ?, ?, ?, ?, ?> visibleArea = gc.getVisibleArea(); for (final Point2d point : element.points()) { if (visibleArea.contains(point)) { final double x = point...
java
public static Point1dfx convert(Tuple1dfx<?> tuple) { if (tuple instanceof Point1dfx) { return (Point1dfx) tuple; } return new Point1dfx(tuple.getSegment(), tuple.getX(), tuple.getY()); }
java
public OffsetRange<CharOffset> offsets() { final CharOffset start = tokens.get(0).offsets().startInclusive(); final CharOffset end = tokens.reverse().get(0).offsets().endInclusive(); return OffsetRange.charOffsetRange(start.asInt(), end.asInt()); }
java
@Override public HashMap readFile(String arg0) { HashMap brMap; try { brMap = getBufferReader(arg0); } catch (FileNotFoundException fe) { LOG.warn("File not found under following path : [" + arg0 + "]!"); return new HashMap(); } catch (IOException ...
java
public HashMap readFile(List<File> files) { HashMap brMap; try { brMap = getBufferReader(files); } catch (IOException e) { LOG.error(Functions.getStackTrace(e)); return new HashMap(); } return read(brMap); }
java
public HashMap readFileFromCRAFT(String arg0) { HashMap brMap; try { File dir = new File(arg0); // Data frin CRAFT with DSSAT format if (dir.isDirectory()) { List<File> files = new ArrayList(); for (File f : dir.listFiles()) { ...
java
private int ensureBuffer(int offset, int length) throws IOException { final int lastPos = offset + length - 1; final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE; final int currentSize = this.buffer.length; if (desiredSize > currentSize) { final byte[] readBuffer = new byte[desiredSize - cu...
java
public byte[] read(int offset, int length) throws IOException { if (ensureBuffer(offset, length) >= length) { final byte[] array = new byte[length]; System.arraycopy(this.buffer, offset, array, 0, length); this.pos = offset + length; return array; } throw new EOFException(); }
java
public byte read(int offset) throws IOException { if (ensureBuffer(offset, 1) > 0) { this.pos = offset + 1; return this.buffer[offset]; } throw new EOFException(); }
java
public String getString(final String param) { checkNotNull(param); checkArgument(!param.isEmpty()); final String ret = params.get(param); observeWithListeners(param); if (ret != null) { return ret; } else { throw new MissingRequiredParameter(fullString(param)); } }
java
public <T> T getMapped(final String param, final Map<String, T> possibleValues) { checkNotNull(possibleValues); checkArgument(!possibleValues.isEmpty()); final String value = getString(param); final T ret = possibleValues.get(value); if (ret == null) { throw new InvalidEnumeratedPropertyExce...
java
public File getExistingFile(final String param) { return get(param, getFileConverter(), new And<>(new FileExists(), new IsFile()), "existing file"); }
java
public File getAndMakeDirectory(final String param) { final File f = get(param, new StringToFile(), new AlwaysValid<File>(), "existing or creatable directory"); if (f.exists()) { if (f.isDirectory()) { return f.getAbsoluteFile(); } else { throw new ParameterValidationExcepti...
java
public File getExistingDirectory(final String param) { return get(param, new StringToFile(), new And<>(new FileExists(), new IsDirectory()), "existing directory"); }
java
public Set<String> getStringSet(final String param) { return get(param, new StringToStringSet(","), new AlwaysValid<Set<String>>(), "comma-separated list of strings"); }
java
public Set<Symbol> getSymbolSet(final String param) { return get(param, new StringToSymbolSet(","), new AlwaysValid<Set<Symbol>>(), "comma-separated list of strings"); }
java
public void assertAtLeastOneDefined(final String param1, final String param2) { if (!isPresent(param1) && !isPresent(param2)) { throw new ParameterException( String.format("At least one of %s and %s must be defined.", param1, param2)); } }
java
public void assertAtLeastOneDefined(final String param1, final String... moreParams) { if (!isPresent(param1)) { for (final String moreParam : moreParams) { if (isPresent(moreParam)) { return; } } final List<String> paramsForError = Lists.newArrayList(); paramsForEr...
java
@Override public Iterator<T> iterator() { final List<T> shuffledList = Lists.newArrayList(data); Collections.shuffle(shuffledList, rng); return Collections.unmodifiableList(shuffledList).iterator(); }
java
@Override public void writeFile(String arg0, Map result) { // Initial variables BufferedWriter bwB; // output object StringBuilder sbData = new StringBuilder(); // construct the data info in the output try { // Set default value for missing data...
java
private String getCropName(Map result) { String ret; String crid; // Get crop id crid = getCrid(result); // Get crop name string ret = LookupCodes.lookupCode("CRID", crid, "common", "DSSAT"); if (ret.equals(crid)) { ret = "Unkown"; sbErro...
java
private static <T extends Comparable<T>> Optional<Range<T>> smallestContainerForRange( Collection<Range<T>> ranges, Range<T> target) { Range<T> best = Range.all(); for (final Range<T> r : ranges) { if (r.equals(target)) { continue; } // prefer a smaller range, always; if (r...
java
@Override public void validate(T arg) throws ValidationException { for (final Validator<T> validator : validators) { validator.validate(arg); } }
java
public <T> void setSocketOption(SocketOption<T> socketOption, T value) { this.socketOptions.put(socketOption, value); }
java
public void setCenterProperties(Point3d center1) { this.center.setProperties(center1.xProperty, center1.yProperty, center1.zProperty); }
java
protected void onChange() { enabled = false; if (getDocument().getLength() > 0) { enabled = true; } buttonModel.setEnabled(enabled); }
java
@Override public Context addWebapp(Host host, String contextPath, String docBase) { final ContextConfig contextConfig = createContextConfig(); // *extension point return addWebapp(host, contextPath, docBase, contextConfig); }
java
protected void fireAttributeChange(AttributeChangeEvent event) { if (this.listeners != null && isEventFirable()) { final AttributeChangeListener[] list = new AttributeChangeListener[this.listeners.size()]; this.listeners.toArray(list); for (final AttributeChangeListener listener : list) { listener.onAttr...
java
@SuppressWarnings("unchecked") private static <T> T maskNull(T value) { return (value == null) ? (T) NULL_VALUE : value; }
java
protected void assertRange(int index, boolean allowLast) { final int csize = expurge(); if (index < 0) { throw new IndexOutOfBoundsException(Locale.getString("E1", index)); //$NON-NLS-1$ } if (allowLast && (index > csize)) { throw new IndexOutOfBoundsException(Locale.getString("E2", csize, index)); //$NON...
java
public void addReferenceListener(ReferenceListener listener) { if (this.listeners == null) { this.listeners = new LinkedList<>(); } final List<ReferenceListener> list = this.listeners; synchronized (list) { list.add(listener); } }
java
public void removeReferenceListener(ReferenceListener listener) { final List<ReferenceListener> list = this.listeners; if (list != null) { synchronized (list) { list.remove(listener); if (list.isEmpty()) { this.listeners = null; } } } }
java
protected void fireReferenceRelease(int released) { final List<ReferenceListener> list = this.listeners; if (list != null && !list.isEmpty()) { for (final ReferenceListener listener : list) { listener.referenceReleased(released); } } }
java
@Pure @SuppressWarnings("checkstyle:cyclomaticcomplexity") public PT getStartingPointFor(int index) { if ((index < 1) || (this.segmentList.size() <= 1)) { if (this.startingPoint != null) { return this.startingPoint; } } else { int idx = index; ST currentSegment = this.segmentList.get(idx); ST p...
java
boolean removeUntil(int index, boolean inclusive) { if (index >= 0) { boolean changed = false; PT startPoint = this.startingPoint; ST segment; int limit = index; if (inclusive) { ++limit; } for (int i = 0; i < limit; ++i) { segment = this.segmentList.remove(0); this.length -= segment....
java
public void invert() { final PT p = this.startingPoint; this.startingPoint = this.endingPoint; this.endingPoint = p; final int middle = this.segmentList.size() / 2; ST segment; for (int i = 0, j = this.segmentList.size() - 1; i < middle; ++i, --j) { segment = this.segmentList.get(i); this.segmentList....
java
public GP splitAt(ST obj, PT startPoint) { return splitAt(indexOf(obj, startPoint), true); }
java
public GP splitAfterLast(ST obj, PT startPoint) { return splitAt(lastIndexOf(obj, startPoint), false); }
java
public GP splitAtLast(ST obj, PT startPoint) { return splitAt(lastIndexOf(obj, startPoint), true); }
java
public GP splitAfter(ST obj, PT startPoint) { return splitAt(indexOf(obj, startPoint), false); }
java
public void transform(Transform3D transform, Point3D pivot) { Point3D refPoint = (pivot == null) ? getPivot() : pivot; Vector3f v = new Vector3f(this.getEquationComponentA(),this.getEquationComponentB(),this.getEquationComponentC()); transform.transform(v); // Update the plane equation according // ...
java
public void translate(double dx, double dy, double dz) { // Compute the reference point for the plane // (usefull for translation) Point3f refPoint = (Point3f) getPivot(); // a.x + b.y + c.z + d = 0 // where (x,y,z) is the translation point setPivot(refPoint.getX()+dx,refPoint.getY()+dy...
java
public void rotate(Quaternion rotation, Point3D pivot) { Point3D currentPivot = getPivot(); // Update the plane equation according // to the desired normal (computed from // the identity vector and the rotations). Transform3D m = new Transform3D(); m.setRotation(rotation); Vector3f v = n...
java
public static double cleanProbability(double prob, double epsilon, boolean allowOne) { if (prob < -epsilon || prob > (1.0 + epsilon)) { throw new InvalidProbabilityException(prob); } if (prob < epsilon) { prob = epsilon; } else { final double limit = allowOne ? 1.0 : (1.0 - epsilon); ...
java
@Pure public static boolean propertyArraysEquals (Property<?>[] array, Property<?> [] array2) { if(array.length==array2.length) { for(int i=0; i<array.length; i++) { if(array[i]==null) { if(array2[i]!=null) return false; } else if(array2[i]==null) { return false; } else if(!array[i].ge...
java
public void moveTo(Point3d point) { if (this.numTypesProperty.get()>0 && this.types[this.numTypesProperty.get()-1]==PathElementType.MOVE_TO) { this.coordsProperty[this.numCoordsProperty.get()-3] = point.xProperty; this.coordsProperty[this.numCoordsProperty.get()-2] = point.yProperty; this.coordsProperty[this...
java
public void lineTo(Point3d point) { ensureSlots(true, 3); this.types[this.numTypesProperty.get()] = PathElementType.LINE_TO; this.numTypesProperty.set(this.numTypesProperty.get()+1); this.coordsProperty[this.numCoordsProperty.get()] = point.xProperty; this.numCoordsProperty.set(this.numCoordsProperty.get()+1...
java
public void quadTo(Point3d controlPoint, Point3d endPoint) { ensureSlots(true, 6); this.types[this.numTypesProperty.get()] = PathElementType.QUAD_TO; this.numTypesProperty.set(this.numTypesProperty.get()+1); this.coordsProperty[this.numCoordsProperty.get()] = controlPoint.xProperty; this.numCoordsProperty.se...
java
public void curveTo(Point3d controlPoint1, Point3d controlPoint2, Point3d endPoint) { ensureSlots(true, 9); this.types[this.numTypesProperty.get()] = PathElementType.CURVE_TO; this.numTypesProperty.set(this.numTypesProperty.get()+1); this.coordsProperty[this.numCoordsProperty.get()] = controlPoint1.xPr...
java
protected void flush() throws IOException { if (this.tempStream != null && this.buffer.position() > 0) { final int pos = this.buffer.position(); this.buffer.rewind(); this.buffer.limit(pos); this.tempStream.write(this.buffer); this.buffer.rewind(); this.buffer.limit(this.buffer.capacity()); th...
java
protected final void writeBEInt(int v) throws IOException { ensureAvailableBytes(4); this.buffer.order(ByteOrder.BIG_ENDIAN); this.buffer.putInt(v); }
java
protected final void writeBEDouble(double v) throws IOException { ensureAvailableBytes(8); this.buffer.order(ByteOrder.BIG_ENDIAN); this.buffer.putDouble(v); }
java
protected final void writeLEInt(int v) throws IOException { ensureAvailableBytes(4); this.buffer.order(ByteOrder.LITTLE_ENDIAN); this.buffer.putInt(v); }
java
protected final void writeLEDouble(double v) throws IOException { ensureAvailableBytes(8); this.buffer.order(ByteOrder.LITTLE_ENDIAN); this.buffer.putDouble(v); }
java
private void writeHeader(ESRIBounds box, ShapeElementType type, Collection<? extends E> elements) throws IOException { if (!this.headerWasWritten) { initializeContentBuffer(); box.ensureMinMax(); //Byte 0 : File Code (9994) writeBEInt(SHAPE_FILE_CODE); //Byte 4 : Unused (0) writeBEInt(0); //Byt...
java
public void write(Collection<? extends E> elements) throws IOException { final Progression progressBar = getTaskProgression(); Progression subTask = null; if (progressBar != null) { progressBar.setProperties(0, 0, (elements.size() + 1) * 100, false); } if (this.fileBounds == null) { this.fileBounds = ...
java
@Pure public static double toSeconds(double value, TimeUnit inputUnit) { switch (inputUnit) { case DAYS: return value * 86400.; case HOURS: return value * 3600.; case MINUTES: return value * 60.; case SECONDS: break; case MILLISECONDS: return milli2unit(value); case MICROSECONDS: return...
java
@Pure @SuppressWarnings("checkstyle:returncount") public static double toMeters(double value, SpaceUnit inputUnit) { switch (inputUnit) { case TERAMETER: return value * 1e12; case GIGAMETER: return value * 1e9; case MEGAMETER: return value * 1e6; case KILOMETER: return value * 1e3; case HECTOM...
java
@Pure public static double fromSeconds(double value, TimeUnit outputUnit) { switch (outputUnit) { case DAYS: return value / 86400.; case HOURS: return value / 3600.; case MINUTES: return value / 60.; case SECONDS: break; case MILLISECONDS: return unit2milli(value); case MICROSECONDS: re...
java
@Pure public static double toMetersPerSecond(double value, SpeedUnit inputUnit) { switch (inputUnit) { case KILOMETERS_PER_HOUR: return 3.6 * value; case MILLIMETERS_PER_SECOND: return value / 1000.; case METERS_PER_SECOND: default: } return value; }
java
@Pure public static double toRadiansPerSecond(double value, AngularUnit inputUnit) { switch (inputUnit) { case TURNS_PER_SECOND: return value * (2. * MathConstants.PI); case DEGREES_PER_SECOND: return Math.toRadians(value); case RADIANS_PER_SECOND: default: } return value; }
java
@Pure public static double fromMetersPerSecond(double value, SpeedUnit outputUnit) { switch (outputUnit) { case KILOMETERS_PER_HOUR: return value / 3.6; case MILLIMETERS_PER_SECOND: return value * 1000.; case METERS_PER_SECOND: default: } return value; }
java
@Pure public static double fromRadiansPerSecond(double value, AngularUnit outputUnit) { switch (outputUnit) { case TURNS_PER_SECOND: return value / (2. * MathConstants.PI); case DEGREES_PER_SECOND: return Math.toDegrees(value); case RADIANS_PER_SECOND: default: } return value; }
java
@Pure public static SpaceUnit getSmallestUnit(double amount, SpaceUnit unit) { final double meters = toMeters(amount, unit); double v; final SpaceUnit[] units = SpaceUnit.values(); SpaceUnit u; for (int i = units.length - 1; i >= 0; --i) { u = units[i]; v = Math.floor(fromMeters(meters, u)); if (v >...
java
public static Vector3d convert(Tuple3D<?> tuple) { if (tuple instanceof Vector3d) { return (Vector3d) tuple; } return new Vector3d(tuple.getX(), tuple.getY(), tuple.getZ()); }
java
private String ljust(String s, Integer length) { if (s.length() >= length) { return s; } length -= s.length(); StringBuffer sb = new StringBuffer(); for (Integer i = 0; i < length; i++) { sb.append(" "); } return s + sb.toString(); }
java
private void appendProperty(StringBuffer sb, String propertyName, Object propertyValue) { if (propertyValue != null) { propertyValue = propertyValue.toString().replaceAll("\\s+", " ") .trim(); } sb.append(ljust(propertyName + ":", 45) + propertyValue + "\n"); }
java
public void inflate(double minx, double miny, double minz, double maxx, double maxy, double maxz) { this.setFromCorners(this.getMinX()+ minx,this.getMinY()+ miny,this.getMinZ()+ minz,this.getMaxX()+ maxx,this.getMaxY()+ maxy,this.getMaxZ()+ maxz); }
java
@Pure public static Point3d computeClosestPoint( double minx, double miny, double minz, double maxx, double maxy, double maxz, double x, double y, double z) { Point3d closest = new Point3d(); if (x < minx) { closest.setX(minx); } else if (x > maxx) { closest.setX(maxx); } else { closest.s...
java
@Override public void setMinX(double x) { double o = this.maxxProperty.doubleValue(); if (o<x) { this.minxProperty.set(o); this.maxxProperty.set(x); } else { this.minxProperty.set(x); } }
java
@Override public void setMaxX(double x) { double o = this.minxProperty.doubleValue(); if (o>x) { this.maxxProperty.set(o); this.minxProperty.set(x); } else { this.maxxProperty.set(x); } }
java
@Override public void setMaxY(double y) { double o = this.minyProperty.doubleValue() ; if (o>y) { this.maxyProperty.set( o); this.minyProperty.set(y); } else { this.maxyProperty.set(y); } }
java
@Pure public static ShapeElementType classifiesElement(MapElement element) { final Class<? extends MapElement> type = element.getClass(); if (MapMultiPoint.class.isAssignableFrom(type)) { return ShapeElementType.MULTIPOINT; } if (MapPolygon.class.isAssignableFrom(type)) { return ShapeElementType.POLYGON;...
java
void add(MapElement element) { final Rectangle2d r = element.getBoundingBox(); if (r != null) { if (Double.isNaN(this.minx) || this.minx > r.getMinX()) { this.minx = r.getMinX(); } if (Double.isNaN(this.maxx) || this.maxx < r.getMaxX()) { this.maxx = r.getMaxX(); } if (Double.isNaN(this.miny)...
java
public void addCollection(Collection<? extends E> collection) { if (collection != null && !collection.isEmpty()) { this.collections.add(collection); } }
java
public static Point2ifx convert(Tuple2D<?> tuple) { if (tuple instanceof Point2ifx) { return (Point2ifx) tuple; } return new Point2ifx(tuple.getX(), tuple.getY()); }
java
public T remove(final T row) { final int index = data.indexOf(row); if (index != -1) { try { return data.remove(index); } finally { fireTableDataChanged(); } } return null; }
java
public List<T> removeAll(final List<T> toRemove) { final List<T> removedList = new ArrayList<>(); for (final T t : toRemove) { final int index = data.indexOf(t); if (index != -1) { removedList.add(data.remove(index)); } } fireTableDataChanged(); return removedList; }
java
public void update(final T row) { final int index = data.indexOf(row); if (index != -1) { data.set(index, row); fireTableDataChanged(); } }
java
public static Point3ifx convert(Tuple3D<?> tuple) { if (tuple instanceof Point3ifx) { return (Point3ifx) tuple; } return new Point3ifx(tuple.getX(), tuple.getY(), tuple.getZ()); }
java
@Pure public ReadOnlyBooleanProperty ccwProperty() { if (this.ccw == null) { this.ccw = new ReadOnlyBooleanWrapper(this, MathFXAttributeNames.CCW); this.ccw.bind(Bindings.createBooleanBinding(() -> Triangle2afp.isCCW( getX1(), getY1(), getX2(), getY2(), getX3(), getY3()), x1Property(), y1P...
java
public static final double chooseMostCommonRightHandClassAccuracy(SummaryConfusionMatrix m) { final double total = m.sumOfallCells(); double max = 0.0; for (final Symbol right : m.rightLabels()) { max = Math.max(max, m.columnSum(right)); } return DoubleUtils.XOverYOrZero(max, total); }
java
public List<GridCell<P>> consumeCells() { final List<GridCell<P>> list = new ArrayList<>(this.cells); this.cells.clear(); return list; }
java