code
stringlengths
73
34.1k
label
stringclasses
1 value
public void ifge(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFGE); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java
public void ifgt(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFGT); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java
public void ifle(String target) throws IOException { if (wideIndex) { out.writeByte(NOT_IFLE); out.writeShort(WIDEFIXOFFSET); Branch branch = createBranch(target); out.writeByte(GOTO_W); out.writeInt(branch); } else ...
java
private void createParentChildRelationships(Database db, HashMap<String, Account> descriptionMap, HashMap<String, ArrayList<String>> seqMap) throws Exception { // List of ID's used to avoid recursion ...
java
public File rename(File f) { if (createNewFile(f)) { return f; } String name = f.getName(); String body = null; String ext = null; int dot = name.lastIndexOf("."); if (dot != -1) { body = name.substring(0, dot); ext = name.substring(dot); // includes "." } else { ...
java
@Api public GeometryValidationState getState() { if (violations.isEmpty()) { return GeometryValidationState.VALID; } else { return violations.get(0).getState(); } }
java
public boolean equalsDelta(Coordinate coordinate, double delta) { return null != coordinate && (Math.abs(this.x - coordinate.x) < delta && Math.abs(this.y - coordinate.y) < delta); }
java
public double distance(Coordinate c) { double dx = x - c.x; double dy = y - c.y; return Math.sqrt(dx * dx + dy * dy); }
java
public static Geometry toPolygon(Bbox bounds) { double minX = bounds.getX(); double minY = bounds.getY(); double maxX = bounds.getMaxX(); double maxY = bounds.getMaxY(); Geometry polygon = new Geometry(Geometry.POLYGON, 0, -1); Geometry linearRing = new Geometry(Geometry.LINEAR_RING, 0, -1); linearRing....
java
public static Geometry toLineString(Coordinate c1, Coordinate c2) { Geometry lineString = new Geometry(Geometry.LINE_STRING, 0, -1); lineString.setCoordinates(new Coordinate[] { (Coordinate) c1.clone(), (Coordinate) c2.clone() }); return lineString; }
java
public static int getNumPoints(Geometry geometry) { if (geometry == null) { throw new IllegalArgumentException("Cannot get total number of points for null geometry."); } int count = 0; if (geometry.getGeometries() != null) { for (Geometry child : geometry.getGeometries()) { count += getNumPoints(child...
java
public static boolean isValid(Geometry geometry, GeometryIndex index) { validate(geometry, index); return validationContext.isValid(); }
java
public static GeometryValidationState validate(Geometry geometry) { validationContext.clear(); if (Geometry.LINE_STRING.equals(geometry.getGeometryType())) { IndexedLineString lineString = helper.createLineString(geometry); validateLineString(lineString); } else if (Geometry.LINEAR_RING.equals(geometry.getG...
java
public static boolean intersects(Geometry one, Geometry two) { if (one == null || two == null || isEmpty(one) || isEmpty(two)) { return false; } if (Geometry.POINT.equals(one.getGeometryType())) { return intersectsPoint(one, two); } else if (Geometry.LINE_STRING.equals(one.getGeometryType())) { return ...
java
public static double getLength(Geometry geometry) { double length = 0; if (geometry.getGeometries() != null) { for (Geometry child : geometry.getGeometries()) { length += getLength(child); } } if (geometry.getCoordinates() != null && (Geometry.LINE_STRING.equals(geometry.getGeometryType()) || Geom...
java
public static double getDistance(Geometry geometry, Coordinate coordinate) { double minDistance = Double.MAX_VALUE; if (coordinate != null && geometry != null) { if (geometry.getGeometries() != null) { for (Geometry child : geometry.getGeometries()) { double distance = getDistance(child, coordinate); ...
java
private static boolean intersectsPoint(Geometry point, Geometry geometry) { if (geometry.getGeometries() != null) { for (Geometry child : geometry.getGeometries()) { if (intersectsPoint(point, child)) { return true; } } } if (geometry.getCoordinates() != null) { Coordinate coordinate = point...
java
public void sendFile(File file, OutputStream os) throws IOException { FileInputStream is = null; BufferedInputStream buf = null;; try { is = new FileInputStream(file); buf = new BufferedInputStream(is); int readBytes = 0; if (LOGGER.isDebugEnabled(...
java
public static String toWkt(Geometry geometry) throws WktException { if (Geometry.POINT.equals(geometry.getGeometryType())) { return toWktPoint(geometry); } else if (Geometry.LINE_STRING.equals(geometry.getGeometryType()) || Geometry.LINEAR_RING.equals(geometry.getGeometryType())) { return toWktLineString(...
java
private static int parseSrid(String ewktPart) { if (ewktPart != null && !"".equals(ewktPart)) { String[] parts = ewktPart.split("="); if (parts.length == 2) { try { return Integer.parseInt(parts[1]); } catch (Exception e) { } } } return 0; }
java
private static Geometry parseWkt(String wkt) throws WktException { if (wkt != null) { int i1 = wkt.indexOf('('); int i2 = wkt.indexOf(' '); // allow both '(' and ' (' int i = Math.min(i1, i2); if (i < 0) { i = (i1 > 0 ? i1 : i2); } String type = null; if (i >= 0) { type = typeWktToGeom...
java
public static XmlPath parse(String xmlPathQuery) { // validations if(xmlPathQuery == null) { throw new XmlPathException("The XML path query can not be a null value"); } xmlPathQuery = xmlPathQuery.trim(); // simple patterns if(! xmlPathQuery.contains("/")) { ...
java
public static int getTypeNumber(TypeKind kind) { switch (kind) { case BOOLEAN: case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: case VOID: return...
java
public static TypeMirror normalizeType(TypeKind kind) { switch (kind) { case BOOLEAN: case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: return Typ.getPrimitiv...
java
public static boolean isInteger(TypeMirror type) { switch (type.getKind()) { case INT: case SHORT: case CHAR: case BYTE: case BOOLEAN: return true; default: return false; } }
java
public static boolean isJavaConstantType(TypeMirror type) { switch (type.getKind()) { case INT: case LONG: case FLOAT: case DOUBLE: return true; case DECLARED: DeclaredType dt = (DeclaredType) type; ...
java
public static Object convert(String constant, TypeKind kind) { switch (kind) { case INT: return Integer.parseInt(constant); case LONG: return java.lang.Long.parseLong(constant); case FLOAT: return java.lang.Float.par...
java
public Collection<FedoraResource> getChildren(final String mixin) throws FedoraException { Node mixinLiteral = null; if ( mixin != null ) { mixinLiteral = NodeFactory.createLiteral(mixin); } final ExtendedIterator<Triple> it = graph.find(Node.ANY, CONTAINS.asNode(), Node.ANY)...
java
public long getTime(String name) { Long res = stats.get(name); return (res == null) ? -1 : res.longValue(); }
java
public String getStatistics() { StringBuilder sb = new StringBuilder(); for(String key : stats.keySet()) { sb.append(key); sb.append(": "); sb.append(stats.get(key)); sb.append("\n"); } return sb.toString(); }
java
public static DateTime getDateTime(final ResultSet rs, final String columnName) throws SQLException { final Timestamp ts = rs.getTimestamp(columnName); return (ts == null) ? null : new DateTime(ts); }
java
public static DateTime getUTCDateTime(final ResultSet rs, final String columnName) throws SQLException { final Timestamp ts = rs.getTimestamp(columnName); return (ts == null) ? null : new DateTime(ts).withZone(DateTimeZone.UTC); }
java
public static <T extends Enum<T>> T getEnum(final ResultSet rs, final Class<T> enumType, final String columnName) throws SQLException { final String str = rs.getString(columnName); return (str == null) ? null : Enum.valueOf(enumType, str); }
java
private Method methodExists(Class<?> clazz, String method, Class<?>[] params) { try { return clazz.getMethod(method, params); } catch (NoSuchMethodException e) { return null; } }
java
private Object invokeAction(Object clazz, Method method, UrlInfo urlInfo, Object... args) throws IllegalAccessException, InvocationTargetException { if (this.isRequestMethodServed(method, urlInfo.getRequestMethod())) { return method.invoke(clazz, args); } else { throw new IllegalArgumentException("Method " + ...
java
public SecureUTF8String makePassword(final SecureUTF8String masterPassword, final Account account, final String inputText) throws Exception { return makePassword(masterPassword, account, inputText, account.getUsername()); }
java
private SecureUTF8String hashTheData(SecureUTF8String masterPassword, SecureUTF8String data, Account account) throws Exception { final SecureUTF8String output = new SecureUTF8String(); final SecureUTF8String secureIteration = new SecureUTF8String(); SecureUTF8String intermediateOutpu...
java
private SecureUTF8String runAlgorithm(SecureUTF8String masterPassword, SecureUTF8String data, Account account) throws Exception { SecureUTF8String output = null; SecureCharArray digestChars = null; SecureByteArray masterPasswordBytes = null; SecureByteArray dataBytes = null; ...
java
private void fill() throws IOException { int i = in.read(buf, 0, buf.length); if (i > 0) { pos = 0; count = i; } }
java
protected void populateCDs(Map<String, List<String[]>> cdMap, String referencedComponentId, String featureId, String operator, String value, String unit) { List<String[]> list; // my ( $comp, $feature, $op, $value, $unit ) = @_; if (!cdMap.containsKey(referencedComponentId)) { ...
java
protected OntologyBuilder getOntologyBuilder(VersionRows vr, String rootModuleId, String rootModuleVersion, Map<String, String> metadata) { return new OntologyBuilder(vr, rootModuleId, rootModuleVersion, metadata); }
java
public static List<File> sort(File sortDir, List<File> files, Comparator<String> comparator) { // validations if(sortDir == null) { throw new DataUtilException("The sort directory parameter can't be a null value"); } else if(!sortDir.exists()) { throw new DataUtilExceptio...
java
public void processRecordInternally(Record record) { if (record instanceof FormatRecord) { FormatRecord fr = (FormatRecord) record; _customFormatRecords.put(Integer.valueOf(fr.getIndexCode()), fr); } if (record instanceof ExtendedFormatRecord) { ExtendedFormat...
java
public int getFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex()); if (xfr == null) { logger.log(POILogger.ERROR, "Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we do...
java
public static String readResourceAsStream(String path) { try { InputStream inputStream = ResourceUtil.getResourceAsStream(path); return ResourceUtil.readFromInputStreamIntoString(inputStream); } catch (Exception e) { throw new DataUtilException("Failed to load resourc...
java
public static String readResource(String path) { try { File file = ResourceUtil.getResourceFile(path); return ResourceUtil.readFromFileIntoString(file); } catch (Exception e) { throw new DataUtilException("Failed to load resource", e); } }
java
private Geometry cloneRecursively(Geometry geometry) { Geometry clone = new Geometry(geometry.geometryType, geometry.srid, geometry.precision); if (geometry.getGeometries() != null) { Geometry[] geometryClones = new Geometry[geometry.getGeometries().length]; for (int i = 0; i < geometry.getGeometries().length...
java
int resolveFieldIndex(VariableElement field) { TypeElement declaringClass = (TypeElement) field.getEnclosingElement(); String descriptor = Descriptor.getDesriptor(field); int index = resolveFieldIndex(declaringClass, field.getSimpleName().toString(), descriptor); addIndexedEleme...
java
private int resolveFieldIndex(TypeElement declaringClass, String name, String descriptor) { int size = 0; int index = 0; constantReadLock.lock(); try { size = getConstantPoolSize(); index = getRefIndex(Fieldref.class, declaringClass.getQualifie...
java
int resolveMethodIndex(ExecutableElement method) { int size = 0; int index = 0; constantReadLock.lock(); TypeElement declaringClass = (TypeElement) method.getEnclosingElement(); String declaringClassname = declaringClass.getQualifiedName().toString(); String d...
java
final int resolveNameIndex(CharSequence name) { int size = 0; int index = 0; constantReadLock.lock(); try { size = getConstantPoolSize(); index = getNameIndex(name); } finally { constantReadLock.unlock();...
java
int resolveNameAndTypeIndex(String name, String descriptor) { int size = 0; int index = 0; constantReadLock.lock(); try { size = getConstantPoolSize(); index = getNameAndTypeIndex(name, descriptor); } finally { ...
java
public void defineConstantField(int modifier, String fieldName, int constant) { DeclaredType dt = (DeclaredType)asType(); VariableBuilder builder = new VariableBuilder(this, fieldName, dt.getTypeArguments(), typeParameterMap); builder.addModifiers(modifier); builder.addModifier(...
java
public void save(ProcessingEnvironment env) throws IOException { Filer filer = env.getFiler(); //JavaFileObject sourceFile = filer.createClassFile(getQualifiedName(), superClass); FileObject sourceFile = filer.createResource( StandardLocation.CLASS_OUTPUT, ...
java
@Override public void write(DataOutput out) throws IOException { addSignatureIfNeed(); out.writeInt(magic); out.writeShort(minor_version); out.writeShort(major_version); out.writeShort(constant_pool.size()+1); for (ConstantInfo ci : constant_pool) ...
java
public boolean matches(LinkedList<Node> nodePath) { if(simplePattern) { // simple pattern return items.get(0).matches(nodePath.getLast()); } // match the full pattern if(items.size() != nodePath.size()) { // different size return false; ...
java
public Lexer newLexer(String name) { PyObject object = pythonInterpreter.get("get_lexer_by_name"); object = object.__call__(new PyString(name)); return new Lexer(object); }
java
public HtmlFormatter newHtmlFormatter(String params) { PyObject object = pythonInterpreter.eval("HtmlFormatter(" + params + ")"); return new HtmlFormatter(object); }
java
public String highlight(String code, Lexer lexer, Formatter formatter) { PyFunction function = pythonInterpreter.get("highlight", PyFunction.class); PyString pyCode = new PyString(code); PyObject pyLexer = lexer.getLexer(); PyObject pyFormatter = formatter.getFormatter(); return function.__call__(pyCode...
java
protected void putParam(String name, Object object) { this.response.getRequest().setAttribute(name, object); }
java
void addToSubroutine(final long id, final int nbSubroutines) { if ((status & VISITED) == 0) { status |= VISITED; srcAndRefPositions = new int[nbSubroutines / 32 + 1]; } srcAndRefPositions[(int) (id >>> 32)] |= (int) id; }
java
void visitSubroutine(final Label JSR, final long id, final int nbSubroutines) { // user managed stack of labels, to avoid using a recursive method // (recursivity can lead to stack overflow with very large methods) Label stack = this; while (stack != null) { // removes a labe...
java
public String serialize(Object object) { XStream xstream = new XStream(); return xstream.toXML(object); }
java
public static void merge(File mergeDir, List<File> sortedFiles, File mergedFile, Comparator<String> comparator) { merge(mergeDir, sortedFiles, mergedFile, comparator, MERGE_FACTOR); }
java
public static void merge(File mergeDir, List<File> sortedFiles, File mergedFile, Comparator<String> comparator, int mergeFactor) { LinkedList<File> mergeFiles = new LinkedList<File>(sortedFiles); // merge all files LinkedList<BatchFile> batch = new LinkedList<BatchF...
java
public void readyToWrite() { addSignatureIfNeed(); this.name_index = ((SubClass)classFile).resolveNameIndex(getSimpleName()); this.descriptor_index = ((SubClass)classFile).resolveNameIndex(Descriptor.getDesriptor(this)); readyToWrite = true; }
java
private boolean bfsComparison(Node root, Node other) { if(root instanceof Content || other instanceof Content) { return root.equals(other); } if(! root.equals(other)) { return false; } List<Node> a = ((Element)root).getChildElements(); List<Node> ...
java
private int bsfHashCode(Node node, int result) { result += 31 * node.hashCode(); if(node instanceof Content) { return result; } Element elem = (Element) node; List<Node> childElements = elem.getChildElements(); for (Node childElement : childElements) { ...
java
private void deepCopy(Element origElement, Element copyElement) { List<Node> children = origElement.getChildElements(); for(Node node : children) { try { if(node instanceof Content) { Content content = (Content) ((Content) node).clone(); ...
java
public String makeJavaIdentifier(String id) { String jid = makeJavaId(id); String old = map.put(jid, id); if (old != null && !old.equals(id)) { throw new IllegalArgumentException("both "+id+" and "+old+" makes the same java id "+jid); } return jid; }
java
public String makeUniqueJavaIdentifier(String id) { String jid = makeJavaId(id); String old = map.put(jid, id); if (old != null) { String oid = jid; for (int ii=1;old != null;ii++) { jid = oid+ii; old = map.put(jid, ...
java
@Override public void write(String output) throws MapReduceException { try { writer.write(output + DataUtilDefaults.lineTerminator); } catch (IOException e) { throw new MapReduceException("Failed to write to the output collector", e); } }
java
public void close() throws MapReduceException { try { if(writer != null) { writer.flush(); writer.close(); } } catch (IOException e) { throw new MapReduceException("Failed to close the output collector", e); } }
java
public static String pad(int repeat, String str) { StringBuilder sb = new StringBuilder(); for(int i=0; i < repeat; i++) { sb.append(str); } return sb.toString(); }
java
public void setFile(File file, String attachmentFilename, String contentType) { this.file = file; this.attachmentFilename = attachmentFilename; this.contentType = contentType; }
java
private Boolean existsPage(String page) throws MalformedURLException { // Searching the page... LOGGER.debug("Searching page [{}]...", page); LOGGER.debug("Page's real path is [{}]", this.context.getRealPath(page)); File file = new File(this.context.getRealPath(page)); Boolean ex...
java
public static <T> Set<T> createSet(T... args) { HashSet<T> newSet = new HashSet<T>(); Collections.addAll(newSet, args); return newSet; }
java
public static <T> Set<T> arrayToSet(T [] array) { return new HashSet<T>(Arrays.asList(array)); }
java
public static <T> Set<T> intersection(Set<T> setA, Set<T> setB) { Set<T> intersection = new HashSet<T>(setA); intersection.retainAll(setB); return intersection; }
java
public static <T> Set<T> union(Set<T> setA, Set<T> setB) { Set<T> union = new HashSet<T>(setA); union.addAll(setB); return union; }
java
public static <T> Set<T> difference(Set<T> setA, Set<T> setB) { Set<T> difference = new HashSet<T>(setA); difference.removeAll(setB); return difference; }
java
public static <T> Set<T> symmetricDifference(Set<T> setA, Set<T> setB) { Set<T> union = union(setA, setB); Set<T> intersection = intersection(setA, setB); return difference(union, intersection); }
java
public static <T> boolean isSubset(Set<T> setA, Set<T> setB) { return setB.containsAll(setA); }
java
public static <T> boolean isSuperset(Set<T> setA, Set<T> setB) { return setA.containsAll(setB); }
java
public String getClassName() { switch (sort) { case VOID: return "void"; case BOOLEAN: return "boolean"; case CHAR: return "char"; case BYTE: return "byte"; case SHORT: return "short"; case INT: ...
java
public static boolean matchUrl(Account account, String url) { for (AccountPatternData pattern : account.getPatterns()) { AccountPatternType type = pattern.getType(); if (type == AccountPatternType.REGEX) { if (regexMatch(pattern.getPattern(), url)) ret...
java
public static void deleteFilesByExtension(File dir, String extension) { if(extension == null) { throw new DataUtilException("Filename extension can not be a null value"); } FilenameFilter filter = new FileExtensionFilenameFilter(extension); FileDeleter.deleteFiles(dir, filter...
java
public static void deleteFilesByRegex(File dir, String regex) { if(regex == null) { throw new DataUtilException("Filename regex can not be null"); } FilenameFilter filter = new RegexFilenameFilter(regex); FileDeleter.deleteFiles(dir, filter); }
java
public static void deleteFiles(File dir, FilenameFilter filter) { // validations if(dir == null) { throw new DataUtilException("The delete directory parameter can not be a null value"); } else if(!dir.exists() || !dir.isDirectory()) { throw new DataUtilException("The dele...
java
public static String readFromFileIntoString(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); StringBuilder text = new StringBuilder(); String line; wh...
java
public static File writeStringToTempFile(String prefix, String suffix, String data) throws IOException { File testFile = File.createTempFile(prefix, suffix); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( testFile.getAbsoluteFile(), false),DataUt...
java
public static String createRandomData(int rows, int rowLength, boolean skipTrailingNewline) { Random random = new Random(System.currentTimeMillis()); StringBuilder strb = new StringBuilder(); for(int i=0; i<rows; i++) { for(int j=0; j<rowLength; j++) { strb.append((ch...
java
public static File createTmpDir(String directoryName) { File tmpDir = new File(System.getProperty("java.io.tmpdir")); File testDir = new File(tmpDir, directoryName); if(!testDir.mkdir()) { throw new ResourceUtilException("Can't create directory: " + testDir.getAbsolutePath()); ...
java
public static Bbox setCenterPoint(Bbox bbox, Coordinate center) { double x = center.getX() - 0.5 * bbox.getWidth(); double y = center.getY() - 0.5 * bbox.getHeight(); return new Bbox(x, y, bbox.getWidth(), bbox.getHeight()); }
java
public static boolean contains(Bbox parent, Bbox child) { if (child.getX() < parent.getX()) { return false; } if (child.getY() < parent.getY()) { return false; } if (child.getMaxX() > parent.getMaxX()) { return false; } if (child.getMaxY() > parent.getMaxY()) { return false; } return true;...
java
public static boolean contains(Bbox bbox, Coordinate coordinate) { if (bbox.getX() >= coordinate.getX()) { return false; } if (bbox.getY() >= coordinate.getY()) { return false; } if (bbox.getMaxX() <= coordinate.getX()) { return false; } if (bbox.getMaxY() <= coordinate.getY()) { return false;...
java
public static boolean intersects(Bbox one, Bbox two) { if (two.getX() > one.getMaxX()) { return false; } if (two.getY() > one.getMaxY()) { return false; } if (two.getMaxX() < one.getX()) { return false; } if (two.getMaxY() < one.getY()) { return false; } return true; }
java
public static Bbox intersection(Bbox one, Bbox two) { if (!intersects(one, two)) { return null; } else { double minx = two.getX() > one.getX() ? two.getX() : one.getX(); double maxx = two.getMaxX() < one.getMaxX() ? two.getMaxX() : one.getMaxX(); double miny = two.getY() > one.getY() ? two.getY() : one....
java
public static Bbox buffer(Bbox bbox, double range) { if (range >= 0) { double r2 = range * 2; return new Bbox(bbox.getX() - range, bbox.getY() - range, bbox.getWidth() + r2, bbox.getHeight() + r2); } throw new IllegalArgumentException("Buffer range must always be positive."); }
java
public static Bbox translate(Bbox bbox, double deltaX, double deltaY) { return new Bbox(bbox.getX() + deltaX, bbox.getY() + deltaY, bbox.getWidth(), bbox.getHeight()); }
java