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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.unRegisterFunction | public static void unRegisterFunction(Statement st, Function function) throws SQLException {
String functionAlias = getStringProperty(function, Function.PROP_NAME);
if(functionAlias.isEmpty()) {
functionAlias = function.getClass().getSimpleName();
}
st.execute("DROP ALIAS IF EXISTS " + functionAlias);
} | java | public static void unRegisterFunction(Statement st, Function function) throws SQLException {
String functionAlias = getStringProperty(function, Function.PROP_NAME);
if(functionAlias.isEmpty()) {
functionAlias = function.getClass().getSimpleName();
}
st.execute("DROP ALIAS IF EXISTS " + functionAlias);
} | [
"public",
"static",
"void",
"unRegisterFunction",
"(",
"Statement",
"st",
",",
"Function",
"function",
")",
"throws",
"SQLException",
"{",
"String",
"functionAlias",
"=",
"getStringProperty",
"(",
"function",
",",
"Function",
".",
"PROP_NAME",
")",
";",
"if",
"(... | Remove the specified function from the provided DataBase connection
@param st Active statement
@param function function to remove
@throws SQLException | [
"Remove",
"the",
"specified",
"function",
"from",
"the",
"provided",
"DataBase",
"connection"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L518-L524 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.registerH2GISFunctions | private static void registerH2GISFunctions(Connection connection, String packagePrepend) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
try {
registerFunction(st, function, packagePrepend);
} catch (SQLException ex) {
// Catch to register other functions
ex.printStackTrace(System.err);
}
}
} | java | private static void registerH2GISFunctions(Connection connection, String packagePrepend) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
try {
registerFunction(st, function, packagePrepend);
} catch (SQLException ex) {
// Catch to register other functions
ex.printStackTrace(System.err);
}
}
} | [
"private",
"static",
"void",
"registerH2GISFunctions",
"(",
"Connection",
"connection",
",",
"String",
"packagePrepend",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"for",
"(",
"Function",
"funct... | Register all H2GIS functions
@param connection JDBC Connection
@param packagePrepend For OSGi environment only, use
Bundle-SymbolicName:Bundle-Version:
@throws SQLException | [
"Register",
"all",
"H2GIS",
"functions"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L535-L545 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java | H2GISFunctions.unRegisterH2GISFunctions | public static void unRegisterH2GISFunctions(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
unRegisterFunction(st, function);
}
unRegisterGeometryType(connection);
} | java | public static void unRegisterH2GISFunctions(Connection connection) throws SQLException {
Statement st = connection.createStatement();
for (Function function : getBuiltInsFunctions()) {
unRegisterFunction(st, function);
}
unRegisterGeometryType(connection);
} | [
"public",
"static",
"void",
"unRegisterH2GISFunctions",
"(",
"Connection",
"connection",
")",
"throws",
"SQLException",
"{",
"Statement",
"st",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"for",
"(",
"Function",
"function",
":",
"getBuiltInsFunctions",... | Unregister spatial type and H2GIS functions from the current connection.
@param connection Active H2 connection with DROP ALIAS rights
@throws java.sql.SQLException | [
"Unregister",
"spatial",
"type",
"and",
"H2GIS",
"functions",
"from",
"the",
"current",
"connection",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/factory/H2GISFunctions.java#L553-L559 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_IsValidReason.java | ST_IsValidReason.isValidReason | public static String isValidReason(Geometry geometry, int flag) {
if (geometry != null) {
if (flag == 0) {
return validReason(geometry, false);
} else if (flag == 1) {
return validReason(geometry, true);
} else {
throw new IllegalArgumentException("Supported arguments are 0 or 1.");
}
}
return "Null Geometry";
} | java | public static String isValidReason(Geometry geometry, int flag) {
if (geometry != null) {
if (flag == 0) {
return validReason(geometry, false);
} else if (flag == 1) {
return validReason(geometry, true);
} else {
throw new IllegalArgumentException("Supported arguments are 0 or 1.");
}
}
return "Null Geometry";
} | [
"public",
"static",
"String",
"isValidReason",
"(",
"Geometry",
"geometry",
",",
"int",
"flag",
")",
"{",
"if",
"(",
"geometry",
"!=",
"null",
")",
"{",
"if",
"(",
"flag",
"==",
"0",
")",
"{",
"return",
"validReason",
"(",
"geometry",
",",
"false",
")"... | Returns text stating whether a geometry is valid.
If not, returns a reason why.
@param geometry
@param flag
@return | [
"Returns",
"text",
"stating",
"whether",
"a",
"geometry",
"is",
"valid",
".",
"If",
"not",
"returns",
"a",
"reason",
"why",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_IsValidReason.java#L67-L78 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/topology/ST_Polygonize.java | ST_Polygonize.polygonize | public static Geometry polygonize(Geometry geometry) {
if(geometry == null){
return null;
}
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geometry);
Collection pols = polygonizer.getPolygons();
if(pols.isEmpty()){
return null;
}
return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols));
} | java | public static Geometry polygonize(Geometry geometry) {
if(geometry == null){
return null;
}
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geometry);
Collection pols = polygonizer.getPolygons();
if(pols.isEmpty()){
return null;
}
return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols));
} | [
"public",
"static",
"Geometry",
"polygonize",
"(",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Polygonizer",
"polygonizer",
"=",
"new",
"Polygonizer",
"(",
")",
";",
"polygonizer",
".",
"add... | Creates a GeometryCollection containing possible polygons formed
from the constituent linework of a set of geometries.
@param geometry
@return | [
"Creates",
"a",
"GeometryCollection",
"containing",
"possible",
"polygons",
"formed",
"from",
"the",
"constituent",
"linework",
"of",
"a",
"set",
"of",
"geometries",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/topology/ST_Polygonize.java#L55-L66 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java | MaxDistanceOp.computeMaxDistance | private void computeMaxDistance() {
HashSet<Coordinate> coordinatesA = new HashSet<Coordinate>(Arrays.asList(geomA.convexHull().getCoordinates()));
Geometry fullHull = geomA.getFactory().createGeometryCollection(new Geometry[]{geomA, geomB}).convexHull();
maxDistanceFilter = new MaxDistanceFilter(coordinatesA);
fullHull.apply(maxDistanceFilter);
} | java | private void computeMaxDistance() {
HashSet<Coordinate> coordinatesA = new HashSet<Coordinate>(Arrays.asList(geomA.convexHull().getCoordinates()));
Geometry fullHull = geomA.getFactory().createGeometryCollection(new Geometry[]{geomA, geomB}).convexHull();
maxDistanceFilter = new MaxDistanceFilter(coordinatesA);
fullHull.apply(maxDistanceFilter);
} | [
"private",
"void",
"computeMaxDistance",
"(",
")",
"{",
"HashSet",
"<",
"Coordinate",
">",
"coordinatesA",
"=",
"new",
"HashSet",
"<",
"Coordinate",
">",
"(",
"Arrays",
".",
"asList",
"(",
"geomA",
".",
"convexHull",
"(",
")",
".",
"getCoordinates",
"(",
"... | Compute the max distance | [
"Compute",
"the",
"max",
"distance"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java#L52-L57 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java | MaxDistanceOp.getDistance | public Double getDistance() {
if (geomA == null || geomB == null) {
return null;
}
if (geomA.isEmpty() || geomB.isEmpty()) {
return 0.0;
}
if (geomA.equals(geomB)) {
sameGeom = true;
}
if (maxDistanceFilter == null) {
computeMaxDistance();
}
return maxDistanceFilter.getDistance();
} | java | public Double getDistance() {
if (geomA == null || geomB == null) {
return null;
}
if (geomA.isEmpty() || geomB.isEmpty()) {
return 0.0;
}
if (geomA.equals(geomB)) {
sameGeom = true;
}
if (maxDistanceFilter == null) {
computeMaxDistance();
}
return maxDistanceFilter.getDistance();
} | [
"public",
"Double",
"getDistance",
"(",
")",
"{",
"if",
"(",
"geomA",
"==",
"null",
"||",
"geomB",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"geomA",
".",
"isEmpty",
"(",
")",
"||",
"geomB",
".",
"isEmpty",
"(",
")",
")",
"{"... | Return the max distance
@return | [
"Return",
"the",
"max",
"distance"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java#L64-L79 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java | MaxDistanceOp.getCoordinatesDistance | public Coordinate[] getCoordinatesDistance() {
if (geomA == null || geomB == null) {
return null;
}
if (geomA.isEmpty() || geomB.isEmpty()) {
return null;
}
if (geomA.equals(geomB)) {
sameGeom = true;
}
if (maxDistanceFilter == null) {
computeMaxDistance();
}
return maxDistanceFilter.getCoordinatesDistance();
} | java | public Coordinate[] getCoordinatesDistance() {
if (geomA == null || geomB == null) {
return null;
}
if (geomA.isEmpty() || geomB.isEmpty()) {
return null;
}
if (geomA.equals(geomB)) {
sameGeom = true;
}
if (maxDistanceFilter == null) {
computeMaxDistance();
}
return maxDistanceFilter.getCoordinatesDistance();
} | [
"public",
"Coordinate",
"[",
"]",
"getCoordinatesDistance",
"(",
")",
"{",
"if",
"(",
"geomA",
"==",
"null",
"||",
"geomB",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"geomA",
".",
"isEmpty",
"(",
")",
"||",
"geomB",
".",
"isEmpty... | Return the two coordinates to build the max distance line
@return | [
"Return",
"the",
"two",
"coordinates",
"to",
"build",
"the",
"max",
"distance",
"line"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/distance/MaxDistanceOp.java#L86-L102 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_GeomFromGML.java | ST_GeomFromGML.toGeometry | public static Geometry toGeometry(String gmlFile, int srid) throws SAXException, IOException, ParserConfigurationException {
if (gmlFile == null) {
return null;
}
if (gf == null) {
gf = new GeometryFactory(new PrecisionModel(), srid);
}
GMLReader gMLReader = new GMLReader();
return gMLReader.read(gmlFile, gf);
} | java | public static Geometry toGeometry(String gmlFile, int srid) throws SAXException, IOException, ParserConfigurationException {
if (gmlFile == null) {
return null;
}
if (gf == null) {
gf = new GeometryFactory(new PrecisionModel(), srid);
}
GMLReader gMLReader = new GMLReader();
return gMLReader.read(gmlFile, gf);
} | [
"public",
"static",
"Geometry",
"toGeometry",
"(",
"String",
"gmlFile",
",",
"int",
"srid",
")",
"throws",
"SAXException",
",",
"IOException",
",",
"ParserConfigurationException",
"{",
"if",
"(",
"gmlFile",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
... | Read the GML representation with a specified SRID
@param gmlFile
@param srid
@return
@throws org.xml.sax.SAXException
@throws java.io.IOException
@throws javax.xml.parsers.ParserConfigurationException | [
"Read",
"the",
"GML",
"representation",
"with",
"a",
"specified",
"SRID"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/ST_GeomFromGML.java#L74-L83 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.write | public void write(ProgressVisitor progress, ResultSet rs, File fileName, String encoding) throws SQLException, IOException {
if (FileUtil.isExtensionWellFormated(fileName, "geojson")) {
FileOutputStream fos = null;
JsonEncoding jsonEncoding = JsonEncoding.UTF8;
if (encoding != null) {
try {
jsonEncoding = JsonEncoding.valueOf(encoding);
} catch (IllegalArgumentException ex) {
throw new SQLException("Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported");
}
}
try {
fos = new FileOutputStream(fileName);
int rowCount = 0;
int type = rs.getType();
if (type == ResultSet.TYPE_SCROLL_INSENSITIVE || type == ResultSet.TYPE_SCROLL_SENSITIVE) {
rs.last();
rowCount = rs.getRow();
rs.beforeFirst();
}
ProgressVisitor copyProgress = progress.subProcess(rowCount);
// Read Geometry Index and type
List<String> spatialFieldNames = SFSUtilities.getGeometryFields(rs);
if (spatialFieldNames.isEmpty()) {
throw new SQLException("The resulset %s does not contain a geometry field");
}
JsonFactory jsonFactory = new JsonFactory();
JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos), jsonEncoding);
// header of the GeoJSON file
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "FeatureCollection");
jsonGenerator.writeArrayFieldStart("features");
try {
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0));
cacheMetadata(resultSetMetaData);
while (rs.next()) {
writeFeature(jsonGenerator, rs, geoFieldIndex);
copyProgress.endStep();
}
copyProgress.endOfProgress();
// footer
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
jsonGenerator.flush();
jsonGenerator.close();
} finally {
rs.close();
}
} catch (FileNotFoundException ex) {
throw new SQLException(ex);
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ex) {
throw new SQLException(ex);
}
}
} else {
throw new SQLException("Only .geojson extension is supported");
}
} | java | public void write(ProgressVisitor progress, ResultSet rs, File fileName, String encoding) throws SQLException, IOException {
if (FileUtil.isExtensionWellFormated(fileName, "geojson")) {
FileOutputStream fos = null;
JsonEncoding jsonEncoding = JsonEncoding.UTF8;
if (encoding != null) {
try {
jsonEncoding = JsonEncoding.valueOf(encoding);
} catch (IllegalArgumentException ex) {
throw new SQLException("Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported");
}
}
try {
fos = new FileOutputStream(fileName);
int rowCount = 0;
int type = rs.getType();
if (type == ResultSet.TYPE_SCROLL_INSENSITIVE || type == ResultSet.TYPE_SCROLL_SENSITIVE) {
rs.last();
rowCount = rs.getRow();
rs.beforeFirst();
}
ProgressVisitor copyProgress = progress.subProcess(rowCount);
// Read Geometry Index and type
List<String> spatialFieldNames = SFSUtilities.getGeometryFields(rs);
if (spatialFieldNames.isEmpty()) {
throw new SQLException("The resulset %s does not contain a geometry field");
}
JsonFactory jsonFactory = new JsonFactory();
JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos), jsonEncoding);
// header of the GeoJSON file
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "FeatureCollection");
jsonGenerator.writeArrayFieldStart("features");
try {
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0));
cacheMetadata(resultSetMetaData);
while (rs.next()) {
writeFeature(jsonGenerator, rs, geoFieldIndex);
copyProgress.endStep();
}
copyProgress.endOfProgress();
// footer
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
jsonGenerator.flush();
jsonGenerator.close();
} finally {
rs.close();
}
} catch (FileNotFoundException ex) {
throw new SQLException(ex);
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ex) {
throw new SQLException(ex);
}
}
} else {
throw new SQLException("Only .geojson extension is supported");
}
} | [
"public",
"void",
"write",
"(",
"ProgressVisitor",
"progress",
",",
"ResultSet",
"rs",
",",
"File",
"fileName",
",",
"String",
"encoding",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"if",
"(",
"FileUtil",
".",
"isExtensionWellFormated",
"(",
"fileNa... | Write a resulset to a geojson file
@param progress
@param rs input resulset
@param fileName the output file
@param encoding
@throws SQLException
@throws java.io.IOException | [
"Write",
"a",
"resulset",
"to",
"a",
"geojson",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L99-L166 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.writeFeature | private void writeFeature(JsonGenerator jsonGenerator, ResultSet rs, int geoFieldIndex) throws IOException, SQLException {
// feature header
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "Feature");
//Write the first geometry
writeGeometry((Geometry) rs.getObject(geoFieldIndex), jsonGenerator);
//Write the properties
writeProperties(jsonGenerator, rs);
// feature footer
jsonGenerator.writeEndObject();
} | java | private void writeFeature(JsonGenerator jsonGenerator, ResultSet rs, int geoFieldIndex) throws IOException, SQLException {
// feature header
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", "Feature");
//Write the first geometry
writeGeometry((Geometry) rs.getObject(geoFieldIndex), jsonGenerator);
//Write the properties
writeProperties(jsonGenerator, rs);
// feature footer
jsonGenerator.writeEndObject();
} | [
"private",
"void",
"writeFeature",
"(",
"JsonGenerator",
"jsonGenerator",
",",
"ResultSet",
"rs",
",",
"int",
"geoFieldIndex",
")",
"throws",
"IOException",
",",
"SQLException",
"{",
"// feature header",
"jsonGenerator",
".",
"writeStartObject",
"(",
")",
";",
"json... | Write a GeoJSON feature.
Features in GeoJSON contain a geometry object and additional properties,
and a feature collection represents a list of features.
A complete GeoJSON data structure is always an object (in JSON terms). In
GeoJSON, an object consists of a collection of name/value pairs -- also
called members. For each member, the name is always a string. Member
values are either a string, number, object, array or one of the literals:
true, false, and null. An array consists of elements where each element
is a value as described above.
Syntax:
{ "type": "Feature", "geometry":{"type": "Point", "coordinates": [102.0,
0.5]}, "properties": {"prop0": "value0"} }
@param writer
@param resultSetMetaData
@param geoFieldIndex | [
"Write",
"a",
"GeoJSON",
"feature",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L288-L298 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.cacheMetadata | private void cacheMetadata(ResultSetMetaData resultSetMetaData) throws SQLException {
cachedColumnNames = new LinkedHashMap<String, Integer>();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
final String fieldTypeName = resultSetMetaData.getColumnTypeName(i);
if (!fieldTypeName.equalsIgnoreCase("geometry")
&& isSupportedPropertyType(resultSetMetaData.getColumnType(i), fieldTypeName)) {
cachedColumnNames.put(resultSetMetaData.getColumnName(i).toUpperCase(), i);
columnCountProperties++;
}
}
} | java | private void cacheMetadata(ResultSetMetaData resultSetMetaData) throws SQLException {
cachedColumnNames = new LinkedHashMap<String, Integer>();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
final String fieldTypeName = resultSetMetaData.getColumnTypeName(i);
if (!fieldTypeName.equalsIgnoreCase("geometry")
&& isSupportedPropertyType(resultSetMetaData.getColumnType(i), fieldTypeName)) {
cachedColumnNames.put(resultSetMetaData.getColumnName(i).toUpperCase(), i);
columnCountProperties++;
}
}
} | [
"private",
"void",
"cacheMetadata",
"(",
"ResultSetMetaData",
"resultSetMetaData",
")",
"throws",
"SQLException",
"{",
"cachedColumnNames",
"=",
"new",
"LinkedHashMap",
"<",
"String",
",",
"Integer",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
... | Cache the column name and its index.
@param resultSetMetaData
@throws SQLException | [
"Cache",
"the",
"column",
"name",
"and",
"its",
"index",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L306-L316 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.writeGeometry | private void writeGeometry(Geometry geom, JsonGenerator gen) throws IOException {
if (geom != null) {
gen.writeObjectFieldStart("geometry");
if (geom instanceof Point) {
write((Point) geom, gen);
} else if (geom instanceof MultiPoint) {
write((MultiPoint) geom, gen);
} else if (geom instanceof LineString) {
write((LineString) geom, gen);
} else if (geom instanceof MultiLineString) {
write((MultiLineString) geom, gen);
} else if (geom instanceof Polygon) {
write((Polygon) geom, gen);
} else if (geom instanceof MultiPolygon) {
write((MultiPolygon) geom, gen);
} else if (geom instanceof GeometryCollection) {
write((GeometryCollection) geom, gen);
} else {
throw new RuntimeException("Unsupported Geomery type");
}
gen.writeEndObject();
} else {
gen.writeNullField("geometry");
}
} | java | private void writeGeometry(Geometry geom, JsonGenerator gen) throws IOException {
if (geom != null) {
gen.writeObjectFieldStart("geometry");
if (geom instanceof Point) {
write((Point) geom, gen);
} else if (geom instanceof MultiPoint) {
write((MultiPoint) geom, gen);
} else if (geom instanceof LineString) {
write((LineString) geom, gen);
} else if (geom instanceof MultiLineString) {
write((MultiLineString) geom, gen);
} else if (geom instanceof Polygon) {
write((Polygon) geom, gen);
} else if (geom instanceof MultiPolygon) {
write((MultiPolygon) geom, gen);
} else if (geom instanceof GeometryCollection) {
write((GeometryCollection) geom, gen);
} else {
throw new RuntimeException("Unsupported Geomery type");
}
gen.writeEndObject();
} else {
gen.writeNullField("geometry");
}
} | [
"private",
"void",
"writeGeometry",
"(",
"Geometry",
"geom",
",",
"JsonGenerator",
"gen",
")",
"throws",
"IOException",
"{",
"if",
"(",
"geom",
"!=",
"null",
")",
"{",
"gen",
".",
"writeObjectFieldStart",
"(",
"\"geometry\"",
")",
";",
"if",
"(",
"geom",
"... | Write a JTS geometry to its GeoJSON geometry representation.
Syntax:
"geometry":{"type": "Point", "coordinates": [102.0, 0.5]}
@param jsonGenerator
@param geometry | [
"Write",
"a",
"JTS",
"geometry",
"to",
"its",
"GeoJSON",
"geometry",
"representation",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L328-L353 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.writeProperties | private void writeProperties(JsonGenerator jsonGenerator, ResultSet rs) throws IOException, SQLException {
if (columnCountProperties != -1) {
jsonGenerator.writeObjectFieldStart("properties");
for (Map.Entry<String, Integer> entry : cachedColumnNames.entrySet()) {
String string = entry.getKey();
string = string.toLowerCase();
Integer fieldId = entry.getValue();
if (rs.getObject(fieldId) instanceof Object[]) {
Object[] array = (Object[]) rs.getObject(fieldId);
jsonGenerator.writeArrayFieldStart(string);
writeArray(jsonGenerator, array, true);
jsonGenerator.writeEndArray();
} else if (rs.getObject(fieldId) != null && rs.getObject(fieldId).equals("{}")){
jsonGenerator.writeObjectFieldStart(string);
jsonGenerator.writeEndObject();
} else if (rs.getObject(fieldId) == "null") {
jsonGenerator.writeFieldName(string);
jsonGenerator.writeNull();
} else {
jsonGenerator.writeObjectField(string, rs.getObject(fieldId));
}
}
jsonGenerator.writeEndObject();
}
} | java | private void writeProperties(JsonGenerator jsonGenerator, ResultSet rs) throws IOException, SQLException {
if (columnCountProperties != -1) {
jsonGenerator.writeObjectFieldStart("properties");
for (Map.Entry<String, Integer> entry : cachedColumnNames.entrySet()) {
String string = entry.getKey();
string = string.toLowerCase();
Integer fieldId = entry.getValue();
if (rs.getObject(fieldId) instanceof Object[]) {
Object[] array = (Object[]) rs.getObject(fieldId);
jsonGenerator.writeArrayFieldStart(string);
writeArray(jsonGenerator, array, true);
jsonGenerator.writeEndArray();
} else if (rs.getObject(fieldId) != null && rs.getObject(fieldId).equals("{}")){
jsonGenerator.writeObjectFieldStart(string);
jsonGenerator.writeEndObject();
} else if (rs.getObject(fieldId) == "null") {
jsonGenerator.writeFieldName(string);
jsonGenerator.writeNull();
} else {
jsonGenerator.writeObjectField(string, rs.getObject(fieldId));
}
}
jsonGenerator.writeEndObject();
}
} | [
"private",
"void",
"writeProperties",
"(",
"JsonGenerator",
"jsonGenerator",
",",
"ResultSet",
"rs",
")",
"throws",
"IOException",
",",
"SQLException",
"{",
"if",
"(",
"columnCountProperties",
"!=",
"-",
"1",
")",
"{",
"jsonGenerator",
".",
"writeObjectFieldStart",
... | Write the GeoJSON properties.
@param jsonGenerator
@param rs
@throws IOException | [
"Write",
"the",
"GeoJSON",
"properties",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L564-L588 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.isSupportedPropertyType | public boolean isSupportedPropertyType(int sqlTypeId, String sqlTypeName) throws SQLException {
switch (sqlTypeId) {
case Types.BOOLEAN:
case Types.DOUBLE:
case Types.FLOAT:
case Types.INTEGER:
case Types.BIGINT:
case Types.SMALLINT:
case Types.DATE:
case Types.VARCHAR:
case Types.NCHAR:
case Types.CHAR:
case Types.ARRAY:
case Types.OTHER:
case Types.DECIMAL:
case Types.REAL:
case Types.TINYINT:
case Types.NUMERIC:
case Types.NULL:
return true;
default:
throw new SQLException("Field type not supported by GeoJSON driver: " + sqlTypeName);
}
} | java | public boolean isSupportedPropertyType(int sqlTypeId, String sqlTypeName) throws SQLException {
switch (sqlTypeId) {
case Types.BOOLEAN:
case Types.DOUBLE:
case Types.FLOAT:
case Types.INTEGER:
case Types.BIGINT:
case Types.SMALLINT:
case Types.DATE:
case Types.VARCHAR:
case Types.NCHAR:
case Types.CHAR:
case Types.ARRAY:
case Types.OTHER:
case Types.DECIMAL:
case Types.REAL:
case Types.TINYINT:
case Types.NUMERIC:
case Types.NULL:
return true;
default:
throw new SQLException("Field type not supported by GeoJSON driver: " + sqlTypeName);
}
} | [
"public",
"boolean",
"isSupportedPropertyType",
"(",
"int",
"sqlTypeId",
",",
"String",
"sqlTypeName",
")",
"throws",
"SQLException",
"{",
"switch",
"(",
"sqlTypeId",
")",
"{",
"case",
"Types",
".",
"BOOLEAN",
":",
"case",
"Types",
".",
"DOUBLE",
":",
"case",
... | Return true is the SQL type is supported by the GeoJSON driver.
@param sqlTypeId
@param sqlTypeName
@return
@throws SQLException | [
"Return",
"true",
"is",
"the",
"SQL",
"type",
"is",
"supported",
"by",
"the",
"GeoJSON",
"driver",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L598-L621 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.writeCRS | private void writeCRS(JsonGenerator jsonGenerator, String[] authorityAndSRID) throws IOException {
if (authorityAndSRID[1] != null) {
jsonGenerator.writeObjectFieldStart("crs");
jsonGenerator.writeStringField("type", "name");
jsonGenerator.writeObjectFieldStart("properties");
StringBuilder sb = new StringBuilder("urn:ogc:def:crs:");
sb.append(authorityAndSRID[0]).append("::").append(authorityAndSRID[1]);
jsonGenerator.writeStringField("name", sb.toString());
jsonGenerator.writeEndObject();
jsonGenerator.writeEndObject();
}
} | java | private void writeCRS(JsonGenerator jsonGenerator, String[] authorityAndSRID) throws IOException {
if (authorityAndSRID[1] != null) {
jsonGenerator.writeObjectFieldStart("crs");
jsonGenerator.writeStringField("type", "name");
jsonGenerator.writeObjectFieldStart("properties");
StringBuilder sb = new StringBuilder("urn:ogc:def:crs:");
sb.append(authorityAndSRID[0]).append("::").append(authorityAndSRID[1]);
jsonGenerator.writeStringField("name", sb.toString());
jsonGenerator.writeEndObject();
jsonGenerator.writeEndObject();
}
} | [
"private",
"void",
"writeCRS",
"(",
"JsonGenerator",
"jsonGenerator",
",",
"String",
"[",
"]",
"authorityAndSRID",
")",
"throws",
"IOException",
"{",
"if",
"(",
"authorityAndSRID",
"[",
"1",
"]",
"!=",
"null",
")",
"{",
"jsonGenerator",
".",
"writeObjectFieldSta... | Write the CRS in the geojson
@param jsonGenerator
@param authorityAndSRID
@throws IOException | [
"Write",
"the",
"CRS",
"in",
"the",
"geojson"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L630-L641 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java | GeoJsonWriteDriver.writeArray | private void writeArray(JsonGenerator jsonGenerator, Object[] array, boolean firstInHierarchy) throws IOException, SQLException {
if(!firstInHierarchy) {
jsonGenerator.writeStartArray();
}
for(int i = 0; i < array.length; i++) {
if (array[i] instanceof Integer) {
jsonGenerator.writeNumber((int) array[i]);
} else if (array[i] instanceof String) {
if (array[i].equals("{}")) {
jsonGenerator.writeStartObject();
jsonGenerator.writeEndObject();
} else {
jsonGenerator.writeString((String) array[i]);
}
} else if (array[i] instanceof Double) {
jsonGenerator.writeNumber((double) array[i]);
} else if (array[i] instanceof Boolean) {
jsonGenerator.writeBoolean((boolean) array[i]);
} else if (array[i] instanceof Object[]) {
writeArray(jsonGenerator, (Object[]) array[i], false);
}
}
if(!firstInHierarchy) {
jsonGenerator.writeEndArray();
}
} | java | private void writeArray(JsonGenerator jsonGenerator, Object[] array, boolean firstInHierarchy) throws IOException, SQLException {
if(!firstInHierarchy) {
jsonGenerator.writeStartArray();
}
for(int i = 0; i < array.length; i++) {
if (array[i] instanceof Integer) {
jsonGenerator.writeNumber((int) array[i]);
} else if (array[i] instanceof String) {
if (array[i].equals("{}")) {
jsonGenerator.writeStartObject();
jsonGenerator.writeEndObject();
} else {
jsonGenerator.writeString((String) array[i]);
}
} else if (array[i] instanceof Double) {
jsonGenerator.writeNumber((double) array[i]);
} else if (array[i] instanceof Boolean) {
jsonGenerator.writeBoolean((boolean) array[i]);
} else if (array[i] instanceof Object[]) {
writeArray(jsonGenerator, (Object[]) array[i], false);
}
}
if(!firstInHierarchy) {
jsonGenerator.writeEndArray();
}
} | [
"private",
"void",
"writeArray",
"(",
"JsonGenerator",
"jsonGenerator",
",",
"Object",
"[",
"]",
"array",
",",
"boolean",
"firstInHierarchy",
")",
"throws",
"IOException",
",",
"SQLException",
"{",
"if",
"(",
"!",
"firstInHierarchy",
")",
"{",
"jsonGenerator",
"... | Write the array in the geojson
@param jsonGenerator
@param array
@throw IOException | [
"Write",
"the",
"array",
"in",
"the",
"geojson"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonWriteDriver.java#L650-L675 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_SideBuffer.java | ST_SideBuffer.singleSideBuffer | public static Geometry singleSideBuffer(Geometry geometry, double distance){
if(geometry==null){
return null;
}
return computeSingleSideBuffer(geometry, distance, new BufferParameters());
} | java | public static Geometry singleSideBuffer(Geometry geometry, double distance){
if(geometry==null){
return null;
}
return computeSingleSideBuffer(geometry, distance, new BufferParameters());
} | [
"public",
"static",
"Geometry",
"singleSideBuffer",
"(",
"Geometry",
"geometry",
",",
"double",
"distance",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"computeSingleSideBuffer",
"(",
"geometry",
",",
"distanc... | Compute a single side buffer with default parameters
@param geometry
@param distance
@return | [
"Compute",
"a",
"single",
"side",
"buffer",
"with",
"default",
"parameters"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_SideBuffer.java#L58-L63 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_SideBuffer.java | ST_SideBuffer.computeSingleSideBuffer | private static Geometry computeSingleSideBuffer(Geometry geometry, double distance, BufferParameters bufferParameters){
bufferParameters.setSingleSided(true);
return BufferOp.bufferOp(geometry, distance, bufferParameters);
} | java | private static Geometry computeSingleSideBuffer(Geometry geometry, double distance, BufferParameters bufferParameters){
bufferParameters.setSingleSided(true);
return BufferOp.bufferOp(geometry, distance, bufferParameters);
} | [
"private",
"static",
"Geometry",
"computeSingleSideBuffer",
"(",
"Geometry",
"geometry",
",",
"double",
"distance",
",",
"BufferParameters",
"bufferParameters",
")",
"{",
"bufferParameters",
".",
"setSingleSided",
"(",
"true",
")",
";",
"return",
"BufferOp",
".",
"b... | Compute the buffer
@param geometry
@param distance
@param bufferParameters
@return | [
"Compute",
"the",
"buffer"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/buffer/ST_SideBuffer.java#L111-L114 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/predicates/ST_Equals.java | ST_Equals.geomEquals | public static Boolean geomEquals(Geometry a, Geometry b) {
if(a==null || b==null) {
return null;
}
return a.equals(b);
} | java | public static Boolean geomEquals(Geometry a, Geometry b) {
if(a==null || b==null) {
return null;
}
return a.equals(b);
} | [
"public",
"static",
"Boolean",
"geomEquals",
"(",
"Geometry",
"a",
",",
"Geometry",
"b",
")",
"{",
"if",
"(",
"a",
"==",
"null",
"||",
"b",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"a",
".",
"equals",
"(",
"b",
")",
";",
"}"
... | Return true if Geometry A is equal to Geometry B
@param a Geometry Geometry.
@param b Geometry instance
@return true if Geometry A is equal to Geometry B | [
"Return",
"true",
"if",
"Geometry",
"A",
"is",
"equal",
"to",
"Geometry",
"B"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/predicates/ST_Equals.java#L51-L56 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/aggregate/ST_Accum.java | ST_Accum.addGeometry | private void addGeometry(Geometry geom) {
if (geom != null) {
if (geom instanceof GeometryCollection) {
List<Geometry> toUnitTmp = new ArrayList<Geometry>(geom.getNumGeometries());
for (int i = 0; i < geom.getNumGeometries(); i++) {
toUnitTmp.add(geom.getGeometryN(i));
feedDim(geom.getGeometryN(i));
}
toUnite.addAll(toUnitTmp);
} else {
toUnite.add(geom);
feedDim(geom);
}
}
} | java | private void addGeometry(Geometry geom) {
if (geom != null) {
if (geom instanceof GeometryCollection) {
List<Geometry> toUnitTmp = new ArrayList<Geometry>(geom.getNumGeometries());
for (int i = 0; i < geom.getNumGeometries(); i++) {
toUnitTmp.add(geom.getGeometryN(i));
feedDim(geom.getGeometryN(i));
}
toUnite.addAll(toUnitTmp);
} else {
toUnite.add(geom);
feedDim(geom);
}
}
} | [
"private",
"void",
"addGeometry",
"(",
"Geometry",
"geom",
")",
"{",
"if",
"(",
"geom",
"!=",
"null",
")",
"{",
"if",
"(",
"geom",
"instanceof",
"GeometryCollection",
")",
"{",
"List",
"<",
"Geometry",
">",
"toUnitTmp",
"=",
"new",
"ArrayList",
"<",
"Geo... | Add geometry into an array to accumulate
@param geom | [
"Add",
"geometry",
"into",
"an",
"array",
"to",
"accumulate"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/aggregate/ST_Accum.java#L76-L90 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonDriverFunction.java | GeoJsonDriverFunction.exportTable | @Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException{
GeoJsonWriteDriver geoJsonDriver = new GeoJsonWriteDriver(connection);
geoJsonDriver.write(progress,tableReference, fileName, encoding);
} | java | @Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException{
GeoJsonWriteDriver geoJsonDriver = new GeoJsonWriteDriver(connection);
geoJsonDriver.write(progress,tableReference, fileName, encoding);
} | [
"@",
"Override",
"public",
"void",
"exportTable",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
",",
"File",
"fileName",
",",
"ProgressVisitor",
"progress",
",",
"String",
"encoding",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"Geo... | Export a table or a query to a geojson file
@param connection
@param tableReference
@param fileName
@param progress
@param encoding
@throws SQLException
@throws IOException | [
"Export",
"a",
"table",
"or",
"a",
"query",
"to",
"a",
"geojson",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/geojson/GeoJsonDriverFunction.java#L88-L92 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMPreParser.java | OSMPreParser.startElement | @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (localName.compareToIgnoreCase("osm") == 0) {
version = attributes.getValue(GPXTags.VERSION);
} else if (localName.compareToIgnoreCase("node") == 0) {
totalNode++;
} else if (localName.compareToIgnoreCase("way") == 0) {
totalWay++;
} else if (localName.compareToIgnoreCase("relation") == 0) {
totalRelation++;
}
} | java | @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (localName.compareToIgnoreCase("osm") == 0) {
version = attributes.getValue(GPXTags.VERSION);
} else if (localName.compareToIgnoreCase("node") == 0) {
totalNode++;
} else if (localName.compareToIgnoreCase("way") == 0) {
totalWay++;
} else if (localName.compareToIgnoreCase("relation") == 0) {
totalRelation++;
}
} | [
"@",
"Override",
"public",
"void",
"startElement",
"(",
"String",
"uri",
",",
"String",
"localName",
",",
"String",
"qName",
",",
"Attributes",
"attributes",
")",
"throws",
"SAXException",
"{",
"if",
"(",
"localName",
".",
"compareToIgnoreCase",
"(",
"\"osm\"",
... | Fires whenever an XML start markup is encountered. It indicates which
version of osm file is to be parsed.
@param uri URI of the local element
@param localName Name of the local element (without prefix)
@param qName qName of the local element (with prefix)
@param attributes Attributes of the local element (contained in the
markup)
@throws SAXException Any SAX exception, possibly wrapping another
exception | [
"Fires",
"whenever",
"an",
"XML",
"start",
"markup",
"is",
"encountered",
".",
"It",
"indicates",
"which",
"version",
"of",
"osm",
"file",
"is",
"to",
"be",
"parsed",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/osm/OSMPreParser.java#L92-L103 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.addPoint | public static Geometry addPoint(Geometry geometry, Point point) throws SQLException {
return addPoint(geometry, point, PRECISION);
} | java | public static Geometry addPoint(Geometry geometry, Point point) throws SQLException {
return addPoint(geometry, point, PRECISION);
} | [
"public",
"static",
"Geometry",
"addPoint",
"(",
"Geometry",
"geometry",
",",
"Point",
"point",
")",
"throws",
"SQLException",
"{",
"return",
"addPoint",
"(",
"geometry",
",",
"point",
",",
"PRECISION",
")",
";",
"}"
] | Returns a new geometry based on an existing one, with a specific point as
a new vertex. A default distance 10E-6 is used to snap the input point.
@param geometry
@param point
@return
@throws SQLException | [
"Returns",
"a",
"new",
"geometry",
"based",
"on",
"an",
"existing",
"one",
"with",
"a",
"specific",
"point",
"as",
"a",
"new",
"vertex",
".",
"A",
"default",
"distance",
"10E",
"-",
"6",
"is",
"used",
"to",
"snap",
"the",
"input",
"point",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L60-L62 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.addPoint | public static Geometry addPoint(Geometry geometry, Point point, double tolerance) throws SQLException {
if(geometry == null || point == null){
return null;
}
if (geometry instanceof MultiPoint) {
return insertVertexInMultipoint(geometry, point);
} else if (geometry instanceof LineString) {
return insertVertexInLineString((LineString) geometry, point, tolerance);
} else if (geometry instanceof MultiLineString) {
LineString[] linestrings = new LineString[geometry.getNumGeometries()];
boolean any = false;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
LineString line = (LineString) geometry.getGeometryN(i);
LineString inserted = insertVertexInLineString(line, point, tolerance);
if (inserted != null) {
linestrings[i] = inserted;
any = true;
} else {
linestrings[i] = line;
}
}
if (any) {
return FACTORY.createMultiLineString(linestrings);
} else {
return null;
}
} else if (geometry instanceof Polygon) {
return insertVertexInPolygon((Polygon) geometry, point, tolerance);
} else if (geometry instanceof MultiPolygon) {
Polygon[] polygons = new Polygon[geometry.getNumGeometries()];
boolean any = false;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
Polygon inserted = insertVertexInPolygon(polygon, point, tolerance);
if (inserted != null) {
any = true;
polygons[i] = inserted;
} else {
polygons[i] = polygon;
}
}
if (any) {
return FACTORY.createMultiPolygon(polygons);
} else {
return null;
}
} else if (geometry instanceof Point) {
return null;
}
throw new SQLException("Unknown geometry type" + " : " + geometry.getGeometryType());
} | java | public static Geometry addPoint(Geometry geometry, Point point, double tolerance) throws SQLException {
if(geometry == null || point == null){
return null;
}
if (geometry instanceof MultiPoint) {
return insertVertexInMultipoint(geometry, point);
} else if (geometry instanceof LineString) {
return insertVertexInLineString((LineString) geometry, point, tolerance);
} else if (geometry instanceof MultiLineString) {
LineString[] linestrings = new LineString[geometry.getNumGeometries()];
boolean any = false;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
LineString line = (LineString) geometry.getGeometryN(i);
LineString inserted = insertVertexInLineString(line, point, tolerance);
if (inserted != null) {
linestrings[i] = inserted;
any = true;
} else {
linestrings[i] = line;
}
}
if (any) {
return FACTORY.createMultiLineString(linestrings);
} else {
return null;
}
} else if (geometry instanceof Polygon) {
return insertVertexInPolygon((Polygon) geometry, point, tolerance);
} else if (geometry instanceof MultiPolygon) {
Polygon[] polygons = new Polygon[geometry.getNumGeometries()];
boolean any = false;
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
Polygon inserted = insertVertexInPolygon(polygon, point, tolerance);
if (inserted != null) {
any = true;
polygons[i] = inserted;
} else {
polygons[i] = polygon;
}
}
if (any) {
return FACTORY.createMultiPolygon(polygons);
} else {
return null;
}
} else if (geometry instanceof Point) {
return null;
}
throw new SQLException("Unknown geometry type" + " : " + geometry.getGeometryType());
} | [
"public",
"static",
"Geometry",
"addPoint",
"(",
"Geometry",
"geometry",
",",
"Point",
"point",
",",
"double",
"tolerance",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometry",
"==",
"null",
"||",
"point",
"==",
"null",
")",
"{",
"return",
"null",
";... | Returns a new geometry based on an existing one, with a specific point as
a new vertex.
@param geometry
@param point
@param tolerance
@return Null if the vertex cannot be inserted
@throws SQLException If the vertex can be inserted but it makes the
geometry to be in an invalid shape | [
"Returns",
"a",
"new",
"geometry",
"based",
"on",
"an",
"existing",
"one",
"with",
"a",
"specific",
"point",
"as",
"a",
"new",
"vertex",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L75-L126 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.insertVertexInMultipoint | private static Geometry insertVertexInMultipoint(Geometry g, Point vertexPoint) {
ArrayList<Point> geoms = new ArrayList<Point>();
for (int i = 0; i < g.getNumGeometries(); i++) {
Point geom = (Point) g.getGeometryN(i);
geoms.add(geom);
}
geoms.add(FACTORY.createPoint(new Coordinate(vertexPoint.getX(), vertexPoint.getY())));
return FACTORY.createMultiPoint(GeometryFactory.toPointArray(geoms));
} | java | private static Geometry insertVertexInMultipoint(Geometry g, Point vertexPoint) {
ArrayList<Point> geoms = new ArrayList<Point>();
for (int i = 0; i < g.getNumGeometries(); i++) {
Point geom = (Point) g.getGeometryN(i);
geoms.add(geom);
}
geoms.add(FACTORY.createPoint(new Coordinate(vertexPoint.getX(), vertexPoint.getY())));
return FACTORY.createMultiPoint(GeometryFactory.toPointArray(geoms));
} | [
"private",
"static",
"Geometry",
"insertVertexInMultipoint",
"(",
"Geometry",
"g",
",",
"Point",
"vertexPoint",
")",
"{",
"ArrayList",
"<",
"Point",
">",
"geoms",
"=",
"new",
"ArrayList",
"<",
"Point",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0"... | Adds a Point into a MultiPoint geometry.
@param g
@param vertexPoint
@return | [
"Adds",
"a",
"Point",
"into",
"a",
"MultiPoint",
"geometry",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L135-L143 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.insertVertexInPolygon | private static Polygon insertVertexInPolygon(Polygon polygon,
Point vertexPoint, double tolerance) throws SQLException {
Polygon geom =polygon;
LineString linearRing = polygon.getExteriorRing();
int index = -1;
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
double distCurr = computeDistance(polygon.getInteriorRingN(i),vertexPoint, tolerance);
if (distCurr<tolerance){
index = i;
}
}
if(index==-1){
//The point is a on the exterior ring.
LinearRing inserted = insertVertexInLinearRing(linearRing, vertexPoint, tolerance);
if(inserted!=null){
LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
for (int i = 0; i < holes.length; i++) {
holes[i]= (LinearRing) polygon.getInteriorRingN(i);
}
geom = FACTORY.createPolygon(inserted, holes);
}
}
else{
//We add the vertex on the first hole
LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
for (int i = 0; i < holes.length; i++) {
if (i == index) {
holes[i] = insertVertexInLinearRing(polygon.getInteriorRingN(i), vertexPoint, tolerance);
} else {
holes[i] = (LinearRing) polygon.getInteriorRingN(i);
}
}
geom = FACTORY.createPolygon((LinearRing) linearRing, holes);
}
if(geom!=null){
if (!geom.isValid()) {
throw new SQLException("Geometry not valid");
}
}
return geom;
} | java | private static Polygon insertVertexInPolygon(Polygon polygon,
Point vertexPoint, double tolerance) throws SQLException {
Polygon geom =polygon;
LineString linearRing = polygon.getExteriorRing();
int index = -1;
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
double distCurr = computeDistance(polygon.getInteriorRingN(i),vertexPoint, tolerance);
if (distCurr<tolerance){
index = i;
}
}
if(index==-1){
//The point is a on the exterior ring.
LinearRing inserted = insertVertexInLinearRing(linearRing, vertexPoint, tolerance);
if(inserted!=null){
LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
for (int i = 0; i < holes.length; i++) {
holes[i]= (LinearRing) polygon.getInteriorRingN(i);
}
geom = FACTORY.createPolygon(inserted, holes);
}
}
else{
//We add the vertex on the first hole
LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
for (int i = 0; i < holes.length; i++) {
if (i == index) {
holes[i] = insertVertexInLinearRing(polygon.getInteriorRingN(i), vertexPoint, tolerance);
} else {
holes[i] = (LinearRing) polygon.getInteriorRingN(i);
}
}
geom = FACTORY.createPolygon((LinearRing) linearRing, holes);
}
if(geom!=null){
if (!geom.isValid()) {
throw new SQLException("Geometry not valid");
}
}
return geom;
} | [
"private",
"static",
"Polygon",
"insertVertexInPolygon",
"(",
"Polygon",
"polygon",
",",
"Point",
"vertexPoint",
",",
"double",
"tolerance",
")",
"throws",
"SQLException",
"{",
"Polygon",
"geom",
"=",
"polygon",
";",
"LineString",
"linearRing",
"=",
"polygon",
"."... | Adds a vertex into a Polygon with a given tolerance.
@param polygon
@param vertexPoint
@param tolerance
@return
@throws SQLException | [
"Adds",
"a",
"vertex",
"into",
"a",
"Polygon",
"with",
"a",
"given",
"tolerance",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L184-L224 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.computeDistance | private static double computeDistance(Geometry geometry, Point vertexPoint, double tolerance) {
DistanceOp distanceOp = new DistanceOp(geometry, vertexPoint, tolerance);
return distanceOp.distance();
} | java | private static double computeDistance(Geometry geometry, Point vertexPoint, double tolerance) {
DistanceOp distanceOp = new DistanceOp(geometry, vertexPoint, tolerance);
return distanceOp.distance();
} | [
"private",
"static",
"double",
"computeDistance",
"(",
"Geometry",
"geometry",
",",
"Point",
"vertexPoint",
",",
"double",
"tolerance",
")",
"{",
"DistanceOp",
"distanceOp",
"=",
"new",
"DistanceOp",
"(",
"geometry",
",",
"vertexPoint",
",",
"tolerance",
")",
";... | Return minimum distance between a geometry and a point.
@param geometry
@param vertexPoint
@param tolerance
@return | [
"Return",
"minimum",
"distance",
"between",
"a",
"geometry",
"and",
"a",
"point",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L234-L237 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java | ST_AddPoint.insertVertexInLinearRing | private static LinearRing insertVertexInLinearRing(LineString lineString,
Point vertexPoint, double tolerance) {
GeometryLocation geomLocation = EditUtilities.getVertexToSnap(lineString, vertexPoint, tolerance);
if (geomLocation != null) {
Coordinate[] coords = lineString.getCoordinates();
int index = geomLocation.getSegmentIndex();
Coordinate coord = geomLocation.getCoordinate();
if (!CoordinateUtils.contains2D(coords, coord)) {
Coordinate[] ret = new Coordinate[coords.length + 1];
System.arraycopy(coords, 0, ret, 0, index + 1);
ret[index + 1] = coord;
System.arraycopy(coords, index + 1, ret, index + 2, coords.length
- (index + 1));
return FACTORY.createLinearRing(ret);
}
return null;
} else {
return null;
}
} | java | private static LinearRing insertVertexInLinearRing(LineString lineString,
Point vertexPoint, double tolerance) {
GeometryLocation geomLocation = EditUtilities.getVertexToSnap(lineString, vertexPoint, tolerance);
if (geomLocation != null) {
Coordinate[] coords = lineString.getCoordinates();
int index = geomLocation.getSegmentIndex();
Coordinate coord = geomLocation.getCoordinate();
if (!CoordinateUtils.contains2D(coords, coord)) {
Coordinate[] ret = new Coordinate[coords.length + 1];
System.arraycopy(coords, 0, ret, 0, index + 1);
ret[index + 1] = coord;
System.arraycopy(coords, index + 1, ret, index + 2, coords.length
- (index + 1));
return FACTORY.createLinearRing(ret);
}
return null;
} else {
return null;
}
} | [
"private",
"static",
"LinearRing",
"insertVertexInLinearRing",
"(",
"LineString",
"lineString",
",",
"Point",
"vertexPoint",
",",
"double",
"tolerance",
")",
"{",
"GeometryLocation",
"geomLocation",
"=",
"EditUtilities",
".",
"getVertexToSnap",
"(",
"lineString",
",",
... | Adds a vertex into a LinearRing with a given tolerance.
@param lineString
@param vertexPoint
@param tolerance
@return | [
"Adds",
"a",
"vertex",
"into",
"a",
"LinearRing",
"with",
"a",
"given",
"tolerance",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_AddPoint.java#L247-L266 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/DriverManager.java | DriverManager.openFile | public static void openFile(Connection connection, String fileName, String tableName) throws SQLException {
String ext = fileName.substring(fileName.lastIndexOf('.') + 1,fileName.length());
final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
for(DriverDef driverDef : DRIVERS) {
if(driverDef.getFileExt().equalsIgnoreCase(ext)) {
try (Statement st = connection.createStatement()) {
st.execute(String.format("CREATE TABLE %s COMMENT %s ENGINE %s WITH %s",
TableLocation.parse(tableName, isH2).toString(isH2),StringUtils.quoteStringSQL(fileName),
StringUtils.quoteJavaString(driverDef.getClassName()),StringUtils.quoteJavaString(fileName)));
}
return;
}
}
throw new SQLException("No driver is available to open the "+ext+" file format");
} | java | public static void openFile(Connection connection, String fileName, String tableName) throws SQLException {
String ext = fileName.substring(fileName.lastIndexOf('.') + 1,fileName.length());
final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
for(DriverDef driverDef : DRIVERS) {
if(driverDef.getFileExt().equalsIgnoreCase(ext)) {
try (Statement st = connection.createStatement()) {
st.execute(String.format("CREATE TABLE %s COMMENT %s ENGINE %s WITH %s",
TableLocation.parse(tableName, isH2).toString(isH2),StringUtils.quoteStringSQL(fileName),
StringUtils.quoteJavaString(driverDef.getClassName()),StringUtils.quoteJavaString(fileName)));
}
return;
}
}
throw new SQLException("No driver is available to open the "+ext+" file format");
} | [
"public",
"static",
"void",
"openFile",
"(",
"Connection",
"connection",
",",
"String",
"fileName",
",",
"String",
"tableName",
")",
"throws",
"SQLException",
"{",
"String",
"ext",
"=",
"fileName",
".",
"substring",
"(",
"fileName",
".",
"lastIndexOf",
"(",
"'... | Create a new table
@param connection Active connection, do not close this connection.
@param fileName File path to write, if exists it may be replaced
@param tableName [[catalog.]schema.]table reference | [
"Create",
"a",
"new",
"table"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/DriverManager.java#L89-L103 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/shp/SHPWrite.java | SHPWrite.exportTable | public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException {
SHPDriverFunction shpDriverFunction = new SHPDriverFunction();
shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding);
} | java | public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException {
SHPDriverFunction shpDriverFunction = new SHPDriverFunction();
shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding);
} | [
"public",
"static",
"void",
"exportTable",
"(",
"Connection",
"connection",
",",
"String",
"fileName",
",",
"String",
"tableReference",
",",
"String",
"encoding",
")",
"throws",
"IOException",
",",
"SQLException",
"{",
"SHPDriverFunction",
"shpDriverFunction",
"=",
... | Read a table and write it into a shape file.
@param connection Active connection
@param fileName Shape file name or URI
@param tableReference Table name or select query
Note : The select query must be enclosed in parenthesis
@param encoding File encoding
@throws IOException
@throws SQLException | [
"Read",
"a",
"table",
"and",
"write",
"it",
"into",
"a",
"shape",
"file",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/SHPWrite.java#L69-L72 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.force | public static Geometry force(Geometry geom, int dimension) {
if (geom instanceof Point) {
return gf.createPoint(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof LineString) {
return gf.createLineString(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof Polygon) {
return GeometryCoordinateDimension.convert((Polygon) geom,dimension);
} else if (geom instanceof MultiPoint) {
return gf.createMultiPoint(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof MultiLineString) {
return GeometryCoordinateDimension.convert((MultiLineString) geom,dimension);
} else if (geom instanceof MultiPolygon) {
return GeometryCoordinateDimension.convert((MultiPolygon) geom,dimension);
} else if (geom instanceof GeometryCollection) {
return GeometryCoordinateDimension.convert((GeometryCollection)geom,dimension);
}
return geom;
} | java | public static Geometry force(Geometry geom, int dimension) {
if (geom instanceof Point) {
return gf.createPoint(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof LineString) {
return gf.createLineString(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof Polygon) {
return GeometryCoordinateDimension.convert((Polygon) geom,dimension);
} else if (geom instanceof MultiPoint) {
return gf.createMultiPoint(convertSequence(geom.getCoordinates(),dimension));
} else if (geom instanceof MultiLineString) {
return GeometryCoordinateDimension.convert((MultiLineString) geom,dimension);
} else if (geom instanceof MultiPolygon) {
return GeometryCoordinateDimension.convert((MultiPolygon) geom,dimension);
} else if (geom instanceof GeometryCollection) {
return GeometryCoordinateDimension.convert((GeometryCollection)geom,dimension);
}
return geom;
} | [
"public",
"static",
"Geometry",
"force",
"(",
"Geometry",
"geom",
",",
"int",
"dimension",
")",
"{",
"if",
"(",
"geom",
"instanceof",
"Point",
")",
"{",
"return",
"gf",
".",
"createPoint",
"(",
"convertSequence",
"(",
"geom",
".",
"getCoordinates",
"(",
")... | Force the dimension of the geometry and update correctly the coordinate
dimension
@param geom the input geometry
@param dimension supported dimension is 2, 3
if the dimension is set to 3 the z measure are set to 0
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"geometry",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L52-L69 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static GeometryCollection convert(GeometryCollection gc, int dimension) {
int nb = gc.getNumGeometries();
final Geometry[] geometries = new Geometry[nb];
for (int i = 0; i < nb; i++) {
geometries[i]=force(gc.getGeometryN(i),dimension);
}
return gf.createGeometryCollection(geometries);
} | java | public static GeometryCollection convert(GeometryCollection gc, int dimension) {
int nb = gc.getNumGeometries();
final Geometry[] geometries = new Geometry[nb];
for (int i = 0; i < nb; i++) {
geometries[i]=force(gc.getGeometryN(i),dimension);
}
return gf.createGeometryCollection(geometries);
} | [
"public",
"static",
"GeometryCollection",
"convert",
"(",
"GeometryCollection",
"gc",
",",
"int",
"dimension",
")",
"{",
"int",
"nb",
"=",
"gc",
".",
"getNumGeometries",
"(",
")",
";",
"final",
"Geometry",
"[",
"]",
"geometries",
"=",
"new",
"Geometry",
"[",... | Force the dimension of the GeometryCollection and update correctly the coordinate
dimension
@param gc
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"GeometryCollection",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L78-L85 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static MultiPolygon convert(MultiPolygon multiPolygon,int dimension) {
int nb = multiPolygon.getNumGeometries();
final Polygon[] pl = new Polygon[nb];
for (int i = 0; i < nb; i++) {
pl[i] = GeometryCoordinateDimension.convert((Polygon) multiPolygon.getGeometryN(i),dimension);
}
return gf.createMultiPolygon(pl);
} | java | public static MultiPolygon convert(MultiPolygon multiPolygon,int dimension) {
int nb = multiPolygon.getNumGeometries();
final Polygon[] pl = new Polygon[nb];
for (int i = 0; i < nb; i++) {
pl[i] = GeometryCoordinateDimension.convert((Polygon) multiPolygon.getGeometryN(i),dimension);
}
return gf.createMultiPolygon(pl);
} | [
"public",
"static",
"MultiPolygon",
"convert",
"(",
"MultiPolygon",
"multiPolygon",
",",
"int",
"dimension",
")",
"{",
"int",
"nb",
"=",
"multiPolygon",
".",
"getNumGeometries",
"(",
")",
";",
"final",
"Polygon",
"[",
"]",
"pl",
"=",
"new",
"Polygon",
"[",
... | Force the dimension of the MultiPolygon and update correctly the coordinate
dimension
@param multiPolygon
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"MultiPolygon",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L94-L101 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static MultiLineString convert(MultiLineString multiLineString, int dimension) {
int nb = multiLineString.getNumGeometries();
final LineString[] ls = new LineString[nb];
for (int i = 0; i < nb; i++) {
ls[i] = GeometryCoordinateDimension.convert((LineString) multiLineString.getGeometryN(i),dimension);
}
return gf.createMultiLineString(ls);
} | java | public static MultiLineString convert(MultiLineString multiLineString, int dimension) {
int nb = multiLineString.getNumGeometries();
final LineString[] ls = new LineString[nb];
for (int i = 0; i < nb; i++) {
ls[i] = GeometryCoordinateDimension.convert((LineString) multiLineString.getGeometryN(i),dimension);
}
return gf.createMultiLineString(ls);
} | [
"public",
"static",
"MultiLineString",
"convert",
"(",
"MultiLineString",
"multiLineString",
",",
"int",
"dimension",
")",
"{",
"int",
"nb",
"=",
"multiLineString",
".",
"getNumGeometries",
"(",
")",
";",
"final",
"LineString",
"[",
"]",
"ls",
"=",
"new",
"Lin... | Force the dimension of the MultiLineString and update correctly the coordinate
dimension
@param multiLineString
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"MultiLineString",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L110-L117 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static Polygon convert(Polygon polygon, int dimension) {
LinearRing shell = GeometryCoordinateDimension.convert(polygon.getExteriorRing(),dimension);
int nbOfHoles = polygon.getNumInteriorRing();
final LinearRing[] holes = new LinearRing[nbOfHoles];
for (int i = 0; i < nbOfHoles; i++) {
holes[i] = GeometryCoordinateDimension.convert(polygon.getInteriorRingN(i),dimension);
}
return gf.createPolygon(shell, holes);
} | java | public static Polygon convert(Polygon polygon, int dimension) {
LinearRing shell = GeometryCoordinateDimension.convert(polygon.getExteriorRing(),dimension);
int nbOfHoles = polygon.getNumInteriorRing();
final LinearRing[] holes = new LinearRing[nbOfHoles];
for (int i = 0; i < nbOfHoles; i++) {
holes[i] = GeometryCoordinateDimension.convert(polygon.getInteriorRingN(i),dimension);
}
return gf.createPolygon(shell, holes);
} | [
"public",
"static",
"Polygon",
"convert",
"(",
"Polygon",
"polygon",
",",
"int",
"dimension",
")",
"{",
"LinearRing",
"shell",
"=",
"GeometryCoordinateDimension",
".",
"convert",
"(",
"polygon",
".",
"getExteriorRing",
"(",
")",
",",
"dimension",
")",
";",
"in... | Force the dimension of the Polygon and update correctly the coordinate
dimension
@param polygon
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"Polygon",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L126-L134 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static LinearRing convert(LineString lineString,int dimension) {
return gf.createLinearRing(convertSequence(lineString.getCoordinates(),dimension));
} | java | public static LinearRing convert(LineString lineString,int dimension) {
return gf.createLinearRing(convertSequence(lineString.getCoordinates(),dimension));
} | [
"public",
"static",
"LinearRing",
"convert",
"(",
"LineString",
"lineString",
",",
"int",
"dimension",
")",
"{",
"return",
"gf",
".",
"createLinearRing",
"(",
"convertSequence",
"(",
"lineString",
".",
"getCoordinates",
"(",
")",
",",
"dimension",
")",
")",
";... | Force the dimension of the LineString and update correctly the coordinate
dimension
@param lineString
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"LineString",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L143-L145 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convert | public static LinearRing convert(LinearRing linearRing,int dimension) {
return gf.createLinearRing(convertSequence(linearRing.getCoordinates(),dimension));
} | java | public static LinearRing convert(LinearRing linearRing,int dimension) {
return gf.createLinearRing(convertSequence(linearRing.getCoordinates(),dimension));
} | [
"public",
"static",
"LinearRing",
"convert",
"(",
"LinearRing",
"linearRing",
",",
"int",
"dimension",
")",
"{",
"return",
"gf",
".",
"createLinearRing",
"(",
"convertSequence",
"(",
"linearRing",
".",
"getCoordinates",
"(",
")",
",",
"dimension",
")",
")",
";... | Force the dimension of the LinearRing and update correctly the coordinate
dimension
@param linearRing
@param dimension
@return | [
"Force",
"the",
"dimension",
"of",
"the",
"LinearRing",
"and",
"update",
"correctly",
"the",
"coordinate",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L154-L156 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java | GeometryCoordinateDimension.convertSequence | private static CoordinateArraySequence convertSequence(Coordinate[] cs,int dimension) {
for (int i = 0; i < cs.length; i++) {
Coordinate coord = cs[i];
switch (dimension) {
case 2:
coord.z = Double.NaN;
cs[i]=coord;
break;
case 3: {
double z = coord.z;
if (Double.isNaN(z)) {
coord.z = 0;
cs[i]=coord;
}
break;
}
default:
break;
}
}
return new CoordinateArraySequence(cs, dimension);
} | java | private static CoordinateArraySequence convertSequence(Coordinate[] cs,int dimension) {
for (int i = 0; i < cs.length; i++) {
Coordinate coord = cs[i];
switch (dimension) {
case 2:
coord.z = Double.NaN;
cs[i]=coord;
break;
case 3: {
double z = coord.z;
if (Double.isNaN(z)) {
coord.z = 0;
cs[i]=coord;
}
break;
}
default:
break;
}
}
return new CoordinateArraySequence(cs, dimension);
} | [
"private",
"static",
"CoordinateArraySequence",
"convertSequence",
"(",
"Coordinate",
"[",
"]",
"cs",
",",
"int",
"dimension",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"cs",
".",
"length",
";",
"i",
"++",
")",
"{",
"Coordinate",
"coor... | Create a new CoordinateArraySequence and update its dimension
@param cs a coordinate array
@return a new CoordinateArraySequence | [
"Create",
"a",
"new",
"CoordinateArraySequence",
"and",
"update",
"its",
"dimension"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/convert/GeometryCoordinateDimension.java#L164-L185 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_CompactnessRatio.java | ST_CompactnessRatio.computeCompacity | public static Double computeCompacity(Geometry geom) {
if(geom == null){
return null;
}
if (geom instanceof Polygon) {
final double circleRadius = Math.sqrt(geom.getArea() / Math.PI);
final double circleCurcumference = 2 * Math.PI * circleRadius;
return circleCurcumference / geom.getLength();
}
return null;
} | java | public static Double computeCompacity(Geometry geom) {
if(geom == null){
return null;
}
if (geom instanceof Polygon) {
final double circleRadius = Math.sqrt(geom.getArea() / Math.PI);
final double circleCurcumference = 2 * Math.PI * circleRadius;
return circleCurcumference / geom.getLength();
}
return null;
} | [
"public",
"static",
"Double",
"computeCompacity",
"(",
"Geometry",
"geom",
")",
"{",
"if",
"(",
"geom",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"geom",
"instanceof",
"Polygon",
")",
"{",
"final",
"double",
"circleRadius",
"=",
"Mat... | Returns the compactness ratio of the given polygon
@param geom Geometry
@return The compactness ratio of the given polygon | [
"Returns",
"the",
"compactness",
"ratio",
"of",
"the",
"given",
"polygon"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_CompactnessRatio.java#L60-L70 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DArea.java | ST_3DArea.st3darea | public static Double st3darea(Geometry geometry) {
if (geometry == null) {
return null;
}
double area = 0;
for (int idPoly = 0; idPoly < geometry.getNumGeometries(); idPoly++) {
Geometry subGeom = geometry.getGeometryN(idPoly);
if (subGeom instanceof Polygon) {
area += compute3DArea((Polygon) subGeom);
}
}
return area;
} | java | public static Double st3darea(Geometry geometry) {
if (geometry == null) {
return null;
}
double area = 0;
for (int idPoly = 0; idPoly < geometry.getNumGeometries(); idPoly++) {
Geometry subGeom = geometry.getGeometryN(idPoly);
if (subGeom instanceof Polygon) {
area += compute3DArea((Polygon) subGeom);
}
}
return area;
} | [
"public",
"static",
"Double",
"st3darea",
"(",
"Geometry",
"geometry",
")",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"double",
"area",
"=",
"0",
";",
"for",
"(",
"int",
"idPoly",
"=",
"0",
";",
"idPoly",
"<",
... | Compute the 3D area of a polygon a geometrycollection that contains
polygons
@param geometry
@return | [
"Compute",
"the",
"3D",
"area",
"of",
"a",
"polygon",
"a",
"geometrycollection",
"that",
"contains",
"polygons"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DArea.java#L52-L64 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DArea.java | ST_3DArea.compute3DArea | private static Double compute3DArea(Polygon geometry) {
DelaunayData delaunayData = new DelaunayData();
delaunayData.put(geometry, DelaunayData.MODE.TESSELLATION);
// Do triangulation
delaunayData.triangulate();
return delaunayData.get3DArea();
} | java | private static Double compute3DArea(Polygon geometry) {
DelaunayData delaunayData = new DelaunayData();
delaunayData.put(geometry, DelaunayData.MODE.TESSELLATION);
// Do triangulation
delaunayData.triangulate();
return delaunayData.get3DArea();
} | [
"private",
"static",
"Double",
"compute3DArea",
"(",
"Polygon",
"geometry",
")",
"{",
"DelaunayData",
"delaunayData",
"=",
"new",
"DelaunayData",
"(",
")",
";",
"delaunayData",
".",
"put",
"(",
"geometry",
",",
"DelaunayData",
".",
"MODE",
".",
"TESSELLATION",
... | Compute the 3D area of a polygon
@param geometry
@return | [
"Compute",
"the",
"3D",
"area",
"of",
"a",
"polygon"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/properties/ST_3DArea.java#L72-L78 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/ST_SetSRID.java | ST_SetSRID.setSRID | public static Geometry setSRID(Geometry geometry, Integer srid) throws IllegalArgumentException {
if (geometry == null) {
return null;
}
if (srid == null) {
throw new IllegalArgumentException("The SRID code cannot be null.");
}
Geometry geom = geometry.copy();
geom.setSRID(srid);
return geom;
} | java | public static Geometry setSRID(Geometry geometry, Integer srid) throws IllegalArgumentException {
if (geometry == null) {
return null;
}
if (srid == null) {
throw new IllegalArgumentException("The SRID code cannot be null.");
}
Geometry geom = geometry.copy();
geom.setSRID(srid);
return geom;
} | [
"public",
"static",
"Geometry",
"setSRID",
"(",
"Geometry",
"geometry",
",",
"Integer",
"srid",
")",
"throws",
"IllegalArgumentException",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"srid",
"==",
"null",
")",... | Set a new SRID to the geometry
@param geometry
@param srid
@return
@throws IllegalArgumentException | [
"Set",
"a",
"new",
"SRID",
"to",
"the",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/crs/ST_SetSRID.java#L51-L61 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/json/JsonWrite.java | JsonWrite.writeGeoJson | public static void writeGeoJson(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException {
JsonDriverFunction jsonDriver = new JsonDriverFunction();
jsonDriver.exportTable(connection,tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(),encoding);
} | java | public static void writeGeoJson(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException {
JsonDriverFunction jsonDriver = new JsonDriverFunction();
jsonDriver.exportTable(connection,tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(),encoding);
} | [
"public",
"static",
"void",
"writeGeoJson",
"(",
"Connection",
"connection",
",",
"String",
"fileName",
",",
"String",
"tableReference",
",",
"String",
"encoding",
")",
"throws",
"IOException",
",",
"SQLException",
"{",
"JsonDriverFunction",
"jsonDriver",
"=",
"new"... | Write the JSON file.
@param connection
@param fileName
@param tableReference
@param encoding
@throws IOException
@throws SQLException | [
"Write",
"the",
"JSON",
"file",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/json/JsonWrite.java#L57-L60 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/GeometryTypeFromConstraint.java | GeometryTypeFromConstraint.geometryTypeFromConstraint | public static int geometryTypeFromConstraint(String constraint, int numericPrecision) {
if(constraint.isEmpty() && numericPrecision > GeometryTypeCodes.GEOMETRYZM) {
return GeometryTypeCodes.GEOMETRY;
}
// Use Domain given parameters
if(numericPrecision <= GeometryTypeCodes.GEOMETRYZM) {
return numericPrecision;
}
// Use user defined constraint. Does not work with VIEW TABLE
Matcher matcher = TYPE_CODE_PATTERN.matcher(constraint);
if(matcher.find()) {
return Integer.valueOf(matcher.group(CODE_GROUP_ID));
} else {
return GeometryTypeCodes.GEOMETRY;
}
} | java | public static int geometryTypeFromConstraint(String constraint, int numericPrecision) {
if(constraint.isEmpty() && numericPrecision > GeometryTypeCodes.GEOMETRYZM) {
return GeometryTypeCodes.GEOMETRY;
}
// Use Domain given parameters
if(numericPrecision <= GeometryTypeCodes.GEOMETRYZM) {
return numericPrecision;
}
// Use user defined constraint. Does not work with VIEW TABLE
Matcher matcher = TYPE_CODE_PATTERN.matcher(constraint);
if(matcher.find()) {
return Integer.valueOf(matcher.group(CODE_GROUP_ID));
} else {
return GeometryTypeCodes.GEOMETRY;
}
} | [
"public",
"static",
"int",
"geometryTypeFromConstraint",
"(",
"String",
"constraint",
",",
"int",
"numericPrecision",
")",
"{",
"if",
"(",
"constraint",
".",
"isEmpty",
"(",
")",
"&&",
"numericPrecision",
">",
"GeometryTypeCodes",
".",
"GEOMETRYZM",
")",
"{",
"r... | Convert H2 constraint string into a OGC geometry type index.
@param constraint SQL Constraint ex: ST_GeometryTypeCode(the_geom) = 5
@param numericPrecision This parameter is available if the user give domain
@return Geometry type code {@link org.h2gis.utilities.GeometryTypeCodes} | [
"Convert",
"H2",
"constraint",
"string",
"into",
"a",
"OGC",
"geometry",
"type",
"index",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/GeometryTypeFromConstraint.java#L57-L72 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java | DBFDriverFunction.getQuestionMark | public static String getQuestionMark(int count) {
StringBuilder qMark = new StringBuilder();
for (int i = 0; i < count; i++) {
if(i > 0) {
qMark.append(", ");
}
qMark.append("?");
}
return qMark.toString();
} | java | public static String getQuestionMark(int count) {
StringBuilder qMark = new StringBuilder();
for (int i = 0; i < count; i++) {
if(i > 0) {
qMark.append(", ");
}
qMark.append("?");
}
return qMark.toString();
} | [
"public",
"static",
"String",
"getQuestionMark",
"(",
"int",
"count",
")",
"{",
"StringBuilder",
"qMark",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i"... | Generate the concatenation of ? characters. Used by PreparedStatement.
@param count Number of ? character to generation
@return Value ex: "?, ?, ?" | [
"Generate",
"the",
"concatenation",
"of",
"?",
"characters",
".",
"Used",
"by",
"PreparedStatement",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java#L286-L295 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java | DBFDriverFunction.getSQLColumnTypes | public static String getSQLColumnTypes(DbaseFileHeader header, boolean isH2Database) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
for(int idColumn = 0; idColumn < header.getNumFields(); idColumn++) {
if(idColumn > 0) {
stringBuilder.append(", ");
}
String fieldName = TableLocation.capsIdentifier(header.getFieldName(idColumn), isH2Database);
stringBuilder.append(TableLocation.quoteIdentifier(fieldName,isH2Database));
stringBuilder.append(" ");
switch (header.getFieldType(idColumn)) {
// (L)logical (T,t,F,f,Y,y,N,n)
case 'l':
case 'L':
stringBuilder.append("BOOLEAN");
break;
// (C)character (String)
case 'c':
case 'C':
stringBuilder.append("VARCHAR(");
// Append size
int length = header.getFieldLength(idColumn);
stringBuilder.append(String.valueOf(length));
stringBuilder.append(")");
break;
// (D)date (Date)
case 'd':
case 'D':
stringBuilder.append("DATE");
break;
// (F)floating (Double)
case 'n':
case 'N':
if ((header.getFieldDecimalCount(idColumn) == 0)) {
if ((header.getFieldLength(idColumn) >= 0)
&& (header.getFieldLength(idColumn) < 10)) {
stringBuilder.append("INT4");
} else {
stringBuilder.append("INT8");
}
} else {
stringBuilder.append("FLOAT8");
}
break;
case 'f':
case 'F': // floating point number
case 'o':
case 'O': // floating point number
stringBuilder.append("FLOAT8");
break;
default:
throw new IOException("Unknown DBF field type " + header.getFieldType(idColumn));
}
}
return stringBuilder.toString();
} | java | public static String getSQLColumnTypes(DbaseFileHeader header, boolean isH2Database) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
for(int idColumn = 0; idColumn < header.getNumFields(); idColumn++) {
if(idColumn > 0) {
stringBuilder.append(", ");
}
String fieldName = TableLocation.capsIdentifier(header.getFieldName(idColumn), isH2Database);
stringBuilder.append(TableLocation.quoteIdentifier(fieldName,isH2Database));
stringBuilder.append(" ");
switch (header.getFieldType(idColumn)) {
// (L)logical (T,t,F,f,Y,y,N,n)
case 'l':
case 'L':
stringBuilder.append("BOOLEAN");
break;
// (C)character (String)
case 'c':
case 'C':
stringBuilder.append("VARCHAR(");
// Append size
int length = header.getFieldLength(idColumn);
stringBuilder.append(String.valueOf(length));
stringBuilder.append(")");
break;
// (D)date (Date)
case 'd':
case 'D':
stringBuilder.append("DATE");
break;
// (F)floating (Double)
case 'n':
case 'N':
if ((header.getFieldDecimalCount(idColumn) == 0)) {
if ((header.getFieldLength(idColumn) >= 0)
&& (header.getFieldLength(idColumn) < 10)) {
stringBuilder.append("INT4");
} else {
stringBuilder.append("INT8");
}
} else {
stringBuilder.append("FLOAT8");
}
break;
case 'f':
case 'F': // floating point number
case 'o':
case 'O': // floating point number
stringBuilder.append("FLOAT8");
break;
default:
throw new IOException("Unknown DBF field type " + header.getFieldType(idColumn));
}
}
return stringBuilder.toString();
} | [
"public",
"static",
"String",
"getSQLColumnTypes",
"(",
"DbaseFileHeader",
"header",
",",
"boolean",
"isH2Database",
")",
"throws",
"IOException",
"{",
"StringBuilder",
"stringBuilder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"idColumn",
"="... | Return SQL Columns declaration
@param header DBAse file header
@param isH2Database true if H2 database
@return Array of columns ex: ["id INTEGER", "len DOUBLE"]
@throws IOException | [
"Return",
"SQL",
"Columns",
"declaration"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java#L304-L358 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java | DBFDriverFunction.dBaseHeaderFromMetaData | public static DbaseFileHeader dBaseHeaderFromMetaData(ResultSetMetaData metaData, List<Integer> retainedColumns) throws SQLException {
DbaseFileHeader dbaseFileHeader = new DbaseFileHeader();
for(int fieldId= 1; fieldId <= metaData.getColumnCount(); fieldId++) {
final String fieldTypeName = metaData.getColumnTypeName(fieldId);
// TODO postgis check field type
if(!fieldTypeName.equalsIgnoreCase("geometry")) {
DBFType dbfType = getDBFType(metaData.getColumnType(fieldId), fieldTypeName, metaData.getColumnDisplaySize(fieldId), metaData.getPrecision(fieldId));
try {
dbaseFileHeader.addColumn(metaData.getColumnName(fieldId),dbfType.type, dbfType.fieldLength, dbfType.decimalCount);
retainedColumns.add(fieldId);
} catch (DbaseFileException ex) {
throw new SQLException(ex.getLocalizedMessage(), ex);
}
}
}
return dbaseFileHeader;
} | java | public static DbaseFileHeader dBaseHeaderFromMetaData(ResultSetMetaData metaData, List<Integer> retainedColumns) throws SQLException {
DbaseFileHeader dbaseFileHeader = new DbaseFileHeader();
for(int fieldId= 1; fieldId <= metaData.getColumnCount(); fieldId++) {
final String fieldTypeName = metaData.getColumnTypeName(fieldId);
// TODO postgis check field type
if(!fieldTypeName.equalsIgnoreCase("geometry")) {
DBFType dbfType = getDBFType(metaData.getColumnType(fieldId), fieldTypeName, metaData.getColumnDisplaySize(fieldId), metaData.getPrecision(fieldId));
try {
dbaseFileHeader.addColumn(metaData.getColumnName(fieldId),dbfType.type, dbfType.fieldLength, dbfType.decimalCount);
retainedColumns.add(fieldId);
} catch (DbaseFileException ex) {
throw new SQLException(ex.getLocalizedMessage(), ex);
}
}
}
return dbaseFileHeader;
} | [
"public",
"static",
"DbaseFileHeader",
"dBaseHeaderFromMetaData",
"(",
"ResultSetMetaData",
"metaData",
",",
"List",
"<",
"Integer",
">",
"retainedColumns",
")",
"throws",
"SQLException",
"{",
"DbaseFileHeader",
"dbaseFileHeader",
"=",
"new",
"DbaseFileHeader",
"(",
")"... | Create a DBF header from the columns specified in parameter.
@param metaData SQL ResultSetMetadata
@param retainedColumns list of column indexes
@return DbfaseFileHeader instance.
@throws SQLException If one or more type are not supported by DBF | [
"Create",
"a",
"DBF",
"header",
"from",
"the",
"columns",
"specified",
"in",
"parameter",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/dbf/DBFDriverFunction.java#L367-L383 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_RemovePoints.java | ST_RemovePoints.removePoint | public static Geometry removePoint(Geometry geometry, Polygon polygon) throws SQLException {
if(geometry == null){
return null;
}
GeometryEditor localGeometryEditor = new GeometryEditor();
PolygonDeleteVertexOperation localBoxDeleteVertexOperation = new PolygonDeleteVertexOperation(geometry.getFactory(), new PreparedPolygon(polygon));
Geometry localGeometry = localGeometryEditor.edit(geometry, localBoxDeleteVertexOperation);
if (localGeometry.isEmpty()) {
return null;
}
return localGeometry;
} | java | public static Geometry removePoint(Geometry geometry, Polygon polygon) throws SQLException {
if(geometry == null){
return null;
}
GeometryEditor localGeometryEditor = new GeometryEditor();
PolygonDeleteVertexOperation localBoxDeleteVertexOperation = new PolygonDeleteVertexOperation(geometry.getFactory(), new PreparedPolygon(polygon));
Geometry localGeometry = localGeometryEditor.edit(geometry, localBoxDeleteVertexOperation);
if (localGeometry.isEmpty()) {
return null;
}
return localGeometry;
} | [
"public",
"static",
"Geometry",
"removePoint",
"(",
"Geometry",
"geometry",
",",
"Polygon",
"polygon",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometry",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"GeometryEditor",
"localGeometryEditor",
"=",
... | Remove all vertices that are located within a polygon
@param geometry
@param polygon
@return
@throws SQLException | [
"Remove",
"all",
"vertices",
"that",
"are",
"located",
"within",
"a",
"polygon"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/edit/ST_RemovePoints.java#L54-L65 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java | URIUtilities.getQueryKeyValuePairs | public static Map<String,String> getQueryKeyValuePairs(URI uri) throws UnsupportedEncodingException {
Map<String,String> queryParameters = new HashMap<String, String>();
String query = uri.getRawQuery();
if(query == null) {
// Maybe invalid URI
try {
uri = URI.create(uri.getRawSchemeSpecificPart());
query = uri.getRawQuery();
if(query == null) {
return queryParameters;
}
} catch (IllegalArgumentException ex) {
return queryParameters;
}
}
StringTokenizer stringTokenizer = new StringTokenizer(query, "&");
while (stringTokenizer.hasMoreTokens()) {
String keyValue = stringTokenizer.nextToken().trim();
if(!keyValue.isEmpty()) {
int equalPos = keyValue.indexOf("=");
// If there is no value
String key = URLDecoder.decode(keyValue.substring(0,equalPos != -1 ?
equalPos : keyValue.length()), ENCODING);
if(equalPos==-1 || equalPos == keyValue.length() - 1) {
// Key without value
queryParameters.put(key.toLowerCase(),"");
} else {
String value = URLDecoder.decode(keyValue.substring(equalPos+1), ENCODING);
queryParameters.put(key.toLowerCase(),value);
}
}
}
return queryParameters;
} | java | public static Map<String,String> getQueryKeyValuePairs(URI uri) throws UnsupportedEncodingException {
Map<String,String> queryParameters = new HashMap<String, String>();
String query = uri.getRawQuery();
if(query == null) {
// Maybe invalid URI
try {
uri = URI.create(uri.getRawSchemeSpecificPart());
query = uri.getRawQuery();
if(query == null) {
return queryParameters;
}
} catch (IllegalArgumentException ex) {
return queryParameters;
}
}
StringTokenizer stringTokenizer = new StringTokenizer(query, "&");
while (stringTokenizer.hasMoreTokens()) {
String keyValue = stringTokenizer.nextToken().trim();
if(!keyValue.isEmpty()) {
int equalPos = keyValue.indexOf("=");
// If there is no value
String key = URLDecoder.decode(keyValue.substring(0,equalPos != -1 ?
equalPos : keyValue.length()), ENCODING);
if(equalPos==-1 || equalPos == keyValue.length() - 1) {
// Key without value
queryParameters.put(key.toLowerCase(),"");
} else {
String value = URLDecoder.decode(keyValue.substring(equalPos+1), ENCODING);
queryParameters.put(key.toLowerCase(),value);
}
}
}
return queryParameters;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"getQueryKeyValuePairs",
"(",
"URI",
"uri",
")",
"throws",
"UnsupportedEncodingException",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"queryParameters",
"=",
"new",
"HashMap",
"<",
"String",
","... | Read the Query part of an URI.
@param uri URI to split
@return Key/Value pairs of query, the key is lowercase and value may be null
@throws java.io.UnsupportedEncodingException | [
"Read",
"the",
"Query",
"part",
"of",
"an",
"URI",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java#L50-L83 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java | URIUtilities.getConcatenatedParameters | public static String getConcatenatedParameters(Map<String, String> parameters, String... keys) {
StringBuilder keyValues = new StringBuilder();
for(String key : keys) {
String value = parameters.get(key.toLowerCase().trim());
if(value!=null) {
if(keyValues.length()!=0) {
keyValues.append("&");
}
keyValues.append(key.toUpperCase());
keyValues.append("=");
keyValues.append(value);
}
}
return keyValues.toString();
} | java | public static String getConcatenatedParameters(Map<String, String> parameters, String... keys) {
StringBuilder keyValues = new StringBuilder();
for(String key : keys) {
String value = parameters.get(key.toLowerCase().trim());
if(value!=null) {
if(keyValues.length()!=0) {
keyValues.append("&");
}
keyValues.append(key.toUpperCase());
keyValues.append("=");
keyValues.append(value);
}
}
return keyValues.toString();
} | [
"public",
"static",
"String",
"getConcatenatedParameters",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"parameters",
",",
"String",
"...",
"keys",
")",
"{",
"StringBuilder",
"keyValues",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"String",
"k... | Create the Query part of an URI
@param parameters Parameters to read
@param keys map property to read
@return Query part of an URI | [
"Create",
"the",
"Query",
"part",
"of",
"an",
"URI"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java#L93-L107 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java | URIUtilities.relativize | public static URI relativize(URI base,URI target) {
if(!base.getScheme().equals(target.getScheme())) {
return target;
}
StringBuilder rel = new StringBuilder();
String path = base.getPath();
String separator = "/";
StringTokenizer tokenizer = new StringTokenizer(target.getPath(), separator);
String targetPart = "";
if(tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
}
if(path.startsWith(separator)) {
path = path.substring(1);
}
StringTokenizer baseTokenizer = new StringTokenizer(path, separator, true);
while(baseTokenizer.hasMoreTokens()) {
String basePart = baseTokenizer.nextToken();
if(baseTokenizer.hasMoreTokens()) {
// Has a / after this folder name
baseTokenizer.nextToken(); // return separator
if(!basePart.isEmpty()) {
if(!basePart.equals(targetPart)) {
rel.append("..");
rel.append(separator);
} else if(tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
}
}
}
}
// Add part of target path that is not in base path
rel.append(targetPart);
while (tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
rel.append(separator);
rel.append(targetPart);
}
try {
return new URI(null, null, rel.toString(), null, null);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException("Illegal URI provided:\n"+base.toString()+"\n"+target.toString());
}
} | java | public static URI relativize(URI base,URI target) {
if(!base.getScheme().equals(target.getScheme())) {
return target;
}
StringBuilder rel = new StringBuilder();
String path = base.getPath();
String separator = "/";
StringTokenizer tokenizer = new StringTokenizer(target.getPath(), separator);
String targetPart = "";
if(tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
}
if(path.startsWith(separator)) {
path = path.substring(1);
}
StringTokenizer baseTokenizer = new StringTokenizer(path, separator, true);
while(baseTokenizer.hasMoreTokens()) {
String basePart = baseTokenizer.nextToken();
if(baseTokenizer.hasMoreTokens()) {
// Has a / after this folder name
baseTokenizer.nextToken(); // return separator
if(!basePart.isEmpty()) {
if(!basePart.equals(targetPart)) {
rel.append("..");
rel.append(separator);
} else if(tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
}
}
}
}
// Add part of target path that is not in base path
rel.append(targetPart);
while (tokenizer.hasMoreTokens()) {
targetPart = tokenizer.nextToken();
rel.append(separator);
rel.append(targetPart);
}
try {
return new URI(null, null, rel.toString(), null, null);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException("Illegal URI provided:\n"+base.toString()+"\n"+target.toString());
}
} | [
"public",
"static",
"URI",
"relativize",
"(",
"URI",
"base",
",",
"URI",
"target",
")",
"{",
"if",
"(",
"!",
"base",
".",
"getScheme",
"(",
")",
".",
"equals",
"(",
"target",
".",
"getScheme",
"(",
")",
")",
")",
"{",
"return",
"target",
";",
"}",
... | Enhanced version of URI.relativize, the target can now be in parent folder of base URI.
@param base Base uri, location from where to relativize.
@param target Target uri, final destination of returned URI.
@return Non-absolute URI, or target if target scheme is different than base scheme. | [
"Enhanced",
"version",
"of",
"URI",
".",
"relativize",
"the",
"target",
"can",
"now",
"be",
"in",
"parent",
"folder",
"of",
"base",
"URI",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java#L117-L160 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java | URIUtilities.fileFromString | public static File fileFromString(String fileName) {
try {
return new File(new URI(fileName).getPath());
} catch (URISyntaxException ex ) {
// Not a valid uri
return new File(fileName);
}
} | java | public static File fileFromString(String fileName) {
try {
return new File(new URI(fileName).getPath());
} catch (URISyntaxException ex ) {
// Not a valid uri
return new File(fileName);
}
} | [
"public",
"static",
"File",
"fileFromString",
"(",
"String",
"fileName",
")",
"{",
"try",
"{",
"return",
"new",
"File",
"(",
"new",
"URI",
"(",
"fileName",
")",
".",
"getPath",
"(",
")",
")",
";",
"}",
"catch",
"(",
"URISyntaxException",
"ex",
")",
"{"... | Get a File from the specified file name.
@param fileName File name using Path or URI
@return File path | [
"Get",
"a",
"File",
"from",
"the",
"specified",
"file",
"name",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/URIUtilities.java#L169-L176 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.shadowLine | private static Geometry shadowLine(LineString lineString, double[] shadowOffset, GeometryFactory factory, boolean doUnion) {
Coordinate[] coords = lineString.getCoordinates();
Collection<Polygon> shadows = new ArrayList<Polygon>();
createShadowPolygons(shadows, coords, shadowOffset, factory);
if (!doUnion) {
return factory.buildGeometry(shadows);
} else {
if (!shadows.isEmpty()) {
CascadedPolygonUnion union = new CascadedPolygonUnion(shadows);
Geometry result = union.union();
result.apply(new UpdateZCoordinateSequenceFilter(0, 1));
return result;
}
return null;
}
} | java | private static Geometry shadowLine(LineString lineString, double[] shadowOffset, GeometryFactory factory, boolean doUnion) {
Coordinate[] coords = lineString.getCoordinates();
Collection<Polygon> shadows = new ArrayList<Polygon>();
createShadowPolygons(shadows, coords, shadowOffset, factory);
if (!doUnion) {
return factory.buildGeometry(shadows);
} else {
if (!shadows.isEmpty()) {
CascadedPolygonUnion union = new CascadedPolygonUnion(shadows);
Geometry result = union.union();
result.apply(new UpdateZCoordinateSequenceFilter(0, 1));
return result;
}
return null;
}
} | [
"private",
"static",
"Geometry",
"shadowLine",
"(",
"LineString",
"lineString",
",",
"double",
"[",
"]",
"shadowOffset",
",",
"GeometryFactory",
"factory",
",",
"boolean",
"doUnion",
")",
"{",
"Coordinate",
"[",
"]",
"coords",
"=",
"lineString",
".",
"getCoordin... | Compute the shadow for a linestring
@param lineString the input linestring
@param shadowOffset computed according the sun position and the height of
the geometry
@return | [
"Compute",
"the",
"shadow",
"for",
"a",
"linestring"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L133-L148 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.shadowPolygon | private static Geometry shadowPolygon(Polygon polygon, double[] shadowOffset, GeometryFactory factory, boolean doUnion) {
Coordinate[] shellCoords = polygon.getExteriorRing().getCoordinates();
Collection<Polygon> shadows = new ArrayList<Polygon>();
createShadowPolygons(shadows, shellCoords, shadowOffset, factory);
final int nbOfHoles = polygon.getNumInteriorRing();
for (int i = 0; i < nbOfHoles; i++) {
createShadowPolygons(shadows, polygon.getInteriorRingN(i).getCoordinates(), shadowOffset, factory);
}
if (!doUnion) {
return factory.buildGeometry(shadows);
} else {
if (!shadows.isEmpty()) {
Collection<Geometry> shadowParts = new ArrayList<Geometry>();
for (Polygon shadowPolygon : shadows) {
shadowParts.add(shadowPolygon.difference(polygon));
}
Geometry allShadowParts = factory.buildGeometry(shadowParts);
Geometry union = allShadowParts.buffer(0);
union.apply(new UpdateZCoordinateSequenceFilter(0, 1));
return union;
}
return null;
}
} | java | private static Geometry shadowPolygon(Polygon polygon, double[] shadowOffset, GeometryFactory factory, boolean doUnion) {
Coordinate[] shellCoords = polygon.getExteriorRing().getCoordinates();
Collection<Polygon> shadows = new ArrayList<Polygon>();
createShadowPolygons(shadows, shellCoords, shadowOffset, factory);
final int nbOfHoles = polygon.getNumInteriorRing();
for (int i = 0; i < nbOfHoles; i++) {
createShadowPolygons(shadows, polygon.getInteriorRingN(i).getCoordinates(), shadowOffset, factory);
}
if (!doUnion) {
return factory.buildGeometry(shadows);
} else {
if (!shadows.isEmpty()) {
Collection<Geometry> shadowParts = new ArrayList<Geometry>();
for (Polygon shadowPolygon : shadows) {
shadowParts.add(shadowPolygon.difference(polygon));
}
Geometry allShadowParts = factory.buildGeometry(shadowParts);
Geometry union = allShadowParts.buffer(0);
union.apply(new UpdateZCoordinateSequenceFilter(0, 1));
return union;
}
return null;
}
} | [
"private",
"static",
"Geometry",
"shadowPolygon",
"(",
"Polygon",
"polygon",
",",
"double",
"[",
"]",
"shadowOffset",
",",
"GeometryFactory",
"factory",
",",
"boolean",
"doUnion",
")",
"{",
"Coordinate",
"[",
"]",
"shellCoords",
"=",
"polygon",
".",
"getExterior... | Compute the shadow for a polygon
@param polygon the input polygon
@param shadowOffset computed according the sun position and the height of
the geometry
@return | [
"Compute",
"the",
"shadow",
"for",
"a",
"polygon"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L158-L182 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.shadowPoint | private static Geometry shadowPoint(Point point, double[] shadowOffset, GeometryFactory factory) {
Coordinate startCoord = point.getCoordinate();
Coordinate offset = moveCoordinate(startCoord, shadowOffset);
if (offset.distance(point.getCoordinate()) < 10E-3) {
return point;
} else {
startCoord.z = 0;
return factory.createLineString(new Coordinate[]{startCoord, offset});
}
} | java | private static Geometry shadowPoint(Point point, double[] shadowOffset, GeometryFactory factory) {
Coordinate startCoord = point.getCoordinate();
Coordinate offset = moveCoordinate(startCoord, shadowOffset);
if (offset.distance(point.getCoordinate()) < 10E-3) {
return point;
} else {
startCoord.z = 0;
return factory.createLineString(new Coordinate[]{startCoord, offset});
}
} | [
"private",
"static",
"Geometry",
"shadowPoint",
"(",
"Point",
"point",
",",
"double",
"[",
"]",
"shadowOffset",
",",
"GeometryFactory",
"factory",
")",
"{",
"Coordinate",
"startCoord",
"=",
"point",
".",
"getCoordinate",
"(",
")",
";",
"Coordinate",
"offset",
... | Compute the shadow for a point
@param point the input point
@param shadowOffset computed according the sun position and the height of
the geometry
@return | [
"Compute",
"the",
"shadow",
"for",
"a",
"point"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L192-L201 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.shadowOffset | public static double[] shadowOffset(double azimuth, double altitude, double height) {
double spread = 1 / Math.tan(altitude);
return new double[]{-height * spread * Math.sin(azimuth), -height * spread * Math.cos(azimuth)};
} | java | public static double[] shadowOffset(double azimuth, double altitude, double height) {
double spread = 1 / Math.tan(altitude);
return new double[]{-height * spread * Math.sin(azimuth), -height * spread * Math.cos(azimuth)};
} | [
"public",
"static",
"double",
"[",
"]",
"shadowOffset",
"(",
"double",
"azimuth",
",",
"double",
"altitude",
",",
"double",
"height",
")",
"{",
"double",
"spread",
"=",
"1",
"/",
"Math",
".",
"tan",
"(",
"altitude",
")",
";",
"return",
"new",
"double",
... | Return the shadow offset in X and Y directions
@param azimuth in radians from north.
@param altitude in radians from east.
@param height of the geometry
@return | [
"Return",
"the",
"shadow",
"offset",
"in",
"X",
"and",
"Y",
"directions"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L211-L214 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.moveCoordinate | private static Coordinate moveCoordinate(Coordinate inputCoordinate, double[] shadowOffset) {
return new Coordinate(inputCoordinate.x + shadowOffset[0], inputCoordinate.y + shadowOffset[1], 0);
} | java | private static Coordinate moveCoordinate(Coordinate inputCoordinate, double[] shadowOffset) {
return new Coordinate(inputCoordinate.x + shadowOffset[0], inputCoordinate.y + shadowOffset[1], 0);
} | [
"private",
"static",
"Coordinate",
"moveCoordinate",
"(",
"Coordinate",
"inputCoordinate",
",",
"double",
"[",
"]",
"shadowOffset",
")",
"{",
"return",
"new",
"Coordinate",
"(",
"inputCoordinate",
".",
"x",
"+",
"shadowOffset",
"[",
"0",
"]",
",",
"inputCoordina... | Move the input coordinate according X and Y offset
@param inputCoordinate
@param shadowOffset
@return | [
"Move",
"the",
"input",
"coordinate",
"according",
"X",
"and",
"Y",
"offset"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L223-L225 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java | ST_GeometryShadow.createShadowPolygons | private static void createShadowPolygons(Collection<Polygon> shadows, Coordinate[] coordinates, double[] shadow, GeometryFactory factory) {
for (int i = 1; i < coordinates.length; i++) {
Coordinate startCoord = coordinates[i - 1];
Coordinate endCoord = coordinates[i];
Coordinate nextEnd = moveCoordinate(endCoord, shadow);
Coordinate nextStart = moveCoordinate(startCoord, shadow);
Polygon polygon = factory.createPolygon(new Coordinate[]{startCoord,
endCoord, nextEnd,
nextStart, startCoord});
if (polygon.isValid()) {
shadows.add(polygon);
}
}
} | java | private static void createShadowPolygons(Collection<Polygon> shadows, Coordinate[] coordinates, double[] shadow, GeometryFactory factory) {
for (int i = 1; i < coordinates.length; i++) {
Coordinate startCoord = coordinates[i - 1];
Coordinate endCoord = coordinates[i];
Coordinate nextEnd = moveCoordinate(endCoord, shadow);
Coordinate nextStart = moveCoordinate(startCoord, shadow);
Polygon polygon = factory.createPolygon(new Coordinate[]{startCoord,
endCoord, nextEnd,
nextStart, startCoord});
if (polygon.isValid()) {
shadows.add(polygon);
}
}
} | [
"private",
"static",
"void",
"createShadowPolygons",
"(",
"Collection",
"<",
"Polygon",
">",
"shadows",
",",
"Coordinate",
"[",
"]",
"coordinates",
",",
"double",
"[",
"]",
"shadow",
",",
"GeometryFactory",
"factory",
")",
"{",
"for",
"(",
"int",
"i",
"=",
... | Create and collect shadow polygons.
@param shadows
@param coordinates
@param shadow
@param factory | [
"Create",
"and",
"collect",
"shadow",
"polygons",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/earth/ST_GeometryShadow.java#L235-L248 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/csv/CSVDriverFunction.java | CSVDriverFunction.exportTable | public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String csvOptions) throws SQLException, IOException {
String regex = ".*(?i)\\b(select|from)\\b.*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(tableReference);
if (matcher.find()) {
if (tableReference.startsWith("(") && tableReference.endsWith(")")) {
try (Statement st = connection.createStatement()) {
JDBCUtilities.attachCancelResultSet(st, progress);
Csv csv = new Csv();
if (csvOptions != null && csvOptions.indexOf('=') >= 0) {
csv.setOptions(csvOptions);
}
csv.write(fileName.getPath(), st.executeQuery(tableReference), null);
}
} else {
throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'.");
}
} else {
if (FileUtil.isExtensionWellFormated(fileName, "csv")) {
final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
TableLocation location = TableLocation.parse(tableReference, isH2);
try (Statement st = connection.createStatement()) {
JDBCUtilities.attachCancelResultSet(st, progress);
Csv csv = new Csv();
if (csvOptions != null && csvOptions.indexOf('=') >= 0) {
csv.setOptions(csvOptions);
}
csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null);
}
} else {
throw new SQLException("Only .csv extension is supported");
}
}
} | java | public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String csvOptions) throws SQLException, IOException {
String regex = ".*(?i)\\b(select|from)\\b.*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(tableReference);
if (matcher.find()) {
if (tableReference.startsWith("(") && tableReference.endsWith(")")) {
try (Statement st = connection.createStatement()) {
JDBCUtilities.attachCancelResultSet(st, progress);
Csv csv = new Csv();
if (csvOptions != null && csvOptions.indexOf('=') >= 0) {
csv.setOptions(csvOptions);
}
csv.write(fileName.getPath(), st.executeQuery(tableReference), null);
}
} else {
throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'.");
}
} else {
if (FileUtil.isExtensionWellFormated(fileName, "csv")) {
final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
TableLocation location = TableLocation.parse(tableReference, isH2);
try (Statement st = connection.createStatement()) {
JDBCUtilities.attachCancelResultSet(st, progress);
Csv csv = new Csv();
if (csvOptions != null && csvOptions.indexOf('=') >= 0) {
csv.setOptions(csvOptions);
}
csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null);
}
} else {
throw new SQLException("Only .csv extension is supported");
}
}
} | [
"public",
"void",
"exportTable",
"(",
"Connection",
"connection",
",",
"String",
"tableReference",
",",
"File",
"fileName",
",",
"ProgressVisitor",
"progress",
",",
"String",
"csvOptions",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"String",
"regex",
... | Export a table or a query to a CSV file
@param connection Active connection, do not close this connection.
@param tableReference [[catalog.]schema.]table reference
@param fileName File path to read
@param progress
@param csvOptions the CSV options ie "charset=UTF-8 fieldSeparator=| fieldDelimiter=,"
@throws SQLException
@throws IOException | [
"Export",
"a",
"table",
"or",
"a",
"query",
"to",
"a",
"CSV",
"file"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/csv/CSVDriverFunction.java#L94-L128 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/spatial/mesh/ST_Delaunay.java | ST_Delaunay.createDT | public static GeometryCollection createDT(Geometry geometry, int flag) throws SQLException {
if (geometry != null) {
DelaunayTriangulationBuilder triangulationBuilder = new DelaunayTriangulationBuilder();
triangulationBuilder.setSites(geometry);
if(flag == 0) {
return getTriangles(geometry.getFactory(), triangulationBuilder);
} else {
return (GeometryCollection)triangulationBuilder.getEdges(geometry.getFactory());
}
}
return null;
} | java | public static GeometryCollection createDT(Geometry geometry, int flag) throws SQLException {
if (geometry != null) {
DelaunayTriangulationBuilder triangulationBuilder = new DelaunayTriangulationBuilder();
triangulationBuilder.setSites(geometry);
if(flag == 0) {
return getTriangles(geometry.getFactory(), triangulationBuilder);
} else {
return (GeometryCollection)triangulationBuilder.getEdges(geometry.getFactory());
}
}
return null;
} | [
"public",
"static",
"GeometryCollection",
"createDT",
"(",
"Geometry",
"geometry",
",",
"int",
"flag",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometry",
"!=",
"null",
")",
"{",
"DelaunayTriangulationBuilder",
"triangulationBuilder",
"=",
"new",
"DelaunayTri... | Build a delaunay triangulation based on all coordinates of the geometry
@param geometry
@param flag for flag=0 (default flag) or a MULTILINESTRING for flag=1
@return a set of polygons (triangles)
@throws SQLException | [
"Build",
"a",
"delaunay",
"triangulation",
"based",
"on",
"all",
"coordinates",
"of",
"the",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/spatial/mesh/ST_Delaunay.java#L71-L82 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/ST_AsKml.java | ST_AsKml.toKml | public static String toKml(Geometry geometry) throws SQLException {
StringBuilder sb = new StringBuilder();
KMLGeometry.toKMLGeometry(geometry, sb);
return sb.toString();
} | java | public static String toKml(Geometry geometry) throws SQLException {
StringBuilder sb = new StringBuilder();
KMLGeometry.toKMLGeometry(geometry, sb);
return sb.toString();
} | [
"public",
"static",
"String",
"toKml",
"(",
"Geometry",
"geometry",
")",
"throws",
"SQLException",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"KMLGeometry",
".",
"toKMLGeometry",
"(",
"geometry",
",",
"sb",
")",
";",
"return",
"s... | Generate a KML geometry
@param geometry
@return
@throws SQLException | [
"Generate",
"a",
"KML",
"geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/ST_AsKml.java#L57-L61 | train |
orbisgis/h2gis | h2gis-functions/src/main/java/org/h2gis/functions/io/kml/ST_AsKml.java | ST_AsKml.toKml | public static String toKml(Geometry geometry, boolean extrude, int altitudeModeEnum) throws SQLException {
StringBuilder sb = new StringBuilder();
if (extrude) {
KMLGeometry.toKMLGeometry(geometry, ExtrudeMode.TRUE, altitudeModeEnum, sb);
} else {
KMLGeometry.toKMLGeometry(geometry, ExtrudeMode.FALSE, altitudeModeEnum, sb);
}
return sb.toString();
} | java | public static String toKml(Geometry geometry, boolean extrude, int altitudeModeEnum) throws SQLException {
StringBuilder sb = new StringBuilder();
if (extrude) {
KMLGeometry.toKMLGeometry(geometry, ExtrudeMode.TRUE, altitudeModeEnum, sb);
} else {
KMLGeometry.toKMLGeometry(geometry, ExtrudeMode.FALSE, altitudeModeEnum, sb);
}
return sb.toString();
} | [
"public",
"static",
"String",
"toKml",
"(",
"Geometry",
"geometry",
",",
"boolean",
"extrude",
",",
"int",
"altitudeModeEnum",
")",
"throws",
"SQLException",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"extrude",
")",
"... | Generates a KML geometry. Specifies the extrude and altitudeMode.
Available extrude values are true, false or none.
Supported altitude mode :
For KML profil
CLAMPTOGROUND = 1; RELATIVETOGROUND = 2; ABSOLUTE = 4;
For GX profil CLAMPTOSEAFLOOR = 8; RELATIVETOSEAFLOOR = 16;
No altitude : NONE = 0;
@param geometry
@param altitudeModeEnum
@param extrude
@return
@throws SQLException | [
"Generates",
"a",
"KML",
"geometry",
".",
"Specifies",
"the",
"extrude",
"and",
"altitudeMode",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-functions/src/main/java/org/h2gis/functions/io/kml/ST_AsKml.java#L84-L92 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getGeometryTypeFromGeometry | public static int getGeometryTypeFromGeometry(Geometry geometry) {
Integer sfsGeomCode = GEOM_TYPE_TO_SFS_CODE.get(geometry.getGeometryType().toLowerCase());
if(sfsGeomCode == null) {
return GeometryTypeCodes.GEOMETRY;
} else {
return sfsGeomCode;
}
} | java | public static int getGeometryTypeFromGeometry(Geometry geometry) {
Integer sfsGeomCode = GEOM_TYPE_TO_SFS_CODE.get(geometry.getGeometryType().toLowerCase());
if(sfsGeomCode == null) {
return GeometryTypeCodes.GEOMETRY;
} else {
return sfsGeomCode;
}
} | [
"public",
"static",
"int",
"getGeometryTypeFromGeometry",
"(",
"Geometry",
"geometry",
")",
"{",
"Integer",
"sfsGeomCode",
"=",
"GEOM_TYPE_TO_SFS_CODE",
".",
"get",
"(",
"geometry",
".",
"getGeometryType",
"(",
")",
".",
"toLowerCase",
"(",
")",
")",
";",
"if",
... | Return the sfs geometry type identifier of the provided Geometry
@param geometry Geometry instance
@return The sfs geometry type identifier | [
"Return",
"the",
"sfs",
"geometry",
"type",
"identifier",
"of",
"the",
"provided",
"Geometry"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L79-L86 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getGeometryType | public static int getGeometryType(Connection connection,TableLocation location, String fieldName)
throws SQLException {
if(fieldName==null || fieldName.isEmpty()) {
List<String> geometryFields = getGeometryFields(connection, location);
if(geometryFields.isEmpty()) {
throw new SQLException("The table "+location+" does not contain a Geometry field, " +
"then geometry type cannot be computed");
}
fieldName = geometryFields.get(0);
}
ResultSet geomResultSet = getGeometryColumnsView(connection,location.getCatalog(),location.getSchema(),
location.getTable());
boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
while(geomResultSet.next()) {
if(fieldName.isEmpty() || geomResultSet.getString("F_GEOMETRY_COLUMN").equalsIgnoreCase(fieldName)) {
if(isH2) {
return geomResultSet.getInt("GEOMETRY_TYPE");
} else {
return GEOM_TYPE_TO_SFS_CODE.get(geomResultSet.getString("type").toLowerCase());
}
}
}
throw new SQLException("Field not found "+fieldName);
} | java | public static int getGeometryType(Connection connection,TableLocation location, String fieldName)
throws SQLException {
if(fieldName==null || fieldName.isEmpty()) {
List<String> geometryFields = getGeometryFields(connection, location);
if(geometryFields.isEmpty()) {
throw new SQLException("The table "+location+" does not contain a Geometry field, " +
"then geometry type cannot be computed");
}
fieldName = geometryFields.get(0);
}
ResultSet geomResultSet = getGeometryColumnsView(connection,location.getCatalog(),location.getSchema(),
location.getTable());
boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
while(geomResultSet.next()) {
if(fieldName.isEmpty() || geomResultSet.getString("F_GEOMETRY_COLUMN").equalsIgnoreCase(fieldName)) {
if(isH2) {
return geomResultSet.getInt("GEOMETRY_TYPE");
} else {
return GEOM_TYPE_TO_SFS_CODE.get(geomResultSet.getString("type").toLowerCase());
}
}
}
throw new SQLException("Field not found "+fieldName);
} | [
"public",
"static",
"int",
"getGeometryType",
"(",
"Connection",
"connection",
",",
"TableLocation",
"location",
",",
"String",
"fieldName",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"fieldName",
"==",
"null",
"||",
"fieldName",
".",
"isEmpty",
"(",
")",
... | Return the sfs geometry type identifier of the provided field of the provided table.
@param connection Active connection
@param location Catalog, schema and table name
@param fieldName Geometry field name or empty (take the first one)
@return The sfs geometry type identifier
@see GeometryTypeCodes
@throws SQLException | [
"Return",
"the",
"sfs",
"geometry",
"type",
"identifier",
"of",
"the",
"provided",
"field",
"of",
"the",
"provided",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L101-L124 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getGeometryTypes | public static Map<String, Integer> getGeometryTypes(Connection connection, TableLocation location)
throws SQLException {
Map<String, Integer> map = new HashMap<>();
ResultSet geomResultSet = getGeometryColumnsView(connection,location.getCatalog(),location.getSchema(),
location.getTable());
boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
while(geomResultSet.next()) {
String fieldName = geomResultSet.getString("F_GEOMETRY_COLUMN");
int type;
if(isH2) {
type = geomResultSet.getInt("GEOMETRY_TYPE");
} else {
type = GEOM_TYPE_TO_SFS_CODE.get(geomResultSet.getString("type").toLowerCase());
}
map.put(fieldName, type);
}
return map;
} | java | public static Map<String, Integer> getGeometryTypes(Connection connection, TableLocation location)
throws SQLException {
Map<String, Integer> map = new HashMap<>();
ResultSet geomResultSet = getGeometryColumnsView(connection,location.getCatalog(),location.getSchema(),
location.getTable());
boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
while(geomResultSet.next()) {
String fieldName = geomResultSet.getString("F_GEOMETRY_COLUMN");
int type;
if(isH2) {
type = geomResultSet.getInt("GEOMETRY_TYPE");
} else {
type = GEOM_TYPE_TO_SFS_CODE.get(geomResultSet.getString("type").toLowerCase());
}
map.put(fieldName, type);
}
return map;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"Integer",
">",
"getGeometryTypes",
"(",
"Connection",
"connection",
",",
"TableLocation",
"location",
")",
"throws",
"SQLException",
"{",
"Map",
"<",
"String",
",",
"Integer",
">",
"map",
"=",
"new",
"HashMap",
... | Returns a map containing the field names as key and the SFS geometry type as value from the given table.
@param connection Active connection
@param location Catalog, schema and table name
@return A map containing the geometric fields names as key and the SFS geometry type as value.
@see GeometryTypeCodes
@throws SQLException | [
"Returns",
"a",
"map",
"containing",
"the",
"field",
"names",
"as",
"key",
"and",
"the",
"SFS",
"geometry",
"type",
"as",
"value",
"from",
"the",
"given",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L138-L155 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getTableEnvelope | public static Envelope getTableEnvelope(Connection connection, TableLocation location, String geometryField)
throws SQLException {
if(geometryField==null || geometryField.isEmpty()) {
List<String> geometryFields = getGeometryFields(connection, location);
if(geometryFields.isEmpty()) {
throw new SQLException("The table "+location+" does not contain a Geometry field, then the extent " +
"cannot be computed");
}
geometryField = geometryFields.get(0);
}
ResultSet rs = connection.createStatement().executeQuery("SELECT ST_Extent("+
TableLocation.quoteIdentifier(geometryField)+") ext FROM "+location);
if(rs.next()) {
// Todo under postgis it is a BOX type
return ((Geometry)rs.getObject(1)).getEnvelopeInternal();
}
throw new SQLException("Unable to get the table extent it may be empty");
} | java | public static Envelope getTableEnvelope(Connection connection, TableLocation location, String geometryField)
throws SQLException {
if(geometryField==null || geometryField.isEmpty()) {
List<String> geometryFields = getGeometryFields(connection, location);
if(geometryFields.isEmpty()) {
throw new SQLException("The table "+location+" does not contain a Geometry field, then the extent " +
"cannot be computed");
}
geometryField = geometryFields.get(0);
}
ResultSet rs = connection.createStatement().executeQuery("SELECT ST_Extent("+
TableLocation.quoteIdentifier(geometryField)+") ext FROM "+location);
if(rs.next()) {
// Todo under postgis it is a BOX type
return ((Geometry)rs.getObject(1)).getEnvelopeInternal();
}
throw new SQLException("Unable to get the table extent it may be empty");
} | [
"public",
"static",
"Envelope",
"getTableEnvelope",
"(",
"Connection",
"connection",
",",
"TableLocation",
"location",
",",
"String",
"geometryField",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"geometryField",
"==",
"null",
"||",
"geometryField",
".",
"isEmpty"... | Merge the bounding box of all geometries inside the provided table.
@param connection Active connection (not closed by this function)
@param location Location of the table
@param geometryField Geometry field or empty string (take the first geometry field)
@return Envelope of the table
@throws SQLException If the table not exists, empty or does not contain a geometry field. | [
"Merge",
"the",
"bounding",
"box",
"of",
"all",
"geometries",
"inside",
"the",
"provided",
"table",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L212-L229 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.prepareInformationSchemaStatement | public static PreparedStatement prepareInformationSchemaStatement(Connection connection,String catalog,
String schema, String table,
String informationSchemaTable,
String endQuery, String catalog_field,
String schema_field, String table_field)
throws SQLException {
Integer catalogIndex = null;
Integer schemaIndex = null;
Integer tableIndex = 1;
StringBuilder sb = new StringBuilder("SELECT * from "+informationSchemaTable+" where ");
if(!catalog.isEmpty()) {
sb.append("UPPER(");
sb.append(catalog_field);
sb.append(") = ? AND ");
catalogIndex = 1;
tableIndex++;
}
if(!schema.isEmpty()) {
sb.append("UPPER(");
sb.append(schema_field);
sb.append(") = ? AND ");
schemaIndex = tableIndex;
tableIndex++;
}
sb.append("UPPER(");
sb.append(table_field);
sb.append(") = ? ");
sb.append(endQuery);
PreparedStatement preparedStatement = connection.prepareStatement(sb.toString());
if(catalogIndex!=null) {
preparedStatement.setString(catalogIndex, catalog.toUpperCase());
}
if(schemaIndex!=null) {
preparedStatement.setString(schemaIndex, schema.toUpperCase());
}
preparedStatement.setString(tableIndex, table.toUpperCase());
return preparedStatement;
} | java | public static PreparedStatement prepareInformationSchemaStatement(Connection connection,String catalog,
String schema, String table,
String informationSchemaTable,
String endQuery, String catalog_field,
String schema_field, String table_field)
throws SQLException {
Integer catalogIndex = null;
Integer schemaIndex = null;
Integer tableIndex = 1;
StringBuilder sb = new StringBuilder("SELECT * from "+informationSchemaTable+" where ");
if(!catalog.isEmpty()) {
sb.append("UPPER(");
sb.append(catalog_field);
sb.append(") = ? AND ");
catalogIndex = 1;
tableIndex++;
}
if(!schema.isEmpty()) {
sb.append("UPPER(");
sb.append(schema_field);
sb.append(") = ? AND ");
schemaIndex = tableIndex;
tableIndex++;
}
sb.append("UPPER(");
sb.append(table_field);
sb.append(") = ? ");
sb.append(endQuery);
PreparedStatement preparedStatement = connection.prepareStatement(sb.toString());
if(catalogIndex!=null) {
preparedStatement.setString(catalogIndex, catalog.toUpperCase());
}
if(schemaIndex!=null) {
preparedStatement.setString(schemaIndex, schema.toUpperCase());
}
preparedStatement.setString(tableIndex, table.toUpperCase());
return preparedStatement;
} | [
"public",
"static",
"PreparedStatement",
"prepareInformationSchemaStatement",
"(",
"Connection",
"connection",
",",
"String",
"catalog",
",",
"String",
"schema",
",",
"String",
"table",
",",
"String",
"informationSchemaTable",
",",
"String",
"endQuery",
",",
"String",
... | For table containing catalog, schema and table name, this function create a prepared statement with a filter
on this combination.
@param connection Active connection
@param catalog Table catalog, may be empty
@param schema Table schema, may be empty
@param table Table name
@param informationSchemaTable Information table location
@param endQuery Additional where statement
@param catalog_field Catalog field name
@param schema_field Schema field name
@param table_field Table field name
@return Prepared statement
@throws SQLException | [
"For",
"table",
"containing",
"catalog",
"schema",
"and",
"table",
"name",
"this",
"function",
"create",
"a",
"prepared",
"statement",
"with",
"a",
"filter",
"on",
"this",
"combination",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L263-L300 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.prepareInformationSchemaStatement | public static PreparedStatement prepareInformationSchemaStatement(Connection connection,String catalog,
String schema, String table,
String informationSchemaTable, String endQuery)
throws SQLException {
return prepareInformationSchemaStatement(connection,catalog, schema, table, informationSchemaTable, endQuery,
"f_table_catalog","f_table_schema","f_table_name");
} | java | public static PreparedStatement prepareInformationSchemaStatement(Connection connection,String catalog,
String schema, String table,
String informationSchemaTable, String endQuery)
throws SQLException {
return prepareInformationSchemaStatement(connection,catalog, schema, table, informationSchemaTable, endQuery,
"f_table_catalog","f_table_schema","f_table_name");
} | [
"public",
"static",
"PreparedStatement",
"prepareInformationSchemaStatement",
"(",
"Connection",
"connection",
",",
"String",
"catalog",
",",
"String",
"schema",
",",
"String",
"table",
",",
"String",
"informationSchemaTable",
",",
"String",
"endQuery",
")",
"throws",
... | For table containing catalog, schema and table name, this function create a prepared statement with a filter on
this combination. Use "f_table_catalog","f_table_schema","f_table_name" as field names.
@param connection Active connection
@param catalog Table catalog, may be empty
@param schema Table schema, may be empty
@param table Table name
@param informationSchemaTable Information table location
@param endQuery Additional where statement
@return Prepared statement
@throws SQLException | [
"For",
"table",
"containing",
"catalog",
"schema",
"and",
"table",
"name",
"this",
"function",
"create",
"a",
"prepared",
"statement",
"with",
"a",
"filter",
"on",
"this",
"combination",
".",
"Use",
"f_table_catalog",
"f_table_schema",
"f_table_name",
"as",
"field... | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L317-L323 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getGeometryFields | public static List<String> getGeometryFields(ResultSet resultSet) throws SQLException {
List<String> fieldsName = new LinkedList<>();
ResultSetMetaData meta = resultSet.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
fieldsName.add(meta.getColumnName(i));
}
}
return fieldsName;
} | java | public static List<String> getGeometryFields(ResultSet resultSet) throws SQLException {
List<String> fieldsName = new LinkedList<>();
ResultSetMetaData meta = resultSet.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
fieldsName.add(meta.getColumnName(i));
}
}
return fieldsName;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getGeometryFields",
"(",
"ResultSet",
"resultSet",
")",
"throws",
"SQLException",
"{",
"List",
"<",
"String",
">",
"fieldsName",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"ResultSetMetaData",
"meta",
"=",
... | Find geometry fields name of a resultSet.
@param resultSet ResultSet to analyse
@return A list of Geometry fields name
@throws SQLException | [
"Find",
"geometry",
"fields",
"name",
"of",
"a",
"resultSet",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L363-L373 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.hasGeometryField | public static boolean hasGeometryField(ResultSet resultSet) throws SQLException {
ResultSetMetaData meta = resultSet.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
return true;
}
}
return false;
} | java | public static boolean hasGeometryField(ResultSet resultSet) throws SQLException {
ResultSetMetaData meta = resultSet.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
return true;
}
}
return false;
} | [
"public",
"static",
"boolean",
"hasGeometryField",
"(",
"ResultSet",
"resultSet",
")",
"throws",
"SQLException",
"{",
"ResultSetMetaData",
"meta",
"=",
"resultSet",
".",
"getMetaData",
"(",
")",
";",
"int",
"columnCount",
"=",
"meta",
".",
"getColumnCount",
"(",
... | Check if the ResultSet contains a geometry field
@param resultSet ResultSet to analyse
@return True if the ResultSet contains one geometry field
@throws SQLException | [
"Check",
"if",
"the",
"ResultSet",
"contains",
"a",
"geometry",
"field"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L427-L436 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getResultSetEnvelope | public static Envelope getResultSetEnvelope(ResultSet resultSet) throws SQLException {
List<String> geometryFields = getGeometryFields(resultSet);
if (geometryFields.isEmpty()) {
throw new SQLException("This ResultSet doesn't contain any geometry field.");
} else {
return getResultSetEnvelope(resultSet, geometryFields.get(0));
}
} | java | public static Envelope getResultSetEnvelope(ResultSet resultSet) throws SQLException {
List<String> geometryFields = getGeometryFields(resultSet);
if (geometryFields.isEmpty()) {
throw new SQLException("This ResultSet doesn't contain any geometry field.");
} else {
return getResultSetEnvelope(resultSet, geometryFields.get(0));
}
} | [
"public",
"static",
"Envelope",
"getResultSetEnvelope",
"(",
"ResultSet",
"resultSet",
")",
"throws",
"SQLException",
"{",
"List",
"<",
"String",
">",
"geometryFields",
"=",
"getGeometryFields",
"(",
"resultSet",
")",
";",
"if",
"(",
"geometryFields",
".",
"isEmpt... | Compute the full extend of a ResultSet using the first geometry field. If
the ResultSet does not contain any geometry field throw an exception
@param resultSet ResultSet to analyse
@return The full envelope of the ResultSet
@throws SQLException | [
"Compute",
"the",
"full",
"extend",
"of",
"a",
"ResultSet",
"using",
"the",
"first",
"geometry",
"field",
".",
"If",
"the",
"ResultSet",
"does",
"not",
"contain",
"any",
"geometry",
"field",
"throw",
"an",
"exception"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L448-L455 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getResultSetEnvelope | public static Envelope getResultSetEnvelope(ResultSet resultSet, String fieldName) throws SQLException {
Envelope aggregatedEnvelope = null;
while (resultSet.next()) {
Geometry geom = (Geometry) resultSet.getObject(fieldName);
if (aggregatedEnvelope != null) {
aggregatedEnvelope.expandToInclude(geom.getEnvelopeInternal());
} else {
aggregatedEnvelope = geom.getEnvelopeInternal();
}
}
return aggregatedEnvelope;
} | java | public static Envelope getResultSetEnvelope(ResultSet resultSet, String fieldName) throws SQLException {
Envelope aggregatedEnvelope = null;
while (resultSet.next()) {
Geometry geom = (Geometry) resultSet.getObject(fieldName);
if (aggregatedEnvelope != null) {
aggregatedEnvelope.expandToInclude(geom.getEnvelopeInternal());
} else {
aggregatedEnvelope = geom.getEnvelopeInternal();
}
}
return aggregatedEnvelope;
} | [
"public",
"static",
"Envelope",
"getResultSetEnvelope",
"(",
"ResultSet",
"resultSet",
",",
"String",
"fieldName",
")",
"throws",
"SQLException",
"{",
"Envelope",
"aggregatedEnvelope",
"=",
"null",
";",
"while",
"(",
"resultSet",
".",
"next",
"(",
")",
")",
"{",... | Compute the full extend of a ResultSet using a specified geometry field.
If the ResultSet does not contain this geometry field throw an exception
@param resultSet ResultSet to analyse
@param fieldName Field to analyse
@return The full extend of the field in the ResultSet
@throws SQLException | [
"Compute",
"the",
"full",
"extend",
"of",
"a",
"ResultSet",
"using",
"a",
"specified",
"geometry",
"field",
".",
"If",
"the",
"ResultSet",
"does",
"not",
"contain",
"this",
"geometry",
"field",
"throw",
"an",
"exception"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L468-L479 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.getSRID | public static int getSRID(Connection connection, TableLocation table) throws SQLException {
ResultSet geomResultSet = getGeometryColumnsView(connection, table.getCatalog(), table.getSchema(),
table.getTable());
int srid = 0;
while (geomResultSet.next()) {
srid = geomResultSet.getInt("srid");
break;
}
geomResultSet.close();
return srid;
} | java | public static int getSRID(Connection connection, TableLocation table) throws SQLException {
ResultSet geomResultSet = getGeometryColumnsView(connection, table.getCatalog(), table.getSchema(),
table.getTable());
int srid = 0;
while (geomResultSet.next()) {
srid = geomResultSet.getInt("srid");
break;
}
geomResultSet.close();
return srid;
} | [
"public",
"static",
"int",
"getSRID",
"(",
"Connection",
"connection",
",",
"TableLocation",
"table",
")",
"throws",
"SQLException",
"{",
"ResultSet",
"geomResultSet",
"=",
"getGeometryColumnsView",
"(",
"connection",
",",
"table",
".",
"getCatalog",
"(",
")",
","... | Return the SRID of the first geometry column of the input table
@param connection Active connection
@param table Table name
@return The SRID of the first geometry column
@throws SQLException | [
"Return",
"the",
"SRID",
"of",
"the",
"first",
"geometry",
"column",
"of",
"the",
"input",
"table"
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L491-L501 | train |
orbisgis/h2gis | h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java | SFSUtilities.addTableSRIDConstraint | public static void addTableSRIDConstraint(Connection connection, TableLocation tableLocation, int srid)
throws SQLException {
//Alter table to set the SRID constraint
if (srid > 0) {
connection.createStatement().execute(String.format("ALTER TABLE %s ADD CHECK ST_SRID(the_geom)=%d",
tableLocation.toString(), srid));
}
} | java | public static void addTableSRIDConstraint(Connection connection, TableLocation tableLocation, int srid)
throws SQLException {
//Alter table to set the SRID constraint
if (srid > 0) {
connection.createStatement().execute(String.format("ALTER TABLE %s ADD CHECK ST_SRID(the_geom)=%d",
tableLocation.toString(), srid));
}
} | [
"public",
"static",
"void",
"addTableSRIDConstraint",
"(",
"Connection",
"connection",
",",
"TableLocation",
"tableLocation",
",",
"int",
"srid",
")",
"throws",
"SQLException",
"{",
"//Alter table to set the SRID constraint",
"if",
"(",
"srid",
">",
"0",
")",
"{",
"... | Alter a table to add a SRID constraint.
The srid must be greater than zero.
@param connection Active connection
@param tableLocation TableLocation of the table to update
@param srid SRID to set
@throws SQLException | [
"Alter",
"a",
"table",
"to",
"add",
"a",
"SRID",
"constraint",
".",
"The",
"srid",
"must",
"be",
"greater",
"than",
"zero",
"."
] | 9cd70b447e6469cecbc2fc64b16774b59491df3b | https://github.com/orbisgis/h2gis/blob/9cd70b447e6469cecbc2fc64b16774b59491df3b/h2gis-utilities/src/main/java/org/h2gis/utilities/SFSUtilities.java#L586-L593 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java | MockInternetGatewayController.createInternetGateway | public MockInternetGateway createInternetGateway() {
MockInternetGateway ret = new MockInternetGateway();
ret.setInternetGatewayId("InternetGateway-"
+ UUID.randomUUID().toString().substring(0, INTERNETGATEWAY_ID_POSTFIX_LENGTH));
allMockInternetGateways.put(ret.getInternetGatewayId(), ret);
return ret;
} | java | public MockInternetGateway createInternetGateway() {
MockInternetGateway ret = new MockInternetGateway();
ret.setInternetGatewayId("InternetGateway-"
+ UUID.randomUUID().toString().substring(0, INTERNETGATEWAY_ID_POSTFIX_LENGTH));
allMockInternetGateways.put(ret.getInternetGatewayId(), ret);
return ret;
} | [
"public",
"MockInternetGateway",
"createInternetGateway",
"(",
")",
"{",
"MockInternetGateway",
"ret",
"=",
"new",
"MockInternetGateway",
"(",
")",
";",
"ret",
".",
"setInternetGatewayId",
"(",
"\"InternetGateway-\"",
"+",
"UUID",
".",
"randomUUID",
"(",
")",
".",
... | Create the mock InternetGateway.
@return mock InternetGateway. | [
"Create",
"the",
"mock",
"InternetGateway",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java#L81-L89 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java | MockInternetGatewayController.attachInternetGateway | public MockInternetGateway attachInternetGateway(final String internetgatewayId,
final String vpcId) {
if (internetgatewayId == null) {
return null;
}
MockInternetGateway ret = allMockInternetGateways.get(internetgatewayId);
if (ret != null) {
MockInternetGatewayAttachmentType internetGatewayAttachmentType = new MockInternetGatewayAttachmentType();
internetGatewayAttachmentType.setVpcId(vpcId);
internetGatewayAttachmentType.setState("Available");
List<MockInternetGatewayAttachmentType> internetGatewayAttachmentSet
= new ArrayList<MockInternetGatewayAttachmentType>();
internetGatewayAttachmentSet.add(internetGatewayAttachmentType);
ret.setAttachmentSet(internetGatewayAttachmentSet);
allMockInternetGateways.put(ret.getInternetGatewayId(), ret);
}
return ret;
} | java | public MockInternetGateway attachInternetGateway(final String internetgatewayId,
final String vpcId) {
if (internetgatewayId == null) {
return null;
}
MockInternetGateway ret = allMockInternetGateways.get(internetgatewayId);
if (ret != null) {
MockInternetGatewayAttachmentType internetGatewayAttachmentType = new MockInternetGatewayAttachmentType();
internetGatewayAttachmentType.setVpcId(vpcId);
internetGatewayAttachmentType.setState("Available");
List<MockInternetGatewayAttachmentType> internetGatewayAttachmentSet
= new ArrayList<MockInternetGatewayAttachmentType>();
internetGatewayAttachmentSet.add(internetGatewayAttachmentType);
ret.setAttachmentSet(internetGatewayAttachmentSet);
allMockInternetGateways.put(ret.getInternetGatewayId(), ret);
}
return ret;
} | [
"public",
"MockInternetGateway",
"attachInternetGateway",
"(",
"final",
"String",
"internetgatewayId",
",",
"final",
"String",
"vpcId",
")",
"{",
"if",
"(",
"internetgatewayId",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"MockInternetGateway",
"ret",
"=",... | Attach the mock InternetGateway.
@param vpcId vpc Id for InternetGateway.
@param internetgatewayId
internetgatewayId to be deleted
@return mock InternetGateway. | [
"Attach",
"the",
"mock",
"InternetGateway",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java#L98-L116 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java | MockInternetGatewayController.deleteInternetGateway | public MockInternetGateway deleteInternetGateway(final String internetgatewayId) {
if (internetgatewayId != null && allMockInternetGateways.containsKey(internetgatewayId)) {
return allMockInternetGateways.remove(internetgatewayId);
}
return null;
} | java | public MockInternetGateway deleteInternetGateway(final String internetgatewayId) {
if (internetgatewayId != null && allMockInternetGateways.containsKey(internetgatewayId)) {
return allMockInternetGateways.remove(internetgatewayId);
}
return null;
} | [
"public",
"MockInternetGateway",
"deleteInternetGateway",
"(",
"final",
"String",
"internetgatewayId",
")",
"{",
"if",
"(",
"internetgatewayId",
"!=",
"null",
"&&",
"allMockInternetGateways",
".",
"containsKey",
"(",
"internetgatewayId",
")",
")",
"{",
"return",
"allM... | Delete InternetGateway.
@param internetgatewayId
internetgatewayId to be deleted
@return Mock InternetGateway. | [
"Delete",
"InternetGateway",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockInternetGatewayController.java#L125-L131 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java | AbstractMockEc2Instance.getMsFromProperty | private static long getMsFromProperty(final String propertyName,
final String propertyNameInSeconds) {
String property = PropertiesUtils.getProperty(propertyName);
if (property != null) {
return Long.parseLong(property);
}
return Integer.parseInt(PropertiesUtils.getProperty(propertyNameInSeconds))
* MILLISECS_IN_A_SECOND;
} | java | private static long getMsFromProperty(final String propertyName,
final String propertyNameInSeconds) {
String property = PropertiesUtils.getProperty(propertyName);
if (property != null) {
return Long.parseLong(property);
}
return Integer.parseInt(PropertiesUtils.getProperty(propertyNameInSeconds))
* MILLISECS_IN_A_SECOND;
} | [
"private",
"static",
"long",
"getMsFromProperty",
"(",
"final",
"String",
"propertyName",
",",
"final",
"String",
"propertyNameInSeconds",
")",
"{",
"String",
"property",
"=",
"PropertiesUtils",
".",
"getProperty",
"(",
"propertyName",
")",
";",
"if",
"(",
"proper... | Get millisecs from properties.
@param propertyName
the property name
@param propertyNameInSeconds
the property name for seconds
@return millisecs | [
"Get",
"millisecs",
"from",
"properties",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java#L495-L503 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java | AbstractMockEc2Instance.initializeInternalTimer | public final void initializeInternalTimer() {
// if it is the first the instance is started, we initialize the
// internal timer thread
if (!internalTimerInitialized) {
TimerTask internalTimerTask = new TimerTask() {
/**
* this method is triggered every TIMER_INTERVAL_MILLIS
*/
@Override
public void run() {
if (terminated) {
running = false;
booting = false;
stopping = false;
pubDns = null;
this.cancel();
onTerminated();
return;
}
if (running) {
if (booting) {
// delay a random 'boot time'
if (MAX_BOOT_TIME_MILLS != 0) {
try {
Thread.sleep(MIN_BOOT_TIME_MILLS
+ random.nextInt((int) (MAX_BOOT_TIME_MILLS
- MIN_BOOT_TIME_MILLS)));
} catch (InterruptedException e) {
throw new AwsMockException(
"InterruptedException caught when delaying a mock random 'boot time'",
e);
}
}
// booted, assign a mock pub dns name
pubDns = generatePubDns();
booting = false;
onBooted();
} else if (stopping) {
// delay a random 'shutdown time'
if (MAX_SHUTDOWN_TIME_MILLS != 0) {
try {
Thread.sleep(MIN_SHUTDOWN_TIME_MILLS
+ random.nextInt((int) (MAX_SHUTDOWN_TIME_MILLS
- MIN_SHUTDOWN_TIME_MILLS)));
} catch (InterruptedException e) {
throw new AwsMockException(
"InterruptedException caught when delaying a mock random 'shutdown time'",
e);
}
}
// unset pub dns name
pubDns = null;
stopping = false;
running = false;
onStopped();
}
onInternalTimer();
}
}
};
timer = new SerializableTimer(true);
timer.schedule(internalTimerTask, 0L, TIMER_INTERVAL_MILLIS);
internalTimerInitialized = true;
}
} | java | public final void initializeInternalTimer() {
// if it is the first the instance is started, we initialize the
// internal timer thread
if (!internalTimerInitialized) {
TimerTask internalTimerTask = new TimerTask() {
/**
* this method is triggered every TIMER_INTERVAL_MILLIS
*/
@Override
public void run() {
if (terminated) {
running = false;
booting = false;
stopping = false;
pubDns = null;
this.cancel();
onTerminated();
return;
}
if (running) {
if (booting) {
// delay a random 'boot time'
if (MAX_BOOT_TIME_MILLS != 0) {
try {
Thread.sleep(MIN_BOOT_TIME_MILLS
+ random.nextInt((int) (MAX_BOOT_TIME_MILLS
- MIN_BOOT_TIME_MILLS)));
} catch (InterruptedException e) {
throw new AwsMockException(
"InterruptedException caught when delaying a mock random 'boot time'",
e);
}
}
// booted, assign a mock pub dns name
pubDns = generatePubDns();
booting = false;
onBooted();
} else if (stopping) {
// delay a random 'shutdown time'
if (MAX_SHUTDOWN_TIME_MILLS != 0) {
try {
Thread.sleep(MIN_SHUTDOWN_TIME_MILLS
+ random.nextInt((int) (MAX_SHUTDOWN_TIME_MILLS
- MIN_SHUTDOWN_TIME_MILLS)));
} catch (InterruptedException e) {
throw new AwsMockException(
"InterruptedException caught when delaying a mock random 'shutdown time'",
e);
}
}
// unset pub dns name
pubDns = null;
stopping = false;
running = false;
onStopped();
}
onInternalTimer();
}
}
};
timer = new SerializableTimer(true);
timer.schedule(internalTimerTask, 0L, TIMER_INTERVAL_MILLIS);
internalTimerInitialized = true;
}
} | [
"public",
"final",
"void",
"initializeInternalTimer",
"(",
")",
"{",
"// if it is the first the instance is started, we initialize the",
"// internal timer thread",
"if",
"(",
"!",
"internalTimerInitialized",
")",
"{",
"TimerTask",
"internalTimerTask",
"=",
"new",
"TimerTask",
... | Start scheduling the internal timer that controls the behaviors and states of this mock ec2 instance. | [
"Start",
"scheduling",
"the",
"internal",
"timer",
"that",
"controls",
"the",
"behaviors",
"and",
"states",
"of",
"this",
"mock",
"ec2",
"instance",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java#L639-L723 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java | AbstractMockEc2Instance.start | public final boolean start() {
if (running || booting || stopping || terminated) {
// do nothing if this instance is not stopped
return false;
} else {
// mark this instance started
booting = true;
running = true;
onStarted();
return true;
}
} | java | public final boolean start() {
if (running || booting || stopping || terminated) {
// do nothing if this instance is not stopped
return false;
} else {
// mark this instance started
booting = true;
running = true;
onStarted();
return true;
}
} | [
"public",
"final",
"boolean",
"start",
"(",
")",
"{",
"if",
"(",
"running",
"||",
"booting",
"||",
"stopping",
"||",
"terminated",
")",
"{",
"// do nothing if this instance is not stopped",
"return",
"false",
";",
"}",
"else",
"{",
"// mark this instance started",
... | Start a stopped mock ec2 instance.
@return true for successfully started and false for nothing changed by this action | [
"Start",
"a",
"stopped",
"mock",
"ec2",
"instance",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java#L739-L753 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java | AbstractMockEc2Instance.stop | public final boolean stop() {
if (booting || running) {
stopping = true;
booting = false;
onStopping();
return true;
} else {
return false;
}
} | java | public final boolean stop() {
if (booting || running) {
stopping = true;
booting = false;
onStopping();
return true;
} else {
return false;
}
} | [
"public",
"final",
"boolean",
"stop",
"(",
")",
"{",
"if",
"(",
"booting",
"||",
"running",
")",
"{",
"stopping",
"=",
"true",
";",
"booting",
"=",
"false",
";",
"onStopping",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",... | Stop this ec2 instance.
@return true for successfully turned into 'stopping' and false for nothing changed | [
"Stop",
"this",
"ec2",
"instance",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java#L760-L771 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java | AbstractMockEc2Instance.getInstanceState | public final InstanceState getInstanceState() {
return isTerminated() ? InstanceState.TERMINATED
: (isBooting() ? InstanceState.PENDING
: (isStopping() ? InstanceState.STOPPING
: (isRunning() ? InstanceState.RUNNING
: InstanceState.STOPPED)));
} | java | public final InstanceState getInstanceState() {
return isTerminated() ? InstanceState.TERMINATED
: (isBooting() ? InstanceState.PENDING
: (isStopping() ? InstanceState.STOPPING
: (isRunning() ? InstanceState.RUNNING
: InstanceState.STOPPED)));
} | [
"public",
"final",
"InstanceState",
"getInstanceState",
"(",
")",
"{",
"return",
"isTerminated",
"(",
")",
"?",
"InstanceState",
".",
"TERMINATED",
":",
"(",
"isBooting",
"(",
")",
"?",
"InstanceState",
".",
"PENDING",
":",
"(",
"isStopping",
"(",
")",
"?",
... | Get state of this mock ec2 instance.
@return state of this mock ec2 instance, should be one of the instance states defined in {@link InstanceState} | [
"Get",
"state",
"of",
"this",
"mock",
"ec2",
"instance",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/model/AbstractMockEc2Instance.java#L795-L801 | train |
treelogic-swe/aws-mock | example/java/simple/DescribeInstancesExample.java | DescribeInstancesExample.describeAllInstances | public static List<Instance> describeAllInstances() {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
DescribeInstancesResult response = amazonEC2Client.describeInstances();
List<Reservation> reservations = response.getReservations();
List<Instance> ret = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
if (null != instances) {
for (Instance i : instances) {
ret.add(i);
}
}
}
return ret;
} | java | public static List<Instance> describeAllInstances() {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
DescribeInstancesResult response = amazonEC2Client.describeInstances();
List<Reservation> reservations = response.getReservations();
List<Instance> ret = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
if (null != instances) {
for (Instance i : instances) {
ret.add(i);
}
}
}
return ret;
} | [
"public",
"static",
"List",
"<",
"Instance",
">",
"describeAllInstances",
"(",
")",
"{",
"// pass any credentials as aws-mock does not authenticate them at all",
"AWSCredentials",
"credentials",
"=",
"new",
"BasicAWSCredentials",
"(",
"\"foo\"",
",",
"\"bar\"",
")",
";",
... | Describe all mock instances within aws-mock.
@return a list of all instances | [
"Describe",
"all",
"mock",
"instances",
"within",
"aws",
"-",
"mock",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/example/java/simple/DescribeInstancesExample.java#L34-L60 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockSubnetController.java | MockSubnetController.createSubnet | public MockSubnet createSubnet(
final String cidrBlock, final String vpcId) {
MockSubnet ret = new MockSubnet();
ret.setCidrBlock(cidrBlock);
ret.setSubnetId(
"subnet-" + UUID.randomUUID().toString().substring(0, SUBNET_ID_POSTFIX_LENGTH));
ret.setVpcId(vpcId);
allMockSubnets.put(ret.getSubnetId(), ret);
return ret;
} | java | public MockSubnet createSubnet(
final String cidrBlock, final String vpcId) {
MockSubnet ret = new MockSubnet();
ret.setCidrBlock(cidrBlock);
ret.setSubnetId(
"subnet-" + UUID.randomUUID().toString().substring(0, SUBNET_ID_POSTFIX_LENGTH));
ret.setVpcId(vpcId);
allMockSubnets.put(ret.getSubnetId(), ret);
return ret;
} | [
"public",
"MockSubnet",
"createSubnet",
"(",
"final",
"String",
"cidrBlock",
",",
"final",
"String",
"vpcId",
")",
"{",
"MockSubnet",
"ret",
"=",
"new",
"MockSubnet",
"(",
")",
";",
"ret",
".",
"setCidrBlock",
"(",
"cidrBlock",
")",
";",
"ret",
".",
"setSu... | Create the mock Subnet.
@param cidrBlock VPC cidr block.
@param vpcId vpc Id for subnet.
@return mock Subnet. | [
"Create",
"the",
"mock",
"Subnet",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockSubnetController.java#L80-L92 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockSubnetController.java | MockSubnetController.deleteSubnet | public MockSubnet deleteSubnet(final String subnetId) {
if (subnetId != null && allMockSubnets.containsKey(subnetId)) {
return allMockSubnets.remove(subnetId);
}
return null;
} | java | public MockSubnet deleteSubnet(final String subnetId) {
if (subnetId != null && allMockSubnets.containsKey(subnetId)) {
return allMockSubnets.remove(subnetId);
}
return null;
} | [
"public",
"MockSubnet",
"deleteSubnet",
"(",
"final",
"String",
"subnetId",
")",
"{",
"if",
"(",
"subnetId",
"!=",
"null",
"&&",
"allMockSubnets",
".",
"containsKey",
"(",
"subnetId",
")",
")",
"{",
"return",
"allMockSubnets",
".",
"remove",
"(",
"subnetId",
... | Delete Subnet.
@param subnetId
subnetId to be deleted
@return Mock Subnet. | [
"Delete",
"Subnet",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockSubnetController.java#L101-L108 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.parseInstanceStates | private Set<String> parseInstanceStates(final Map<String, String[]> queryParams) {
Set<String> instanceStates = new TreeSet<String>();
for (String queryKey : queryParams.keySet()) {
// e.g. Filter.1.Value.1: running, Filter.1.Value.2: pending
if (queryKey.startsWith("Filter.1.Value")) {
for (String state : queryParams.get(queryKey)) {
instanceStates.add(state);
}
}
}
return instanceStates;
} | java | private Set<String> parseInstanceStates(final Map<String, String[]> queryParams) {
Set<String> instanceStates = new TreeSet<String>();
for (String queryKey : queryParams.keySet()) {
// e.g. Filter.1.Value.1: running, Filter.1.Value.2: pending
if (queryKey.startsWith("Filter.1.Value")) {
for (String state : queryParams.get(queryKey)) {
instanceStates.add(state);
}
}
}
return instanceStates;
} | [
"private",
"Set",
"<",
"String",
">",
"parseInstanceStates",
"(",
"final",
"Map",
"<",
"String",
",",
"String",
"[",
"]",
">",
"queryParams",
")",
"{",
"Set",
"<",
"String",
">",
"instanceStates",
"=",
"new",
"TreeSet",
"<",
"String",
">",
"(",
")",
";... | Parse instance states from query parameters.
@param queryParams
map of query parameters in http request
@return a set of instance states in the parameter map | [
"Parse",
"instance",
"states",
"from",
"query",
"parameters",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L944-L956 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeAvailabilityZones | private DescribeAvailabilityZonesResponseType describeAvailabilityZones() {
DescribeAvailabilityZonesResponseType ret = new DescribeAvailabilityZonesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
AvailabilityZoneSetType info = new AvailabilityZoneSetType();
AvailabilityZoneItemType item = new AvailabilityZoneItemType();
item.setRegionName(currentRegion);
item.setZoneName(currentRegion);
info.getItem().add(item);
ret.setAvailabilityZoneInfo(info);
return ret;
} | java | private DescribeAvailabilityZonesResponseType describeAvailabilityZones() {
DescribeAvailabilityZonesResponseType ret = new DescribeAvailabilityZonesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
AvailabilityZoneSetType info = new AvailabilityZoneSetType();
AvailabilityZoneItemType item = new AvailabilityZoneItemType();
item.setRegionName(currentRegion);
item.setZoneName(currentRegion);
info.getItem().add(item);
ret.setAvailabilityZoneInfo(info);
return ret;
} | [
"private",
"DescribeAvailabilityZonesResponseType",
"describeAvailabilityZones",
"(",
")",
"{",
"DescribeAvailabilityZonesResponseType",
"ret",
"=",
"new",
"DescribeAvailabilityZonesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(... | Handles "describeAvailabilityZones" request, as simple as without any filters to use.
@return a DescribeAvailabilityZonesResponseType with our predefined AMIs
in aws-mock.properties (or if not overridden, as defined in aws-mock-default.properties) | [
"Handles",
"describeAvailabilityZones",
"request",
"as",
"simple",
"as",
"without",
"any",
"filters",
"to",
"use",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L964-L976 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.parseInstanceIDs | private Set<String> parseInstanceIDs(final Map<String, String[]> queryParams) {
Set<String> ret = new TreeSet<String>();
Set<Map.Entry<String, String[]>> entries = queryParams.entrySet();
for (Map.Entry<String, String[]> entry : entries) {
if (null != entry && null != entry.getKey()
&& entry.getKey().matches("InstanceId\\.(\\d)+")) {
if (null != entry.getValue() && entry.getValue().length > 0) {
ret.add(entry.getValue()[0]);
}
}
}
return ret;
} | java | private Set<String> parseInstanceIDs(final Map<String, String[]> queryParams) {
Set<String> ret = new TreeSet<String>();
Set<Map.Entry<String, String[]>> entries = queryParams.entrySet();
for (Map.Entry<String, String[]> entry : entries) {
if (null != entry && null != entry.getKey()
&& entry.getKey().matches("InstanceId\\.(\\d)+")) {
if (null != entry.getValue() && entry.getValue().length > 0) {
ret.add(entry.getValue()[0]);
}
}
}
return ret;
} | [
"private",
"Set",
"<",
"String",
">",
"parseInstanceIDs",
"(",
"final",
"Map",
"<",
"String",
",",
"String",
"[",
"]",
">",
"queryParams",
")",
"{",
"Set",
"<",
"String",
">",
"ret",
"=",
"new",
"TreeSet",
"<",
"String",
">",
"(",
")",
";",
"Set",
... | Parse instance IDs from query parameters.
@param queryParams
map of query parameters in http request
@return a set of instance IDs in the parameter map | [
"Parse",
"instance",
"IDs",
"from",
"query",
"parameters",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L985-L998 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.generateToken | protected String generateToken() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < TOKEN_MIDDLE_LEN; i++) {
sb.append(TOKEN_DICT.charAt(random.nextInt(TOKEN_DICT.length())));
}
return TOKEN_PREFIX + sb.toString() + TOKEN_SUFFIX;
} | java | protected String generateToken() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < TOKEN_MIDDLE_LEN; i++) {
sb.append(TOKEN_DICT.charAt(random.nextInt(TOKEN_DICT.length())));
}
return TOKEN_PREFIX + sb.toString() + TOKEN_SUFFIX;
} | [
"protected",
"String",
"generateToken",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"TOKEN_MIDDLE_LEN",
";",
"i",
"++",
")",
"{",
"sb",
".",
"append",
"(",
"TOKEN_... | Generate a new token used in describeInstanceResponse while paging enabled.
@return a random string as a token | [
"Generate",
"a",
"new",
"token",
"used",
"in",
"describeInstanceResponse",
"while",
"paging",
"enabled",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1174-L1180 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.runInstances | private RunInstancesResponseType runInstances(final String imageId, final String instanceType,
final int minCount, final int maxCount) {
RunInstancesResponseType ret = new RunInstancesResponseType();
RunningInstancesSetType instSet = new RunningInstancesSetType();
Class<? extends AbstractMockEc2Instance> clazzOfMockEc2Instance = null;
try {
// clazzOfMockEc2Instance = (Class<? extends MockEc2Instance>) Class.forName(MOCK_EC2_INSTANCE_CLASS_NAME);
clazzOfMockEc2Instance = (Class.forName(MOCK_EC2_INSTANCE_CLASS_NAME)
.asSubclass(AbstractMockEc2Instance.class));
} catch (ClassNotFoundException e) {
throw new AwsMockException(
"badly configured class '" + MOCK_EC2_INSTANCE_CLASS_NAME + "' not found", e);
}
List<AbstractMockEc2Instance> newInstances = null;
newInstances = mockEc2Controller
.runInstances(clazzOfMockEc2Instance, imageId, instanceType, minCount, maxCount);
for (AbstractMockEc2Instance i : newInstances) {
RunningInstancesItemType instItem = new RunningInstancesItemType();
instItem.setInstanceId(i.getInstanceID());
instItem.setImageId(i.getImageId());
instItem.setInstanceType(i.getInstanceType().getName());
InstanceStateType state = new InstanceStateType();
state.setCode(i.getInstanceState().getCode());
state.setName(i.getInstanceState().getName());
instItem.setInstanceState(state);
instItem.setDnsName(i.getPubDns());
instItem.setPlacement(DEFAULT_MOCK_PLACEMENT);
// set network information
instItem.setVpcId(MOCK_VPC_ID);
instItem.setPrivateIpAddress(MOCK_PRIVATE_IP_ADDRESS);
instItem.setSubnetId(MOCK_SUBNET_ID);
instSet.getItem().add(instItem);
}
ret.setInstancesSet(instSet);
return ret;
} | java | private RunInstancesResponseType runInstances(final String imageId, final String instanceType,
final int minCount, final int maxCount) {
RunInstancesResponseType ret = new RunInstancesResponseType();
RunningInstancesSetType instSet = new RunningInstancesSetType();
Class<? extends AbstractMockEc2Instance> clazzOfMockEc2Instance = null;
try {
// clazzOfMockEc2Instance = (Class<? extends MockEc2Instance>) Class.forName(MOCK_EC2_INSTANCE_CLASS_NAME);
clazzOfMockEc2Instance = (Class.forName(MOCK_EC2_INSTANCE_CLASS_NAME)
.asSubclass(AbstractMockEc2Instance.class));
} catch (ClassNotFoundException e) {
throw new AwsMockException(
"badly configured class '" + MOCK_EC2_INSTANCE_CLASS_NAME + "' not found", e);
}
List<AbstractMockEc2Instance> newInstances = null;
newInstances = mockEc2Controller
.runInstances(clazzOfMockEc2Instance, imageId, instanceType, minCount, maxCount);
for (AbstractMockEc2Instance i : newInstances) {
RunningInstancesItemType instItem = new RunningInstancesItemType();
instItem.setInstanceId(i.getInstanceID());
instItem.setImageId(i.getImageId());
instItem.setInstanceType(i.getInstanceType().getName());
InstanceStateType state = new InstanceStateType();
state.setCode(i.getInstanceState().getCode());
state.setName(i.getInstanceState().getName());
instItem.setInstanceState(state);
instItem.setDnsName(i.getPubDns());
instItem.setPlacement(DEFAULT_MOCK_PLACEMENT);
// set network information
instItem.setVpcId(MOCK_VPC_ID);
instItem.setPrivateIpAddress(MOCK_PRIVATE_IP_ADDRESS);
instItem.setSubnetId(MOCK_SUBNET_ID);
instSet.getItem().add(instItem);
}
ret.setInstancesSet(instSet);
return ret;
} | [
"private",
"RunInstancesResponseType",
"runInstances",
"(",
"final",
"String",
"imageId",
",",
"final",
"String",
"instanceType",
",",
"final",
"int",
"minCount",
",",
"final",
"int",
"maxCount",
")",
"{",
"RunInstancesResponseType",
"ret",
"=",
"new",
"RunInstances... | Handles "runInstances" request, with only simplified filters of imageId, instanceType, minCount and maxCount.
@param imageId
AMI of new mock ec2 instance(s)
@param instanceType
type(scale) of new mock ec2 instance(s), refer to {@link AbstractMockEc2Instance#instanceType}
@param minCount
max count of instances to run
@param maxCount
min count of instances to run
@return a RunInstancesResponse that includes all information for the started new mock ec2 instances | [
"Handles",
"runInstances",
"request",
"with",
"only",
"simplified",
"filters",
"of",
"imageId",
"instanceType",
"minCount",
"and",
"maxCount",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1195-L1245 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.startInstances | private StartInstancesResponseType startInstances(final Set<String> instanceIDs) {
StartInstancesResponseType ret = new StartInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.startInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | java | private StartInstancesResponseType startInstances(final Set<String> instanceIDs) {
StartInstancesResponseType ret = new StartInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.startInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | [
"private",
"StartInstancesResponseType",
"startInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"StartInstancesResponseType",
"ret",
"=",
"new",
"StartInstancesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
... | Handles "startInstances" request, with only a simplified filter of instanceIDs.
@param instanceIDs
a filter of specified instance IDs for the target instance to start
@return a StartInstancesResponse with information for all mock ec2 instances to start | [
"Handles",
"startInstances",
"request",
"with",
"only",
"a",
"simplified",
"filter",
"of",
"instanceIDs",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1254-L1262 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.stopInstances | private StopInstancesResponseType stopInstances(final Set<String> instanceIDs) {
StopInstancesResponseType ret = new StopInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.stopInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | java | private StopInstancesResponseType stopInstances(final Set<String> instanceIDs) {
StopInstancesResponseType ret = new StopInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.stopInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | [
"private",
"StopInstancesResponseType",
"stopInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"StopInstancesResponseType",
"ret",
"=",
"new",
"StopInstancesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"ra... | Handles "stopInstances" request, with only a simplified filter of instanceIDs.
@param instanceIDs
a filter of specified instance IDs for the target instance to stop
@return a StopInstancesResponse with information for all mock ec2 instances to stop | [
"Handles",
"stopInstances",
"request",
"with",
"only",
"a",
"simplified",
"filter",
"of",
"instanceIDs",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1271-L1278 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.terminateInstances | private TerminateInstancesResponseType terminateInstances(final Set<String> instanceIDs) {
TerminateInstancesResponseType ret = new TerminateInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.terminateInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | java | private TerminateInstancesResponseType terminateInstances(final Set<String> instanceIDs) {
TerminateInstancesResponseType ret = new TerminateInstancesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
changeSet.getItem().addAll(mockEc2Controller.terminateInstances(instanceIDs));
ret.setInstancesSet(changeSet);
return ret;
} | [
"private",
"TerminateInstancesResponseType",
"terminateInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"TerminateInstancesResponseType",
"ret",
"=",
"new",
"TerminateInstancesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
... | Handles "terminateInstances" request, with only a simplified filter of instanceIDs.
@param instanceIDs
a filter of specified instance IDs for the target instance to terminate
@return a StartInstancesResponse with information for all mock ec2 instances to terminate | [
"Handles",
"terminateInstances",
"request",
"with",
"only",
"a",
"simplified",
"filter",
"of",
"instanceIDs",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1287-L1294 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeImages | private DescribeImagesResponseType describeImages(final Set<String> imageId) {
DescribeImagesResponseType ret = new DescribeImagesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
DescribeImagesResponseInfoType info = new DescribeImagesResponseInfoType();
for (String ami : MOCK_AMIS) {
if (imageId == null || imageId.isEmpty()) {
DescribeImagesResponseItemType item = new DescribeImagesResponseItemType();
item.setImageId(ami);
item.setArchitecture("x86_64");
item.setVirtualizationType("paravirtual");
item.setName("My server");
item.setHypervisor("xen");
item.setRootDeviceType("ebs");
item.setImageLocation("123456789012/My server");
item.setKernelId("aki-88aa75e1");
item.setImageOwnerId("123456789012");
item.setRootDeviceName("/dev/sda1");
item.setIsPublic(false);
item.setImageType("machine");
BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType();
BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType();
blockDeviceMapping.setDeviceName("/dev/sda1");
EbsBlockDeviceType ebs = new EbsBlockDeviceType();
ebs.setDeleteOnTermination(true);
ebs.setSnapshotId("snap-1234567890abcdef0");
ebs.setVolumeSize(1);
ebs.setVolumeType("standard");
blockDeviceMapping.setEbs(ebs);
blockDeviceMappingType.getItem().add(blockDeviceMapping);
item.setBlockDeviceMapping(blockDeviceMappingType);
info.getItem().add(item);
} else if (imageId.contains(ami)) {
DescribeImagesResponseItemType item = new DescribeImagesResponseItemType();
item.setImageId(ami);
item.setArchitecture("x86_64");
item.setVirtualizationType("paravirtual");
item.setName("My server");
item.setHypervisor("xen");
item.setRootDeviceType("ebs");
item.setImageLocation("123456789012/My server");
item.setKernelId("aki-88aa75e1");
item.setImageOwnerId("123456789012");
item.setRootDeviceName("/dev/sda1");
item.setIsPublic(false);
item.setImageType("machine");
BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType();
BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType();
blockDeviceMapping.setDeviceName("/dev/sda1");
EbsBlockDeviceType ebs = new EbsBlockDeviceType();
ebs.setDeleteOnTermination(true);
ebs.setSnapshotId("snap-1234567890abcdef0");
ebs.setVolumeSize(1);
ebs.setVolumeType("standard");
blockDeviceMapping.setEbs(ebs);
blockDeviceMappingType.getItem().add(blockDeviceMapping);
item.setBlockDeviceMapping(blockDeviceMappingType);
info.getItem().add(item);
}
}
ret.setImagesSet(info);
return ret;
} | java | private DescribeImagesResponseType describeImages(final Set<String> imageId) {
DescribeImagesResponseType ret = new DescribeImagesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
DescribeImagesResponseInfoType info = new DescribeImagesResponseInfoType();
for (String ami : MOCK_AMIS) {
if (imageId == null || imageId.isEmpty()) {
DescribeImagesResponseItemType item = new DescribeImagesResponseItemType();
item.setImageId(ami);
item.setArchitecture("x86_64");
item.setVirtualizationType("paravirtual");
item.setName("My server");
item.setHypervisor("xen");
item.setRootDeviceType("ebs");
item.setImageLocation("123456789012/My server");
item.setKernelId("aki-88aa75e1");
item.setImageOwnerId("123456789012");
item.setRootDeviceName("/dev/sda1");
item.setIsPublic(false);
item.setImageType("machine");
BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType();
BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType();
blockDeviceMapping.setDeviceName("/dev/sda1");
EbsBlockDeviceType ebs = new EbsBlockDeviceType();
ebs.setDeleteOnTermination(true);
ebs.setSnapshotId("snap-1234567890abcdef0");
ebs.setVolumeSize(1);
ebs.setVolumeType("standard");
blockDeviceMapping.setEbs(ebs);
blockDeviceMappingType.getItem().add(blockDeviceMapping);
item.setBlockDeviceMapping(blockDeviceMappingType);
info.getItem().add(item);
} else if (imageId.contains(ami)) {
DescribeImagesResponseItemType item = new DescribeImagesResponseItemType();
item.setImageId(ami);
item.setArchitecture("x86_64");
item.setVirtualizationType("paravirtual");
item.setName("My server");
item.setHypervisor("xen");
item.setRootDeviceType("ebs");
item.setImageLocation("123456789012/My server");
item.setKernelId("aki-88aa75e1");
item.setImageOwnerId("123456789012");
item.setRootDeviceName("/dev/sda1");
item.setIsPublic(false);
item.setImageType("machine");
BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType();
BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType();
blockDeviceMapping.setDeviceName("/dev/sda1");
EbsBlockDeviceType ebs = new EbsBlockDeviceType();
ebs.setDeleteOnTermination(true);
ebs.setSnapshotId("snap-1234567890abcdef0");
ebs.setVolumeSize(1);
ebs.setVolumeType("standard");
blockDeviceMapping.setEbs(ebs);
blockDeviceMappingType.getItem().add(blockDeviceMapping);
item.setBlockDeviceMapping(blockDeviceMappingType);
info.getItem().add(item);
}
}
ret.setImagesSet(info);
return ret;
} | [
"private",
"DescribeImagesResponseType",
"describeImages",
"(",
"final",
"Set",
"<",
"String",
">",
"imageId",
")",
"{",
"DescribeImagesResponseType",
"ret",
"=",
"new",
"DescribeImagesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"ra... | Handles "describeImages" request, as simple as without any filters to use.
@param imageId : Set of imgaesId.
@return a DescribeImagesResponse with our predefined AMIs in aws-mock.properties (or if not overridden, as
defined in aws-mock-default.properties) | [
"Handles",
"describeImages",
"request",
"as",
"simple",
"as",
"without",
"any",
"filters",
"to",
"use",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1302-L1364 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeRouteTables | private DescribeRouteTablesResponseType describeRouteTables() {
DescribeRouteTablesResponseType ret = new DescribeRouteTablesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
RouteTableSetType routeTableSet = new RouteTableSetType();
for (Iterator<MockRouteTable> mockRouteTable = mockRouteTableController
.describeRouteTables().iterator(); mockRouteTable.hasNext();) {
MockRouteTable item = mockRouteTable.next();
RouteTableType routeTable = new RouteTableType();
if (!DEFAULT_MOCK_PLACEMENT.getAvailabilityZone().equals(currentRegion)) {
routeTable.setVpcId(currentRegion + "_" + item.getVpcId());
routeTable.setRouteTableId(currentRegion + "_" + item.getRouteTableId());
} else {
routeTable.setVpcId(item.getVpcId());
routeTable.setRouteTableId(item.getRouteTableId());
}
RouteTableAssociationSetType associationSet = new RouteTableAssociationSetType();
routeTable.setAssociationSet(associationSet);
RouteSetType routeSet = new RouteSetType();
routeTable.setRouteSet(routeSet);
routeTableSet.getItem().add(routeTable);
}
ret.setRouteTableSet(routeTableSet);
return ret;
} | java | private DescribeRouteTablesResponseType describeRouteTables() {
DescribeRouteTablesResponseType ret = new DescribeRouteTablesResponseType();
ret.setRequestId(UUID.randomUUID().toString());
RouteTableSetType routeTableSet = new RouteTableSetType();
for (Iterator<MockRouteTable> mockRouteTable = mockRouteTableController
.describeRouteTables().iterator(); mockRouteTable.hasNext();) {
MockRouteTable item = mockRouteTable.next();
RouteTableType routeTable = new RouteTableType();
if (!DEFAULT_MOCK_PLACEMENT.getAvailabilityZone().equals(currentRegion)) {
routeTable.setVpcId(currentRegion + "_" + item.getVpcId());
routeTable.setRouteTableId(currentRegion + "_" + item.getRouteTableId());
} else {
routeTable.setVpcId(item.getVpcId());
routeTable.setRouteTableId(item.getRouteTableId());
}
RouteTableAssociationSetType associationSet = new RouteTableAssociationSetType();
routeTable.setAssociationSet(associationSet);
RouteSetType routeSet = new RouteSetType();
routeTable.setRouteSet(routeSet);
routeTableSet.getItem().add(routeTable);
}
ret.setRouteTableSet(routeTableSet);
return ret;
} | [
"private",
"DescribeRouteTablesResponseType",
"describeRouteTables",
"(",
")",
"{",
"DescribeRouteTablesResponseType",
"ret",
"=",
"new",
"DescribeRouteTablesResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toSt... | Handles "describeRouteTables" request and returns response with a route table.
@return a DescribeRouteTablesResponseType with our predefined route table in aws-mock.properties (or if not
overridden, as defined in aws-mock-default.properties) | [
"Handles",
"describeRouteTables",
"request",
"and",
"returns",
"response",
"with",
"a",
"route",
"table",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1372-L1402 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createRouteTable | private CreateRouteTableResponseType createRouteTable(final String vpcId,
final String cidrBlock) {
CreateRouteTableResponseType ret = new CreateRouteTableResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockRouteTable mockRouteTable = mockRouteTableController.createRouteTable(cidrBlock, vpcId);
RouteTableType routeTableType = new RouteTableType();
routeTableType.setVpcId(mockRouteTable.getVpcId());
routeTableType.setRouteTableId(mockRouteTable.getRouteTableId());
ret.setRouteTable(routeTableType);
return ret;
} | java | private CreateRouteTableResponseType createRouteTable(final String vpcId,
final String cidrBlock) {
CreateRouteTableResponseType ret = new CreateRouteTableResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockRouteTable mockRouteTable = mockRouteTableController.createRouteTable(cidrBlock, vpcId);
RouteTableType routeTableType = new RouteTableType();
routeTableType.setVpcId(mockRouteTable.getVpcId());
routeTableType.setRouteTableId(mockRouteTable.getRouteTableId());
ret.setRouteTable(routeTableType);
return ret;
} | [
"private",
"CreateRouteTableResponseType",
"createRouteTable",
"(",
"final",
"String",
"vpcId",
",",
"final",
"String",
"cidrBlock",
")",
"{",
"CreateRouteTableResponseType",
"ret",
"=",
"new",
"CreateRouteTableResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
... | Handles "createRouteTable" request to create routetable and returns response with a route table.
@param vpcId vpc Id for Route Table.
@param cidrBlock VPC cidr block.
@return a CreateRouteTableResponseType with our new route table in (or if not
overridden, as defined in aws-mock-default.properties) | [
"Handles",
"createRouteTable",
"request",
"to",
"create",
"routetable",
"and",
"returns",
"response",
"with",
"a",
"route",
"table",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1411-L1423 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createRoute | private CreateRouteResponseType createRoute(final String destinationCidrBlock,
final String internetGatewayId, final String routeTableId) {
CreateRouteResponseType ret = new CreateRouteResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockRouteTableController.createRoute(destinationCidrBlock, internetGatewayId, routeTableId);
return ret;
} | java | private CreateRouteResponseType createRoute(final String destinationCidrBlock,
final String internetGatewayId, final String routeTableId) {
CreateRouteResponseType ret = new CreateRouteResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockRouteTableController.createRoute(destinationCidrBlock, internetGatewayId, routeTableId);
return ret;
} | [
"private",
"CreateRouteResponseType",
"createRoute",
"(",
"final",
"String",
"destinationCidrBlock",
",",
"final",
"String",
"internetGatewayId",
",",
"final",
"String",
"routeTableId",
")",
"{",
"CreateRouteResponseType",
"ret",
"=",
"new",
"CreateRouteResponseType",
"("... | Handles "createRoute" request to create route and returns response with a route table.
@param destinationCidrBlock : Route destinationCidrBlock.
@param internetGatewayId : for gateway Id.
@param routeTableId : for Route.
@return a CreateRouteResponseType with our new route. | [
"Handles",
"createRoute",
"request",
"to",
"create",
"route",
"and",
"returns",
"response",
"with",
"a",
"route",
"table",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1432-L1439 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createVolume | private CreateVolumeResponseType createVolume(final String volumeType, final String size,
final String availabilityZone,
final int iops, final String snapshotId) {
CreateVolumeResponseType ret = new CreateVolumeResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockVolume mockVolume = mockVolumeController.createVolume(volumeType, size,
availabilityZone, iops, snapshotId);
ret.setVolumeId(mockVolume.getVolumeId());
ret.setVolumeType(mockVolume.getVolumeType());
ret.setSize(mockVolume.getSize());
ret.setAvailabilityZone(mockVolume.getAvailabilityZone());
ret.setIops(mockVolume.getIops());
ret.setSnapshotId(mockVolume.getSnapshotId());
return ret;
} | java | private CreateVolumeResponseType createVolume(final String volumeType, final String size,
final String availabilityZone,
final int iops, final String snapshotId) {
CreateVolumeResponseType ret = new CreateVolumeResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockVolume mockVolume = mockVolumeController.createVolume(volumeType, size,
availabilityZone, iops, snapshotId);
ret.setVolumeId(mockVolume.getVolumeId());
ret.setVolumeType(mockVolume.getVolumeType());
ret.setSize(mockVolume.getSize());
ret.setAvailabilityZone(mockVolume.getAvailabilityZone());
ret.setIops(mockVolume.getIops());
ret.setSnapshotId(mockVolume.getSnapshotId());
return ret;
} | [
"private",
"CreateVolumeResponseType",
"createVolume",
"(",
"final",
"String",
"volumeType",
",",
"final",
"String",
"size",
",",
"final",
"String",
"availabilityZone",
",",
"final",
"int",
"iops",
",",
"final",
"String",
"snapshotId",
")",
"{",
"CreateVolumeRespons... | Handles "createVolume" request to create volume and returns response with a volume.
@param volumeType of Volume.
@param size : Volume size.
@param availabilityZone : Volume availability zone.
@param iops : Volume iops count
@param snapshotId : Volume's SnapshotId.
@return a CreateRouteTableResponseType with our new route table in (or if not
overridden, as defined in aws-mock-default.properties) | [
"Handles",
"createVolume",
"request",
"to",
"create",
"volume",
"and",
"returns",
"response",
"with",
"a",
"volume",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1451-L1466 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createSubnet | private CreateSubnetResponseType createSubnet(final String vpcId, final String cidrBlock) {
CreateSubnetResponseType ret = new CreateSubnetResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockSubnet mockSubnet = mockSubnetController.createSubnet(cidrBlock, vpcId);
SubnetType subnetType = new SubnetType();
subnetType.setVpcId(mockSubnet.getVpcId());
subnetType.setSubnetId(mockSubnet.getSubnetId());
ret.setSubnet(subnetType);
return ret;
} | java | private CreateSubnetResponseType createSubnet(final String vpcId, final String cidrBlock) {
CreateSubnetResponseType ret = new CreateSubnetResponseType();
ret.setRequestId(UUID.randomUUID().toString());
MockSubnet mockSubnet = mockSubnetController.createSubnet(cidrBlock, vpcId);
SubnetType subnetType = new SubnetType();
subnetType.setVpcId(mockSubnet.getVpcId());
subnetType.setSubnetId(mockSubnet.getSubnetId());
ret.setSubnet(subnetType);
return ret;
} | [
"private",
"CreateSubnetResponseType",
"createSubnet",
"(",
"final",
"String",
"vpcId",
",",
"final",
"String",
"cidrBlock",
")",
"{",
"CreateSubnetResponseType",
"ret",
"=",
"new",
"CreateSubnetResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
... | Handles "createSubnet" request to create Subnet and returns response with a subnet.
@param vpcId vpc Id for subnet.
@param cidrBlock VPC cidr block.
@return a CreateSubnetResponseType with our new Subnet | [
"Handles",
"createSubnet",
"request",
"to",
"create",
"Subnet",
"and",
"returns",
"response",
"with",
"a",
"subnet",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1474-L1485 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.