repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/Assembler.java | Assembler.ifge | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFGE);
out.writeShort(branch);
}
} | java | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFGE);
out.writeShort(branch);
}
} | [
"public",
"void",
"ifge",
"(",
"String",
"target",
")",
"throws",
"IOException",
"{",
"if",
"(",
"wideIndex",
")",
"{",
"out",
".",
"writeByte",
"(",
"NOT_IFGE",
")",
";",
"out",
".",
"writeShort",
"(",
"WIDEFIXOFFSET",
")",
";",
"Branch",
"branch",
"=",... | ge succeeds if and only if value >= 0
@param target
@throws IOException | [
"ge",
"succeeds",
"if",
"and",
"only",
"if",
"value",
">",
";",
"=",
"0"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/Assembler.java#L1067-L1083 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/Assembler.java | Assembler.ifgt | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFGT);
out.writeShort(branch);
}
} | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFGT);
out.writeShort(branch);
}
} | [
"public",
"void",
"ifgt",
"(",
"String",
"target",
")",
"throws",
"IOException",
"{",
"if",
"(",
"wideIndex",
")",
"{",
"out",
".",
"writeByte",
"(",
"NOT_IFGT",
")",
";",
"out",
".",
"writeShort",
"(",
"WIDEFIXOFFSET",
")",
";",
"Branch",
"branch",
"=",... | gt succeeds if and only if value > 0
@param target
@throws IOException | [
"gt",
"succeeds",
"if",
"and",
"only",
"if",
"value",
">",
";",
"0"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/Assembler.java#L1090-L1106 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/Assembler.java | Assembler.ifle | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFLE);
out.writeShort(branch);
}
} | 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
{
Branch branch = createBranch(target);
out.writeOpCode(IFLE);
out.writeShort(branch);
}
} | [
"public",
"void",
"ifle",
"(",
"String",
"target",
")",
"throws",
"IOException",
"{",
"if",
"(",
"wideIndex",
")",
"{",
"out",
".",
"writeByte",
"(",
"NOT_IFLE",
")",
";",
"out",
".",
"writeShort",
"(",
"WIDEFIXOFFSET",
")",
";",
"Branch",
"branch",
"=",... | le succeeds if and only if value <= 0
@param target
@throws IOException | [
"le",
"succeeds",
"if",
"and",
"only",
"if",
"value",
"<",
";",
"=",
"0"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/Assembler.java#L1113-L1129 | train |
passwordmaker/java-passwordmaker-lib | src/main/java/org/daveware/passwordmaker/RDFDatabaseReader.java | RDFDatabaseReader.createParentChildRelationships | private void createParentChildRelationships(Database db,
HashMap<String, Account> descriptionMap,
HashMap<String, ArrayList<String>> seqMap)
throws Exception {
// List of ID's used to avoid recursion
ArrayList<String> parentIdStack = new ArrayList<String>();
// Verify the root node exists
if (!seqMap.containsKey(Account.ROOT_ACCOUNT_URI))
throw new Exception("File does not contain the root account, '" + Account.ROOT_ACCOUNT_URI + "'");
parentIdStack.add(Account.ROOT_ACCOUNT_URI);
// Until we run out of parent nodes...
while (parentIdStack.size() > 0) {
String parentId = parentIdStack.get(0);
Account parentAccount = descriptionMap.get(parentId);
parentIdStack.remove(0);
// Attempt to add the parent node if it's not the root. Root already exists
// in the database by default.
if (parentId.compareTo(Account.ROOT_ACCOUNT_URI) != 0) {
if (parentAccount != null) {
// If the parent node is not already in the db, add it
if (db.findAccountById(parentId) == null) {
Account parentParentAccount = db.findParent(parentAccount);
if (parentParentAccount == null) {
logger.warning("SeqNode[" + parentId + "] does not have a parent, will be dropped");
parentAccount = null;
}
}
} else {
logger.warning("SeqNode[" + parentId + "] does not have a matching RDF:Description node, it will be dropped");
}
} else {
parentAccount = db.getRootAccount();
}
// Now add the children
if (parentAccount != null) {
for (String childId : seqMap.get(parentId)) {
Account childAccount = descriptionMap.get(childId);
if (childAccount != null) {
if (!parentAccount.hasChild(childAccount)) {
parentAccount.getChildren().add(childAccount);
// If the child has children, add it to the parentIdStack for later processing, also mark
// it as a folder (which should have been done already based on it not having an algorithm.
if (seqMap.containsKey(childAccount.getId())) {
parentIdStack.add(childId);
childAccount.setIsFolder(true);
}
} else {
logger.warning("Duplicate child '" + childId + "' found of parent '" + parentAccount.getId() + "'");
}
} else {
logger.warning("Cannot find RDF:Description for '" + childId + "', it will be dropped");
}
}
}
}
} | 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
ArrayList<String> parentIdStack = new ArrayList<String>();
// Verify the root node exists
if (!seqMap.containsKey(Account.ROOT_ACCOUNT_URI))
throw new Exception("File does not contain the root account, '" + Account.ROOT_ACCOUNT_URI + "'");
parentIdStack.add(Account.ROOT_ACCOUNT_URI);
// Until we run out of parent nodes...
while (parentIdStack.size() > 0) {
String parentId = parentIdStack.get(0);
Account parentAccount = descriptionMap.get(parentId);
parentIdStack.remove(0);
// Attempt to add the parent node if it's not the root. Root already exists
// in the database by default.
if (parentId.compareTo(Account.ROOT_ACCOUNT_URI) != 0) {
if (parentAccount != null) {
// If the parent node is not already in the db, add it
if (db.findAccountById(parentId) == null) {
Account parentParentAccount = db.findParent(parentAccount);
if (parentParentAccount == null) {
logger.warning("SeqNode[" + parentId + "] does not have a parent, will be dropped");
parentAccount = null;
}
}
} else {
logger.warning("SeqNode[" + parentId + "] does not have a matching RDF:Description node, it will be dropped");
}
} else {
parentAccount = db.getRootAccount();
}
// Now add the children
if (parentAccount != null) {
for (String childId : seqMap.get(parentId)) {
Account childAccount = descriptionMap.get(childId);
if (childAccount != null) {
if (!parentAccount.hasChild(childAccount)) {
parentAccount.getChildren().add(childAccount);
// If the child has children, add it to the parentIdStack for later processing, also mark
// it as a folder (which should have been done already based on it not having an algorithm.
if (seqMap.containsKey(childAccount.getId())) {
parentIdStack.add(childId);
childAccount.setIsFolder(true);
}
} else {
logger.warning("Duplicate child '" + childId + "' found of parent '" + parentAccount.getId() + "'");
}
} else {
logger.warning("Cannot find RDF:Description for '" + childId + "', it will be dropped");
}
}
}
}
} | [
"private",
"void",
"createParentChildRelationships",
"(",
"Database",
"db",
",",
"HashMap",
"<",
"String",
",",
"Account",
">",
"descriptionMap",
",",
"HashMap",
"<",
"String",
",",
"ArrayList",
"<",
"String",
">",
">",
"seqMap",
")",
"throws",
"Exception",
"{... | Iterates through the list of Seqs read in adding the parent node and
then adding children which belong to it.
@param db The database to add nodes to.
@param descriptionMap The list of RDF:Description nodes.
@param seqMap The list of RDF:Seq nodes, which contain RDF:li nodes.
@throws Exception on unrecoverable error. | [
"Iterates",
"through",
"the",
"list",
"of",
"Seqs",
"read",
"in",
"adding",
"the",
"parent",
"node",
"and",
"then",
"adding",
"children",
"which",
"belong",
"to",
"it",
"."
] | 18c22fca7dd9a47f08161425b85a5bd257afbb2b | https://github.com/passwordmaker/java-passwordmaker-lib/blob/18c22fca7dd9a47f08161425b85a5bd257afbb2b/src/main/java/org/daveware/passwordmaker/RDFDatabaseReader.java#L385-L445 | train |
Teddy-Zhu/SilentGo | framework/src/main/java/com/silentgo/servlet/oreilly/multipart/DefaultFileRenamePolicy.java | DefaultFileRenamePolicy.rename | 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 {
body = name;
ext = "";
}
// Increase the count until an empty spot is found.
// Max out at 9999 to avoid an infinite loop caused by a persistent
// IOException, like when the destination dir becomes non-writable.
// We don't pass the exception up because our job is just to rename,
// and the caller will hit any IOException in normal processing.
int count = 0;
while (!createNewFile(f) && count < 9999) {
count++;
String newName = body + count + ext;
f = new File(f.getParent(), newName);
}
return f;
} | 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 {
body = name;
ext = "";
}
// Increase the count until an empty spot is found.
// Max out at 9999 to avoid an infinite loop caused by a persistent
// IOException, like when the destination dir becomes non-writable.
// We don't pass the exception up because our job is just to rename,
// and the caller will hit any IOException in normal processing.
int count = 0;
while (!createNewFile(f) && count < 9999) {
count++;
String newName = body + count + ext;
f = new File(f.getParent(), newName);
}
return f;
} | [
"public",
"File",
"rename",
"(",
"File",
"f",
")",
"{",
"if",
"(",
"createNewFile",
"(",
"f",
")",
")",
"{",
"return",
"f",
";",
"}",
"String",
"name",
"=",
"f",
".",
"getName",
"(",
")",
";",
"String",
"body",
"=",
"null",
";",
"String",
"ext",
... | is atomic and used here to mark when a file name is chosen | [
"is",
"atomic",
"and",
"used",
"here",
"to",
"mark",
"when",
"a",
"file",
"name",
"is",
"chosen"
] | 27f58b0cafe56b2eb9fc6993efa9ca2b529661e1 | https://github.com/Teddy-Zhu/SilentGo/blob/27f58b0cafe56b2eb9fc6993efa9ca2b529661e1/framework/src/main/java/com/silentgo/servlet/oreilly/multipart/DefaultFileRenamePolicy.java#L27-L58 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryValidationContext.java | GeometryValidationContext.getState | @Api
public GeometryValidationState getState() {
if (violations.isEmpty()) {
return GeometryValidationState.VALID;
} else {
return violations.get(0).getState();
}
} | java | @Api
public GeometryValidationState getState() {
if (violations.isEmpty()) {
return GeometryValidationState.VALID;
} else {
return violations.get(0).getState();
}
} | [
"@",
"Api",
"public",
"GeometryValidationState",
"getState",
"(",
")",
"{",
"if",
"(",
"violations",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"GeometryValidationState",
".",
"VALID",
";",
"}",
"else",
"{",
"return",
"violations",
".",
"get",
"(",
"0",... | Get the validation state of the geometry. We take the state of the first violation encountered.
@return the invalid state or {@link GeometryValidationState.VALID} if there are no violations. | [
"Get",
"the",
"validation",
"state",
"of",
"the",
"geometry",
".",
"We",
"take",
"the",
"state",
"of",
"the",
"first",
"violation",
"encountered",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryValidationContext.java#L102-L109 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/Coordinate.java | Coordinate.equalsDelta | 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 boolean equalsDelta(Coordinate coordinate, double delta) {
return null != coordinate &&
(Math.abs(this.x - coordinate.x) < delta && Math.abs(this.y - coordinate.y) < delta);
} | [
"public",
"boolean",
"equalsDelta",
"(",
"Coordinate",
"coordinate",
",",
"double",
"delta",
")",
"{",
"return",
"null",
"!=",
"coordinate",
"&&",
"(",
"Math",
".",
"abs",
"(",
"this",
".",
"x",
"-",
"coordinate",
".",
"x",
")",
"<",
"delta",
"&&",
"Ma... | Comparison using a tolerance for the equality check.
@param coordinate
coordinate to compare with
@param delta
maximum deviation (along one axis, the actual maximum distance is sqrt(2*delta^2))
@return true | [
"Comparison",
"using",
"a",
"tolerance",
"for",
"the",
"equality",
"check",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/Coordinate.java#L115-L118 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/Coordinate.java | Coordinate.distance | public double distance(Coordinate c) {
double dx = x - c.x;
double dy = y - c.y;
return Math.sqrt(dx * dx + dy * dy);
} | java | public double distance(Coordinate c) {
double dx = x - c.x;
double dy = y - c.y;
return Math.sqrt(dx * dx + dy * dy);
} | [
"public",
"double",
"distance",
"(",
"Coordinate",
"c",
")",
"{",
"double",
"dx",
"=",
"x",
"-",
"c",
".",
"x",
";",
"double",
"dy",
"=",
"y",
"-",
"c",
".",
"y",
";",
"return",
"Math",
".",
"sqrt",
"(",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy",... | Computes the 2-dimensional Euclidean distance to another location.
@param c
Another coordinate
@return the 2-dimensional Euclidean distance between the locations | [
"Computes",
"the",
"2",
"-",
"dimensional",
"Euclidean",
"distance",
"to",
"another",
"location",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/Coordinate.java#L177-L182 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.toPolygon | 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.setCoordinates(new Coordinate[] { new Coordinate(minX, minY), new Coordinate(maxX, minY),
new Coordinate(maxX, maxY), new Coordinate(minX, maxY), new Coordinate(minX, minY) });
polygon.setGeometries(new Geometry[] { linearRing });
return polygon;
} | 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.setCoordinates(new Coordinate[] { new Coordinate(minX, minY), new Coordinate(maxX, minY),
new Coordinate(maxX, maxY), new Coordinate(minX, maxY), new Coordinate(minX, minY) });
polygon.setGeometries(new Geometry[] { linearRing });
return polygon;
} | [
"public",
"static",
"Geometry",
"toPolygon",
"(",
"Bbox",
"bounds",
")",
"{",
"double",
"minX",
"=",
"bounds",
".",
"getX",
"(",
")",
";",
"double",
"minY",
"=",
"bounds",
".",
"getY",
"(",
")",
";",
"double",
"maxX",
"=",
"bounds",
".",
"getMaxX",
"... | Transform the given bounding box into a polygon geometry.
@param bounds The bounding box to transform.
@return Returns the polygon equivalent of the given bounding box. | [
"Transform",
"the",
"given",
"bounding",
"box",
"into",
"a",
"polygon",
"geometry",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L140-L153 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.toLineString | 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 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;
} | [
"public",
"static",
"Geometry",
"toLineString",
"(",
"Coordinate",
"c1",
",",
"Coordinate",
"c2",
")",
"{",
"Geometry",
"lineString",
"=",
"new",
"Geometry",
"(",
"Geometry",
".",
"LINE_STRING",
",",
"0",
",",
"-",
"1",
")",
";",
"lineString",
".",
"setCoo... | Create a new linestring based on the specified coordinates.
@param c1 first coordinate
@param c2 second coordinate
@return the linestring
@since 1.2.0 | [
"Create",
"a",
"new",
"linestring",
"based",
"on",
"the",
"specified",
"coordinates",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L163-L167 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.getNumPoints | 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);
}
}
if (geometry.getCoordinates() != null) {
count += geometry.getCoordinates().length;
}
return count;
} | 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);
}
}
if (geometry.getCoordinates() != null) {
count += geometry.getCoordinates().length;
}
return count;
} | [
"public",
"static",
"int",
"getNumPoints",
"(",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot get total number of points for null geometry.\"",
")",
";",
"}",
"int",
"count... | Return the total number of coordinates within the geometry. This add up all coordinates within the
sub-geometries.
@param geometry The geometry to calculate the total number of points for.
@return The total number of coordinates within this geometry. | [
"Return",
"the",
"total",
"number",
"of",
"coordinates",
"within",
"the",
"geometry",
".",
"This",
"add",
"up",
"all",
"coordinates",
"within",
"the",
"sub",
"-",
"geometries",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L176-L190 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.isValid | public static boolean isValid(Geometry geometry, GeometryIndex index) {
validate(geometry, index);
return validationContext.isValid();
} | java | public static boolean isValid(Geometry geometry, GeometryIndex index) {
validate(geometry, index);
return validationContext.isValid();
} | [
"public",
"static",
"boolean",
"isValid",
"(",
"Geometry",
"geometry",
",",
"GeometryIndex",
"index",
")",
"{",
"validate",
"(",
"geometry",
",",
"index",
")",
";",
"return",
"validationContext",
".",
"isValid",
"(",
")",
";",
"}"
] | Validates a geometry, focusing on changes at a specific sub-level of the geometry. The sublevel is indicated by
passing an index. The only checks are on intersection and containment, we don't check on too few coordinates as
we want to support incremental creation of polygons.
@param geometry The geometry to check.
@param index index that points to a sub-geometry, edge, vertex, etc...
@return True or false.
@since 1.3.0 | [
"Validates",
"a",
"geometry",
"focusing",
"on",
"changes",
"at",
"a",
"specific",
"sub",
"-",
"level",
"of",
"the",
"geometry",
".",
"The",
"sublevel",
"is",
"indicated",
"by",
"passing",
"an",
"index",
".",
"The",
"only",
"checks",
"are",
"on",
"intersect... | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L276-L279 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.validate | 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.getGeometryType())) {
IndexedLinearRing ring = helper.createLinearRing(geometry);
validateLinearRing(ring);
} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
IndexedPolygon polygon = helper.createPolygon(geometry);
validatePolygon(polygon);
} else if (Geometry.MULTI_LINE_STRING.equals(geometry.getGeometryType())) {
IndexedMultiLineString multiLineString = helper.createMultiLineString(geometry);
validateMultiLineString(multiLineString);
} else if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
IndexedMultiPolygon multiPolygon = helper.createMultiPolygon(geometry);
validateMultiPolygon(multiPolygon);
}
return validationContext.getState();
} | 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.getGeometryType())) {
IndexedLinearRing ring = helper.createLinearRing(geometry);
validateLinearRing(ring);
} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
IndexedPolygon polygon = helper.createPolygon(geometry);
validatePolygon(polygon);
} else if (Geometry.MULTI_LINE_STRING.equals(geometry.getGeometryType())) {
IndexedMultiLineString multiLineString = helper.createMultiLineString(geometry);
validateMultiLineString(multiLineString);
} else if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
IndexedMultiPolygon multiPolygon = helper.createMultiPolygon(geometry);
validateMultiPolygon(multiPolygon);
}
return validationContext.getState();
} | [
"public",
"static",
"GeometryValidationState",
"validate",
"(",
"Geometry",
"geometry",
")",
"{",
"validationContext",
".",
"clear",
"(",
")",
";",
"if",
"(",
"Geometry",
".",
"LINE_STRING",
".",
"equals",
"(",
"geometry",
".",
"getGeometryType",
"(",
")",
")"... | Validate this geometry.
@param geometry The geometry to check.
@return validation state.
@since 1.2.0 | [
"Validate",
"this",
"geometry",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L448-L467 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.intersects | 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 intersectsLineString(one, two);
} else if (Geometry.MULTI_POINT.equals(one.getGeometryType())
|| Geometry.MULTI_LINE_STRING.equals(one.getGeometryType())) {
return intersectsMultiSomething(one, two);
}
List<Coordinate> coords1 = new ArrayList<Coordinate>();
List<Coordinate> coords2 = new ArrayList<Coordinate>();
getAllCoordinates(one, coords1);
getAllCoordinates(two, coords2);
for (int i = 0; i < coords1.size() - 1; i++) {
for (int j = 0; j < coords2.size() - 1; j++) {
if (MathService.intersectsLineSegment(coords1.get(i), coords1.get(i + 1), coords2.get(j),
coords2.get(j + 1))) {
return true;
}
}
}
return false;
} | 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 intersectsLineString(one, two);
} else if (Geometry.MULTI_POINT.equals(one.getGeometryType())
|| Geometry.MULTI_LINE_STRING.equals(one.getGeometryType())) {
return intersectsMultiSomething(one, two);
}
List<Coordinate> coords1 = new ArrayList<Coordinate>();
List<Coordinate> coords2 = new ArrayList<Coordinate>();
getAllCoordinates(one, coords1);
getAllCoordinates(two, coords2);
for (int i = 0; i < coords1.size() - 1; i++) {
for (int j = 0; j < coords2.size() - 1; j++) {
if (MathService.intersectsLineSegment(coords1.get(i), coords1.get(i + 1), coords2.get(j),
coords2.get(j + 1))) {
return true;
}
}
}
return false;
} | [
"public",
"static",
"boolean",
"intersects",
"(",
"Geometry",
"one",
",",
"Geometry",
"two",
")",
"{",
"if",
"(",
"one",
"==",
"null",
"||",
"two",
"==",
"null",
"||",
"isEmpty",
"(",
"one",
")",
"||",
"isEmpty",
"(",
"two",
")",
")",
"{",
"return",
... | Calculate whether or not two given geometries intersect each other.
@param one The first geometry to check for intersection with the second.
@param two The second geometry to check for intersection with the first.
@return Returns true or false. | [
"Calculate",
"whether",
"or",
"not",
"two",
"given",
"geometries",
"intersect",
"each",
"other",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L476-L502 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.getLength | 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()) || Geometry.LINEAR_RING.equals(geometry
.getGeometryType()))) {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double deltaX = geometry.getCoordinates()[i + 1].getX() - geometry.getCoordinates()[i].getX();
double deltaY = geometry.getCoordinates()[i + 1].getY() - geometry.getCoordinates()[i].getY();
length += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
}
}
return length;
} | 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()) || Geometry.LINEAR_RING.equals(geometry
.getGeometryType()))) {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double deltaX = geometry.getCoordinates()[i + 1].getX() - geometry.getCoordinates()[i].getX();
double deltaY = geometry.getCoordinates()[i + 1].getY() - geometry.getCoordinates()[i].getY();
length += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
}
}
return length;
} | [
"public",
"static",
"double",
"getLength",
"(",
"Geometry",
"geometry",
")",
"{",
"double",
"length",
"=",
"0",
";",
"if",
"(",
"geometry",
".",
"getGeometries",
"(",
")",
"!=",
"null",
")",
"{",
"for",
"(",
"Geometry",
"child",
":",
"geometry",
".",
"... | Return the length of the geometry. This adds up the length of all edges within the geometry.
@param geometry The other geometry to calculate the length for.
@return The total length of all edges of the given geometry. | [
"Return",
"the",
"length",
"of",
"the",
"geometry",
".",
"This",
"adds",
"up",
"the",
"length",
"of",
"all",
"edges",
"within",
"the",
"geometry",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L520-L537 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.getDistance | 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);
if (distance < minDistance) {
minDistance = distance;
}
}
}
if (geometry.getCoordinates() != null) {
if (geometry.getCoordinates().length == 1) {
double distance = MathService.distance(coordinate, geometry.getCoordinates()[0]);
if (distance < minDistance) {
minDistance = distance;
}
} else if (geometry.getCoordinates().length > 1) {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double distance = MathService.distance(geometry.getCoordinates()[i],
geometry.getCoordinates()[i + 1], coordinate);
if (distance < minDistance) {
minDistance = distance;
}
}
}
}
}
return minDistance;
} | 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);
if (distance < minDistance) {
minDistance = distance;
}
}
}
if (geometry.getCoordinates() != null) {
if (geometry.getCoordinates().length == 1) {
double distance = MathService.distance(coordinate, geometry.getCoordinates()[0]);
if (distance < minDistance) {
minDistance = distance;
}
} else if (geometry.getCoordinates().length > 1) {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double distance = MathService.distance(geometry.getCoordinates()[i],
geometry.getCoordinates()[i + 1], coordinate);
if (distance < minDistance) {
minDistance = distance;
}
}
}
}
}
return minDistance;
} | [
"public",
"static",
"double",
"getDistance",
"(",
"Geometry",
"geometry",
",",
"Coordinate",
"coordinate",
")",
"{",
"double",
"minDistance",
"=",
"Double",
".",
"MAX_VALUE",
";",
"if",
"(",
"coordinate",
"!=",
"null",
"&&",
"geometry",
"!=",
"null",
")",
"{... | Return the minimal distance between a coordinate and any vertex of a geometry.
@param geometry The other geometry to calculate the distance for.
@param coordinate The coordinate for which to calculate the distance to the geometry.
@return Return the minimal distance | [
"Return",
"the",
"minimal",
"distance",
"between",
"a",
"coordinate",
"and",
"any",
"vertex",
"of",
"a",
"geometry",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L572-L601 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/GeometryService.java | GeometryService.intersectsPoint | 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.getCoordinates()[0];
if (geometry.getCoordinates().length == 1) {
return coordinate.equals(geometry.getCoordinates()[0]);
} else {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double distance = MathService.distance(geometry.getCoordinates()[i],
geometry.getCoordinates()[i + 1], coordinate);
if (distance < DEFAULT_DOUBLE_DELTA) {
return true;
}
}
}
}
return false;
} | 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.getCoordinates()[0];
if (geometry.getCoordinates().length == 1) {
return coordinate.equals(geometry.getCoordinates()[0]);
} else {
for (int i = 0; i < geometry.getCoordinates().length - 1; i++) {
double distance = MathService.distance(geometry.getCoordinates()[i],
geometry.getCoordinates()[i + 1], coordinate);
if (distance < DEFAULT_DOUBLE_DELTA) {
return true;
}
}
}
}
return false;
} | [
"private",
"static",
"boolean",
"intersectsPoint",
"(",
"Geometry",
"point",
",",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
".",
"getGeometries",
"(",
")",
"!=",
"null",
")",
"{",
"for",
"(",
"Geometry",
"child",
":",
"geometry",
".",
"getGe... | We assume neither is null or empty. | [
"We",
"assume",
"neither",
"is",
"null",
"or",
"empty",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/GeometryService.java#L950-L973 | train |
eyp/serfj | src/main/java/net/sf/serfj/serializers/FileSerializer.java | FileSerializer.sendFile | 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()) {
LOGGER.debug("Writing file...");
}
while ((readBytes = buf.read()) != -1) {
os.write(readBytes);
}
os.flush();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("File written");
}
} finally {
if (is != null) {
is.close();
}
if (buf != null) {
buf.close();
}
}
} | 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()) {
LOGGER.debug("Writing file...");
}
while ((readBytes = buf.read()) != -1) {
os.write(readBytes);
}
os.flush();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("File written");
}
} finally {
if (is != null) {
is.close();
}
if (buf != null) {
buf.close();
}
}
} | [
"public",
"void",
"sendFile",
"(",
"File",
"file",
",",
"OutputStream",
"os",
")",
"throws",
"IOException",
"{",
"FileInputStream",
"is",
"=",
"null",
";",
"BufferedInputStream",
"buf",
"=",
"null",
";",
";",
"try",
"{",
"is",
"=",
"new",
"FileInputStream",
... | Write a file to an OuputStream.
@param file File that will be written.
@param os The target OutputStream.
@throws IOException if any error happens. | [
"Write",
"a",
"file",
"to",
"an",
"OuputStream",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/serializers/FileSerializer.java#L54-L79 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/WktService.java | WktService.toWkt | 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(geometry);
} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
return toWktPolygon(geometry);
} else if (Geometry.MULTI_POINT.equals(geometry.getGeometryType())) {
return toWktMultiPoint(geometry);
} else if (Geometry.MULTI_LINE_STRING.equals(geometry.getGeometryType())) {
return toWktMultiLineString(geometry);
} else if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
return toWktMultiPolygon(geometry);
}
return "";
} | 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(geometry);
} else if (Geometry.POLYGON.equals(geometry.getGeometryType())) {
return toWktPolygon(geometry);
} else if (Geometry.MULTI_POINT.equals(geometry.getGeometryType())) {
return toWktMultiPoint(geometry);
} else if (Geometry.MULTI_LINE_STRING.equals(geometry.getGeometryType())) {
return toWktMultiLineString(geometry);
} else if (Geometry.MULTI_POLYGON.equals(geometry.getGeometryType())) {
return toWktMultiPolygon(geometry);
}
return "";
} | [
"public",
"static",
"String",
"toWkt",
"(",
"Geometry",
"geometry",
")",
"throws",
"WktException",
"{",
"if",
"(",
"Geometry",
".",
"POINT",
".",
"equals",
"(",
"geometry",
".",
"getGeometryType",
"(",
")",
")",
")",
"{",
"return",
"toWktPoint",
"(",
"geom... | Format a given geometry to Well Known Text.
@param geometry
The geometry to format.
@return Returns the WKT string.
@throws WktException
In case something went wrong while formatting. | [
"Format",
"a",
"given",
"geometry",
"to",
"Well",
"Known",
"Text",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/WktService.java#L68-L84 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/WktService.java | WktService.parseSrid | 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 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;
} | [
"private",
"static",
"int",
"parseSrid",
"(",
"String",
"ewktPart",
")",
"{",
"if",
"(",
"ewktPart",
"!=",
"null",
"&&",
"!",
"\"\"",
".",
"equals",
"(",
"ewktPart",
")",
")",
"{",
"String",
"[",
"]",
"parts",
"=",
"ewktPart",
".",
"split",
"(",
"\"=... | Get the SRID from a string like "SRDI=4326". Used in parsing EWKT. | [
"Get",
"the",
"SRID",
"from",
"a",
"string",
"like",
"SRDI",
"=",
"4326",
".",
"Used",
"in",
"parsing",
"EWKT",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/WktService.java#L117-L128 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/WktService.java | WktService.parseWkt | 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(wkt.substring(0, i).trim());
}
if (type == null) {
throw new WktException(ERR_MSG + "type of geometry not supported");
}
if (wkt.indexOf("EMPTY") >= 0) {
return new Geometry(type, 0, 0);
}
Geometry geometry = new Geometry(type, 0, 0);
String result = parse(wkt.substring(wkt.indexOf('(')), geometry);
if (result.length() != 0) {
throw new WktException(ERR_MSG + "unexpected ending \"" + result + "\"");
}
return geometry;
}
throw new WktException(ERR_MSG + "illegal argument; no WKT");
} | 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(wkt.substring(0, i).trim());
}
if (type == null) {
throw new WktException(ERR_MSG + "type of geometry not supported");
}
if (wkt.indexOf("EMPTY") >= 0) {
return new Geometry(type, 0, 0);
}
Geometry geometry = new Geometry(type, 0, 0);
String result = parse(wkt.substring(wkt.indexOf('(')), geometry);
if (result.length() != 0) {
throw new WktException(ERR_MSG + "unexpected ending \"" + result + "\"");
}
return geometry;
}
throw new WktException(ERR_MSG + "illegal argument; no WKT");
} | [
"private",
"static",
"Geometry",
"parseWkt",
"(",
"String",
"wkt",
")",
"throws",
"WktException",
"{",
"if",
"(",
"wkt",
"!=",
"null",
")",
"{",
"int",
"i1",
"=",
"wkt",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"int",
"i2",
"=",
"wkt",
".",
"indexO... | Parse a WKT string. No EWKT here! | [
"Parse",
"a",
"WKT",
"string",
".",
"No",
"EWKT",
"here!"
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/WktService.java#L131-L158 | train |
btaz/data-util | src/main/java/com/btaz/util/xml/xmlpath/XmlPathParser.java | XmlPathParser.parse | 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("/")) {
if("*".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyElement());
} else if("@*".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyAttributeElement());
} else if("node()".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyNode());
} else if(xmlPathQuery.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
return new XmlPath(new XmlPathNodenameAttribute(xmlPathQuery));
} else if(xmlPathQuery.matches(XmlPathNodename.REGEX_MATCH)) {
return new XmlPath(new XmlPathNodename(xmlPathQuery));
}
}
// sub-tree patterns
Matcher m = rePath.matcher(xmlPathQuery);
if(! m.matches()) {
throw new XmlPathException("Invalid xml path query: " + xmlPathQuery);
}
XmlPath.Builder builder = XmlPath.builder();
m = rePathPart.matcher(xmlPathQuery);
while(m.find()) {
String part = m.group(1);
if("*".equals(part)) {
builder.add(new XmlPathAnyElement());
} else if("@*".equals(part)) {
builder.add(new XmlPathAnyAttributeElement());
} else if("node()".equals(part)) {
builder.add(new XmlPathAnyNode());
} else if(part.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
builder.add(new XmlPathNodenameAttribute(part));
} else if (part.matches(XmlPathNodename.REGEX_MATCH)) {
builder.add(new XmlPathNodename(part));
} else {
throw new XmlPathException("Invalid part(" + part + ") in xml path query: " + xmlPathQuery);
}
}
return builder.construct();
} | 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("/")) {
if("*".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyElement());
} else if("@*".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyAttributeElement());
} else if("node()".equals(xmlPathQuery)) {
return new XmlPath(new XmlPathAnyNode());
} else if(xmlPathQuery.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
return new XmlPath(new XmlPathNodenameAttribute(xmlPathQuery));
} else if(xmlPathQuery.matches(XmlPathNodename.REGEX_MATCH)) {
return new XmlPath(new XmlPathNodename(xmlPathQuery));
}
}
// sub-tree patterns
Matcher m = rePath.matcher(xmlPathQuery);
if(! m.matches()) {
throw new XmlPathException("Invalid xml path query: " + xmlPathQuery);
}
XmlPath.Builder builder = XmlPath.builder();
m = rePathPart.matcher(xmlPathQuery);
while(m.find()) {
String part = m.group(1);
if("*".equals(part)) {
builder.add(new XmlPathAnyElement());
} else if("@*".equals(part)) {
builder.add(new XmlPathAnyAttributeElement());
} else if("node()".equals(part)) {
builder.add(new XmlPathAnyNode());
} else if(part.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
builder.add(new XmlPathNodenameAttribute(part));
} else if (part.matches(XmlPathNodename.REGEX_MATCH)) {
builder.add(new XmlPathNodename(part));
} else {
throw new XmlPathException("Invalid part(" + part + ") in xml path query: " + xmlPathQuery);
}
}
return builder.construct();
} | [
"public",
"static",
"XmlPath",
"parse",
"(",
"String",
"xmlPathQuery",
")",
"{",
"// validations",
"if",
"(",
"xmlPathQuery",
"==",
"null",
")",
"{",
"throw",
"new",
"XmlPathException",
"(",
"\"The XML path query can not be a null value\"",
")",
";",
"}",
"xmlPathQu... | Parse XML path query
@param xmlPathQuery XML path query
@return @{code XmlPath} XML path | [
"Parse",
"XML",
"path",
"query"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/xml/xmlpath/XmlPathParser.java#L18-L65 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Typ.java | Typ.getTypeNumber | 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 kind.ordinal();
case DECLARED:
case TYPEVAR:
case ARRAY:
return TypeKind.DECLARED.ordinal();
default:
throw new IllegalArgumentException(kind+" not valid");
}
} | 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 kind.ordinal();
case DECLARED:
case TYPEVAR:
case ARRAY:
return TypeKind.DECLARED.ordinal();
default:
throw new IllegalArgumentException(kind+" not valid");
}
} | [
"public",
"static",
"int",
"getTypeNumber",
"(",
"TypeKind",
"kind",
")",
"{",
"switch",
"(",
"kind",
")",
"{",
"case",
"BOOLEAN",
":",
"case",
"BYTE",
":",
"case",
"CHAR",
":",
"case",
"SHORT",
":",
"case",
"INT",
":",
"case",
"LONG",
":",
"case",
"... | Returns TypeKind ordinal for primitive types and DECLARED ordinal for DECLARED, ARRAY and TYPEVAR
@param kind
@return | [
"Returns",
"TypeKind",
"ordinal",
"for",
"primitive",
"types",
"and",
"DECLARED",
"ordinal",
"for",
"DECLARED",
"ARRAY",
"and",
"TYPEVAR"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Typ.java#L113-L134 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Typ.java | Typ.normalizeType | 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.getPrimitiveType(kind);
case DECLARED:
case TYPEVAR:
case ARRAY:
return El.getTypeElement("java.lang.Object").asType();
case VOID:
return Typ.Void;
default:
throw new IllegalArgumentException(kind+" not valid");
}
} | 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.getPrimitiveType(kind);
case DECLARED:
case TYPEVAR:
case ARRAY:
return El.getTypeElement("java.lang.Object").asType();
case VOID:
return Typ.Void;
default:
throw new IllegalArgumentException(kind+" not valid");
}
} | [
"public",
"static",
"TypeMirror",
"normalizeType",
"(",
"TypeKind",
"kind",
")",
"{",
"switch",
"(",
"kind",
")",
"{",
"case",
"BOOLEAN",
":",
"case",
"BYTE",
":",
"case",
"CHAR",
":",
"case",
"SHORT",
":",
"case",
"INT",
":",
"case",
"LONG",
":",
"cas... | Returns primitive type for primitive and java.lang.Object type for references
@param kind
@return | [
"Returns",
"primitive",
"type",
"for",
"primitive",
"and",
"java",
".",
"lang",
".",
"Object",
"type",
"for",
"references"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Typ.java#L140-L162 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Typ.java | Typ.isInteger | 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 isInteger(TypeMirror type)
{
switch (type.getKind())
{
case INT:
case SHORT:
case CHAR:
case BYTE:
case BOOLEAN:
return true;
default:
return false;
}
} | [
"public",
"static",
"boolean",
"isInteger",
"(",
"TypeMirror",
"type",
")",
"{",
"switch",
"(",
"type",
".",
"getKind",
"(",
")",
")",
"{",
"case",
"INT",
":",
"case",
"SHORT",
":",
"case",
"CHAR",
":",
"case",
"BYTE",
":",
"case",
"BOOLEAN",
":",
"r... | Returns true if type is one of int, short, char, byte or boolean
@param type
@return | [
"Returns",
"true",
"if",
"type",
"is",
"one",
"of",
"int",
"short",
"char",
"byte",
"or",
"boolean"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Typ.java#L477-L490 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Typ.java | Typ.isJavaConstantType | 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;
TypeElement te = (TypeElement) dt.asElement();
return "java.lang.String".contentEquals(te.getQualifiedName());
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;
TypeElement te = (TypeElement) dt.asElement();
return "java.lang.String".contentEquals(te.getQualifiedName());
default:
return false;
}
} | [
"public",
"static",
"boolean",
"isJavaConstantType",
"(",
"TypeMirror",
"type",
")",
"{",
"switch",
"(",
"type",
".",
"getKind",
"(",
")",
")",
"{",
"case",
"INT",
":",
"case",
"LONG",
":",
"case",
"FLOAT",
":",
"case",
"DOUBLE",
":",
"return",
"true",
... | Returns true if type is one of int, long, float, double or java.lang.String
@param type
@return | [
"Returns",
"true",
"if",
"type",
"is",
"one",
"of",
"int",
"long",
"float",
"double",
"or",
"java",
".",
"lang",
".",
"String"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Typ.java#L496-L512 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Typ.java | Typ.convert | 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.parseFloat(constant);
case DOUBLE:
return java.lang.Double.parseDouble(constant);
default:
throw new UnsupportedOperationException(kind+ "Not yet implemented");
}
} | 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.parseFloat(constant);
case DOUBLE:
return java.lang.Double.parseDouble(constant);
default:
throw new UnsupportedOperationException(kind+ "Not yet implemented");
}
} | [
"public",
"static",
"Object",
"convert",
"(",
"String",
"constant",
",",
"TypeKind",
"kind",
")",
"{",
"switch",
"(",
"kind",
")",
"{",
"case",
"INT",
":",
"return",
"Integer",
".",
"parseInt",
"(",
"constant",
")",
";",
"case",
"LONG",
":",
"return",
... | Returns a Object of type type converted from constant
@param constant
@param kind
@return | [
"Returns",
"a",
"Object",
"of",
"type",
"type",
"converted",
"from",
"constant"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Typ.java#L519-L534 | train |
fcrepo4-labs/fcrepo4-client | fcrepo-client-impl/src/main/java/org/fcrepo/client/impl/FedoraObjectImpl.java | FedoraObjectImpl.getChildren | 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);
final Set<FedoraResource> set = new HashSet<>();
while (it.hasNext()) {
final Node child = it.next().getObject();
if ( mixin == null || graph.contains(child, HAS_MIXIN_TYPE.asNode(), mixinLiteral) ) {
final String path = child.getURI().toString()
.replaceAll(repository.getRepositoryUrl(),"");
if ( graph.contains(child, HAS_MIXIN_TYPE.asNode(), binaryType) ) {
set.add( repository.getDatastream(path) );
} else {
set.add( repository.getObject(path) );
}
}
}
return set;
} | 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);
final Set<FedoraResource> set = new HashSet<>();
while (it.hasNext()) {
final Node child = it.next().getObject();
if ( mixin == null || graph.contains(child, HAS_MIXIN_TYPE.asNode(), mixinLiteral) ) {
final String path = child.getURI().toString()
.replaceAll(repository.getRepositoryUrl(),"");
if ( graph.contains(child, HAS_MIXIN_TYPE.asNode(), binaryType) ) {
set.add( repository.getDatastream(path) );
} else {
set.add( repository.getObject(path) );
}
}
}
return set;
} | [
"public",
"Collection",
"<",
"FedoraResource",
">",
"getChildren",
"(",
"final",
"String",
"mixin",
")",
"throws",
"FedoraException",
"{",
"Node",
"mixinLiteral",
"=",
"null",
";",
"if",
"(",
"mixin",
"!=",
"null",
")",
"{",
"mixinLiteral",
"=",
"NodeFactory",... | Get the Object and Datastream nodes that are children of the current Object.
@param mixin If not null, limit to results that have this mixin. | [
"Get",
"the",
"Object",
"and",
"Datastream",
"nodes",
"that",
"are",
"children",
"of",
"the",
"current",
"Object",
"."
] | 21eaf27200c5b2542095f6ebb9dd8ec865b95bbd | https://github.com/fcrepo4-labs/fcrepo4-client/blob/21eaf27200c5b2542095f6ebb9dd8ec865b95bbd/fcrepo-client-impl/src/main/java/org/fcrepo/client/impl/FedoraObjectImpl.java#L61-L81 | train |
aehrc/ontology-core | ontology-model/src/main/java/au/csiro/ontology/util/Statistics.java | Statistics.getTime | public long getTime(String name) {
Long res = stats.get(name);
return (res == null) ? -1 : res.longValue();
} | java | public long getTime(String name) {
Long res = stats.get(name);
return (res == null) ? -1 : res.longValue();
} | [
"public",
"long",
"getTime",
"(",
"String",
"name",
")",
"{",
"Long",
"res",
"=",
"stats",
".",
"get",
"(",
"name",
")",
";",
"return",
"(",
"res",
"==",
"null",
")",
"?",
"-",
"1",
":",
"res",
".",
"longValue",
"(",
")",
";",
"}"
] | Gets a time for a performance measurement. If no measurement with the
specified name exists then it returns -1.
@param name
@return | [
"Gets",
"a",
"time",
"for",
"a",
"performance",
"measurement",
".",
"If",
"no",
"measurement",
"with",
"the",
"specified",
"name",
"exists",
"then",
"it",
"returns",
"-",
"1",
"."
] | 446aa691119f2bbcb8d184566084b8da7a07a44e | https://github.com/aehrc/ontology-core/blob/446aa691119f2bbcb8d184566084b8da7a07a44e/ontology-model/src/main/java/au/csiro/ontology/util/Statistics.java#L53-L56 | train |
aehrc/ontology-core | ontology-model/src/main/java/au/csiro/ontology/util/Statistics.java | Statistics.getStatistics | 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 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();
} | [
"public",
"String",
"getStatistics",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"String",
"key",
":",
"stats",
".",
"keySet",
"(",
")",
")",
"{",
"sb",
".",
"append",
"(",
"key",
")",
";",
"sb",
".... | Returns a string with all the current statistics.
@return | [
"Returns",
"a",
"string",
"with",
"all",
"the",
"current",
"statistics",
"."
] | 446aa691119f2bbcb8d184566084b8da7a07a44e | https://github.com/aehrc/ontology-core/blob/446aa691119f2bbcb8d184566084b8da7a07a44e/ontology-model/src/main/java/au/csiro/ontology/util/Statistics.java#L71-L82 | train |
NessComputing/components-ness-jdbi | src/main/java/com/nesscomputing/jdbi/JdbiMappers.java | JdbiMappers.getDateTime | 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 getDateTime(final ResultSet rs, final String columnName) throws SQLException
{
final Timestamp ts = rs.getTimestamp(columnName);
return (ts == null) ? null : new DateTime(ts);
} | [
"public",
"static",
"DateTime",
"getDateTime",
"(",
"final",
"ResultSet",
"rs",
",",
"final",
"String",
"columnName",
")",
"throws",
"SQLException",
"{",
"final",
"Timestamp",
"ts",
"=",
"rs",
".",
"getTimestamp",
"(",
"columnName",
")",
";",
"return",
"(",
... | Returns a DateTime object representing the date or null if the input is null. | [
"Returns",
"a",
"DateTime",
"object",
"representing",
"the",
"date",
"or",
"null",
"if",
"the",
"input",
"is",
"null",
"."
] | d446217b6f29b5409e55c5e72172cf0dbeacfec3 | https://github.com/NessComputing/components-ness-jdbi/blob/d446217b6f29b5409e55c5e72172cf0dbeacfec3/src/main/java/com/nesscomputing/jdbi/JdbiMappers.java#L73-L78 | train |
NessComputing/components-ness-jdbi | src/main/java/com/nesscomputing/jdbi/JdbiMappers.java | JdbiMappers.getUTCDateTime | 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 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);
} | [
"public",
"static",
"DateTime",
"getUTCDateTime",
"(",
"final",
"ResultSet",
"rs",
",",
"final",
"String",
"columnName",
")",
"throws",
"SQLException",
"{",
"final",
"Timestamp",
"ts",
"=",
"rs",
".",
"getTimestamp",
"(",
"columnName",
")",
";",
"return",
"(",... | Returns a DateTime object representing the date in UTC or null if the input is null. | [
"Returns",
"a",
"DateTime",
"object",
"representing",
"the",
"date",
"in",
"UTC",
"or",
"null",
"if",
"the",
"input",
"is",
"null",
"."
] | d446217b6f29b5409e55c5e72172cf0dbeacfec3 | https://github.com/NessComputing/components-ness-jdbi/blob/d446217b6f29b5409e55c5e72172cf0dbeacfec3/src/main/java/com/nesscomputing/jdbi/JdbiMappers.java#L91-L96 | train |
NessComputing/components-ness-jdbi | src/main/java/com/nesscomputing/jdbi/JdbiMappers.java | JdbiMappers.getEnum | 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 | 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);
} | [
"public",
"static",
"<",
"T",
"extends",
"Enum",
"<",
"T",
">",
">",
"T",
"getEnum",
"(",
"final",
"ResultSet",
"rs",
",",
"final",
"Class",
"<",
"T",
">",
"enumType",
",",
"final",
"String",
"columnName",
")",
"throws",
"SQLException",
"{",
"final",
"... | Returns an Enum representing the data or null if the input is null. | [
"Returns",
"an",
"Enum",
"representing",
"the",
"data",
"or",
"null",
"if",
"the",
"input",
"is",
"null",
"."
] | d446217b6f29b5409e55c5e72172cf0dbeacfec3 | https://github.com/NessComputing/components-ness-jdbi/blob/d446217b6f29b5409e55c5e72172cf0dbeacfec3/src/main/java/com/nesscomputing/jdbi/JdbiMappers.java#L108-L113 | train |
eyp/serfj | src/main/java/net/sf/serfj/ServletHelper.java | ServletHelper.methodExists | private Method methodExists(Class<?> clazz, String method, Class<?>[] params) {
try {
return clazz.getMethod(method, params);
} catch (NoSuchMethodException e) {
return null;
}
} | java | private Method methodExists(Class<?> clazz, String method, Class<?>[] params) {
try {
return clazz.getMethod(method, params);
} catch (NoSuchMethodException e) {
return null;
}
} | [
"private",
"Method",
"methodExists",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"method",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"params",
")",
"{",
"try",
"{",
"return",
"clazz",
".",
"getMethod",
"(",
"method",
",",
"params",
")",
";",
... | Checks if a class method exists.
@param clazz
Class.
@param method
Method.
@param params
Method's params.
@return the method, or null if it doesn't exist. | [
"Checks",
"if",
"a",
"class",
"method",
"exists",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/ServletHelper.java#L116-L122 | train |
eyp/serfj | src/main/java/net/sf/serfj/ServletHelper.java | ServletHelper.invokeAction | 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 " + urlInfo.getController() + "." + urlInfo.getAction() + " doesn't accept requests by " + urlInfo.getRequestMethod() + " HTTP_METHOD");
}
} | 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 " + urlInfo.getController() + "." + urlInfo.getAction() + " doesn't accept requests by " + urlInfo.getRequestMethod() + " HTTP_METHOD");
}
} | [
"private",
"Object",
"invokeAction",
"(",
"Object",
"clazz",
",",
"Method",
"method",
",",
"UrlInfo",
"urlInfo",
",",
"Object",
"...",
"args",
")",
"throws",
"IllegalAccessException",
",",
"InvocationTargetException",
"{",
"if",
"(",
"this",
".",
"isRequestMethodS... | Invokes a method checking previously if that method accepts requests
using a particular HTTP_METHOD.
@param clazz
A class.
@param method
A method to invoke.
@param urlInfo
URL information extracted by the framework.
@param args
Arguments for the method which will be invoked.
@return the object returned by the method onvoked, or null.
@throws IllegalArgumentException
if the HTTP_METHOD that comes in the request is not accepted
by class's method. | [
"Invokes",
"a",
"method",
"checking",
"previously",
"if",
"that",
"method",
"accepts",
"requests",
"using",
"a",
"particular",
"HTTP_METHOD",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/ServletHelper.java#L264-L270 | train |
passwordmaker/java-passwordmaker-lib | src/main/java/org/daveware/passwordmaker/PasswordMaker.java | PasswordMaker.makePassword | public SecureUTF8String makePassword(final SecureUTF8String masterPassword, final Account account, final String inputText)
throws Exception {
return makePassword(masterPassword, account, inputText, account.getUsername());
} | java | public SecureUTF8String makePassword(final SecureUTF8String masterPassword, final Account account, final String inputText)
throws Exception {
return makePassword(masterPassword, account, inputText, account.getUsername());
} | [
"public",
"SecureUTF8String",
"makePassword",
"(",
"final",
"SecureUTF8String",
"masterPassword",
",",
"final",
"Account",
"account",
",",
"final",
"String",
"inputText",
")",
"throws",
"Exception",
"{",
"return",
"makePassword",
"(",
"masterPassword",
",",
"account",... | Generates a hash of the master password with settings from the account.
It will use the username assigned to the account.
@param masterPassword The password to use as a key for the various algorithms.
@param account The account with the specific settings for the hash.
@param inputText The text to use as the input into the password maker algorithm
@return A SecureCharArray with the hashed data.
@throws Exception if something bad happened. | [
"Generates",
"a",
"hash",
"of",
"the",
"master",
"password",
"with",
"settings",
"from",
"the",
"account",
".",
"It",
"will",
"use",
"the",
"username",
"assigned",
"to",
"the",
"account",
"."
] | 18c22fca7dd9a47f08161425b85a5bd257afbb2b | https://github.com/passwordmaker/java-passwordmaker-lib/blob/18c22fca7dd9a47f08161425b85a5bd257afbb2b/src/main/java/org/daveware/passwordmaker/PasswordMaker.java#L377-L381 | train |
passwordmaker/java-passwordmaker-lib | src/main/java/org/daveware/passwordmaker/PasswordMaker.java | PasswordMaker.hashTheData | private SecureUTF8String hashTheData(SecureUTF8String masterPassword, SecureUTF8String data, Account account)
throws Exception {
final SecureUTF8String output = new SecureUTF8String();
final SecureUTF8String secureIteration = new SecureUTF8String();
SecureUTF8String intermediateOutput = null;
int count = 0;
final int length = account.getLength();
try {
while (output.size() < length) {
if (count == 0) {
intermediateOutput = runAlgorithm(masterPassword, data, account);
} else {
// add ye bit'o chaos
secureIteration.replace(masterPassword);
secureIteration.append(NEW_LINE);
secureIteration.append(new SecureCharArray(Integer.toString(count)));
intermediateOutput = runAlgorithm(secureIteration, data, account);
secureIteration.erase();
}
output.append(intermediateOutput);
intermediateOutput.erase();
count++;
}
} catch (Exception e) {
output.erase();
throw e;
} finally {
if (intermediateOutput != null)
intermediateOutput.erase();
secureIteration.erase();
}
return output;
} | java | private SecureUTF8String hashTheData(SecureUTF8String masterPassword, SecureUTF8String data, Account account)
throws Exception {
final SecureUTF8String output = new SecureUTF8String();
final SecureUTF8String secureIteration = new SecureUTF8String();
SecureUTF8String intermediateOutput = null;
int count = 0;
final int length = account.getLength();
try {
while (output.size() < length) {
if (count == 0) {
intermediateOutput = runAlgorithm(masterPassword, data, account);
} else {
// add ye bit'o chaos
secureIteration.replace(masterPassword);
secureIteration.append(NEW_LINE);
secureIteration.append(new SecureCharArray(Integer.toString(count)));
intermediateOutput = runAlgorithm(secureIteration, data, account);
secureIteration.erase();
}
output.append(intermediateOutput);
intermediateOutput.erase();
count++;
}
} catch (Exception e) {
output.erase();
throw e;
} finally {
if (intermediateOutput != null)
intermediateOutput.erase();
secureIteration.erase();
}
return output;
} | [
"private",
"SecureUTF8String",
"hashTheData",
"(",
"SecureUTF8String",
"masterPassword",
",",
"SecureUTF8String",
"data",
",",
"Account",
"account",
")",
"throws",
"Exception",
"{",
"final",
"SecureUTF8String",
"output",
"=",
"new",
"SecureUTF8String",
"(",
")",
";",
... | Intermediate step of generating a password. Performs constant hashing until
the resulting hash is long enough.
@param masterPassword You should know by now.
@param data Not much has changed.
@param account A donut?
@return A suitable hash.
@throws Exception if we ran out of donuts. | [
"Intermediate",
"step",
"of",
"generating",
"a",
"password",
".",
"Performs",
"constant",
"hashing",
"until",
"the",
"resulting",
"hash",
"is",
"long",
"enough",
"."
] | 18c22fca7dd9a47f08161425b85a5bd257afbb2b | https://github.com/passwordmaker/java-passwordmaker-lib/blob/18c22fca7dd9a47f08161425b85a5bd257afbb2b/src/main/java/org/daveware/passwordmaker/PasswordMaker.java#L410-L447 | train |
passwordmaker/java-passwordmaker-lib | src/main/java/org/daveware/passwordmaker/PasswordMaker.java | PasswordMaker.runAlgorithm | private SecureUTF8String runAlgorithm(SecureUTF8String masterPassword, SecureUTF8String data, Account account)
throws Exception {
SecureUTF8String output = null;
SecureCharArray digestChars = null;
SecureByteArray masterPasswordBytes = null;
SecureByteArray dataBytes = null;
try {
masterPasswordBytes = new SecureByteArray(masterPassword);
dataBytes = new SecureByteArray(data);
if (!account.isHmac()) {
dataBytes.prepend(masterPasswordBytes);
}
if (account.isHmac()) {
Mac mac;
String algoName = "HMAC" + account.getAlgorithm().getName();
mac = Mac.getInstance(algoName, CRYPTO_PROVIDER);
mac.init(new SecretKeySpec(masterPasswordBytes.getData(), algoName));
mac.reset();
mac.update(dataBytes.getData());
digestChars = new SecureCharArray(mac.doFinal());
} else {
MessageDigest md = MessageDigest.getInstance(account.getAlgorithm().getName(), CRYPTO_PROVIDER);
digestChars = new SecureCharArray(md.digest(dataBytes.getData()));
}
output = rstr2any(digestChars.getData(), account.getCharacterSet(), account.isTrim());
} catch (Exception e) {
if (output != null)
output.erase();
throw e;
} finally {
if (masterPasswordBytes != null)
masterPasswordBytes.erase();
if (dataBytes != null)
dataBytes.erase();
if (digestChars != null)
digestChars.erase();
}
return output;
} | java | private SecureUTF8String runAlgorithm(SecureUTF8String masterPassword, SecureUTF8String data, Account account)
throws Exception {
SecureUTF8String output = null;
SecureCharArray digestChars = null;
SecureByteArray masterPasswordBytes = null;
SecureByteArray dataBytes = null;
try {
masterPasswordBytes = new SecureByteArray(masterPassword);
dataBytes = new SecureByteArray(data);
if (!account.isHmac()) {
dataBytes.prepend(masterPasswordBytes);
}
if (account.isHmac()) {
Mac mac;
String algoName = "HMAC" + account.getAlgorithm().getName();
mac = Mac.getInstance(algoName, CRYPTO_PROVIDER);
mac.init(new SecretKeySpec(masterPasswordBytes.getData(), algoName));
mac.reset();
mac.update(dataBytes.getData());
digestChars = new SecureCharArray(mac.doFinal());
} else {
MessageDigest md = MessageDigest.getInstance(account.getAlgorithm().getName(), CRYPTO_PROVIDER);
digestChars = new SecureCharArray(md.digest(dataBytes.getData()));
}
output = rstr2any(digestChars.getData(), account.getCharacterSet(), account.isTrim());
} catch (Exception e) {
if (output != null)
output.erase();
throw e;
} finally {
if (masterPasswordBytes != null)
masterPasswordBytes.erase();
if (dataBytes != null)
dataBytes.erase();
if (digestChars != null)
digestChars.erase();
}
return output;
} | [
"private",
"SecureUTF8String",
"runAlgorithm",
"(",
"SecureUTF8String",
"masterPassword",
",",
"SecureUTF8String",
"data",
",",
"Account",
"account",
")",
"throws",
"Exception",
"{",
"SecureUTF8String",
"output",
"=",
"null",
";",
"SecureCharArray",
"digestChars",
"=",
... | This performs the actual hashing. It obtains an instance of the hashing algorithm
and feeds in the necessary data.
@param masterPassword The master password to use as a key.
@param data The data to be hashed.
@param account The account with the hash settings to use.
@return A SecureCharArray of the hash.
@throws Exception if something bad happened. | [
"This",
"performs",
"the",
"actual",
"hashing",
".",
"It",
"obtains",
"an",
"instance",
"of",
"the",
"hashing",
"algorithm",
"and",
"feeds",
"in",
"the",
"necessary",
"data",
"."
] | 18c22fca7dd9a47f08161425b85a5bd257afbb2b | https://github.com/passwordmaker/java-passwordmaker-lib/blob/18c22fca7dd9a47f08161425b85a5bd257afbb2b/src/main/java/org/daveware/passwordmaker/PasswordMaker.java#L459-L505 | train |
Teddy-Zhu/SilentGo | framework/src/main/java/com/silentgo/servlet/oreilly/multipart/BufferedServletInputStream.java | BufferedServletInputStream.fill | private void fill() throws IOException {
int i = in.read(buf, 0, buf.length);
if (i > 0) {
pos = 0;
count = i;
}
} | java | private void fill() throws IOException {
int i = in.read(buf, 0, buf.length);
if (i > 0) {
pos = 0;
count = i;
}
} | [
"private",
"void",
"fill",
"(",
")",
"throws",
"IOException",
"{",
"int",
"i",
"=",
"in",
".",
"read",
"(",
"buf",
",",
"0",
",",
"buf",
".",
"length",
")",
";",
"if",
"(",
"i",
">",
"0",
")",
"{",
"pos",
"=",
"0",
";",
"count",
"=",
"i",
"... | Fill up our buffer from the underlying input stream. Users of this
method must ensure that they use all characters in the buffer before
calling this method.
@exception IOException if an I/O error occurs. | [
"Fill",
"up",
"our",
"buffer",
"from",
"the",
"underlying",
"input",
"stream",
".",
"Users",
"of",
"this",
"method",
"must",
"ensure",
"that",
"they",
"use",
"all",
"characters",
"in",
"the",
"buffer",
"before",
"calling",
"this",
"method",
"."
] | 27f58b0cafe56b2eb9fc6993efa9ca2b529661e1 | https://github.com/Teddy-Zhu/SilentGo/blob/27f58b0cafe56b2eb9fc6993efa9ca2b529661e1/framework/src/main/java/com/silentgo/servlet/oreilly/multipart/BufferedServletInputStream.java#L64-L70 | train |
aehrc/ontology-core | ontology-import/src/main/java/au/csiro/ontology/importer/rf2/RF2Importer.java | RF2Importer.populateCDs | 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)) {
list = new ArrayList<>();
cdMap.put(referencedComponentId, list);
} else {
list = cdMap.get(referencedComponentId);
}
list.add(new String[] { featureId, operator, value, unit });
} | 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)) {
list = new ArrayList<>();
cdMap.put(referencedComponentId, list);
} else {
list = cdMap.get(referencedComponentId);
}
list.add(new String[] { featureId, operator, value, unit });
} | [
"protected",
"void",
"populateCDs",
"(",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
"[",
"]",
">",
">",
"cdMap",
",",
"String",
"referencedComponentId",
",",
"String",
"featureId",
",",
"String",
"operator",
",",
"String",
"value",
",",
"String",
"u... | Populates concrete domains information.
@param cdMap
@param referencedComponentId
@param featureId
@param operator
@param value
@param unit | [
"Populates",
"concrete",
"domains",
"information",
"."
] | 446aa691119f2bbcb8d184566084b8da7a07a44e | https://github.com/aehrc/ontology-core/blob/446aa691119f2bbcb8d184566084b8da7a07a44e/ontology-import/src/main/java/au/csiro/ontology/importer/rf2/RF2Importer.java#L187-L198 | train |
aehrc/ontology-core | ontology-import/src/main/java/au/csiro/ontology/importer/rf2/RF2Importer.java | RF2Importer.getOntologyBuilder | protected OntologyBuilder getOntologyBuilder(VersionRows vr, String rootModuleId, String rootModuleVersion,
Map<String, String> metadata) {
return new OntologyBuilder(vr, rootModuleId, rootModuleVersion, metadata);
} | java | protected OntologyBuilder getOntologyBuilder(VersionRows vr, String rootModuleId, String rootModuleVersion,
Map<String, String> metadata) {
return new OntologyBuilder(vr, rootModuleId, rootModuleVersion, metadata);
} | [
"protected",
"OntologyBuilder",
"getOntologyBuilder",
"(",
"VersionRows",
"vr",
",",
"String",
"rootModuleId",
",",
"String",
"rootModuleVersion",
",",
"Map",
"<",
"String",
",",
"String",
">",
"metadata",
")",
"{",
"return",
"new",
"OntologyBuilder",
"(",
"vr",
... | Hook method for subclasses to override.
@param vr
@param rootModuleId
@param rootModuleVersion
@param includeInactiveAxioms
@return | [
"Hook",
"method",
"for",
"subclasses",
"to",
"override",
"."
] | 446aa691119f2bbcb8d184566084b8da7a07a44e | https://github.com/aehrc/ontology-core/blob/446aa691119f2bbcb8d184566084b8da7a07a44e/ontology-import/src/main/java/au/csiro/ontology/importer/rf2/RF2Importer.java#L663-L666 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileSorter.java | FileSorter.sort | 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 DataUtilException("The sort directory doesn't exist");
}
if(files == null) {
throw new DataUtilException("The files parameter can't be a null value");
}
// sort files
List<File> sortedFiles = new ArrayList<File>();
for(File file : files) {
FileInputStream inputStream = null;
BufferedWriter writer = null;
try {
// readLine part into memory
ArrayList<String> list = new ArrayList<String>();
inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, DataUtilDefaults.charSet));
String line;
while((line = br.readLine()) != null) {
list.add(line);
}
inputStream.close();
inputStream = null;
// sort
Collections.sort(list, comparator);
// write sorted partial
File sortedFile = File.createTempFile("sorted-", ".part", sortDir);
sortedFiles.add(sortedFile);
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
sortedFile.getAbsoluteFile(), false),DataUtilDefaults.charSet));
for(String item : list) {
writer.write(item + DataUtilDefaults.lineTerminator);
}
writer.flush();
writer.close();
writer = null;
} catch (FileNotFoundException e) {
throw new DataUtilException(e);
} catch (UnsupportedEncodingException e) {
throw new DataUtilException(e);
} catch (IOException e) {
throw new DataUtilException(e);
} finally {
if(inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// intentionally, do nothing
}
}
if(writer != null) {
try {
writer.close();
} catch (IOException e) {
// intentionally, do nothing
}
}
}
}
return sortedFiles;
} | 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 DataUtilException("The sort directory doesn't exist");
}
if(files == null) {
throw new DataUtilException("The files parameter can't be a null value");
}
// sort files
List<File> sortedFiles = new ArrayList<File>();
for(File file : files) {
FileInputStream inputStream = null;
BufferedWriter writer = null;
try {
// readLine part into memory
ArrayList<String> list = new ArrayList<String>();
inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, DataUtilDefaults.charSet));
String line;
while((line = br.readLine()) != null) {
list.add(line);
}
inputStream.close();
inputStream = null;
// sort
Collections.sort(list, comparator);
// write sorted partial
File sortedFile = File.createTempFile("sorted-", ".part", sortDir);
sortedFiles.add(sortedFile);
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
sortedFile.getAbsoluteFile(), false),DataUtilDefaults.charSet));
for(String item : list) {
writer.write(item + DataUtilDefaults.lineTerminator);
}
writer.flush();
writer.close();
writer = null;
} catch (FileNotFoundException e) {
throw new DataUtilException(e);
} catch (UnsupportedEncodingException e) {
throw new DataUtilException(e);
} catch (IOException e) {
throw new DataUtilException(e);
} finally {
if(inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// intentionally, do nothing
}
}
if(writer != null) {
try {
writer.close();
} catch (IOException e) {
// intentionally, do nothing
}
}
}
}
return sortedFiles;
} | [
"public",
"static",
"List",
"<",
"File",
">",
"sort",
"(",
"File",
"sortDir",
",",
"List",
"<",
"File",
">",
"files",
",",
"Comparator",
"<",
"String",
">",
"comparator",
")",
"{",
"// validations",
"if",
"(",
"sortDir",
"==",
"null",
")",
"{",
"throw"... | This method sorts every file in a list of input files
@param sortDir directory to provide the sorting in. If null, then system temp directory is used.
@param files files to sort
@param comparator comparator to use for sorting | [
"This",
"method",
"sorts",
"every",
"file",
"in",
"a",
"list",
"of",
"input",
"files"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileSorter.java#L22-L91 | train |
FlyingHe/UtilsMaven | src/main/java/com/github/flyinghe/depdcy/FormatTrackingHSSFListenerPlus.java | FormatTrackingHSSFListenerPlus.processRecordInternally | public void processRecordInternally(Record record) {
if (record instanceof FormatRecord) {
FormatRecord fr = (FormatRecord) record;
_customFormatRecords.put(Integer.valueOf(fr.getIndexCode()), fr);
}
if (record instanceof ExtendedFormatRecord) {
ExtendedFormatRecord xr = (ExtendedFormatRecord) record;
_xfRecords.add(xr);
}
} | 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) {
ExtendedFormatRecord xr = (ExtendedFormatRecord) record;
_xfRecords.add(xr);
}
} | [
"public",
"void",
"processRecordInternally",
"(",
"Record",
"record",
")",
"{",
"if",
"(",
"record",
"instanceof",
"FormatRecord",
")",
"{",
"FormatRecord",
"fr",
"=",
"(",
"FormatRecord",
")",
"record",
";",
"_customFormatRecords",
".",
"put",
"(",
"Integer",
... | Process the record ourselves, but do not pass it on to the child
Listener.
@param record the record to be processed | [
"Process",
"the",
"record",
"ourselves",
"but",
"do",
"not",
"pass",
"it",
"on",
"to",
"the",
"child",
"Listener",
"."
] | d9605b7bfe0c28a05289252e12d163e114080b4a | https://github.com/FlyingHe/UtilsMaven/blob/d9605b7bfe0c28a05289252e12d163e114080b4a/src/main/java/com/github/flyinghe/depdcy/FormatTrackingHSSFListenerPlus.java#L96-L105 | train |
FlyingHe/UtilsMaven | src/main/java/com/github/flyinghe/depdcy/FormatTrackingHSSFListenerPlus.java | FormatTrackingHSSFListenerPlus.getFormatIndex | 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 don't have that");
return -1;
}
return xfr.getFormatIndex();
} | 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 don't have that");
return -1;
}
return xfr.getFormatIndex();
} | [
"public",
"int",
"getFormatIndex",
"(",
"CellValueRecordInterface",
"cell",
")",
"{",
"ExtendedFormatRecord",
"xfr",
"=",
"_xfRecords",
".",
"get",
"(",
"cell",
".",
"getXFIndex",
"(",
")",
")",
";",
"if",
"(",
"xfr",
"==",
"null",
")",
"{",
"logger",
".",... | Returns the index of the format string, used by your cell, or -1 if none found
@param cell the cell
@return the index of the format string | [
"Returns",
"the",
"index",
"of",
"the",
"format",
"string",
"used",
"by",
"your",
"cell",
"or",
"-",
"1",
"if",
"none",
"found"
] | d9605b7bfe0c28a05289252e12d163e114080b4a | https://github.com/FlyingHe/UtilsMaven/blob/d9605b7bfe0c28a05289252e12d163e114080b4a/src/main/java/com/github/flyinghe/depdcy/FormatTrackingHSSFListenerPlus.java#L210-L218 | train |
btaz/data-util | src/main/java/com/btaz/util/tf/Template.java | Template.readResourceAsStream | 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 resource", e);
}
} | 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 resource", e);
}
} | [
"public",
"static",
"String",
"readResourceAsStream",
"(",
"String",
"path",
")",
"{",
"try",
"{",
"InputStream",
"inputStream",
"=",
"ResourceUtil",
".",
"getResourceAsStream",
"(",
"path",
")",
";",
"return",
"ResourceUtil",
".",
"readFromInputStreamIntoString",
"... | This method looks for a file on the provided path, attempts to load it as a stream and returns it as a string
@param path path
@return {@code String} text | [
"This",
"method",
"looks",
"for",
"a",
"file",
"on",
"the",
"provided",
"path",
"attempts",
"to",
"load",
"it",
"as",
"a",
"stream",
"and",
"returns",
"it",
"as",
"a",
"string"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/tf/Template.java#L47-L54 | train |
btaz/data-util | src/main/java/com/btaz/util/tf/Template.java | Template.readResource | 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 | 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);
}
} | [
"public",
"static",
"String",
"readResource",
"(",
"String",
"path",
")",
"{",
"try",
"{",
"File",
"file",
"=",
"ResourceUtil",
".",
"getResourceFile",
"(",
"path",
")",
";",
"return",
"ResourceUtil",
".",
"readFromFileIntoString",
"(",
"file",
")",
";",
"}"... | This method looks for a file on the provided path and returns it as a string
@param path path
@return {@code String} text | [
"This",
"method",
"looks",
"for",
"a",
"file",
"on",
"the",
"provided",
"path",
"and",
"returns",
"it",
"as",
"a",
"string"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/tf/Template.java#L61-L68 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/Geometry.java | Geometry.cloneRecursively | 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; i++) {
geometryClones[i] = cloneRecursively(geometry.getGeometries()[i]);
}
clone.setGeometries(geometryClones);
}
if (geometry.getCoordinates() != null) {
Coordinate[] coordinateClones = new Coordinate[geometry.getCoordinates().length];
for (int i = 0; i < geometry.getCoordinates().length; i++) {
coordinateClones[i] = (Coordinate) geometry.getCoordinates()[i].clone();
}
clone.setCoordinates(coordinateClones);
}
return clone;
} | 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; i++) {
geometryClones[i] = cloneRecursively(geometry.getGeometries()[i]);
}
clone.setGeometries(geometryClones);
}
if (geometry.getCoordinates() != null) {
Coordinate[] coordinateClones = new Coordinate[geometry.getCoordinates().length];
for (int i = 0; i < geometry.getCoordinates().length; i++) {
coordinateClones[i] = (Coordinate) geometry.getCoordinates()[i].clone();
}
clone.setCoordinates(coordinateClones);
}
return clone;
} | [
"private",
"Geometry",
"cloneRecursively",
"(",
"Geometry",
"geometry",
")",
"{",
"Geometry",
"clone",
"=",
"new",
"Geometry",
"(",
"geometry",
".",
"geometryType",
",",
"geometry",
".",
"srid",
",",
"geometry",
".",
"precision",
")",
";",
"if",
"(",
"geomet... | Recursive cloning of geometries.
@param geometry
The geometry to clone.
@return The cloned geometry. | [
"Recursive",
"cloning",
"of",
"geometries",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/Geometry.java#L241-L258 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.resolveFieldIndex | int resolveFieldIndex(VariableElement field)
{
TypeElement declaringClass = (TypeElement) field.getEnclosingElement();
String descriptor = Descriptor.getDesriptor(field);
int index = resolveFieldIndex(declaringClass, field.getSimpleName().toString(), descriptor);
addIndexedElement(index, field);
return index;
} | java | int resolveFieldIndex(VariableElement field)
{
TypeElement declaringClass = (TypeElement) field.getEnclosingElement();
String descriptor = Descriptor.getDesriptor(field);
int index = resolveFieldIndex(declaringClass, field.getSimpleName().toString(), descriptor);
addIndexedElement(index, field);
return index;
} | [
"int",
"resolveFieldIndex",
"(",
"VariableElement",
"field",
")",
"{",
"TypeElement",
"declaringClass",
"=",
"(",
"TypeElement",
")",
"field",
".",
"getEnclosingElement",
"(",
")",
";",
"String",
"descriptor",
"=",
"Descriptor",
".",
"getDesriptor",
"(",
"field",
... | Returns the constant map index to field.
If entry doesn't exist it is created.
@param field
@return | [
"Returns",
"the",
"constant",
"map",
"index",
"to",
"field",
".",
"If",
"entry",
"doesn",
"t",
"exist",
"it",
"is",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L179-L186 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.resolveFieldIndex | 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.getQualifiedName().toString(), name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index == -1)
{
// add entry to constant pool
int ci = resolveClassIndex(declaringClass);
int nati = resolveNameAndTypeIndex(name, descriptor);
return addConstantInfo(new Fieldref(ci, nati), size);
}
return index;
} | 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.getQualifiedName().toString(), name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index == -1)
{
// add entry to constant pool
int ci = resolveClassIndex(declaringClass);
int nati = resolveNameAndTypeIndex(name, descriptor);
return addConstantInfo(new Fieldref(ci, nati), size);
}
return index;
} | [
"private",
"int",
"resolveFieldIndex",
"(",
"TypeElement",
"declaringClass",
",",
"String",
"name",
",",
"String",
"descriptor",
")",
"{",
"int",
"size",
"=",
"0",
";",
"int",
"index",
"=",
"0",
";",
"constantReadLock",
".",
"lock",
"(",
")",
";",
"try",
... | Returns the constant map index to field
If entry doesn't exist it is created.
@param declaringClass
@param name
@param descriptor
@return | [
"Returns",
"the",
"constant",
"map",
"index",
"to",
"field",
"If",
"entry",
"doesn",
"t",
"exist",
"it",
"is",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L195-L217 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.resolveMethodIndex | int resolveMethodIndex(ExecutableElement method)
{
int size = 0;
int index = 0;
constantReadLock.lock();
TypeElement declaringClass = (TypeElement) method.getEnclosingElement();
String declaringClassname = declaringClass.getQualifiedName().toString();
String descriptor = Descriptor.getDesriptor(method);
String name = method.getSimpleName().toString();
try
{
size = getConstantPoolSize();
index = getRefIndex(Methodref.class, declaringClassname, name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index == -1)
{
// add entry to constant pool
int ci = resolveClassIndex(declaringClass);
int nati = resolveNameAndTypeIndex(name, descriptor);
index = addConstantInfo(new Methodref(ci, nati), size);
}
addIndexedElement(index, method);
return index;
} | java | int resolveMethodIndex(ExecutableElement method)
{
int size = 0;
int index = 0;
constantReadLock.lock();
TypeElement declaringClass = (TypeElement) method.getEnclosingElement();
String declaringClassname = declaringClass.getQualifiedName().toString();
String descriptor = Descriptor.getDesriptor(method);
String name = method.getSimpleName().toString();
try
{
size = getConstantPoolSize();
index = getRefIndex(Methodref.class, declaringClassname, name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index == -1)
{
// add entry to constant pool
int ci = resolveClassIndex(declaringClass);
int nati = resolveNameAndTypeIndex(name, descriptor);
index = addConstantInfo(new Methodref(ci, nati), size);
}
addIndexedElement(index, method);
return index;
} | [
"int",
"resolveMethodIndex",
"(",
"ExecutableElement",
"method",
")",
"{",
"int",
"size",
"=",
"0",
";",
"int",
"index",
"=",
"0",
";",
"constantReadLock",
".",
"lock",
"(",
")",
";",
"TypeElement",
"declaringClass",
"=",
"(",
"TypeElement",
")",
"method",
... | Returns the constant map index to method
If entry doesn't exist it is created.
@param method
@return | [
"Returns",
"the",
"constant",
"map",
"index",
"to",
"method",
"If",
"entry",
"doesn",
"t",
"exist",
"it",
"is",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L224-L251 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.resolveNameIndex | final int resolveNameIndex(CharSequence name)
{
int size = 0;
int index = 0;
constantReadLock.lock();
try
{
size = getConstantPoolSize();
index = getNameIndex(name);
}
finally
{
constantReadLock.unlock();
}
if (index != -1)
{
return index;
}
else
{
return addConstantInfo(new Utf8(name), size);
}
} | java | final int resolveNameIndex(CharSequence name)
{
int size = 0;
int index = 0;
constantReadLock.lock();
try
{
size = getConstantPoolSize();
index = getNameIndex(name);
}
finally
{
constantReadLock.unlock();
}
if (index != -1)
{
return index;
}
else
{
return addConstantInfo(new Utf8(name), size);
}
} | [
"final",
"int",
"resolveNameIndex",
"(",
"CharSequence",
"name",
")",
"{",
"int",
"size",
"=",
"0",
";",
"int",
"index",
"=",
"0",
";",
"constantReadLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"size",
"=",
"getConstantPoolSize",
"(",
")",
";",
"inde... | Returns the constant map index to name
If entry doesn't exist it is created.
@param name
@return | [
"Returns",
"the",
"constant",
"map",
"index",
"to",
"name",
"If",
"entry",
"doesn",
"t",
"exist",
"it",
"is",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L292-L314 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.resolveNameAndTypeIndex | int resolveNameAndTypeIndex(String name, String descriptor)
{
int size = 0;
int index = 0;
constantReadLock.lock();
try
{
size = getConstantPoolSize();
index = getNameAndTypeIndex(name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index != -1)
{
return index;
}
else
{
int nameIndex = resolveNameIndex(name);
int typeIndex = resolveNameIndex(descriptor);
return addConstantInfo(new NameAndType(nameIndex, typeIndex), size);
}
} | java | int resolveNameAndTypeIndex(String name, String descriptor)
{
int size = 0;
int index = 0;
constantReadLock.lock();
try
{
size = getConstantPoolSize();
index = getNameAndTypeIndex(name, descriptor);
}
finally
{
constantReadLock.unlock();
}
if (index != -1)
{
return index;
}
else
{
int nameIndex = resolveNameIndex(name);
int typeIndex = resolveNameIndex(descriptor);
return addConstantInfo(new NameAndType(nameIndex, typeIndex), size);
}
} | [
"int",
"resolveNameAndTypeIndex",
"(",
"String",
"name",
",",
"String",
"descriptor",
")",
"{",
"int",
"size",
"=",
"0",
";",
"int",
"index",
"=",
"0",
";",
"constantReadLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"size",
"=",
"getConstantPoolSize",
"... | Returns the constant map index to name and type
If entry doesn't exist it is created.
@param name
@param descriptor
@return | [
"Returns",
"the",
"constant",
"map",
"index",
"to",
"name",
"and",
"type",
"If",
"entry",
"doesn",
"t",
"exist",
"it",
"is",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L322-L346 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.defineConstantField | 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(Modifier.STATIC);
builder.setType(Typ.IntA);
FieldInfo fieldInfo = new FieldInfo(this, builder.getVariableElement(), new ConstantValue(this, constant));
addFieldInfo(fieldInfo);
fieldInfo.readyToWrite();
} | 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(Modifier.STATIC);
builder.setType(Typ.IntA);
FieldInfo fieldInfo = new FieldInfo(this, builder.getVariableElement(), new ConstantValue(this, constant));
addFieldInfo(fieldInfo);
fieldInfo.readyToWrite();
} | [
"public",
"void",
"defineConstantField",
"(",
"int",
"modifier",
",",
"String",
"fieldName",
",",
"int",
"constant",
")",
"{",
"DeclaredType",
"dt",
"=",
"(",
"DeclaredType",
")",
"asType",
"(",
")",
";",
"VariableBuilder",
"builder",
"=",
"new",
"VariableBuil... | Define constant field and set the constant value.
@param modifier
@param fieldName
@param constant | [
"Define",
"constant",
"field",
"and",
"set",
"the",
"constant",
"value",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L636-L646 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.save | public void save(ProcessingEnvironment env) throws IOException
{
Filer filer = env.getFiler();
//JavaFileObject sourceFile = filer.createClassFile(getQualifiedName(), superClass);
FileObject sourceFile = filer.createResource(
StandardLocation.CLASS_OUTPUT,
El.getPackageOf(this).getQualifiedName(),
getSimpleName()+".class"
);
BufferedOutputStream bos = new BufferedOutputStream(sourceFile.openOutputStream());
DataOutputStream dos = new DataOutputStream(bos);
write(dos);
dos.close();
System.err.println("wrote "+sourceFile.getName());
} | 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,
El.getPackageOf(this).getQualifiedName(),
getSimpleName()+".class"
);
BufferedOutputStream bos = new BufferedOutputStream(sourceFile.openOutputStream());
DataOutputStream dos = new DataOutputStream(bos);
write(dos);
dos.close();
System.err.println("wrote "+sourceFile.getName());
} | [
"public",
"void",
"save",
"(",
"ProcessingEnvironment",
"env",
")",
"throws",
"IOException",
"{",
"Filer",
"filer",
"=",
"env",
".",
"getFiler",
"(",
")",
";",
"//JavaFileObject sourceFile = filer.createClassFile(getQualifiedName(), superClass);\r",
"FileObject",
"sourceFil... | Saves subclass as class file
@param env
@throws IOException | [
"Saves",
"subclass",
"as",
"class",
"file"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L889-L903 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/SubClass.java | SubClass.write | @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)
{
ci.write(out);
}
int modifier = ClassFlags.getModifier(getModifiers());
modifier |= ClassFlags.ACC_SYNTHETIC | ClassFlags.ACC_PUBLIC | ClassFlags.ACC_SUPER;
out.writeShort(modifier);
out.writeShort(this_class);
out.writeShort(super_class);
out.writeShort(interfaces.size());
for (int ii : interfaces)
{
out.writeShort(ii);
}
out.writeShort(fields.size());
for (FieldInfo fi : fields)
{
fi.write(out);
}
out.writeShort(methods.size());
for (MethodInfo mi : methods)
{
mi.write(out);
}
out.writeShort(attributes.size());
for (AttributeInfo ai : attributes)
{
ai.write(out);
}
} | 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)
{
ci.write(out);
}
int modifier = ClassFlags.getModifier(getModifiers());
modifier |= ClassFlags.ACC_SYNTHETIC | ClassFlags.ACC_PUBLIC | ClassFlags.ACC_SUPER;
out.writeShort(modifier);
out.writeShort(this_class);
out.writeShort(super_class);
out.writeShort(interfaces.size());
for (int ii : interfaces)
{
out.writeShort(ii);
}
out.writeShort(fields.size());
for (FieldInfo fi : fields)
{
fi.write(out);
}
out.writeShort(methods.size());
for (MethodInfo mi : methods)
{
mi.write(out);
}
out.writeShort(attributes.size());
for (AttributeInfo ai : attributes)
{
ai.write(out);
}
} | [
"@",
"Override",
"public",
"void",
"write",
"(",
"DataOutput",
"out",
")",
"throws",
"IOException",
"{",
"addSignatureIfNeed",
"(",
")",
";",
"out",
".",
"writeInt",
"(",
"magic",
")",
";",
"out",
".",
"writeShort",
"(",
"minor_version",
")",
";",
"out",
... | Writes the class
@param out
@throws IOException | [
"Writes",
"the",
"class"
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/SubClass.java#L910-L948 | train |
btaz/data-util | src/main/java/com/btaz/util/xml/xmlpath/XmlPath.java | XmlPath.matches | 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;
}
for(int i=0; i<items.size(); i++) {
if (! items.get(i).matches(nodePath.get(i))) {
// failed a comparison
return false;
}
}
// pass all comparisons
return true;
} | 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;
}
for(int i=0; i<items.size(); i++) {
if (! items.get(i).matches(nodePath.get(i))) {
// failed a comparison
return false;
}
}
// pass all comparisons
return true;
} | [
"public",
"boolean",
"matches",
"(",
"LinkedList",
"<",
"Node",
">",
"nodePath",
")",
"{",
"if",
"(",
"simplePattern",
")",
"{",
"// simple pattern",
"return",
"items",
".",
"get",
"(",
"0",
")",
".",
"matches",
"(",
"nodePath",
".",
"getLast",
"(",
")",... | Compare an XML node path with the path query
@param nodePath XML data path
@return {@code boolean} true if a match | [
"Compare",
"an",
"XML",
"node",
"path",
"with",
"the",
"path",
"query"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/xml/xmlpath/XmlPath.java#L35-L53 | train |
sangupta/pepmint | src/main/java/com/sangupta/pepmint/Pepmint.java | Pepmint.newLexer | 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 Lexer newLexer(String name) {
PyObject object = pythonInterpreter.get("get_lexer_by_name");
object = object.__call__(new PyString(name));
return new Lexer(object);
} | [
"public",
"Lexer",
"newLexer",
"(",
"String",
"name",
")",
"{",
"PyObject",
"object",
"=",
"pythonInterpreter",
".",
"get",
"(",
"\"get_lexer_by_name\"",
")",
";",
"object",
"=",
"object",
".",
"__call__",
"(",
"new",
"PyString",
"(",
"name",
")",
")",
";"... | Obtain a new lexer implementation based on the given lexer name.
@param name
@return | [
"Obtain",
"a",
"new",
"lexer",
"implementation",
"based",
"on",
"the",
"given",
"lexer",
"name",
"."
] | 2918d76b9632762e9d496c59f254c5faa83a386d | https://github.com/sangupta/pepmint/blob/2918d76b9632762e9d496c59f254c5faa83a386d/src/main/java/com/sangupta/pepmint/Pepmint.java#L58-L62 | train |
sangupta/pepmint | src/main/java/com/sangupta/pepmint/Pepmint.java | Pepmint.newHtmlFormatter | public HtmlFormatter newHtmlFormatter(String params) {
PyObject object = pythonInterpreter.eval("HtmlFormatter(" + params + ")");
return new HtmlFormatter(object);
} | java | public HtmlFormatter newHtmlFormatter(String params) {
PyObject object = pythonInterpreter.eval("HtmlFormatter(" + params + ")");
return new HtmlFormatter(object);
} | [
"public",
"HtmlFormatter",
"newHtmlFormatter",
"(",
"String",
"params",
")",
"{",
"PyObject",
"object",
"=",
"pythonInterpreter",
".",
"eval",
"(",
"\"HtmlFormatter(\"",
"+",
"params",
"+",
"\")\"",
")",
";",
"return",
"new",
"HtmlFormatter",
"(",
"object",
")",... | Create a new HTMLFormatter object using the given parameters.
@param params
@return | [
"Create",
"a",
"new",
"HTMLFormatter",
"object",
"using",
"the",
"given",
"parameters",
"."
] | 2918d76b9632762e9d496c59f254c5faa83a386d | https://github.com/sangupta/pepmint/blob/2918d76b9632762e9d496c59f254c5faa83a386d/src/main/java/com/sangupta/pepmint/Pepmint.java#L70-L73 | train |
sangupta/pepmint | src/main/java/com/sangupta/pepmint/Pepmint.java | Pepmint.highlight | 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, pyLexer, pyFormatter).asString();
} | 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, pyLexer, pyFormatter).asString();
} | [
"public",
"String",
"highlight",
"(",
"String",
"code",
",",
"Lexer",
"lexer",
",",
"Formatter",
"formatter",
")",
"{",
"PyFunction",
"function",
"=",
"pythonInterpreter",
".",
"get",
"(",
"\"highlight\"",
",",
"PyFunction",
".",
"class",
")",
";",
"PyString",... | Highlight the given code piece using the provided lexer and formatter.
@param code
@param lexer
@param formatter
@return | [
"Highlight",
"the",
"given",
"code",
"piece",
"using",
"the",
"provided",
"lexer",
"and",
"formatter",
"."
] | 2918d76b9632762e9d496c59f254c5faa83a386d | https://github.com/sangupta/pepmint/blob/2918d76b9632762e9d496c59f254c5faa83a386d/src/main/java/com/sangupta/pepmint/Pepmint.java#L83-L91 | train |
eyp/serfj | src/main/java/net/sf/serfj/RestController.java | RestController.putParam | protected void putParam(String name, Object object) {
this.response.getRequest().setAttribute(name, object);
} | java | protected void putParam(String name, Object object) {
this.response.getRequest().setAttribute(name, object);
} | [
"protected",
"void",
"putParam",
"(",
"String",
"name",
",",
"Object",
"object",
")",
"{",
"this",
".",
"response",
".",
"getRequest",
"(",
")",
".",
"setAttribute",
"(",
"name",
",",
"object",
")",
";",
"}"
] | Adds an object to the request. If a page will be renderer and it needs some objects
to work, with this method a developer can add objects to the request, so the page can
obtain them.
@param name Parameter name
@param object Object to put in the request | [
"Adds",
"an",
"object",
"to",
"the",
"request",
".",
"If",
"a",
"page",
"will",
"be",
"renderer",
"and",
"it",
"needs",
"some",
"objects",
"to",
"work",
"with",
"this",
"method",
"a",
"developer",
"can",
"add",
"objects",
"to",
"the",
"request",
"so",
... | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/RestController.java#L85-L87 | train |
Teddy-Zhu/SilentGo | utils/src/main/java/com/silentgo/utils/asm/Label.java | Label.addToSubroutine | 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 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;
} | [
"void",
"addToSubroutine",
"(",
"final",
"long",
"id",
",",
"final",
"int",
"nbSubroutines",
")",
"{",
"if",
"(",
"(",
"status",
"&",
"VISITED",
")",
"==",
"0",
")",
"{",
"status",
"|=",
"VISITED",
";",
"srcAndRefPositions",
"=",
"new",
"int",
"[",
"nb... | Marks this basic block as belonging to the given subroutine.
@param id
a subroutine id.
@param nbSubroutines
the total number of subroutines in the method. | [
"Marks",
"this",
"basic",
"block",
"as",
"belonging",
"to",
"the",
"given",
"subroutine",
"."
] | 27f58b0cafe56b2eb9fc6993efa9ca2b529661e1 | https://github.com/Teddy-Zhu/SilentGo/blob/27f58b0cafe56b2eb9fc6993efa9ca2b529661e1/utils/src/main/java/com/silentgo/utils/asm/Label.java#L477-L483 | train |
Teddy-Zhu/SilentGo | utils/src/main/java/com/silentgo/utils/asm/Label.java | Label.visitSubroutine | 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 label l from the stack
Label l = stack;
stack = l.next;
l.next = null;
if (JSR != null) {
if ((l.status & VISITED2) != 0) {
continue;
}
l.status |= VISITED2;
// adds JSR to the successors of l, if it is a RET block
if ((l.status & RET) != 0) {
if (!l.inSameSubroutine(JSR)) {
Edge e = new Edge();
e.info = l.inputStackTop;
e.successor = JSR.successors.successor;
e.next = l.successors;
l.successors = e;
}
}
} else {
// if the l block already belongs to subroutine 'id', continue
if (l.inSubroutine(id)) {
continue;
}
// marks the l block as belonging to subroutine 'id'
l.addToSubroutine(id, nbSubroutines);
}
// pushes each successor of l on the stack, except JSR targets
Edge e = l.successors;
while (e != null) {
// if the l block is a JSR block, then 'l.successors.next' leads
// to the JSR target (see {@link #visitJumpInsn}) and must
// therefore not be followed
if ((l.status & Label.JSR) == 0 || e != l.successors.next) {
// pushes e.successor on the stack if it not already added
if (e.successor.next == null) {
e.successor.next = stack;
stack = e.successor;
}
}
e = e.next;
}
}
} | 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 label l from the stack
Label l = stack;
stack = l.next;
l.next = null;
if (JSR != null) {
if ((l.status & VISITED2) != 0) {
continue;
}
l.status |= VISITED2;
// adds JSR to the successors of l, if it is a RET block
if ((l.status & RET) != 0) {
if (!l.inSameSubroutine(JSR)) {
Edge e = new Edge();
e.info = l.inputStackTop;
e.successor = JSR.successors.successor;
e.next = l.successors;
l.successors = e;
}
}
} else {
// if the l block already belongs to subroutine 'id', continue
if (l.inSubroutine(id)) {
continue;
}
// marks the l block as belonging to subroutine 'id'
l.addToSubroutine(id, nbSubroutines);
}
// pushes each successor of l on the stack, except JSR targets
Edge e = l.successors;
while (e != null) {
// if the l block is a JSR block, then 'l.successors.next' leads
// to the JSR target (see {@link #visitJumpInsn}) and must
// therefore not be followed
if ((l.status & Label.JSR) == 0 || e != l.successors.next) {
// pushes e.successor on the stack if it not already added
if (e.successor.next == null) {
e.successor.next = stack;
stack = e.successor;
}
}
e = e.next;
}
}
} | [
"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... | Finds the basic blocks that belong to a given subroutine, and marks these
blocks as belonging to this subroutine. This method follows the control
flow graph to find all the blocks that are reachable from the current
block WITHOUT following any JSR target.
@param JSR
a JSR block that jumps to this subroutine. If this JSR is not
null it is added to the successor of the RET blocks found in
the subroutine.
@param id
the id of this subroutine.
@param nbSubroutines
the total number of subroutines in the method. | [
"Finds",
"the",
"basic",
"blocks",
"that",
"belong",
"to",
"a",
"given",
"subroutine",
"and",
"marks",
"these",
"blocks",
"as",
"belonging",
"to",
"this",
"subroutine",
".",
"This",
"method",
"follows",
"the",
"control",
"flow",
"graph",
"to",
"find",
"all",... | 27f58b0cafe56b2eb9fc6993efa9ca2b529661e1 | https://github.com/Teddy-Zhu/SilentGo/blob/27f58b0cafe56b2eb9fc6993efa9ca2b529661e1/utils/src/main/java/com/silentgo/utils/asm/Label.java#L500-L549 | train |
eyp/serfj | src/main/java/net/sf/serfj/serializers/XmlSerializer.java | XmlSerializer.serialize | public String serialize(Object object) {
XStream xstream = new XStream();
return xstream.toXML(object);
} | java | public String serialize(Object object) {
XStream xstream = new XStream();
return xstream.toXML(object);
} | [
"public",
"String",
"serialize",
"(",
"Object",
"object",
")",
"{",
"XStream",
"xstream",
"=",
"new",
"XStream",
"(",
")",
";",
"return",
"xstream",
".",
"toXML",
"(",
"object",
")",
";",
"}"
] | Serializes an object to XML using the default XStream converter. | [
"Serializes",
"an",
"object",
"to",
"XML",
"using",
"the",
"default",
"XStream",
"converter",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/serializers/XmlSerializer.java#L30-L33 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileMerger.java | FileMerger.merge | 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) {
merge(mergeDir, sortedFiles, mergedFile, comparator, MERGE_FACTOR);
} | [
"public",
"static",
"void",
"merge",
"(",
"File",
"mergeDir",
",",
"List",
"<",
"File",
">",
"sortedFiles",
",",
"File",
"mergedFile",
",",
"Comparator",
"<",
"String",
">",
"comparator",
")",
"{",
"merge",
"(",
"mergeDir",
",",
"sortedFiles",
",",
"merged... | Merge multiple files into a single file. Multi-pass approach where the merge factor controls how many passes that
are required. This method uses the default merge factor for merging.
@param mergeDir merge directory. If null, then it defaults to system temp.
@param sortedFiles sorted files that are to be merged
@param mergedFile final output file
@param comparator comparator used to merge files (sorting) | [
"Merge",
"multiple",
"files",
"into",
"a",
"single",
"file",
".",
"Multi",
"-",
"pass",
"approach",
"where",
"the",
"merge",
"factor",
"controls",
"how",
"many",
"passes",
"that",
"are",
"required",
".",
"This",
"method",
"uses",
"the",
"default",
"merge",
... | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileMerger.java#L27-L29 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileMerger.java | FileMerger.merge | 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<BatchFile>();
try {
while(mergeFiles.size() > 0) {
// create batch
batch.clear();
for(int i = 0; i < mergeFactor && mergeFiles.size() > 0; i++) {
batch.add(new BatchFile(mergeFiles.remove()));
}
// create aggregation file
File aggFile;
if(mergeFiles.size() > 0) {
// create new aggregate file
aggFile = File.createTempFile("merge-", ".part", mergeDir);
mergeFiles.addLast(aggFile);
} else {
// create final file
aggFile = mergedFile;
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(aggFile.getAbsoluteFile(), false),DataUtilDefaults.charSet));
// process batch
String [] buffer = new String[batch.size()];
Arrays.fill(buffer, null);
boolean [] inUse = new boolean[batch.size()];
Arrays.fill(inUse, true);
boolean inUseFlag = true;
while(inUseFlag) {
// load comparison buffer
int index = -1;
String selected = null;
for (int i = 0; i < batch.size(); i++) {
if(inUse[i]) {
if(buffer[i] == null) {
// need more data
buffer[i] = batch.get(i).getRow();
if(buffer[i] == null) {
inUse[i] = false;
}
}
if(buffer[i] != null) {
if(index == -1) {
// set item
index = i;
selected = buffer[i];
} else if(comparator.compare(buffer[i], selected) < 0) {
// replace item
index = i;
selected = buffer[i];
}
}
}
}
if(index >= 0) {
// select item and write to new aggregate file
writer.write(buffer[index] + DataUtilDefaults.lineTerminator);
buffer[index] = null;
inUseFlag = true;
} else {
inUseFlag = false;
}
}
// no more data
writer.flush();
writer.close();
}
} catch (IOException e) {
throw new DataUtilException(e);
}
} | 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<BatchFile>();
try {
while(mergeFiles.size() > 0) {
// create batch
batch.clear();
for(int i = 0; i < mergeFactor && mergeFiles.size() > 0; i++) {
batch.add(new BatchFile(mergeFiles.remove()));
}
// create aggregation file
File aggFile;
if(mergeFiles.size() > 0) {
// create new aggregate file
aggFile = File.createTempFile("merge-", ".part", mergeDir);
mergeFiles.addLast(aggFile);
} else {
// create final file
aggFile = mergedFile;
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(aggFile.getAbsoluteFile(), false),DataUtilDefaults.charSet));
// process batch
String [] buffer = new String[batch.size()];
Arrays.fill(buffer, null);
boolean [] inUse = new boolean[batch.size()];
Arrays.fill(inUse, true);
boolean inUseFlag = true;
while(inUseFlag) {
// load comparison buffer
int index = -1;
String selected = null;
for (int i = 0; i < batch.size(); i++) {
if(inUse[i]) {
if(buffer[i] == null) {
// need more data
buffer[i] = batch.get(i).getRow();
if(buffer[i] == null) {
inUse[i] = false;
}
}
if(buffer[i] != null) {
if(index == -1) {
// set item
index = i;
selected = buffer[i];
} else if(comparator.compare(buffer[i], selected) < 0) {
// replace item
index = i;
selected = buffer[i];
}
}
}
}
if(index >= 0) {
// select item and write to new aggregate file
writer.write(buffer[index] + DataUtilDefaults.lineTerminator);
buffer[index] = null;
inUseFlag = true;
} else {
inUseFlag = false;
}
}
// no more data
writer.flush();
writer.close();
}
} catch (IOException e) {
throw new DataUtilException(e);
}
} | [
"public",
"static",
"void",
"merge",
"(",
"File",
"mergeDir",
",",
"List",
"<",
"File",
">",
"sortedFiles",
",",
"File",
"mergedFile",
",",
"Comparator",
"<",
"String",
">",
"comparator",
",",
"int",
"mergeFactor",
")",
"{",
"LinkedList",
"<",
"File",
">",... | Merge multiple files into a single file. Multi-pass approach where the merge factor controls how many passes that
are required. If a merge factor of X is specified, then X files will be opened concurrently for merging.
@param mergeDir merge directory. If null, then it defaults to system temp.
@param sortedFiles sorted files that are to be merged
@param mergedFile final output file
@param comparator comparator used to merge files (sorting)
@param mergeFactor merge factor, a higher number typically merges faster but uses more file handles. | [
"Merge",
"multiple",
"files",
"into",
"a",
"single",
"file",
".",
"Multi",
"-",
"pass",
"approach",
"where",
"the",
"merge",
"factor",
"controls",
"how",
"many",
"passes",
"that",
"are",
"required",
".",
"If",
"a",
"merge",
"factor",
"of",
"X",
"is",
"sp... | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileMerger.java#L40-L117 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/FieldInfo.java | FieldInfo.readyToWrite | public void readyToWrite()
{
addSignatureIfNeed();
this.name_index = ((SubClass)classFile).resolveNameIndex(getSimpleName());
this.descriptor_index = ((SubClass)classFile).resolveNameIndex(Descriptor.getDesriptor(this));
readyToWrite = true;
} | java | public void readyToWrite()
{
addSignatureIfNeed();
this.name_index = ((SubClass)classFile).resolveNameIndex(getSimpleName());
this.descriptor_index = ((SubClass)classFile).resolveNameIndex(Descriptor.getDesriptor(this));
readyToWrite = true;
} | [
"public",
"void",
"readyToWrite",
"(",
")",
"{",
"addSignatureIfNeed",
"(",
")",
";",
"this",
".",
"name_index",
"=",
"(",
"(",
"SubClass",
")",
"classFile",
")",
".",
"resolveNameIndex",
"(",
"getSimpleName",
"(",
")",
")",
";",
"this",
".",
"descriptor_i... | Call to this method tells that the Attribute is ready writing. This method
must be called before constant pool is written. | [
"Call",
"to",
"this",
"method",
"tells",
"that",
"the",
"Attribute",
"is",
"ready",
"writing",
".",
"This",
"method",
"must",
"be",
"called",
"before",
"constant",
"pool",
"is",
"written",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/FieldInfo.java#L79-L85 | train |
btaz/data-util | src/main/java/com/btaz/util/xml/model/Xml.java | Xml.bfsComparison | 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> b = ((Element)other).getChildElements();
if(a.size() != b.size()) {
return false;
}
for(int i=0; i<a.size(); i++) {
if(! a.get(i).equals(b.get(i))) {
return false;
}
}
for(int i=0; i<a.size(); i++) {
if(! bfsComparison(a.get(i), b.get(i))) {
return false;
}
}
return 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> b = ((Element)other).getChildElements();
if(a.size() != b.size()) {
return false;
}
for(int i=0; i<a.size(); i++) {
if(! a.get(i).equals(b.get(i))) {
return false;
}
}
for(int i=0; i<a.size(); i++) {
if(! bfsComparison(a.get(i), b.get(i))) {
return false;
}
}
return true;
} | [
"private",
"boolean",
"bfsComparison",
"(",
"Node",
"root",
",",
"Node",
"other",
")",
"{",
"if",
"(",
"root",
"instanceof",
"Content",
"||",
"other",
"instanceof",
"Content",
")",
"{",
"return",
"root",
".",
"equals",
"(",
"other",
")",
";",
"}",
"if",
... | A strict breadth-first search traversal to evaluate two XML trees against each other
@param root first tree
@param other second tree
@return {@code boolean} true if the trees matches, false otherwise | [
"A",
"strict",
"breadth",
"-",
"first",
"search",
"traversal",
"to",
"evaluate",
"two",
"XML",
"trees",
"against",
"each",
"other"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/xml/model/Xml.java#L179-L205 | train |
btaz/data-util | src/main/java/com/btaz/util/xml/model/Xml.java | Xml.bsfHashCode | 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) {
result += 31 * childElement.hashCode();
}
for (Node child : childElements) {
if (child instanceof Content) {
result += 31 * child.hashCode();
} else {
result = bsfHashCode(child, result);
}
}
return result;
} | 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) {
result += 31 * childElement.hashCode();
}
for (Node child : childElements) {
if (child instanceof Content) {
result += 31 * child.hashCode();
} else {
result = bsfHashCode(child, result);
}
}
return result;
} | [
"private",
"int",
"bsfHashCode",
"(",
"Node",
"node",
",",
"int",
"result",
")",
"{",
"result",
"+=",
"31",
"*",
"node",
".",
"hashCode",
"(",
")",
";",
"if",
"(",
"node",
"instanceof",
"Content",
")",
"{",
"return",
"result",
";",
"}",
"Element",
"e... | Recursive hash code creator
@param node root node
@param result cumulative hash code value
@return result resulting cumulative hash code value | [
"Recursive",
"hash",
"code",
"creator"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/xml/model/Xml.java#L228-L251 | train |
btaz/data-util | src/main/java/com/btaz/util/xml/model/Xml.java | Xml.deepCopy | 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();
copyElement.addChildElement(content);
} else {
Element element = (Element) ((Element) node).clone();
copyElement.addChildElement(element);
deepCopy((Element)node, element);
}
} catch (CloneNotSupportedException e) {
throw new XmlModelException("Unable to clone object", e);
}
}
} | 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();
copyElement.addChildElement(content);
} else {
Element element = (Element) ((Element) node).clone();
copyElement.addChildElement(element);
deepCopy((Element)node, element);
}
} catch (CloneNotSupportedException e) {
throw new XmlModelException("Unable to clone object", e);
}
}
} | [
"private",
"void",
"deepCopy",
"(",
"Element",
"origElement",
",",
"Element",
"copyElement",
")",
"{",
"List",
"<",
"Node",
">",
"children",
"=",
"origElement",
".",
"getChildElements",
"(",
")",
";",
"for",
"(",
"Node",
"node",
":",
"children",
")",
"{",
... | Deep copy recursive helper method.
@param origElement original element
@param copyElement copy element | [
"Deep",
"copy",
"recursive",
"helper",
"method",
"."
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/xml/model/Xml.java#L310-L326 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Jav.java | Jav.makeJavaIdentifier | 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 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;
} | [
"public",
"String",
"makeJavaIdentifier",
"(",
"String",
"id",
")",
"{",
"String",
"jid",
"=",
"makeJavaId",
"(",
"id",
")",
";",
"String",
"old",
"=",
"map",
".",
"put",
"(",
"jid",
",",
"id",
")",
";",
"if",
"(",
"old",
"!=",
"null",
"&&",
"!",
... | Returns a String capable for java identifier. Throws IllegalArgumentException
if same id was already created.
<p>Same id returns always the same java id.
@param id
@return | [
"Returns",
"a",
"String",
"capable",
"for",
"java",
"identifier",
".",
"Throws",
"IllegalArgumentException",
"if",
"same",
"id",
"was",
"already",
"created",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Jav.java#L37-L46 | train |
tvesalainen/bcc | src/main/java/org/vesalainen/bcc/model/Jav.java | Jav.makeUniqueJavaIdentifier | 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, id);
}
}
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, id);
}
}
return jid;
} | [
"public",
"String",
"makeUniqueJavaIdentifier",
"(",
"String",
"id",
")",
"{",
"String",
"jid",
"=",
"makeJavaId",
"(",
"id",
")",
";",
"String",
"old",
"=",
"map",
".",
"put",
"(",
"jid",
",",
"id",
")",
";",
"if",
"(",
"old",
"!=",
"null",
")",
"... | Returns a unique String capable for java identifier.
<p>Note! Even with the same id the returned string is unique.
@param id
@return | [
"Returns",
"a",
"unique",
"String",
"capable",
"for",
"java",
"identifier",
"."
] | 4e84e313018d487f1a8cca3952d71bc21e77d16b | https://github.com/tvesalainen/bcc/blob/4e84e313018d487f1a8cca3952d71bc21e77d16b/src/main/java/org/vesalainen/bcc/model/Jav.java#L54-L68 | train |
btaz/data-util | src/main/java/com/btaz/util/mr/FileOutputCollector.java | FileOutputCollector.write | @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 | @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);
}
} | [
"@",
"Override",
"public",
"void",
"write",
"(",
"String",
"output",
")",
"throws",
"MapReduceException",
"{",
"try",
"{",
"writer",
".",
"write",
"(",
"output",
"+",
"DataUtilDefaults",
".",
"lineTerminator",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",... | Write to the output collector
@param output data to write
@exception MapReduceException map reduce exception | [
"Write",
"to",
"the",
"output",
"collector"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/mr/FileOutputCollector.java#L62-L69 | train |
btaz/data-util | src/main/java/com/btaz/util/mr/FileOutputCollector.java | FileOutputCollector.close | 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 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);
}
} | [
"public",
"void",
"close",
"(",
")",
"throws",
"MapReduceException",
"{",
"try",
"{",
"if",
"(",
"writer",
"!=",
"null",
")",
"{",
"writer",
".",
"flush",
"(",
")",
";",
"writer",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
... | Close the output collector
@throws MapReduceException map reduce exception | [
"Close",
"the",
"output",
"collector"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/mr/FileOutputCollector.java#L83-L92 | train |
btaz/data-util | src/main/java/com/btaz/util/string/StringUtil.java | StringUtil.pad | 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 static String pad(int repeat, String str) {
StringBuilder sb = new StringBuilder();
for(int i=0; i < repeat; i++) {
sb.append(str);
}
return sb.toString();
} | [
"public",
"static",
"String",
"pad",
"(",
"int",
"repeat",
",",
"String",
"str",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"repeat",
";",
"i",
"++",
")",
"{",
"sb... | This method will pad a String with a character or string
@param repeat how many times the string should be repeated
@param str character or string to be repeated
@return padded {@code String} | [
"This",
"method",
"will",
"pad",
"a",
"String",
"with",
"a",
"character",
"or",
"string"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/string/StringUtil.java#L15-L21 | train |
eyp/serfj | src/main/java/net/sf/serfj/ResponseHelper.java | ResponseHelper.setFile | public void setFile(File file, String attachmentFilename, String contentType) {
this.file = file;
this.attachmentFilename = attachmentFilename;
this.contentType = contentType;
} | java | public void setFile(File file, String attachmentFilename, String contentType) {
this.file = file;
this.attachmentFilename = attachmentFilename;
this.contentType = contentType;
} | [
"public",
"void",
"setFile",
"(",
"File",
"file",
",",
"String",
"attachmentFilename",
",",
"String",
"contentType",
")",
"{",
"this",
".",
"file",
"=",
"file",
";",
"this",
".",
"attachmentFilename",
"=",
"attachmentFilename",
";",
"this",
".",
"contentType",... | Sets the file to send to the client. If a file is set then the framework will try to read it
and write it into the response using a FileSerializer.
@param file The file.
@param attachmentFilename Name for the file that will be sent.
@param contentType Content type for the response header. | [
"Sets",
"the",
"file",
"to",
"send",
"to",
"the",
"client",
".",
"If",
"a",
"file",
"is",
"set",
"then",
"the",
"framework",
"will",
"try",
"to",
"read",
"it",
"and",
"write",
"it",
"into",
"the",
"response",
"using",
"a",
"FileSerializer",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/ResponseHelper.java#L214-L218 | train |
eyp/serfj | src/main/java/net/sf/serfj/ResponseHelper.java | ResponseHelper.existsPage | 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 exists = file.exists();
LOGGER.debug("Page [{}]{}found", page, (exists ? " " : " not "));
return exists;
} | 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 exists = file.exists();
LOGGER.debug("Page [{}]{}found", page, (exists ? " " : " not "));
return exists;
} | [
"private",
"Boolean",
"existsPage",
"(",
"String",
"page",
")",
"throws",
"MalformedURLException",
"{",
"// Searching the page...",
"LOGGER",
".",
"debug",
"(",
"\"Searching page [{}]...\"",
",",
"page",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Page's real path is [{... | Checks if a given page exists in the container and could be served.
@param page
Page requested.
@return true if exists, false otherwise.
@throws MalformedURLException
if the page's URL is not right. | [
"Checks",
"if",
"a",
"given",
"page",
"exists",
"in",
"the",
"container",
"and",
"could",
"be",
"served",
"."
] | e617592af6f24e59ea58443f2785c44aa2312189 | https://github.com/eyp/serfj/blob/e617592af6f24e59ea58443f2785c44aa2312189/src/main/java/net/sf/serfj/ResponseHelper.java#L435-L443 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.createSet | 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> createSet(T... args) {
HashSet<T> newSet = new HashSet<T>();
Collections.addAll(newSet, args);
return newSet;
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"createSet",
"(",
"T",
"...",
"args",
")",
"{",
"HashSet",
"<",
"T",
">",
"newSet",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
";",
"Collections",
".",
"addAll",
"(",
"newSet",
",",
... | Convenience method for building a set from vararg arguments
@param args argument list
@param <T> set type
@return a new set created from var args | [
"Convenience",
"method",
"for",
"building",
"a",
"set",
"from",
"vararg",
"arguments"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L18-L22 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.arrayToSet | public static <T> Set<T> arrayToSet(T [] array) {
return new HashSet<T>(Arrays.asList(array));
} | java | public static <T> Set<T> arrayToSet(T [] array) {
return new HashSet<T>(Arrays.asList(array));
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"arrayToSet",
"(",
"T",
"[",
"]",
"array",
")",
"{",
"return",
"new",
"HashSet",
"<",
"T",
">",
"(",
"Arrays",
".",
"asList",
"(",
"array",
")",
")",
";",
"}"
] | Convenience method for building a set from an array
@param array
@param <T>
@return a new set created from var args | [
"Convenience",
"method",
"for",
"building",
"a",
"set",
"from",
"an",
"array"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L30-L32 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.intersection | 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> intersection(Set<T> setA, Set<T> setB) {
Set<T> intersection = new HashSet<T>(setA);
intersection.retainAll(setB);
return intersection;
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"intersection",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"Set",
"<",
"T",
">",
"intersection",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
"setA",
... | This method finds the intersection between set A and set B
@param setA set A
@param setB set B
@param <T> type
@return a new set containing the intersection | [
"This",
"method",
"finds",
"the",
"intersection",
"between",
"set",
"A",
"and",
"set",
"B"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L41-L45 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.union | 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> union(Set<T> setA, Set<T> setB) {
Set<T> union = new HashSet<T>(setA);
union.addAll(setB);
return union;
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"union",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"Set",
"<",
"T",
">",
"union",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
"setA",
")",
";",
... | This method finds the union of set A and set B
@param setA set A
@param setB set B
@param <T> type
@return a new set containing the union | [
"This",
"method",
"finds",
"the",
"union",
"of",
"set",
"A",
"and",
"set",
"B"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L54-L58 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.difference | 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> difference(Set<T> setA, Set<T> setB) {
Set<T> difference = new HashSet<T>(setA);
difference.removeAll(setB);
return difference;
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"difference",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"Set",
"<",
"T",
">",
"difference",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
"setA",
")",... | This method finds the difference between set A and set B i.e. set A minus set B
@param setA set A
@param setB set B
@param <T> type
@return a new set containing the difference | [
"This",
"method",
"finds",
"the",
"difference",
"between",
"set",
"A",
"and",
"set",
"B",
"i",
".",
"e",
".",
"set",
"A",
"minus",
"set",
"B"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L67-L71 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.symmetricDifference | 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> 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);
} | [
"public",
"static",
"<",
"T",
">",
"Set",
"<",
"T",
">",
"symmetricDifference",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"Set",
"<",
"T",
">",
"union",
"=",
"union",
"(",
"setA",
",",
"setB",
")",
";",
"... | This method finds the symmetric difference between set A and set B i.e. which items does not exist in either
set A or set B. This is the opposite of the intersect of set A and set B.
@param setA set A
@param setB set B
@param <T> type
@return a new set containing the symmetric difference | [
"This",
"method",
"finds",
"the",
"symmetric",
"difference",
"between",
"set",
"A",
"and",
"set",
"B",
"i",
".",
"e",
".",
"which",
"items",
"does",
"not",
"exist",
"in",
"either",
"set",
"A",
"or",
"set",
"B",
".",
"This",
"is",
"the",
"opposite",
"... | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L81-L85 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.isSubset | public static <T> boolean isSubset(Set<T> setA, Set<T> setB) {
return setB.containsAll(setA);
} | java | public static <T> boolean isSubset(Set<T> setA, Set<T> setB) {
return setB.containsAll(setA);
} | [
"public",
"static",
"<",
"T",
">",
"boolean",
"isSubset",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"return",
"setB",
".",
"containsAll",
"(",
"setA",
")",
";",
"}"
] | This method returns true if set A is a subset of set B
i.e. it answers the question if all items in A exists in B
@param setA set A
@param setB set B
@param <T> type
@return {@code boolean} true if A is a subset of B | [
"This",
"method",
"returns",
"true",
"if",
"set",
"A",
"is",
"a",
"subset",
"of",
"set",
"B",
"i",
".",
"e",
".",
"it",
"answers",
"the",
"question",
"if",
"all",
"items",
"in",
"A",
"exists",
"in",
"B"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L127-L129 | train |
btaz/data-util | src/main/java/com/btaz/util/collections/Sets.java | Sets.isSuperset | public static <T> boolean isSuperset(Set<T> setA, Set<T> setB) {
return setA.containsAll(setB);
} | java | public static <T> boolean isSuperset(Set<T> setA, Set<T> setB) {
return setA.containsAll(setB);
} | [
"public",
"static",
"<",
"T",
">",
"boolean",
"isSuperset",
"(",
"Set",
"<",
"T",
">",
"setA",
",",
"Set",
"<",
"T",
">",
"setB",
")",
"{",
"return",
"setA",
".",
"containsAll",
"(",
"setB",
")",
";",
"}"
] | This method returns true if set A is a superset of set B
i.e. it answers the question if A contains all items from B
@param setA set A
@param setB set B
@param <T> type
@return {@code boolean} true if A is a superset of B | [
"This",
"method",
"returns",
"true",
"if",
"set",
"A",
"is",
"a",
"superset",
"of",
"set",
"B",
"i",
".",
"e",
".",
"it",
"answers",
"the",
"question",
"if",
"A",
"contains",
"all",
"items",
"from",
"B"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/collections/Sets.java#L139-L141 | train |
Teddy-Zhu/SilentGo | utils/src/main/java/com/silentgo/utils/asm/Type.java | Type.getClassName | 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:
return "int";
case FLOAT:
return "float";
case LONG:
return "long";
case DOUBLE:
return "double";
case ARRAY:
StringBuilder sb = new StringBuilder(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) {
sb.append("[]");
}
return sb.toString();
case OBJECT:
return new String(buf, off, len).replace('/', '.').intern();
default:
return null;
}
} | 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:
return "int";
case FLOAT:
return "float";
case LONG:
return "long";
case DOUBLE:
return "double";
case ARRAY:
StringBuilder sb = new StringBuilder(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) {
sb.append("[]");
}
return sb.toString();
case OBJECT:
return new String(buf, off, len).replace('/', '.').intern();
default:
return null;
}
} | [
"public",
"String",
"getClassName",
"(",
")",
"{",
"switch",
"(",
"sort",
")",
"{",
"case",
"VOID",
":",
"return",
"\"void\"",
";",
"case",
"BOOLEAN",
":",
"return",
"\"boolean\"",
";",
"case",
"CHAR",
":",
"return",
"\"char\"",
";",
"case",
"BYTE",
":",... | Returns the binary name of the class corresponding to this type. This
method must not be used on method types.
@return the binary name of the class corresponding to this type. | [
"Returns",
"the",
"binary",
"name",
"of",
"the",
"class",
"corresponding",
"to",
"this",
"type",
".",
"This",
"method",
"must",
"not",
"be",
"used",
"on",
"method",
"types",
"."
] | 27f58b0cafe56b2eb9fc6993efa9ca2b529661e1 | https://github.com/Teddy-Zhu/SilentGo/blob/27f58b0cafe56b2eb9fc6993efa9ca2b529661e1/utils/src/main/java/com/silentgo/utils/asm/Type.java#L547-L578 | train |
passwordmaker/java-passwordmaker-lib | src/main/java/org/daveware/passwordmaker/AccountPatternMatcher.java | AccountPatternMatcher.matchUrl | 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))
return true;
} else if (type == AccountPatternType.WILDCARD) {
if (globMatch(pattern.getPattern(), url))
return true;
} else {
Logger logger = Logger.getLogger(AccountPatternMatcher.class.getName());
logger.warning("Unknown pattern match type '" + type.toString() + "' for account '" +
account.getName() + "' id='" + account.getId() + "'");
// meh
}
}
return account.getUrl().equalsIgnoreCase(url);
} | 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))
return true;
} else if (type == AccountPatternType.WILDCARD) {
if (globMatch(pattern.getPattern(), url))
return true;
} else {
Logger logger = Logger.getLogger(AccountPatternMatcher.class.getName());
logger.warning("Unknown pattern match type '" + type.toString() + "' for account '" +
account.getName() + "' id='" + account.getId() + "'");
// meh
}
}
return account.getUrl().equalsIgnoreCase(url);
} | [
"public",
"static",
"boolean",
"matchUrl",
"(",
"Account",
"account",
",",
"String",
"url",
")",
"{",
"for",
"(",
"AccountPatternData",
"pattern",
":",
"account",
".",
"getPatterns",
"(",
")",
")",
"{",
"AccountPatternType",
"type",
"=",
"pattern",
".",
"get... | Tests all patterns in an account for a match against the url string.
@param account The account to test with.
@param url THe url to test with.
@return true if one of the | [
"Tests",
"all",
"patterns",
"in",
"an",
"account",
"for",
"a",
"match",
"against",
"the",
"url",
"string",
"."
] | 18c22fca7dd9a47f08161425b85a5bd257afbb2b | https://github.com/passwordmaker/java-passwordmaker-lib/blob/18c22fca7dd9a47f08161425b85a5bd257afbb2b/src/main/java/org/daveware/passwordmaker/AccountPatternMatcher.java#L36-L53 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileDeleter.java | FileDeleter.deleteFilesByExtension | 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 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);
} | [
"public",
"static",
"void",
"deleteFilesByExtension",
"(",
"File",
"dir",
",",
"String",
"extension",
")",
"{",
"if",
"(",
"extension",
"==",
"null",
")",
"{",
"throw",
"new",
"DataUtilException",
"(",
"\"Filename extension can not be a null value\"",
")",
";",
"}... | Delete files in a directory matching a file extension
@param dir directory
@param extension filename extension | [
"Delete",
"files",
"in",
"a",
"directory",
"matching",
"a",
"file",
"extension"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileDeleter.java#L17-L23 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileDeleter.java | FileDeleter.deleteFilesByRegex | 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 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);
} | [
"public",
"static",
"void",
"deleteFilesByRegex",
"(",
"File",
"dir",
",",
"String",
"regex",
")",
"{",
"if",
"(",
"regex",
"==",
"null",
")",
"{",
"throw",
"new",
"DataUtilException",
"(",
"\"Filename regex can not be null\"",
")",
";",
"}",
"FilenameFilter",
... | Delete files in a directory matching a regular expression
@param dir directory
@param regex regular expression | [
"Delete",
"files",
"in",
"a",
"directory",
"matching",
"a",
"regular",
"expression"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileDeleter.java#L30-L36 | train |
btaz/data-util | src/main/java/com/btaz/util/files/FileDeleter.java | FileDeleter.deleteFiles | 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 delete directory does not exist: " + dir.getAbsolutePath());
}
// delete files
File [] files;
if(filter == null) {
files = dir.listFiles();
} else {
files = dir.listFiles(filter);
}
if (files != null) {
for(File file : files) {
if(file.isFile()) {
if(!file.delete()) {
throw new DataUtilException("Failed to delete file: " + file.getAbsolutePath());
}
}
}
}
} | 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 delete directory does not exist: " + dir.getAbsolutePath());
}
// delete files
File [] files;
if(filter == null) {
files = dir.listFiles();
} else {
files = dir.listFiles(filter);
}
if (files != null) {
for(File file : files) {
if(file.isFile()) {
if(!file.delete()) {
throw new DataUtilException("Failed to delete file: " + file.getAbsolutePath());
}
}
}
}
} | [
"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\""... | Delete files in a directory matching a filename filter
@param dir directory
@param filter filename filter, if null then delete all files | [
"Delete",
"files",
"in",
"a",
"directory",
"matching",
"a",
"filename",
"filter"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/files/FileDeleter.java#L43-L67 | train |
btaz/data-util | src/main/java/com/btaz/util/unit/ResourceUtil.java | ResourceUtil.readFromFileIntoString | 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;
while( (line = reader.readLine()) != null) {
text.append(line).append("\n");
}
inputStream.close();
return text.toString();
} | 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;
while( (line = reader.readLine()) != null) {
text.append(line).append("\n");
}
inputStream.close();
return text.toString();
} | [
"public",
"static",
"String",
"readFromFileIntoString",
"(",
"File",
"file",
")",
"throws",
"IOException",
"{",
"FileInputStream",
"inputStream",
"=",
"new",
"FileInputStream",
"(",
"file",
")",
";",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"... | This method reads all data from a file into a String object
@param file file to read text from
@return <code>String</code> containing all file data
@throws IOException IO exception | [
"This",
"method",
"reads",
"all",
"data",
"from",
"a",
"file",
"into",
"a",
"String",
"object"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/unit/ResourceUtil.java#L43-L55 | train |
btaz/data-util | src/main/java/com/btaz/util/unit/ResourceUtil.java | ResourceUtil.writeStringToTempFile | 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),DataUtilDefaults.charSet));
writer.write(data);
writer.flush();
writer.close();
return testFile;
} | 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),DataUtilDefaults.charSet));
writer.write(data);
writer.flush();
writer.close();
return testFile;
} | [
"public",
"static",
"File",
"writeStringToTempFile",
"(",
"String",
"prefix",
",",
"String",
"suffix",
",",
"String",
"data",
")",
"throws",
"IOException",
"{",
"File",
"testFile",
"=",
"File",
".",
"createTempFile",
"(",
"prefix",
",",
"suffix",
")",
";",
"... | This method writes all data from a string to a temp file. The file will be automatically deleted on JVM shutdown.
@param prefix file prefix i.e. "abc" in abc.txt
@param suffix file suffix i.e. ".txt" in abc.txt
@param data string containing the data to write to the file
@return <code>File</code> object
@throws IOException IO exception | [
"This",
"method",
"writes",
"all",
"data",
"from",
"a",
"string",
"to",
"a",
"temp",
"file",
".",
"The",
"file",
"will",
"be",
"automatically",
"deleted",
"on",
"JVM",
"shutdown",
"."
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/unit/ResourceUtil.java#L94-L103 | train |
btaz/data-util | src/main/java/com/btaz/util/unit/ResourceUtil.java | ResourceUtil.createRandomData | 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((char)(((int)'a') + random.nextFloat() * 25));
}
if(skipTrailingNewline || i<rows) {
strb.append("\n");
}
}
return strb.toString();
} | 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((char)(((int)'a') + random.nextFloat() * 25));
}
if(skipTrailingNewline || i<rows) {
strb.append("\n");
}
}
return strb.toString();
} | [
"public",
"static",
"String",
"createRandomData",
"(",
"int",
"rows",
",",
"int",
"rowLength",
",",
"boolean",
"skipTrailingNewline",
")",
"{",
"Random",
"random",
"=",
"new",
"Random",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"StringBuilde... | This method creates test data containing letters between a-z
@param rows how many rows of data to create
@param rowLength how many characters per row
@param skipTrailingNewline if true then a trailing newline is always added
@return <code>String</code> contain all random data | [
"This",
"method",
"creates",
"test",
"data",
"containing",
"letters",
"between",
"a",
"-",
"z"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/unit/ResourceUtil.java#L112-L124 | train |
btaz/data-util | src/main/java/com/btaz/util/unit/ResourceUtil.java | ResourceUtil.createTmpDir | 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());
}
testDir.deleteOnExit();
return testDir;
} | 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());
}
testDir.deleteOnExit();
return testDir;
} | [
"public",
"static",
"File",
"createTmpDir",
"(",
"String",
"directoryName",
")",
"{",
"File",
"tmpDir",
"=",
"new",
"File",
"(",
"System",
".",
"getProperty",
"(",
"\"java.io.tmpdir\"",
")",
")",
";",
"File",
"testDir",
"=",
"new",
"File",
"(",
"tmpDir",
"... | This method will create a new directory in the system temp folder
@param directoryName directory name | [
"This",
"method",
"will",
"create",
"a",
"new",
"directory",
"in",
"the",
"system",
"temp",
"folder"
] | f01de64854c456a88a31ffbe8bac6d605151b496 | https://github.com/btaz/data-util/blob/f01de64854c456a88a31ffbe8bac6d605151b496/src/main/java/com/btaz/util/unit/ResourceUtil.java#L130-L138 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.setCenterPoint | 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 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());
} | [
"public",
"static",
"Bbox",
"setCenterPoint",
"(",
"Bbox",
"bbox",
",",
"Coordinate",
"center",
")",
"{",
"double",
"x",
"=",
"center",
".",
"getX",
"(",
")",
"-",
"0.5",
"*",
"bbox",
".",
"getWidth",
"(",
")",
";",
"double",
"y",
"=",
"center",
".",... | Translate a bounding box by applying a new center point.
@param bbox
The original bounding box to translate. This one will remain untouched.
@param center
The new center point.
@return The result as a new bounding box. | [
"Translate",
"a",
"bounding",
"box",
"by",
"applying",
"a",
"new",
"center",
"point",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L80-L84 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.contains | 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 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;
} | [
"public",
"static",
"boolean",
"contains",
"(",
"Bbox",
"parent",
",",
"Bbox",
"child",
")",
"{",
"if",
"(",
"child",
".",
"getX",
"(",
")",
"<",
"parent",
".",
"getX",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"child",
".",
"ge... | Does one bounding box contain another?
@param parent
The parent bounding box in the relation. Does this one contain the child?
@param child
The child bounding box in the relation. Is this one contained within the parent?
@return true if the child is completely contained(surrounded) by the parent, false otherwise. | [
"Does",
"one",
"bounding",
"box",
"contain",
"another?"
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L106-L120 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.contains | 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;
}
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;
}
return true;
} | [
"public",
"static",
"boolean",
"contains",
"(",
"Bbox",
"bbox",
",",
"Coordinate",
"coordinate",
")",
"{",
"if",
"(",
"bbox",
".",
"getX",
"(",
")",
">=",
"coordinate",
".",
"getX",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"bbox",
... | Is the given coordinate contained within the bounding box or not? If the coordinate is on the bounding box
border, it is considered outside.
@param bbox
The bounding box.
@param coordinate
The coordinate to check.
@return True if the coordinate is within the bounding box, false otherwise.
@since 1.1.0 | [
"Is",
"the",
"given",
"coordinate",
"contained",
"within",
"the",
"bounding",
"box",
"or",
"not?",
"If",
"the",
"coordinate",
"is",
"on",
"the",
"bounding",
"box",
"border",
"it",
"is",
"considered",
"outside",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L133-L147 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.intersects | 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 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;
} | [
"public",
"static",
"boolean",
"intersects",
"(",
"Bbox",
"one",
",",
"Bbox",
"two",
")",
"{",
"if",
"(",
"two",
".",
"getX",
"(",
")",
">",
"one",
".",
"getMaxX",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"two",
".",
"getY",
... | Does one bounding box intersect another?
@param one
The first bounding box.
@param two
The second bounding box.
@return true if the both bounding boxes intersect, false otherwise. | [
"Does",
"one",
"bounding",
"box",
"intersect",
"another?"
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L158-L172 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.intersection | 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.getY();
double maxy = two.getMaxY() < one.getMaxY() ? two.getMaxY() : one.getMaxY();
return new Bbox(minx, miny, (maxx - minx), (maxy - miny));
}
} | 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.getY();
double maxy = two.getMaxY() < one.getMaxY() ? two.getMaxY() : one.getMaxY();
return new Bbox(minx, miny, (maxx - minx), (maxy - miny));
}
} | [
"public",
"static",
"Bbox",
"intersection",
"(",
"Bbox",
"one",
",",
"Bbox",
"two",
")",
"{",
"if",
"(",
"!",
"intersects",
"(",
"one",
",",
"two",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"double",
"minx",
"=",
"two",
".",
"getX",
... | Calculates the intersection between 2 bounding boxes.
@param one
The first bounding box.
@param two
The second bounding box.
@return A new bounding box representing intersection or null if they do not intersect. | [
"Calculates",
"the",
"intersection",
"between",
"2",
"bounding",
"boxes",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L183-L193 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.buffer | 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 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.");
} | [
"public",
"static",
"Bbox",
"buffer",
"(",
"Bbox",
"bbox",
",",
"double",
"range",
")",
"{",
"if",
"(",
"range",
">=",
"0",
")",
"{",
"double",
"r2",
"=",
"range",
"*",
"2",
";",
"return",
"new",
"Bbox",
"(",
"bbox",
".",
"getX",
"(",
")",
"-",
... | Return a new bounding box that has increased in size by adding a range to a given bounding box.
@param bbox
The original bounding box to calculate a buffer for. This one will remain untouched.
@param range
Must be a positive number, otherwise null will be returned.
@return The result as a new bounding box. | [
"Return",
"a",
"new",
"bounding",
"box",
"that",
"has",
"increased",
"in",
"size",
"by",
"adding",
"a",
"range",
"to",
"a",
"given",
"bounding",
"box",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L228-L234 | train |
geomajas/geomajas-project-geometry | core/src/main/java/org/geomajas/geometry/service/BboxService.java | BboxService.translate | public static Bbox translate(Bbox bbox, double deltaX, double deltaY) {
return new Bbox(bbox.getX() + deltaX, bbox.getY() + deltaY, bbox.getWidth(), bbox.getHeight());
} | java | public static Bbox translate(Bbox bbox, double deltaX, double deltaY) {
return new Bbox(bbox.getX() + deltaX, bbox.getY() + deltaY, bbox.getWidth(), bbox.getHeight());
} | [
"public",
"static",
"Bbox",
"translate",
"(",
"Bbox",
"bbox",
",",
"double",
"deltaX",
",",
"double",
"deltaY",
")",
"{",
"return",
"new",
"Bbox",
"(",
"bbox",
".",
"getX",
"(",
")",
"+",
"deltaX",
",",
"bbox",
".",
"getY",
"(",
")",
"+",
"deltaY",
... | Translate the given bounding box.
@param bbox
The original bounding box to scale. This one will remain untouched.
@param deltaX
Translation factor along the X-axis.
@param deltaY
Translation factor along the Y-axis.
@return The result as a new bounding box. | [
"Translate",
"the",
"given",
"bounding",
"box",
"."
] | 09a214fede69c9c01e41630828c4abbb551a557d | https://github.com/geomajas/geomajas-project-geometry/blob/09a214fede69c9c01e41630828c4abbb551a557d/core/src/main/java/org/geomajas/geometry/service/BboxService.java#L267-L269 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.