id int32 0 165k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
137,300 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/Database.java | Database.compile | public Vm compile( String sql, String args[] ) throws jsqlite.Exception {
synchronized (this) {
Vm vm = new Vm();
vm_compile_args(sql, vm, args);
return vm;
}
} | java | public Vm compile( String sql, String args[] ) throws jsqlite.Exception {
synchronized (this) {
Vm vm = new Vm();
vm_compile_args(sql, vm, args);
return vm;
}
} | [
"public",
"Vm",
"compile",
"(",
"String",
"sql",
",",
"String",
"args",
"[",
"]",
")",
"throws",
"jsqlite",
".",
"Exception",
"{",
"synchronized",
"(",
"this",
")",
"{",
"Vm",
"vm",
"=",
"new",
"Vm",
"(",
")",
";",
"vm_compile_args",
"(",
"sql",
",",
"vm",
",",
"args",
")",
";",
"return",
"vm",
";",
"}",
"}"
] | Compile and return SQLite VM for SQL statement. Only available
in SQLite 3.0 and above, otherwise a no-op.
@param sql SQL statement to be compiled
@param args arguments for the SQL statement, '%q' substitution
@return a Vm object | [
"Compile",
"and",
"return",
"SQLite",
"VM",
"for",
"SQL",
"statement",
".",
"Only",
"available",
"in",
"SQLite",
"3",
".",
"0",
"and",
"above",
"otherwise",
"a",
"no",
"-",
"op",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/Database.java#L696-L702 |
137,301 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/Database.java | Database.prepare | public Stmt prepare( String sql ) throws jsqlite.Exception {
synchronized (this) {
Stmt stmt = new Stmt();
stmt_prepare(sql, stmt);
return stmt;
}
} | java | public Stmt prepare( String sql ) throws jsqlite.Exception {
synchronized (this) {
Stmt stmt = new Stmt();
stmt_prepare(sql, stmt);
return stmt;
}
} | [
"public",
"Stmt",
"prepare",
"(",
"String",
"sql",
")",
"throws",
"jsqlite",
".",
"Exception",
"{",
"synchronized",
"(",
"this",
")",
"{",
"Stmt",
"stmt",
"=",
"new",
"Stmt",
"(",
")",
";",
"stmt_prepare",
"(",
"sql",
",",
"stmt",
")",
";",
"return",
"stmt",
";",
"}",
"}"
] | Prepare and return SQLite3 statement for SQL. Only available
in SQLite 3.0 and above, otherwise a no-op.
@param sql SQL statement to be prepared
@return a Stmt object | [
"Prepare",
"and",
"return",
"SQLite3",
"statement",
"for",
"SQL",
".",
"Only",
"available",
"in",
"SQLite",
"3",
".",
"0",
"and",
"above",
"otherwise",
"a",
"no",
"-",
"op",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/Database.java#L712-L718 |
137,302 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/Database.java | Database.open_blob | public Blob open_blob( String db, String table, String column, long row, boolean rw ) throws jsqlite.Exception {
synchronized (this) {
Blob blob = new Blob();
_open_blob(db, table, column, row, rw, blob);
return blob;
}
} | java | public Blob open_blob( String db, String table, String column, long row, boolean rw ) throws jsqlite.Exception {
synchronized (this) {
Blob blob = new Blob();
_open_blob(db, table, column, row, rw, blob);
return blob;
}
} | [
"public",
"Blob",
"open_blob",
"(",
"String",
"db",
",",
"String",
"table",
",",
"String",
"column",
",",
"long",
"row",
",",
"boolean",
"rw",
")",
"throws",
"jsqlite",
".",
"Exception",
"{",
"synchronized",
"(",
"this",
")",
"{",
"Blob",
"blob",
"=",
"new",
"Blob",
"(",
")",
";",
"_open_blob",
"(",
"db",
",",
"table",
",",
"column",
",",
"row",
",",
"rw",
",",
"blob",
")",
";",
"return",
"blob",
";",
"}",
"}"
] | Open an SQLite3 blob. Only available in SQLite 3.4.0 and above.
@param db database name
@param table table name
@param column column name
@param row row identifier
@param rw if true, open for read-write, else read-only
@return a Blob object | [
"Open",
"an",
"SQLite3",
"blob",
".",
"Only",
"available",
"in",
"SQLite",
"3",
".",
"4",
".",
"0",
"and",
"above",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/Database.java#L730-L736 |
137,303 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/Database.java | Database.long_from_julian | public static long long_from_julian( String s ) throws jsqlite.Exception {
try {
double d = Double.valueOf(s).doubleValue();
return long_from_julian(d);
} catch (java.lang.Exception ee) {
throw new jsqlite.Exception("not a julian date: " + s + ": " + ee);
}
} | java | public static long long_from_julian( String s ) throws jsqlite.Exception {
try {
double d = Double.valueOf(s).doubleValue();
return long_from_julian(d);
} catch (java.lang.Exception ee) {
throw new jsqlite.Exception("not a julian date: " + s + ": " + ee);
}
} | [
"public",
"static",
"long",
"long_from_julian",
"(",
"String",
"s",
")",
"throws",
"jsqlite",
".",
"Exception",
"{",
"try",
"{",
"double",
"d",
"=",
"Double",
".",
"valueOf",
"(",
"s",
")",
".",
"doubleValue",
"(",
")",
";",
"return",
"long_from_julian",
"(",
"d",
")",
";",
"}",
"catch",
"(",
"java",
".",
"lang",
".",
"Exception",
"ee",
")",
"{",
"throw",
"new",
"jsqlite",
".",
"Exception",
"(",
"\"not a julian date: \"",
"+",
"s",
"+",
"\": \"",
"+",
"ee",
")",
";",
"}",
"}"
] | Make long value from julian date for java.lang.Date
@param s string (double value) (julian date in SQLite3 format)
@return long | [
"Make",
"long",
"value",
"from",
"julian",
"date",
"for",
"java",
".",
"lang",
".",
"Date"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/Database.java#L910-L917 |
137,304 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/TableResult.java | TableResult.clear | public void clear() {
column = new String[0];
types = null;
rows = new Vector();
ncolumns = nrows = 0;
atmaxrows = false;
} | java | public void clear() {
column = new String[0];
types = null;
rows = new Vector();
ncolumns = nrows = 0;
atmaxrows = false;
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"column",
"=",
"new",
"String",
"[",
"0",
"]",
";",
"types",
"=",
"null",
";",
"rows",
"=",
"new",
"Vector",
"(",
")",
";",
"ncolumns",
"=",
"nrows",
"=",
"0",
";",
"atmaxrows",
"=",
"false",
";",
"}"
] | Clear result set. | [
"Clear",
"result",
"set",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/TableResult.java#L95-L101 |
137,305 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/TableResult.java | TableResult.newrow | public boolean newrow(String rowdata[]) {
if (rowdata != null) {
if (maxrows > 0 && nrows >= maxrows) {
atmaxrows = true;
return true;
}
rows.addElement(rowdata);
nrows++;
}
return false;
} | java | public boolean newrow(String rowdata[]) {
if (rowdata != null) {
if (maxrows > 0 && nrows >= maxrows) {
atmaxrows = true;
return true;
}
rows.addElement(rowdata);
nrows++;
}
return false;
} | [
"public",
"boolean",
"newrow",
"(",
"String",
"rowdata",
"[",
"]",
")",
"{",
"if",
"(",
"rowdata",
"!=",
"null",
")",
"{",
"if",
"(",
"maxrows",
">",
"0",
"&&",
"nrows",
">=",
"maxrows",
")",
"{",
"atmaxrows",
"=",
"true",
";",
"return",
"true",
";",
"}",
"rows",
".",
"addElement",
"(",
"rowdata",
")",
";",
"nrows",
"++",
";",
"}",
"return",
"false",
";",
"}"
] | Callback method used while the query is executed. | [
"Callback",
"method",
"used",
"while",
"the",
"query",
"is",
"executed",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/TableResult.java#L124-L134 |
137,306 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java | LinearSystem.solve | public ColumnVector solve(ColumnVector b, boolean improve)
throws MatrixException
{
// Validate b's size.
if (b.nRows != nRows) {
throw new MatrixException(
MatrixException.INVALID_DIMENSIONS);
}
decompose();
// Solve Ly = b for y by forward substitution.
// Solve Ux = y for x by back substitution.
ColumnVector y = forwardSubstitution(b);
ColumnVector x = backSubstitution(y);
// Improve and return x.
if (improve) improve(b, x);
return x;
} | java | public ColumnVector solve(ColumnVector b, boolean improve)
throws MatrixException
{
// Validate b's size.
if (b.nRows != nRows) {
throw new MatrixException(
MatrixException.INVALID_DIMENSIONS);
}
decompose();
// Solve Ly = b for y by forward substitution.
// Solve Ux = y for x by back substitution.
ColumnVector y = forwardSubstitution(b);
ColumnVector x = backSubstitution(y);
// Improve and return x.
if (improve) improve(b, x);
return x;
} | [
"public",
"ColumnVector",
"solve",
"(",
"ColumnVector",
"b",
",",
"boolean",
"improve",
")",
"throws",
"MatrixException",
"{",
"// Validate b's size.",
"if",
"(",
"b",
".",
"nRows",
"!=",
"nRows",
")",
"{",
"throw",
"new",
"MatrixException",
"(",
"MatrixException",
".",
"INVALID_DIMENSIONS",
")",
";",
"}",
"decompose",
"(",
")",
";",
"// Solve Ly = b for y by forward substitution.",
"// Solve Ux = y for x by back substitution.",
"ColumnVector",
"y",
"=",
"forwardSubstitution",
"(",
"b",
")",
";",
"ColumnVector",
"x",
"=",
"backSubstitution",
"(",
"y",
")",
";",
"// Improve and return x.",
"if",
"(",
"improve",
")",
"improve",
"(",
"b",
",",
"x",
")",
";",
"return",
"x",
";",
"}"
] | Solve Ax = b for x using the Gaussian elimination algorithm.
@param b the right-hand-side column vector
@param improve true to improve the solution
@return the solution column vector
@throws matrix.MatrixException if an error occurred | [
"Solve",
"Ax",
"=",
"b",
"for",
"x",
"using",
"the",
"Gaussian",
"elimination",
"algorithm",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java#L111-L130 |
137,307 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java | LinearSystem.forwardElimination | private void forwardElimination(double scales[])
throws MatrixException
{
// Loop once per pivot row 0..nRows-1.
for (int rPivot = 0; rPivot < nRows - 1; ++rPivot) {
double largestScaledElmt = 0;
int rLargest = 0;
// Starting from the pivot row rPivot, look down
// column rPivot to find the largest scaled element.
for (int r = rPivot; r < nRows; ++r) {
// Use the permuted row index.
int pr = permutation[r];
double absElmt = Math.abs(LU.at(pr, rPivot));
double scaledElmt = absElmt*scales[pr];
if (largestScaledElmt < scaledElmt) {
// The largest scaled element and
// its row index.
largestScaledElmt = scaledElmt;
rLargest = r;
}
}
// Is the matrix singular?
if (largestScaledElmt == 0) {
throw new MatrixException(MatrixException.SINGULAR);
}
// Exchange rows if necessary to choose the best
// pivot element by making its row the pivot row.
if (rLargest != rPivot) {
int temp = permutation[rPivot];
permutation[rPivot] = permutation[rLargest];
permutation[rLargest] = temp;
++exchangeCount;
}
// Use the permuted pivot row index.
int prPivot = permutation[rPivot];
double pivotElmt = LU.at(prPivot, rPivot);
// Do the elimination below the pivot row.
for (int r = rPivot + 1; r < nRows; ++r) {
// Use the permuted row index.
int pr = permutation[r];
double multiple = LU.at(pr, rPivot)/pivotElmt;
// Set the multiple into matrix L.
LU.set(pr, rPivot, multiple);
// Eliminate an unknown from matrix U.
if (multiple != 0) {
for (int c = rPivot + 1; c < nCols; ++c) {
double elmt = LU.at(pr, c);
// Subtract the multiple of the pivot row.
elmt -= multiple*LU.at(prPivot, c);
LU.set(pr, c, elmt);
}
}
}
}
} | java | private void forwardElimination(double scales[])
throws MatrixException
{
// Loop once per pivot row 0..nRows-1.
for (int rPivot = 0; rPivot < nRows - 1; ++rPivot) {
double largestScaledElmt = 0;
int rLargest = 0;
// Starting from the pivot row rPivot, look down
// column rPivot to find the largest scaled element.
for (int r = rPivot; r < nRows; ++r) {
// Use the permuted row index.
int pr = permutation[r];
double absElmt = Math.abs(LU.at(pr, rPivot));
double scaledElmt = absElmt*scales[pr];
if (largestScaledElmt < scaledElmt) {
// The largest scaled element and
// its row index.
largestScaledElmt = scaledElmt;
rLargest = r;
}
}
// Is the matrix singular?
if (largestScaledElmt == 0) {
throw new MatrixException(MatrixException.SINGULAR);
}
// Exchange rows if necessary to choose the best
// pivot element by making its row the pivot row.
if (rLargest != rPivot) {
int temp = permutation[rPivot];
permutation[rPivot] = permutation[rLargest];
permutation[rLargest] = temp;
++exchangeCount;
}
// Use the permuted pivot row index.
int prPivot = permutation[rPivot];
double pivotElmt = LU.at(prPivot, rPivot);
// Do the elimination below the pivot row.
for (int r = rPivot + 1; r < nRows; ++r) {
// Use the permuted row index.
int pr = permutation[r];
double multiple = LU.at(pr, rPivot)/pivotElmt;
// Set the multiple into matrix L.
LU.set(pr, rPivot, multiple);
// Eliminate an unknown from matrix U.
if (multiple != 0) {
for (int c = rPivot + 1; c < nCols; ++c) {
double elmt = LU.at(pr, c);
// Subtract the multiple of the pivot row.
elmt -= multiple*LU.at(prPivot, c);
LU.set(pr, c, elmt);
}
}
}
}
} | [
"private",
"void",
"forwardElimination",
"(",
"double",
"scales",
"[",
"]",
")",
"throws",
"MatrixException",
"{",
"// Loop once per pivot row 0..nRows-1.",
"for",
"(",
"int",
"rPivot",
"=",
"0",
";",
"rPivot",
"<",
"nRows",
"-",
"1",
";",
"++",
"rPivot",
")",
"{",
"double",
"largestScaledElmt",
"=",
"0",
";",
"int",
"rLargest",
"=",
"0",
";",
"// Starting from the pivot row rPivot, look down",
"// column rPivot to find the largest scaled element.",
"for",
"(",
"int",
"r",
"=",
"rPivot",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"// Use the permuted row index.",
"int",
"pr",
"=",
"permutation",
"[",
"r",
"]",
";",
"double",
"absElmt",
"=",
"Math",
".",
"abs",
"(",
"LU",
".",
"at",
"(",
"pr",
",",
"rPivot",
")",
")",
";",
"double",
"scaledElmt",
"=",
"absElmt",
"*",
"scales",
"[",
"pr",
"]",
";",
"if",
"(",
"largestScaledElmt",
"<",
"scaledElmt",
")",
"{",
"// The largest scaled element and",
"// its row index.",
"largestScaledElmt",
"=",
"scaledElmt",
";",
"rLargest",
"=",
"r",
";",
"}",
"}",
"// Is the matrix singular?",
"if",
"(",
"largestScaledElmt",
"==",
"0",
")",
"{",
"throw",
"new",
"MatrixException",
"(",
"MatrixException",
".",
"SINGULAR",
")",
";",
"}",
"// Exchange rows if necessary to choose the best",
"// pivot element by making its row the pivot row.",
"if",
"(",
"rLargest",
"!=",
"rPivot",
")",
"{",
"int",
"temp",
"=",
"permutation",
"[",
"rPivot",
"]",
";",
"permutation",
"[",
"rPivot",
"]",
"=",
"permutation",
"[",
"rLargest",
"]",
";",
"permutation",
"[",
"rLargest",
"]",
"=",
"temp",
";",
"++",
"exchangeCount",
";",
"}",
"// Use the permuted pivot row index.",
"int",
"prPivot",
"=",
"permutation",
"[",
"rPivot",
"]",
";",
"double",
"pivotElmt",
"=",
"LU",
".",
"at",
"(",
"prPivot",
",",
"rPivot",
")",
";",
"// Do the elimination below the pivot row.",
"for",
"(",
"int",
"r",
"=",
"rPivot",
"+",
"1",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"// Use the permuted row index.",
"int",
"pr",
"=",
"permutation",
"[",
"r",
"]",
";",
"double",
"multiple",
"=",
"LU",
".",
"at",
"(",
"pr",
",",
"rPivot",
")",
"/",
"pivotElmt",
";",
"// Set the multiple into matrix L.",
"LU",
".",
"set",
"(",
"pr",
",",
"rPivot",
",",
"multiple",
")",
";",
"// Eliminate an unknown from matrix U.",
"if",
"(",
"multiple",
"!=",
"0",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"rPivot",
"+",
"1",
";",
"c",
"<",
"nCols",
";",
"++",
"c",
")",
"{",
"double",
"elmt",
"=",
"LU",
".",
"at",
"(",
"pr",
",",
"c",
")",
";",
"// Subtract the multiple of the pivot row.",
"elmt",
"-=",
"multiple",
"*",
"LU",
".",
"at",
"(",
"prPivot",
",",
"c",
")",
";",
"LU",
".",
"set",
"(",
"pr",
",",
"c",
",",
"elmt",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Do forward elimination with scaled partial row pivoting.
@parm scales the scaling vector
@throws matrix.MatrixException for a singular matrix | [
"Do",
"forward",
"elimination",
"with",
"scaled",
"partial",
"row",
"pivoting",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java#L186-L253 |
137,308 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java | LinearSystem.forwardSubstitution | private ColumnVector forwardSubstitution(ColumnVector b)
throws MatrixException
{
ColumnVector y = new ColumnVector(nRows);
// Do forward substitution.
for (int r = 0; r < nRows; ++r) {
int pr = permutation[r]; // permuted row index
double dot = 0;
for (int c = 0; c < r; ++c) {
dot += LU.at(pr, c)*y.at(c);
}
y.set(r, b.at(pr) - dot);
}
return y;
} | java | private ColumnVector forwardSubstitution(ColumnVector b)
throws MatrixException
{
ColumnVector y = new ColumnVector(nRows);
// Do forward substitution.
for (int r = 0; r < nRows; ++r) {
int pr = permutation[r]; // permuted row index
double dot = 0;
for (int c = 0; c < r; ++c) {
dot += LU.at(pr, c)*y.at(c);
}
y.set(r, b.at(pr) - dot);
}
return y;
} | [
"private",
"ColumnVector",
"forwardSubstitution",
"(",
"ColumnVector",
"b",
")",
"throws",
"MatrixException",
"{",
"ColumnVector",
"y",
"=",
"new",
"ColumnVector",
"(",
"nRows",
")",
";",
"// Do forward substitution.",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"int",
"pr",
"=",
"permutation",
"[",
"r",
"]",
";",
"// permuted row index",
"double",
"dot",
"=",
"0",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"r",
";",
"++",
"c",
")",
"{",
"dot",
"+=",
"LU",
".",
"at",
"(",
"pr",
",",
"c",
")",
"*",
"y",
".",
"at",
"(",
"c",
")",
";",
"}",
"y",
".",
"set",
"(",
"r",
",",
"b",
".",
"at",
"(",
"pr",
")",
"-",
"dot",
")",
";",
"}",
"return",
"y",
";",
"}"
] | Solve Ly = b for y by forward substitution.
@param b the column vector b
@return the column vector y
@throws matrix.MatrixException if an error occurred | [
"Solve",
"Ly",
"=",
"b",
"for",
"y",
"by",
"forward",
"substitution",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java#L261-L277 |
137,309 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java | LinearSystem.backSubstitution | private ColumnVector backSubstitution(ColumnVector y)
throws MatrixException
{
ColumnVector x = new ColumnVector(nRows);
// Do back substitution.
for (int r = nRows - 1; r >= 0; --r) {
int pr = permutation[r]; // permuted row index
double dot = 0;
for (int c = r+1; c < nRows; ++c) {
dot += LU.at(pr, c)*x.at(c);
}
x.set(r, (y.at(r) - dot)/LU.at(pr, r));
}
return x;
} | java | private ColumnVector backSubstitution(ColumnVector y)
throws MatrixException
{
ColumnVector x = new ColumnVector(nRows);
// Do back substitution.
for (int r = nRows - 1; r >= 0; --r) {
int pr = permutation[r]; // permuted row index
double dot = 0;
for (int c = r+1; c < nRows; ++c) {
dot += LU.at(pr, c)*x.at(c);
}
x.set(r, (y.at(r) - dot)/LU.at(pr, r));
}
return x;
} | [
"private",
"ColumnVector",
"backSubstitution",
"(",
"ColumnVector",
"y",
")",
"throws",
"MatrixException",
"{",
"ColumnVector",
"x",
"=",
"new",
"ColumnVector",
"(",
"nRows",
")",
";",
"// Do back substitution.",
"for",
"(",
"int",
"r",
"=",
"nRows",
"-",
"1",
";",
"r",
">=",
"0",
";",
"--",
"r",
")",
"{",
"int",
"pr",
"=",
"permutation",
"[",
"r",
"]",
";",
"// permuted row index",
"double",
"dot",
"=",
"0",
";",
"for",
"(",
"int",
"c",
"=",
"r",
"+",
"1",
";",
"c",
"<",
"nRows",
";",
"++",
"c",
")",
"{",
"dot",
"+=",
"LU",
".",
"at",
"(",
"pr",
",",
"c",
")",
"*",
"x",
".",
"at",
"(",
"c",
")",
";",
"}",
"x",
".",
"set",
"(",
"r",
",",
"(",
"y",
".",
"at",
"(",
"r",
")",
"-",
"dot",
")",
"/",
"LU",
".",
"at",
"(",
"pr",
",",
"r",
")",
")",
";",
"}",
"return",
"x",
";",
"}"
] | Solve Ux = y for x by back substitution.
@param y the column vector y
@return the solution column vector x
@throws matrix.MatrixException if an error occurred | [
"Solve",
"Ux",
"=",
"y",
"for",
"x",
"by",
"back",
"substitution",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java#L285-L301 |
137,310 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java | LinearSystem.improve | private void improve(ColumnVector b, ColumnVector x)
throws MatrixException
{
// Find the largest x element.
double largestX = 0;
for (int r = 0; r < nRows; ++r) {
double absX = Math.abs(x.values[r][0]);
if (largestX < absX) largestX = absX;
}
// Is x already as good as possible?
if (largestX == 0) return;
ColumnVector residuals = new ColumnVector(nRows);
// Iterate to improve x.
for (int iter = 0; iter < MAX_ITER; ++iter) {
// Compute residuals = b - Ax.
// Must use double precision!
for (int r = 0; r < nRows; ++r) {
double dot = 0;
double row[] = values[r];
for (int c = 0; c < nRows; ++c) {
double elmt = at(r, c);
dot += elmt*x.at(c); // dbl.prec. *
}
double value = b.at(r) - dot; // dbl.prec. -
residuals.set(r, (double) value);
}
// Solve Az = residuals for z.
ColumnVector z = solve(residuals, false);
// Set x = x + z.
// Find largest the largest difference.
double largestDiff = 0;
for (int r = 0; r < nRows; ++r) {
double oldX = x.at(r);
x.set(r, oldX + z.at(r));
double diff = Math.abs(x.at(r) - oldX);
if (largestDiff < diff) largestDiff = diff;
}
// Is any further improvement possible?
if (largestDiff < largestX*TOLERANCE) return;
}
// Failed to converge because A is nearly singular.
throw new MatrixException(MatrixException.NO_CONVERGENCE);
} | java | private void improve(ColumnVector b, ColumnVector x)
throws MatrixException
{
// Find the largest x element.
double largestX = 0;
for (int r = 0; r < nRows; ++r) {
double absX = Math.abs(x.values[r][0]);
if (largestX < absX) largestX = absX;
}
// Is x already as good as possible?
if (largestX == 0) return;
ColumnVector residuals = new ColumnVector(nRows);
// Iterate to improve x.
for (int iter = 0; iter < MAX_ITER; ++iter) {
// Compute residuals = b - Ax.
// Must use double precision!
for (int r = 0; r < nRows; ++r) {
double dot = 0;
double row[] = values[r];
for (int c = 0; c < nRows; ++c) {
double elmt = at(r, c);
dot += elmt*x.at(c); // dbl.prec. *
}
double value = b.at(r) - dot; // dbl.prec. -
residuals.set(r, (double) value);
}
// Solve Az = residuals for z.
ColumnVector z = solve(residuals, false);
// Set x = x + z.
// Find largest the largest difference.
double largestDiff = 0;
for (int r = 0; r < nRows; ++r) {
double oldX = x.at(r);
x.set(r, oldX + z.at(r));
double diff = Math.abs(x.at(r) - oldX);
if (largestDiff < diff) largestDiff = diff;
}
// Is any further improvement possible?
if (largestDiff < largestX*TOLERANCE) return;
}
// Failed to converge because A is nearly singular.
throw new MatrixException(MatrixException.NO_CONVERGENCE);
} | [
"private",
"void",
"improve",
"(",
"ColumnVector",
"b",
",",
"ColumnVector",
"x",
")",
"throws",
"MatrixException",
"{",
"// Find the largest x element.",
"double",
"largestX",
"=",
"0",
";",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"double",
"absX",
"=",
"Math",
".",
"abs",
"(",
"x",
".",
"values",
"[",
"r",
"]",
"[",
"0",
"]",
")",
";",
"if",
"(",
"largestX",
"<",
"absX",
")",
"largestX",
"=",
"absX",
";",
"}",
"// Is x already as good as possible?",
"if",
"(",
"largestX",
"==",
"0",
")",
"return",
";",
"ColumnVector",
"residuals",
"=",
"new",
"ColumnVector",
"(",
"nRows",
")",
";",
"// Iterate to improve x.",
"for",
"(",
"int",
"iter",
"=",
"0",
";",
"iter",
"<",
"MAX_ITER",
";",
"++",
"iter",
")",
"{",
"// Compute residuals = b - Ax.",
"// Must use double precision!",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"double",
"dot",
"=",
"0",
";",
"double",
"row",
"[",
"]",
"=",
"values",
"[",
"r",
"]",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"nRows",
";",
"++",
"c",
")",
"{",
"double",
"elmt",
"=",
"at",
"(",
"r",
",",
"c",
")",
";",
"dot",
"+=",
"elmt",
"*",
"x",
".",
"at",
"(",
"c",
")",
";",
"// dbl.prec. *",
"}",
"double",
"value",
"=",
"b",
".",
"at",
"(",
"r",
")",
"-",
"dot",
";",
"// dbl.prec. -",
"residuals",
".",
"set",
"(",
"r",
",",
"(",
"double",
")",
"value",
")",
";",
"}",
"// Solve Az = residuals for z.",
"ColumnVector",
"z",
"=",
"solve",
"(",
"residuals",
",",
"false",
")",
";",
"// Set x = x + z.",
"// Find largest the largest difference.",
"double",
"largestDiff",
"=",
"0",
";",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"nRows",
";",
"++",
"r",
")",
"{",
"double",
"oldX",
"=",
"x",
".",
"at",
"(",
"r",
")",
";",
"x",
".",
"set",
"(",
"r",
",",
"oldX",
"+",
"z",
".",
"at",
"(",
"r",
")",
")",
";",
"double",
"diff",
"=",
"Math",
".",
"abs",
"(",
"x",
".",
"at",
"(",
"r",
")",
"-",
"oldX",
")",
";",
"if",
"(",
"largestDiff",
"<",
"diff",
")",
"largestDiff",
"=",
"diff",
";",
"}",
"// Is any further improvement possible?",
"if",
"(",
"largestDiff",
"<",
"largestX",
"*",
"TOLERANCE",
")",
"return",
";",
"}",
"// Failed to converge because A is nearly singular.",
"throw",
"new",
"MatrixException",
"(",
"MatrixException",
".",
"NO_CONVERGENCE",
")",
";",
"}"
] | Iteratively improve the solution x to machine accuracy.
@param b the right-hand side column vector
@param x the improved solution column vector
@throws matrix.MatrixException if failed to converge | [
"Iteratively",
"improve",
"the",
"solution",
"x",
"to",
"machine",
"accuracy",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/LinearSystem.java#L309-L360 |
137,311 | TheHortonMachine/hortonmachine | apps/src/main/java/org/hortonmachine/geopaparazzi/GeopaparazziView.java | GeopaparazziView.addFillComponents | void addFillComponents( Container panel, int[] cols, int[] rows )
{
Dimension filler = new Dimension(10,10);
boolean filled_cell_11 = false;
CellConstraints cc = new CellConstraints();
if ( cols.length > 0 && rows.length > 0 )
{
if ( cols[0] == 1 && rows[0] == 1 )
{
/** add a rigid area */
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
filled_cell_11 = true;
}
}
for( int index = 0; index < cols.length; index++ )
{
if ( cols[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
}
for( int index = 0; index < rows.length; index++ )
{
if ( rows[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
}
} | java | void addFillComponents( Container panel, int[] cols, int[] rows )
{
Dimension filler = new Dimension(10,10);
boolean filled_cell_11 = false;
CellConstraints cc = new CellConstraints();
if ( cols.length > 0 && rows.length > 0 )
{
if ( cols[0] == 1 && rows[0] == 1 )
{
/** add a rigid area */
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
filled_cell_11 = true;
}
}
for( int index = 0; index < cols.length; index++ )
{
if ( cols[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
}
for( int index = 0; index < rows.length; index++ )
{
if ( rows[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
}
} | [
"void",
"addFillComponents",
"(",
"Container",
"panel",
",",
"int",
"[",
"]",
"cols",
",",
"int",
"[",
"]",
"rows",
")",
"{",
"Dimension",
"filler",
"=",
"new",
"Dimension",
"(",
"10",
",",
"10",
")",
";",
"boolean",
"filled_cell_11",
"=",
"false",
";",
"CellConstraints",
"cc",
"=",
"new",
"CellConstraints",
"(",
")",
";",
"if",
"(",
"cols",
".",
"length",
">",
"0",
"&&",
"rows",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"cols",
"[",
"0",
"]",
"==",
"1",
"&&",
"rows",
"[",
"0",
"]",
"==",
"1",
")",
"{",
"/** add a rigid area */",
"panel",
".",
"add",
"(",
"Box",
".",
"createRigidArea",
"(",
"filler",
")",
",",
"cc",
".",
"xy",
"(",
"1",
",",
"1",
")",
")",
";",
"filled_cell_11",
"=",
"true",
";",
"}",
"}",
"for",
"(",
"int",
"index",
"=",
"0",
";",
"index",
"<",
"cols",
".",
"length",
";",
"index",
"++",
")",
"{",
"if",
"(",
"cols",
"[",
"index",
"]",
"==",
"1",
"&&",
"filled_cell_11",
")",
"{",
"continue",
";",
"}",
"panel",
".",
"add",
"(",
"Box",
".",
"createRigidArea",
"(",
"filler",
")",
",",
"cc",
".",
"xy",
"(",
"cols",
"[",
"index",
"]",
",",
"1",
")",
")",
";",
"}",
"for",
"(",
"int",
"index",
"=",
"0",
";",
"index",
"<",
"rows",
".",
"length",
";",
"index",
"++",
")",
"{",
"if",
"(",
"rows",
"[",
"index",
"]",
"==",
"1",
"&&",
"filled_cell_11",
")",
"{",
"continue",
";",
"}",
"panel",
".",
"add",
"(",
"Box",
".",
"createRigidArea",
"(",
"filler",
")",
",",
"cc",
".",
"xy",
"(",
"1",
",",
"rows",
"[",
"index",
"]",
")",
")",
";",
"}",
"}"
] | Adds fill components to empty cells in the first row and first column of the grid.
This ensures that the grid spacing will be the same as shown in the designer.
@param cols an array of column indices in the first row where fill components should be added.
@param rows an array of row indices in the first column where fill components should be added. | [
"Adds",
"fill",
"components",
"to",
"empty",
"cells",
"in",
"the",
"first",
"row",
"and",
"first",
"column",
"of",
"the",
"grid",
".",
"This",
"ensures",
"that",
"the",
"grid",
"spacing",
"will",
"be",
"the",
"same",
"as",
"shown",
"in",
"the",
"designer",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/apps/src/main/java/org/hortonmachine/geopaparazzi/GeopaparazziView.java#L56-L90 |
137,312 | TheHortonMachine/hortonmachine | apps/src/main/java/org/hortonmachine/geopaparazzi/GeopaparazziView.java | GeopaparazziView.loadImage | public ImageIcon loadImage( String imageName )
{
try
{
ClassLoader classloader = getClass().getClassLoader();
java.net.URL url = classloader.getResource( imageName );
if ( url != null )
{
ImageIcon icon = new ImageIcon( url );
return icon;
}
}
catch( Exception e )
{
e.printStackTrace();
}
throw new IllegalArgumentException( "Unable to load image: " + imageName );
} | java | public ImageIcon loadImage( String imageName )
{
try
{
ClassLoader classloader = getClass().getClassLoader();
java.net.URL url = classloader.getResource( imageName );
if ( url != null )
{
ImageIcon icon = new ImageIcon( url );
return icon;
}
}
catch( Exception e )
{
e.printStackTrace();
}
throw new IllegalArgumentException( "Unable to load image: " + imageName );
} | [
"public",
"ImageIcon",
"loadImage",
"(",
"String",
"imageName",
")",
"{",
"try",
"{",
"ClassLoader",
"classloader",
"=",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
";",
"java",
".",
"net",
".",
"URL",
"url",
"=",
"classloader",
".",
"getResource",
"(",
"imageName",
")",
";",
"if",
"(",
"url",
"!=",
"null",
")",
"{",
"ImageIcon",
"icon",
"=",
"new",
"ImageIcon",
"(",
"url",
")",
";",
"return",
"icon",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unable to load image: \"",
"+",
"imageName",
")",
";",
"}"
] | Helper method to load an image file from the CLASSPATH
@param imageName the package and name of the file to load relative to the CLASSPATH
@return an ImageIcon instance with the specified image file
@throws IllegalArgumentException if the image resource cannot be loaded. | [
"Helper",
"method",
"to",
"load",
"an",
"image",
"file",
"from",
"the",
"CLASSPATH"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/apps/src/main/java/org/hortonmachine/geopaparazzi/GeopaparazziView.java#L98-L115 |
137,313 | TheHortonMachine/hortonmachine | gears/src/main/java/oms3/compiler/Compiler.java | Compiler.compileSource | public synchronized Class<?> compileSource(String name, String code) throws Exception {
Class<?> c = cache.get(name);
if (c == null) {
c = compileSource0(name, code);
cache.put(name, c);
}
return c;
} | java | public synchronized Class<?> compileSource(String name, String code) throws Exception {
Class<?> c = cache.get(name);
if (c == null) {
c = compileSource0(name, code);
cache.put(name, c);
}
return c;
} | [
"public",
"synchronized",
"Class",
"<",
"?",
">",
"compileSource",
"(",
"String",
"name",
",",
"String",
"code",
")",
"throws",
"Exception",
"{",
"Class",
"<",
"?",
">",
"c",
"=",
"cache",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"c",
"==",
"null",
")",
"{",
"c",
"=",
"compileSource0",
"(",
"name",
",",
"code",
")",
";",
"cache",
".",
"put",
"(",
"name",
",",
"c",
")",
";",
"}",
"return",
"c",
";",
"}"
] | Compiles a single source file and loads the class with a
default class loader. The default class loader is the one used
to load the test case class.
@param name the name of the class to compile.
@param code the source code of the class.
@return the compiled class. | [
"Compiles",
"a",
"single",
"source",
"file",
"and",
"loads",
"the",
"class",
"with",
"a",
"default",
"class",
"loader",
".",
"The",
"default",
"class",
"loader",
"is",
"the",
"one",
"used",
"to",
"load",
"the",
"test",
"case",
"class",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/oms3/compiler/Compiler.java#L68-L75 |
137,314 | TheHortonMachine/hortonmachine | gears/src/main/java/oms3/compiler/Compiler.java | Compiler.compileSource0 | private Class<?> compileSource0(String className, String sourceCode) throws Exception {
List<MemorySourceJavaFileObject> compUnits = new ArrayList<MemorySourceJavaFileObject>(1);
compUnits.add(new MemorySourceJavaFileObject(className + ".java", sourceCode));
DiagnosticCollector<JavaFileObject> diag = new DiagnosticCollector<JavaFileObject>();
Boolean result = compiler.getTask(null, fileManager, diag, compilerOptions, null, compUnits).call();
if (result.equals(Boolean.FALSE)) {
throw new RuntimeException(diag.getDiagnostics().toString());
}
try {
String classDotName = className.replace('/', '.');
return Class.forName(classDotName, true, loader);
} catch (ClassNotFoundException e) {
throw e;
}
} | java | private Class<?> compileSource0(String className, String sourceCode) throws Exception {
List<MemorySourceJavaFileObject> compUnits = new ArrayList<MemorySourceJavaFileObject>(1);
compUnits.add(new MemorySourceJavaFileObject(className + ".java", sourceCode));
DiagnosticCollector<JavaFileObject> diag = new DiagnosticCollector<JavaFileObject>();
Boolean result = compiler.getTask(null, fileManager, diag, compilerOptions, null, compUnits).call();
if (result.equals(Boolean.FALSE)) {
throw new RuntimeException(diag.getDiagnostics().toString());
}
try {
String classDotName = className.replace('/', '.');
return Class.forName(classDotName, true, loader);
} catch (ClassNotFoundException e) {
throw e;
}
} | [
"private",
"Class",
"<",
"?",
">",
"compileSource0",
"(",
"String",
"className",
",",
"String",
"sourceCode",
")",
"throws",
"Exception",
"{",
"List",
"<",
"MemorySourceJavaFileObject",
">",
"compUnits",
"=",
"new",
"ArrayList",
"<",
"MemorySourceJavaFileObject",
">",
"(",
"1",
")",
";",
"compUnits",
".",
"add",
"(",
"new",
"MemorySourceJavaFileObject",
"(",
"className",
"+",
"\".java\"",
",",
"sourceCode",
")",
")",
";",
"DiagnosticCollector",
"<",
"JavaFileObject",
">",
"diag",
"=",
"new",
"DiagnosticCollector",
"<",
"JavaFileObject",
">",
"(",
")",
";",
"Boolean",
"result",
"=",
"compiler",
".",
"getTask",
"(",
"null",
",",
"fileManager",
",",
"diag",
",",
"compilerOptions",
",",
"null",
",",
"compUnits",
")",
".",
"call",
"(",
")",
";",
"if",
"(",
"result",
".",
"equals",
"(",
"Boolean",
".",
"FALSE",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"diag",
".",
"getDiagnostics",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"}",
"try",
"{",
"String",
"classDotName",
"=",
"className",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
";",
"return",
"Class",
".",
"forName",
"(",
"classDotName",
",",
"true",
",",
"loader",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"}"
] | Compiles multiple sources file and loads the classes.
@param sourceFiles the source files to compile.
@param parentLoader the parent class loader to use when loading classes.
@return a map of compiled classes. This maps class names to
Class objects.
@throws Exception | [
"Compiles",
"multiple",
"sources",
"file",
"and",
"loads",
"the",
"classes",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/oms3/compiler/Compiler.java#L100-L115 |
137,315 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/DynamicDoubleArray.java | DynamicDoubleArray.setValue | public void setValue( int position, double value ) {
if (position >= internalArray.length) {
double[] newArray = new double[position + growingSize];
System.arraycopy(internalArray, 0, newArray, 0, internalArray.length);
internalArray = newArray;
}
internalArray[position] = value;
lastIndex = max(lastIndex, position);
} | java | public void setValue( int position, double value ) {
if (position >= internalArray.length) {
double[] newArray = new double[position + growingSize];
System.arraycopy(internalArray, 0, newArray, 0, internalArray.length);
internalArray = newArray;
}
internalArray[position] = value;
lastIndex = max(lastIndex, position);
} | [
"public",
"void",
"setValue",
"(",
"int",
"position",
",",
"double",
"value",
")",
"{",
"if",
"(",
"position",
">=",
"internalArray",
".",
"length",
")",
"{",
"double",
"[",
"]",
"newArray",
"=",
"new",
"double",
"[",
"position",
"+",
"growingSize",
"]",
";",
"System",
".",
"arraycopy",
"(",
"internalArray",
",",
"0",
",",
"newArray",
",",
"0",
",",
"internalArray",
".",
"length",
")",
";",
"internalArray",
"=",
"newArray",
";",
"}",
"internalArray",
"[",
"position",
"]",
"=",
"value",
";",
"lastIndex",
"=",
"max",
"(",
"lastIndex",
",",
"position",
")",
";",
"}"
] | Safe set the value in a certain position.
<p>If the array is smaller than the position, the array is extended and substituted.</p>
@param position the index in which to set the value.
@param value the value to set. | [
"Safe",
"set",
"the",
"value",
"in",
"a",
"certain",
"position",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/DynamicDoubleArray.java#L61-L69 |
137,316 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/DynamicDoubleArray.java | DynamicDoubleArray.getTrimmedInternalArray | public double[] getTrimmedInternalArray() {
if (internalArray.length == lastIndex + 1) {
return internalArray;
}
double[] newArray = new double[lastIndex + 1];
System.arraycopy(internalArray, 0, newArray, 0, newArray.length);
return newArray;
} | java | public double[] getTrimmedInternalArray() {
if (internalArray.length == lastIndex + 1) {
return internalArray;
}
double[] newArray = new double[lastIndex + 1];
System.arraycopy(internalArray, 0, newArray, 0, newArray.length);
return newArray;
} | [
"public",
"double",
"[",
"]",
"getTrimmedInternalArray",
"(",
")",
"{",
"if",
"(",
"internalArray",
".",
"length",
"==",
"lastIndex",
"+",
"1",
")",
"{",
"return",
"internalArray",
";",
"}",
"double",
"[",
"]",
"newArray",
"=",
"new",
"double",
"[",
"lastIndex",
"+",
"1",
"]",
";",
"System",
".",
"arraycopy",
"(",
"internalArray",
",",
"0",
",",
"newArray",
",",
"0",
",",
"newArray",
".",
"length",
")",
";",
"return",
"newArray",
";",
"}"
] | Get a trimmed version of the array, i.e. without ending unset positions.
@return the trimmed array. | [
"Get",
"a",
"trimmed",
"version",
"of",
"the",
"array",
"i",
".",
"e",
".",
"without",
"ending",
"unset",
"positions",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/DynamicDoubleArray.java#L114-L121 |
137,317 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/map/color/ColorRule.java | ColorRule.getColor | public byte[] getColor(float cat)
{
/* First check to see if the category
* value is within the range of this rule. */
float diff = cat - low;
if (diff <= 0f)
return catColor;
// else if (diff < 0)
// {
// /* Category value below lowest value in this rule. */
// return new byte[]{(byte)catColor[0], (byte)catColor[1],
// (byte)catColor[2], (byte)catColor[3]};
// }
else if (diff > range)
{
return new byte[]{(byte)((int)(rmul*range)+(int)catColor[0]),
(byte)((int)(gmul*range)+(int)catColor[1]),
(byte)((int)(bmul*range)+(int)catColor[2]),
(byte)catColor[3]};
}
/* Calculate the color from the gradient */
return new byte[]{(byte)((int)(rmul*diff)+(int)catColor[0]),
(byte)((int)(gmul*diff)+(int)catColor[1]),
(byte)((int)(bmul*diff)+(int)catColor[2]),
(byte)catColor[3]};
} | java | public byte[] getColor(float cat)
{
/* First check to see if the category
* value is within the range of this rule. */
float diff = cat - low;
if (diff <= 0f)
return catColor;
// else if (diff < 0)
// {
// /* Category value below lowest value in this rule. */
// return new byte[]{(byte)catColor[0], (byte)catColor[1],
// (byte)catColor[2], (byte)catColor[3]};
// }
else if (diff > range)
{
return new byte[]{(byte)((int)(rmul*range)+(int)catColor[0]),
(byte)((int)(gmul*range)+(int)catColor[1]),
(byte)((int)(bmul*range)+(int)catColor[2]),
(byte)catColor[3]};
}
/* Calculate the color from the gradient */
return new byte[]{(byte)((int)(rmul*diff)+(int)catColor[0]),
(byte)((int)(gmul*diff)+(int)catColor[1]),
(byte)((int)(bmul*diff)+(int)catColor[2]),
(byte)catColor[3]};
} | [
"public",
"byte",
"[",
"]",
"getColor",
"(",
"float",
"cat",
")",
"{",
"/* First check to see if the category\n * value is within the range of this rule. */",
"float",
"diff",
"=",
"cat",
"-",
"low",
";",
"if",
"(",
"diff",
"<=",
"0f",
")",
"return",
"catColor",
";",
"// else if (diff < 0)",
"// {",
"// /* Category value below lowest value in this rule. */",
"// return new byte[]{(byte)catColor[0], (byte)catColor[1],",
"// (byte)catColor[2], (byte)catColor[3]};",
"// }",
"else",
"if",
"(",
"diff",
">",
"range",
")",
"{",
"return",
"new",
"byte",
"[",
"]",
"{",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"rmul",
"*",
"range",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"0",
"]",
")",
",",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"gmul",
"*",
"range",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"1",
"]",
")",
",",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"bmul",
"*",
"range",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"2",
"]",
")",
",",
"(",
"byte",
")",
"catColor",
"[",
"3",
"]",
"}",
";",
"}",
"/* Calculate the color from the gradient */",
"return",
"new",
"byte",
"[",
"]",
"{",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"rmul",
"*",
"diff",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"0",
"]",
")",
",",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"gmul",
"*",
"diff",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"1",
"]",
")",
",",
"(",
"byte",
")",
"(",
"(",
"int",
")",
"(",
"bmul",
"*",
"diff",
")",
"+",
"(",
"int",
")",
"catColor",
"[",
"2",
"]",
")",
",",
"(",
"byte",
")",
"catColor",
"[",
"3",
"]",
"}",
";",
"}"
] | Return the colour tupple for specified category value | [
"Return",
"the",
"colour",
"tupple",
"for",
"specified",
"category",
"value"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/map/color/ColorRule.java#L99-L125 |
137,318 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/timedependent/OmsTimeSeriesIteratorReader.java | OmsTimeSeriesIteratorReader.getExpectedRow | private String[] getExpectedRow( TableIterator<String[]> tableRowIterator, DateTime expectedDT ) throws IOException {
while( tableRowIterator.hasNext() ) {
String[] row = tableRowIterator.next();
DateTime currentTimestamp = formatter.parseDateTime(row[1]);
if (currentTimestamp.equals(expectedDT)) {
if (pNum == 1) {
return row;
} else {
String[][] allRows = new String[pNum][];
allRows[0] = row;
int rowNum = 1;
for( int i = 1; i < pNum; i++ ) {
if (tableRowIterator.hasNext()) {
String[] nextRow = tableRowIterator.next();
allRows[i] = nextRow;
rowNum++;
}
}
// now aggregate
String[] aggregatedRow = new String[row.length];
// date is the one of the first instant
aggregatedRow[0] = allRows[0][0];
aggregatedRow[1] = allRows[0][1];
for( int col = 2; col < allRows[0].length; col++ ) {
boolean hasOne = false;
switch( pAggregation ) {
case 0:
double sum = 0;
for( int j = 0; j < rowNum; j++ ) {
String valueStr = allRows[j][col];
if (!valueStr.equals(fileNovalue)) {
double value = Double.parseDouble(valueStr);
sum = sum + value;
hasOne = true;
}
}
if (!hasOne) {
sum = doubleNovalue;
}
aggregatedRow[col] = String.valueOf(sum);
break;
case 1:
double avg = 0;
for( int j = 0; j < rowNum; j++ ) {
String valueStr = allRows[j][col];
if (!valueStr.equals(fileNovalue)) {
double value = Double.parseDouble(valueStr);
avg = avg + value;
hasOne = true;
}
}
if (!hasOne) {
avg = doubleNovalue;
} else {
avg = avg / pNum;
}
aggregatedRow[col] = String.valueOf(avg);
break;
default:
break;
}
}
return aggregatedRow;
}
} else if (currentTimestamp.isBefore(expectedDT)) {
// browse until the instant is found
continue;
} else if (currentTimestamp.isAfter(expectedDT)) {
/*
* lost the moment, for now throw exception.
* Could be enhanced in future.
*/
String message = "The data are not aligned with the simulation interval (" + currentTimestamp + "/" + expectedDT
+ "). Check your data file: " + file;
throw new IOException(message);
}
}
return null;
} | java | private String[] getExpectedRow( TableIterator<String[]> tableRowIterator, DateTime expectedDT ) throws IOException {
while( tableRowIterator.hasNext() ) {
String[] row = tableRowIterator.next();
DateTime currentTimestamp = formatter.parseDateTime(row[1]);
if (currentTimestamp.equals(expectedDT)) {
if (pNum == 1) {
return row;
} else {
String[][] allRows = new String[pNum][];
allRows[0] = row;
int rowNum = 1;
for( int i = 1; i < pNum; i++ ) {
if (tableRowIterator.hasNext()) {
String[] nextRow = tableRowIterator.next();
allRows[i] = nextRow;
rowNum++;
}
}
// now aggregate
String[] aggregatedRow = new String[row.length];
// date is the one of the first instant
aggregatedRow[0] = allRows[0][0];
aggregatedRow[1] = allRows[0][1];
for( int col = 2; col < allRows[0].length; col++ ) {
boolean hasOne = false;
switch( pAggregation ) {
case 0:
double sum = 0;
for( int j = 0; j < rowNum; j++ ) {
String valueStr = allRows[j][col];
if (!valueStr.equals(fileNovalue)) {
double value = Double.parseDouble(valueStr);
sum = sum + value;
hasOne = true;
}
}
if (!hasOne) {
sum = doubleNovalue;
}
aggregatedRow[col] = String.valueOf(sum);
break;
case 1:
double avg = 0;
for( int j = 0; j < rowNum; j++ ) {
String valueStr = allRows[j][col];
if (!valueStr.equals(fileNovalue)) {
double value = Double.parseDouble(valueStr);
avg = avg + value;
hasOne = true;
}
}
if (!hasOne) {
avg = doubleNovalue;
} else {
avg = avg / pNum;
}
aggregatedRow[col] = String.valueOf(avg);
break;
default:
break;
}
}
return aggregatedRow;
}
} else if (currentTimestamp.isBefore(expectedDT)) {
// browse until the instant is found
continue;
} else if (currentTimestamp.isAfter(expectedDT)) {
/*
* lost the moment, for now throw exception.
* Could be enhanced in future.
*/
String message = "The data are not aligned with the simulation interval (" + currentTimestamp + "/" + expectedDT
+ "). Check your data file: " + file;
throw new IOException(message);
}
}
return null;
} | [
"private",
"String",
"[",
"]",
"getExpectedRow",
"(",
"TableIterator",
"<",
"String",
"[",
"]",
">",
"tableRowIterator",
",",
"DateTime",
"expectedDT",
")",
"throws",
"IOException",
"{",
"while",
"(",
"tableRowIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"String",
"[",
"]",
"row",
"=",
"tableRowIterator",
".",
"next",
"(",
")",
";",
"DateTime",
"currentTimestamp",
"=",
"formatter",
".",
"parseDateTime",
"(",
"row",
"[",
"1",
"]",
")",
";",
"if",
"(",
"currentTimestamp",
".",
"equals",
"(",
"expectedDT",
")",
")",
"{",
"if",
"(",
"pNum",
"==",
"1",
")",
"{",
"return",
"row",
";",
"}",
"else",
"{",
"String",
"[",
"]",
"[",
"]",
"allRows",
"=",
"new",
"String",
"[",
"pNum",
"]",
"[",
"",
"]",
";",
"allRows",
"[",
"0",
"]",
"=",
"row",
";",
"int",
"rowNum",
"=",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"pNum",
";",
"i",
"++",
")",
"{",
"if",
"(",
"tableRowIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"String",
"[",
"]",
"nextRow",
"=",
"tableRowIterator",
".",
"next",
"(",
")",
";",
"allRows",
"[",
"i",
"]",
"=",
"nextRow",
";",
"rowNum",
"++",
";",
"}",
"}",
"// now aggregate",
"String",
"[",
"]",
"aggregatedRow",
"=",
"new",
"String",
"[",
"row",
".",
"length",
"]",
";",
"// date is the one of the first instant",
"aggregatedRow",
"[",
"0",
"]",
"=",
"allRows",
"[",
"0",
"]",
"[",
"0",
"]",
";",
"aggregatedRow",
"[",
"1",
"]",
"=",
"allRows",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"for",
"(",
"int",
"col",
"=",
"2",
";",
"col",
"<",
"allRows",
"[",
"0",
"]",
".",
"length",
";",
"col",
"++",
")",
"{",
"boolean",
"hasOne",
"=",
"false",
";",
"switch",
"(",
"pAggregation",
")",
"{",
"case",
"0",
":",
"double",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"rowNum",
";",
"j",
"++",
")",
"{",
"String",
"valueStr",
"=",
"allRows",
"[",
"j",
"]",
"[",
"col",
"]",
";",
"if",
"(",
"!",
"valueStr",
".",
"equals",
"(",
"fileNovalue",
")",
")",
"{",
"double",
"value",
"=",
"Double",
".",
"parseDouble",
"(",
"valueStr",
")",
";",
"sum",
"=",
"sum",
"+",
"value",
";",
"hasOne",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"hasOne",
")",
"{",
"sum",
"=",
"doubleNovalue",
";",
"}",
"aggregatedRow",
"[",
"col",
"]",
"=",
"String",
".",
"valueOf",
"(",
"sum",
")",
";",
"break",
";",
"case",
"1",
":",
"double",
"avg",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"rowNum",
";",
"j",
"++",
")",
"{",
"String",
"valueStr",
"=",
"allRows",
"[",
"j",
"]",
"[",
"col",
"]",
";",
"if",
"(",
"!",
"valueStr",
".",
"equals",
"(",
"fileNovalue",
")",
")",
"{",
"double",
"value",
"=",
"Double",
".",
"parseDouble",
"(",
"valueStr",
")",
";",
"avg",
"=",
"avg",
"+",
"value",
";",
"hasOne",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"hasOne",
")",
"{",
"avg",
"=",
"doubleNovalue",
";",
"}",
"else",
"{",
"avg",
"=",
"avg",
"/",
"pNum",
";",
"}",
"aggregatedRow",
"[",
"col",
"]",
"=",
"String",
".",
"valueOf",
"(",
"avg",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"return",
"aggregatedRow",
";",
"}",
"}",
"else",
"if",
"(",
"currentTimestamp",
".",
"isBefore",
"(",
"expectedDT",
")",
")",
"{",
"// browse until the instant is found",
"continue",
";",
"}",
"else",
"if",
"(",
"currentTimestamp",
".",
"isAfter",
"(",
"expectedDT",
")",
")",
"{",
"/*\n * lost the moment, for now throw exception.\n * Could be enhanced in future.\n */",
"String",
"message",
"=",
"\"The data are not aligned with the simulation interval (\"",
"+",
"currentTimestamp",
"+",
"\"/\"",
"+",
"expectedDT",
"+",
"\"). Check your data file: \"",
"+",
"file",
";",
"throw",
"new",
"IOException",
"(",
"message",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get the needed datarow from the table.
@param tableRowIterator
@return the row that is aligned with the expected timestep.
@throws IOException if the expected timestep is < than the current. | [
"Get",
"the",
"needed",
"datarow",
"from",
"the",
"table",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/timedependent/OmsTimeSeriesIteratorReader.java#L269-L351 |
137,319 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/modules/r/houghes/OmsHoughCirclesRasterCleaner.java | OmsHoughCirclesRasterCleaner.process | @SuppressWarnings("unchecked")
@Execute
public void process() throws Exception {
checkNull(inVector, pMaxOverlap, inRaster);
RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
GridGeometry2D gridGeometry = inRaster.getGridGeometry();
double[] tm_utm_tac = new double[3];
STRtree circlesTree = FeatureUtilities.featureCollectionToSTRtree(inVector);
List<SimpleFeature> circlesList = FeatureUtilities.featureCollectionToList(inVector);
DefaultFeatureCollection outFC = new DefaultFeatureCollection();
for( SimpleFeature circleFeature : circlesList ) {
Geometry geometry = (Geometry) circleFeature.getDefaultGeometry();
Polygon circle = (Polygon) geometry.getGeometryN(0);
PreparedGeometry preparedCircle = PreparedGeometryFactory.prepare(circle);
List<SimpleFeature> circlesAround = circlesTree.query(circle.getEnvelopeInternal());
List<Geometry> intersectedCircles = new ArrayList<Geometry>();
for( SimpleFeature circleAround : circlesAround ) {
if (circleAround.equals(circleFeature)) {
continue;
}
Geometry circleAroundGeometry = (Geometry) circleAround.getDefaultGeometry();
if (preparedCircle.intersects(circleAroundGeometry)) {
intersectedCircles.add(circleAroundGeometry);
}
}
Point centroid = circle.getCentroid();
int intersectionsCount = intersectedCircles.size();
if (intersectionsCount != 0) {
// check how many circles overlapped
if (intersectionsCount > pMaxOverlapCount) {
continue;
}
// check if the circles overlap too much, i.e. cover their baricenter
boolean intersected = false;
for( Geometry intersectedCircle : intersectedCircles ) {
if (intersectedCircle.intersects(centroid)) {
intersected = true;
break;
}
}
if (intersected) {
continue;
}
}
// check if the center has a raster value, i.e. is not empty
double value = CoverageUtilities.getValue(inRaster, centroid.getCoordinate());
if (!HMConstants.isNovalue(value)) {
continue;
}
// check if the inner part of the circle is indeed rather empty
// min, max, mean, var, sdev, activeCellCount, passiveCellCount
double[] stats = OmsZonalStats.polygonStats(circle, gridGeometry, rasterIter, false, tm_utm_tac, 0, pm);
// if we have many more active cells than passive cells, that is not a circle
double activeCells = stats[5];
double novalues = stats[6];
if (activeCells * 1.5 > novalues) {
continue;
}
// take it as valid circle
outFC.add(circleFeature);
}
outCircles = outFC;
rasterIter.done();
} | java | @SuppressWarnings("unchecked")
@Execute
public void process() throws Exception {
checkNull(inVector, pMaxOverlap, inRaster);
RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
GridGeometry2D gridGeometry = inRaster.getGridGeometry();
double[] tm_utm_tac = new double[3];
STRtree circlesTree = FeatureUtilities.featureCollectionToSTRtree(inVector);
List<SimpleFeature> circlesList = FeatureUtilities.featureCollectionToList(inVector);
DefaultFeatureCollection outFC = new DefaultFeatureCollection();
for( SimpleFeature circleFeature : circlesList ) {
Geometry geometry = (Geometry) circleFeature.getDefaultGeometry();
Polygon circle = (Polygon) geometry.getGeometryN(0);
PreparedGeometry preparedCircle = PreparedGeometryFactory.prepare(circle);
List<SimpleFeature> circlesAround = circlesTree.query(circle.getEnvelopeInternal());
List<Geometry> intersectedCircles = new ArrayList<Geometry>();
for( SimpleFeature circleAround : circlesAround ) {
if (circleAround.equals(circleFeature)) {
continue;
}
Geometry circleAroundGeometry = (Geometry) circleAround.getDefaultGeometry();
if (preparedCircle.intersects(circleAroundGeometry)) {
intersectedCircles.add(circleAroundGeometry);
}
}
Point centroid = circle.getCentroid();
int intersectionsCount = intersectedCircles.size();
if (intersectionsCount != 0) {
// check how many circles overlapped
if (intersectionsCount > pMaxOverlapCount) {
continue;
}
// check if the circles overlap too much, i.e. cover their baricenter
boolean intersected = false;
for( Geometry intersectedCircle : intersectedCircles ) {
if (intersectedCircle.intersects(centroid)) {
intersected = true;
break;
}
}
if (intersected) {
continue;
}
}
// check if the center has a raster value, i.e. is not empty
double value = CoverageUtilities.getValue(inRaster, centroid.getCoordinate());
if (!HMConstants.isNovalue(value)) {
continue;
}
// check if the inner part of the circle is indeed rather empty
// min, max, mean, var, sdev, activeCellCount, passiveCellCount
double[] stats = OmsZonalStats.polygonStats(circle, gridGeometry, rasterIter, false, tm_utm_tac, 0, pm);
// if we have many more active cells than passive cells, that is not a circle
double activeCells = stats[5];
double novalues = stats[6];
if (activeCells * 1.5 > novalues) {
continue;
}
// take it as valid circle
outFC.add(circleFeature);
}
outCircles = outFC;
rasterIter.done();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"@",
"Execute",
"public",
"void",
"process",
"(",
")",
"throws",
"Exception",
"{",
"checkNull",
"(",
"inVector",
",",
"pMaxOverlap",
",",
"inRaster",
")",
";",
"RandomIter",
"rasterIter",
"=",
"CoverageUtilities",
".",
"getRandomIterator",
"(",
"inRaster",
")",
";",
"GridGeometry2D",
"gridGeometry",
"=",
"inRaster",
".",
"getGridGeometry",
"(",
")",
";",
"double",
"[",
"]",
"tm_utm_tac",
"=",
"new",
"double",
"[",
"3",
"]",
";",
"STRtree",
"circlesTree",
"=",
"FeatureUtilities",
".",
"featureCollectionToSTRtree",
"(",
"inVector",
")",
";",
"List",
"<",
"SimpleFeature",
">",
"circlesList",
"=",
"FeatureUtilities",
".",
"featureCollectionToList",
"(",
"inVector",
")",
";",
"DefaultFeatureCollection",
"outFC",
"=",
"new",
"DefaultFeatureCollection",
"(",
")",
";",
"for",
"(",
"SimpleFeature",
"circleFeature",
":",
"circlesList",
")",
"{",
"Geometry",
"geometry",
"=",
"(",
"Geometry",
")",
"circleFeature",
".",
"getDefaultGeometry",
"(",
")",
";",
"Polygon",
"circle",
"=",
"(",
"Polygon",
")",
"geometry",
".",
"getGeometryN",
"(",
"0",
")",
";",
"PreparedGeometry",
"preparedCircle",
"=",
"PreparedGeometryFactory",
".",
"prepare",
"(",
"circle",
")",
";",
"List",
"<",
"SimpleFeature",
">",
"circlesAround",
"=",
"circlesTree",
".",
"query",
"(",
"circle",
".",
"getEnvelopeInternal",
"(",
")",
")",
";",
"List",
"<",
"Geometry",
">",
"intersectedCircles",
"=",
"new",
"ArrayList",
"<",
"Geometry",
">",
"(",
")",
";",
"for",
"(",
"SimpleFeature",
"circleAround",
":",
"circlesAround",
")",
"{",
"if",
"(",
"circleAround",
".",
"equals",
"(",
"circleFeature",
")",
")",
"{",
"continue",
";",
"}",
"Geometry",
"circleAroundGeometry",
"=",
"(",
"Geometry",
")",
"circleAround",
".",
"getDefaultGeometry",
"(",
")",
";",
"if",
"(",
"preparedCircle",
".",
"intersects",
"(",
"circleAroundGeometry",
")",
")",
"{",
"intersectedCircles",
".",
"add",
"(",
"circleAroundGeometry",
")",
";",
"}",
"}",
"Point",
"centroid",
"=",
"circle",
".",
"getCentroid",
"(",
")",
";",
"int",
"intersectionsCount",
"=",
"intersectedCircles",
".",
"size",
"(",
")",
";",
"if",
"(",
"intersectionsCount",
"!=",
"0",
")",
"{",
"// check how many circles overlapped",
"if",
"(",
"intersectionsCount",
">",
"pMaxOverlapCount",
")",
"{",
"continue",
";",
"}",
"// check if the circles overlap too much, i.e. cover their baricenter",
"boolean",
"intersected",
"=",
"false",
";",
"for",
"(",
"Geometry",
"intersectedCircle",
":",
"intersectedCircles",
")",
"{",
"if",
"(",
"intersectedCircle",
".",
"intersects",
"(",
"centroid",
")",
")",
"{",
"intersected",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"intersected",
")",
"{",
"continue",
";",
"}",
"}",
"// check if the center has a raster value, i.e. is not empty",
"double",
"value",
"=",
"CoverageUtilities",
".",
"getValue",
"(",
"inRaster",
",",
"centroid",
".",
"getCoordinate",
"(",
")",
")",
";",
"if",
"(",
"!",
"HMConstants",
".",
"isNovalue",
"(",
"value",
")",
")",
"{",
"continue",
";",
"}",
"// check if the inner part of the circle is indeed rather empty",
"// min, max, mean, var, sdev, activeCellCount, passiveCellCount",
"double",
"[",
"]",
"stats",
"=",
"OmsZonalStats",
".",
"polygonStats",
"(",
"circle",
",",
"gridGeometry",
",",
"rasterIter",
",",
"false",
",",
"tm_utm_tac",
",",
"0",
",",
"pm",
")",
";",
"// if we have many more active cells than passive cells, that is not a circle",
"double",
"activeCells",
"=",
"stats",
"[",
"5",
"]",
";",
"double",
"novalues",
"=",
"stats",
"[",
"6",
"]",
";",
"if",
"(",
"activeCells",
"*",
"1.5",
">",
"novalues",
")",
"{",
"continue",
";",
"}",
"// take it as valid circle",
"outFC",
".",
"add",
"(",
"circleFeature",
")",
";",
"}",
"outCircles",
"=",
"outFC",
";",
"rasterIter",
".",
"done",
"(",
")",
";",
"}"
] | VARS DESCR END | [
"VARS",
"DESCR",
"END"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/modules/r/houghes/OmsHoughCirclesRasterCleaner.java#L104-L177 |
137,320 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/StringEncoder.java | StringEncoder.byteCopy | private static byte[] byteCopy(byte[] source, int offset,
int count, byte[] target) {
for (int i = offset, j = 0; i < offset + count; i++, j++) {
target[j] = source[i];
}
return target;
} | java | private static byte[] byteCopy(byte[] source, int offset,
int count, byte[] target) {
for (int i = offset, j = 0; i < offset + count; i++, j++) {
target[j] = source[i];
}
return target;
} | [
"private",
"static",
"byte",
"[",
"]",
"byteCopy",
"(",
"byte",
"[",
"]",
"source",
",",
"int",
"offset",
",",
"int",
"count",
",",
"byte",
"[",
"]",
"target",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"offset",
",",
"j",
"=",
"0",
";",
"i",
"<",
"offset",
"+",
"count",
";",
"i",
"++",
",",
"j",
"++",
")",
"{",
"target",
"[",
"j",
"]",
"=",
"source",
"[",
"i",
"]",
";",
"}",
"return",
"target",
";",
"}"
] | Copies count elements from source, starting at element with
index offset, to the given target.
@param source the source.
@param offset the offset.
@param count the number of elements to be copied.
@param target the target to be returned.
@return the target being copied to. | [
"Copies",
"count",
"elements",
"from",
"source",
"starting",
"at",
"element",
"with",
"index",
"offset",
"to",
"the",
"given",
"target",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/StringEncoder.java#L207-L213 |
137,321 | TheHortonMachine/hortonmachine | dbs/src/main/java/jsqlite/StringEncoder.java | StringEncoder.encodeX | public static String encodeX(byte[] a) {
// check input
if (a == null || a.length == 0) {
return "X''";
}
char[] out = new char[a.length * 2 + 3];
int i = 2;
for (int j = 0; j < a.length; j++) {
out[i++] = xdigits[(a[j] >> 4) & 0x0F];
out[i++] = xdigits[a[j] & 0x0F];
}
out[0] = 'X';
out[1] = '\'';
out[i] = '\'';
return new String(out);
} | java | public static String encodeX(byte[] a) {
// check input
if (a == null || a.length == 0) {
return "X''";
}
char[] out = new char[a.length * 2 + 3];
int i = 2;
for (int j = 0; j < a.length; j++) {
out[i++] = xdigits[(a[j] >> 4) & 0x0F];
out[i++] = xdigits[a[j] & 0x0F];
}
out[0] = 'X';
out[1] = '\'';
out[i] = '\'';
return new String(out);
} | [
"public",
"static",
"String",
"encodeX",
"(",
"byte",
"[",
"]",
"a",
")",
"{",
"// check input",
"if",
"(",
"a",
"==",
"null",
"||",
"a",
".",
"length",
"==",
"0",
")",
"{",
"return",
"\"X''\"",
";",
"}",
"char",
"[",
"]",
"out",
"=",
"new",
"char",
"[",
"a",
".",
"length",
"*",
"2",
"+",
"3",
"]",
";",
"int",
"i",
"=",
"2",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"a",
".",
"length",
";",
"j",
"++",
")",
"{",
"out",
"[",
"i",
"++",
"]",
"=",
"xdigits",
"[",
"(",
"a",
"[",
"j",
"]",
">>",
"4",
")",
"&",
"0x0F",
"]",
";",
"out",
"[",
"i",
"++",
"]",
"=",
"xdigits",
"[",
"a",
"[",
"j",
"]",
"&",
"0x0F",
"]",
";",
"}",
"out",
"[",
"0",
"]",
"=",
"'",
"'",
";",
"out",
"[",
"1",
"]",
"=",
"'",
"'",
";",
"out",
"[",
"i",
"]",
"=",
"'",
"'",
";",
"return",
"new",
"String",
"(",
"out",
")",
";",
"}"
] | Encodes the given byte array into SQLite3 blob notation, ie X'..'
@param a the byte array to be encoded. A null reference is handled as
an empty array.
@return the encoded bytes as a string. | [
"Encodes",
"the",
"given",
"byte",
"array",
"into",
"SQLite3",
"blob",
"notation",
"ie",
"X",
".."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/jsqlite/StringEncoder.java#L228-L243 |
137,322 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.getWindow | public double[][] getWindow( int size, boolean doCircular ) {
if (size % 2 == 0) {
size++;
}
double[][] window = new double[size][size];
int delta = (size - 1) / 2;
if (!doCircular) {
for( int c = -delta; c <= delta; c++ ) {
int tmpCol = col + c;
for( int r = -delta; r <= delta; r++ ) {
int tmpRow = row + r;
GridNode n = new GridNode(gridIter, cols, rows, xRes, yRes, tmpCol, tmpRow);
window[r + delta][c + delta] = n.elevation;
}
}
} else {
double radius = delta; // rows + half cell
for( int c = -delta; c <= delta; c++ ) {
int tmpCol = col + c;
for( int r = -delta; r <= delta; r++ ) {
int tmpRow = row + r;
double distance = sqrt(c * c + r * r);
if (distance <= radius) {
GridNode n = new GridNode(gridIter, cols, rows, xRes, yRes, tmpCol, tmpRow);
window[r + delta][c + delta] = n.elevation;
} else {
window[r + delta][c + delta] = doubleNovalue;
}
}
}
}
return window;
} | java | public double[][] getWindow( int size, boolean doCircular ) {
if (size % 2 == 0) {
size++;
}
double[][] window = new double[size][size];
int delta = (size - 1) / 2;
if (!doCircular) {
for( int c = -delta; c <= delta; c++ ) {
int tmpCol = col + c;
for( int r = -delta; r <= delta; r++ ) {
int tmpRow = row + r;
GridNode n = new GridNode(gridIter, cols, rows, xRes, yRes, tmpCol, tmpRow);
window[r + delta][c + delta] = n.elevation;
}
}
} else {
double radius = delta; // rows + half cell
for( int c = -delta; c <= delta; c++ ) {
int tmpCol = col + c;
for( int r = -delta; r <= delta; r++ ) {
int tmpRow = row + r;
double distance = sqrt(c * c + r * r);
if (distance <= radius) {
GridNode n = new GridNode(gridIter, cols, rows, xRes, yRes, tmpCol, tmpRow);
window[r + delta][c + delta] = n.elevation;
} else {
window[r + delta][c + delta] = doubleNovalue;
}
}
}
}
return window;
} | [
"public",
"double",
"[",
"]",
"[",
"]",
"getWindow",
"(",
"int",
"size",
",",
"boolean",
"doCircular",
")",
"{",
"if",
"(",
"size",
"%",
"2",
"==",
"0",
")",
"{",
"size",
"++",
";",
"}",
"double",
"[",
"]",
"[",
"]",
"window",
"=",
"new",
"double",
"[",
"size",
"]",
"[",
"size",
"]",
";",
"int",
"delta",
"=",
"(",
"size",
"-",
"1",
")",
"/",
"2",
";",
"if",
"(",
"!",
"doCircular",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"-",
"delta",
";",
"c",
"<=",
"delta",
";",
"c",
"++",
")",
"{",
"int",
"tmpCol",
"=",
"col",
"+",
"c",
";",
"for",
"(",
"int",
"r",
"=",
"-",
"delta",
";",
"r",
"<=",
"delta",
";",
"r",
"++",
")",
"{",
"int",
"tmpRow",
"=",
"row",
"+",
"r",
";",
"GridNode",
"n",
"=",
"new",
"GridNode",
"(",
"gridIter",
",",
"cols",
",",
"rows",
",",
"xRes",
",",
"yRes",
",",
"tmpCol",
",",
"tmpRow",
")",
";",
"window",
"[",
"r",
"+",
"delta",
"]",
"[",
"c",
"+",
"delta",
"]",
"=",
"n",
".",
"elevation",
";",
"}",
"}",
"}",
"else",
"{",
"double",
"radius",
"=",
"delta",
";",
"// rows + half cell",
"for",
"(",
"int",
"c",
"=",
"-",
"delta",
";",
"c",
"<=",
"delta",
";",
"c",
"++",
")",
"{",
"int",
"tmpCol",
"=",
"col",
"+",
"c",
";",
"for",
"(",
"int",
"r",
"=",
"-",
"delta",
";",
"r",
"<=",
"delta",
";",
"r",
"++",
")",
"{",
"int",
"tmpRow",
"=",
"row",
"+",
"r",
";",
"double",
"distance",
"=",
"sqrt",
"(",
"c",
"*",
"c",
"+",
"r",
"*",
"r",
")",
";",
"if",
"(",
"distance",
"<=",
"radius",
")",
"{",
"GridNode",
"n",
"=",
"new",
"GridNode",
"(",
"gridIter",
",",
"cols",
",",
"rows",
",",
"xRes",
",",
"yRes",
",",
"tmpCol",
",",
"tmpRow",
")",
";",
"window",
"[",
"r",
"+",
"delta",
"]",
"[",
"c",
"+",
"delta",
"]",
"=",
"n",
".",
"elevation",
";",
"}",
"else",
"{",
"window",
"[",
"r",
"+",
"delta",
"]",
"[",
"c",
"+",
"delta",
"]",
"=",
"doubleNovalue",
";",
"}",
"}",
"}",
"}",
"return",
"window",
";",
"}"
] | Get a window of values surrounding the current node.
<p>Notes:</p>
<ul>
<li>the size has to be odd, so that the current node can be in the center.
If the size is even, size+1 will be used.</li>
<li>values outside the boundaries of the raster will be set to novalue.
No exception is thrown.</li>
</ul>
@param size the size of the window. The window will be a matrix window[size][size].
@param doCircular if <code>true</code> the window values are set to novalue
were necessary to make it circular.
@return the read window. | [
"Get",
"a",
"window",
"of",
"values",
"surrounding",
"the",
"current",
"node",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L265-L298 |
137,323 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.getElevationAt | public double getElevationAt( Direction direction ) {
switch( direction ) {
case E:
return eElev;
case W:
return wElev;
case N:
return nElev;
case S:
return sElev;
case EN:
return enElev;
case NW:
return nwElev;
case WS:
return wsElev;
case SE:
return seElev;
default:
throw new IllegalArgumentException();
}
} | java | public double getElevationAt( Direction direction ) {
switch( direction ) {
case E:
return eElev;
case W:
return wElev;
case N:
return nElev;
case S:
return sElev;
case EN:
return enElev;
case NW:
return nwElev;
case WS:
return wsElev;
case SE:
return seElev;
default:
throw new IllegalArgumentException();
}
} | [
"public",
"double",
"getElevationAt",
"(",
"Direction",
"direction",
")",
"{",
"switch",
"(",
"direction",
")",
"{",
"case",
"E",
":",
"return",
"eElev",
";",
"case",
"W",
":",
"return",
"wElev",
";",
"case",
"N",
":",
"return",
"nElev",
";",
"case",
"S",
":",
"return",
"sElev",
";",
"case",
"EN",
":",
"return",
"enElev",
";",
"case",
"NW",
":",
"return",
"nwElev",
";",
"case",
"WS",
":",
"return",
"wsElev",
";",
"case",
"SE",
":",
"return",
"seElev",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"}"
] | Get the value of the elevation in one of the surrounding direction.
@param direction the {@link Direction}.
@return the elevation value. | [
"Get",
"the",
"value",
"of",
"the",
"elevation",
"in",
"one",
"of",
"the",
"surrounding",
"direction",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L306-L327 |
137,324 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.getFlow | public int getFlow() {
GridNode nextDown = goDownstreamSP();
if (nextDown == null) {
return HMConstants.intNovalue;
}
int dcol = nextDown.col - col;
int drow = nextDown.row - row;
Direction dir = Direction.getDir(dcol, drow);
return dir.getFlow();
} | java | public int getFlow() {
GridNode nextDown = goDownstreamSP();
if (nextDown == null) {
return HMConstants.intNovalue;
}
int dcol = nextDown.col - col;
int drow = nextDown.row - row;
Direction dir = Direction.getDir(dcol, drow);
return dir.getFlow();
} | [
"public",
"int",
"getFlow",
"(",
")",
"{",
"GridNode",
"nextDown",
"=",
"goDownstreamSP",
"(",
")",
";",
"if",
"(",
"nextDown",
"==",
"null",
")",
"{",
"return",
"HMConstants",
".",
"intNovalue",
";",
"}",
"int",
"dcol",
"=",
"nextDown",
".",
"col",
"-",
"col",
";",
"int",
"drow",
"=",
"nextDown",
".",
"row",
"-",
"row",
";",
"Direction",
"dir",
"=",
"Direction",
".",
"getDir",
"(",
"dcol",
",",
"drow",
")",
";",
"return",
"dir",
".",
"getFlow",
"(",
")",
";",
"}"
] | Get the flow value of this node based in the steepest path.
@return the value of flow. | [
"Get",
"the",
"flow",
"value",
"of",
"this",
"node",
"based",
"in",
"the",
"steepest",
"path",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L363-L374 |
137,325 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.getNodeAt | public GridNode getNodeAt( Direction direction ) {
int newCol = col + direction.col;
int newRow = row + direction.row;
GridNode node = new GridNode(gridIter, cols, rows, xRes, yRes, newCol, newRow);
return node;
} | java | public GridNode getNodeAt( Direction direction ) {
int newCol = col + direction.col;
int newRow = row + direction.row;
GridNode node = new GridNode(gridIter, cols, rows, xRes, yRes, newCol, newRow);
return node;
} | [
"public",
"GridNode",
"getNodeAt",
"(",
"Direction",
"direction",
")",
"{",
"int",
"newCol",
"=",
"col",
"+",
"direction",
".",
"col",
";",
"int",
"newRow",
"=",
"row",
"+",
"direction",
".",
"row",
";",
"GridNode",
"node",
"=",
"new",
"GridNode",
"(",
"gridIter",
",",
"cols",
",",
"rows",
",",
"xRes",
",",
"yRes",
",",
"newCol",
",",
"newRow",
")",
";",
"return",
"node",
";",
"}"
] | Get a neighbor node at a certain direction.
@param direction the direction to get the node at.
@return the node. | [
"Get",
"a",
"neighbor",
"node",
"at",
"a",
"certain",
"direction",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L410-L415 |
137,326 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.isNeighborOf | public Direction isNeighborOf( GridNode otherNode ) {
Direction[] orderedDirs = Direction.getOrderedDirs();
for( int i = 0; i < orderedDirs.length; i++ ) {
Direction direction = orderedDirs[i];
int newCol = col + direction.col;
int newRow = row + direction.row;
if (otherNode.col == newCol && otherNode.row == newRow) {
return direction;
}
}
return null;
} | java | public Direction isNeighborOf( GridNode otherNode ) {
Direction[] orderedDirs = Direction.getOrderedDirs();
for( int i = 0; i < orderedDirs.length; i++ ) {
Direction direction = orderedDirs[i];
int newCol = col + direction.col;
int newRow = row + direction.row;
if (otherNode.col == newCol && otherNode.row == newRow) {
return direction;
}
}
return null;
} | [
"public",
"Direction",
"isNeighborOf",
"(",
"GridNode",
"otherNode",
")",
"{",
"Direction",
"[",
"]",
"orderedDirs",
"=",
"Direction",
".",
"getOrderedDirs",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"orderedDirs",
".",
"length",
";",
"i",
"++",
")",
"{",
"Direction",
"direction",
"=",
"orderedDirs",
"[",
"i",
"]",
";",
"int",
"newCol",
"=",
"col",
"+",
"direction",
".",
"col",
";",
"int",
"newRow",
"=",
"row",
"+",
"direction",
".",
"row",
";",
"if",
"(",
"otherNode",
".",
"col",
"==",
"newCol",
"&&",
"otherNode",
".",
"row",
"==",
"newRow",
")",
"{",
"return",
"direction",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Checks if the supplied node is adjacent to the current.
@return the {@link Direction} if the two cells touch, else <code>null</code>. | [
"Checks",
"if",
"the",
"supplied",
"node",
"is",
"adjacent",
"to",
"the",
"current",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L422-L433 |
137,327 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.isSameValueNeighborOf | public Direction isSameValueNeighborOf( GridNode otherNode ) {
Direction direction = isNeighborOf(otherNode);
if (direction != null && NumericsUtilities.dEq(elevation, otherNode.elevation)) {
return direction;
}
return null;
} | java | public Direction isSameValueNeighborOf( GridNode otherNode ) {
Direction direction = isNeighborOf(otherNode);
if (direction != null && NumericsUtilities.dEq(elevation, otherNode.elevation)) {
return direction;
}
return null;
} | [
"public",
"Direction",
"isSameValueNeighborOf",
"(",
"GridNode",
"otherNode",
")",
"{",
"Direction",
"direction",
"=",
"isNeighborOf",
"(",
"otherNode",
")",
";",
"if",
"(",
"direction",
"!=",
"null",
"&&",
"NumericsUtilities",
".",
"dEq",
"(",
"elevation",
",",
"otherNode",
".",
"elevation",
")",
")",
"{",
"return",
"direction",
";",
"}",
"return",
"null",
";",
"}"
] | Checks if the supplied node is adjacent to the current and has the same value.
@return the {@link Direction} if the two cells touch and have the same value, else <code>null</code>. | [
"Checks",
"if",
"the",
"supplied",
"node",
"is",
"adjacent",
"to",
"the",
"current",
"and",
"has",
"the",
"same",
"value",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L440-L446 |
137,328 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java | GridNode.getSlopeTo | public double getSlopeTo( GridNode node ) {
double slope = (elevation - node.elevation) / getDistance(node);
return slope;
} | java | public double getSlopeTo( GridNode node ) {
double slope = (elevation - node.elevation) / getDistance(node);
return slope;
} | [
"public",
"double",
"getSlopeTo",
"(",
"GridNode",
"node",
")",
"{",
"double",
"slope",
"=",
"(",
"elevation",
"-",
"node",
".",
"elevation",
")",
"/",
"getDistance",
"(",
"node",
")",
";",
"return",
"slope",
";",
"}"
] | Calculates the slope from the current to the supplied point.
@param node the node to which to calculate the slope to.
@return the slope. | [
"Calculates",
"the",
"slope",
"from",
"the",
"current",
"to",
"the",
"supplied",
"point",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/GridNode.java#L523-L526 |
137,329 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/style/sld/XmlCharsetDetector.java | XmlCharsetDetector.getXmlEncoding | protected static String getXmlEncoding(Reader reader) {
try {
StringWriter sw = new StringWriter(MAX_XMLDECL_SIZE);
int c;
int count = 0;
for (; (6 > count) && (-1 != (c = reader.read())); count++) {
sw.write(c);
}
/*
* Hmm, checking for the case when there is no XML declaration and
* document begins with processing instruction whose target name
* starts with "<?xml" ("<?xmlfoo"). Sounds like a nearly impossible
* thing, but Xerces guys are checking for that somewhere in the
* depths of their code :)
*/
if ((6 > count) || (!"<?xml ".equals(sw.toString()))) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Invalid(?) XML declaration: " + sw.toString() + ".");
}
return null;
}
/*
* Continuing reading declaration(?) til the first '>' ('\u003E')
* encountered. Conversion from `int` to `char` should be safe
* for our purposes, at least I'm not expecting any extended
* (0x10000+) characters in xml declaration. I also limited
* the total number of chars read this way to prevent any
* malformed (no '>') input potentially forcing us to read
* megabytes of useless data :)
*/
for (;
(MAX_XMLDECL_SIZE > count)
&& (-1 != (c = reader.read()))
&& (RIGHT_ANGLE_BRACKET != (char) c);
count++) {
sw.write(c);
}
Matcher m = ENCODING_PATTERN.matcher(sw.toString());
if (m.find()) {
String result = m.group(1);
return result;
} else {
return null;
}
} catch (IOException e) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(
"Failed to extract charset info from XML "
+ "declaration due to IOException: "
+ e.getMessage());
}
return null;
}
} | java | protected static String getXmlEncoding(Reader reader) {
try {
StringWriter sw = new StringWriter(MAX_XMLDECL_SIZE);
int c;
int count = 0;
for (; (6 > count) && (-1 != (c = reader.read())); count++) {
sw.write(c);
}
/*
* Hmm, checking for the case when there is no XML declaration and
* document begins with processing instruction whose target name
* starts with "<?xml" ("<?xmlfoo"). Sounds like a nearly impossible
* thing, but Xerces guys are checking for that somewhere in the
* depths of their code :)
*/
if ((6 > count) || (!"<?xml ".equals(sw.toString()))) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Invalid(?) XML declaration: " + sw.toString() + ".");
}
return null;
}
/*
* Continuing reading declaration(?) til the first '>' ('\u003E')
* encountered. Conversion from `int` to `char` should be safe
* for our purposes, at least I'm not expecting any extended
* (0x10000+) characters in xml declaration. I also limited
* the total number of chars read this way to prevent any
* malformed (no '>') input potentially forcing us to read
* megabytes of useless data :)
*/
for (;
(MAX_XMLDECL_SIZE > count)
&& (-1 != (c = reader.read()))
&& (RIGHT_ANGLE_BRACKET != (char) c);
count++) {
sw.write(c);
}
Matcher m = ENCODING_PATTERN.matcher(sw.toString());
if (m.find()) {
String result = m.group(1);
return result;
} else {
return null;
}
} catch (IOException e) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(
"Failed to extract charset info from XML "
+ "declaration due to IOException: "
+ e.getMessage());
}
return null;
}
} | [
"protected",
"static",
"String",
"getXmlEncoding",
"(",
"Reader",
"reader",
")",
"{",
"try",
"{",
"StringWriter",
"sw",
"=",
"new",
"StringWriter",
"(",
"MAX_XMLDECL_SIZE",
")",
";",
"int",
"c",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
";",
"(",
"6",
">",
"count",
")",
"&&",
"(",
"-",
"1",
"!=",
"(",
"c",
"=",
"reader",
".",
"read",
"(",
")",
")",
")",
";",
"count",
"++",
")",
"{",
"sw",
".",
"write",
"(",
"c",
")",
";",
"}",
"/*\n * Hmm, checking for the case when there is no XML declaration and\n * document begins with processing instruction whose target name\n * starts with \"<?xml\" (\"<?xmlfoo\"). Sounds like a nearly impossible\n * thing, but Xerces guys are checking for that somewhere in the\n * depths of their code :)\n */",
"if",
"(",
"(",
"6",
">",
"count",
")",
"||",
"(",
"!",
"\"<?xml \"",
".",
"equals",
"(",
"sw",
".",
"toString",
"(",
")",
")",
")",
")",
"{",
"if",
"(",
"LOGGER",
".",
"isLoggable",
"(",
"Level",
".",
"FINER",
")",
")",
"{",
"LOGGER",
".",
"finer",
"(",
"\"Invalid(?) XML declaration: \"",
"+",
"sw",
".",
"toString",
"(",
")",
"+",
"\".\"",
")",
";",
"}",
"return",
"null",
";",
"}",
"/*\n * Continuing reading declaration(?) til the first '>' ('\\u003E')\n * encountered. Conversion from `int` to `char` should be safe\n * for our purposes, at least I'm not expecting any extended\n * (0x10000+) characters in xml declaration. I also limited\n * the total number of chars read this way to prevent any\n * malformed (no '>') input potentially forcing us to read\n * megabytes of useless data :)\n */",
"for",
"(",
";",
"(",
"MAX_XMLDECL_SIZE",
">",
"count",
")",
"&&",
"(",
"-",
"1",
"!=",
"(",
"c",
"=",
"reader",
".",
"read",
"(",
")",
")",
")",
"&&",
"(",
"RIGHT_ANGLE_BRACKET",
"!=",
"(",
"char",
")",
"c",
")",
";",
"count",
"++",
")",
"{",
"sw",
".",
"write",
"(",
"c",
")",
";",
"}",
"Matcher",
"m",
"=",
"ENCODING_PATTERN",
".",
"matcher",
"(",
"sw",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"m",
".",
"find",
"(",
")",
")",
"{",
"String",
"result",
"=",
"m",
".",
"group",
"(",
"1",
")",
";",
"return",
"result",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"if",
"(",
"LOGGER",
".",
"isLoggable",
"(",
"Level",
".",
"WARNING",
")",
")",
"{",
"LOGGER",
".",
"warning",
"(",
"\"Failed to extract charset info from XML \"",
"+",
"\"declaration due to IOException: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
"}"
] | Gets the encoding of the xml request made to the dispatcher. This works by reading the temp
file where we are storing the request, looking to match the header specified encoding that
should be present on all xml files. This call should only be made after the temp file has
been set. If no encoding is found, or if an IOError is encountered then null shall be
returned.
@param reader This character stream is supposed to contain XML data (i.e. it should start
with valid XML declaration).
@return The encoding specified in the xml header read from the supplied character stream. | [
"Gets",
"the",
"encoding",
"of",
"the",
"xml",
"request",
"made",
"to",
"the",
"dispatcher",
".",
"This",
"works",
"by",
"reading",
"the",
"temp",
"file",
"where",
"we",
"are",
"storing",
"the",
"request",
"looking",
"to",
"match",
"the",
"header",
"specified",
"encoding",
"that",
"should",
"be",
"present",
"on",
"all",
"xml",
"files",
".",
"This",
"call",
"should",
"only",
"be",
"made",
"after",
"the",
"temp",
"file",
"has",
"been",
"set",
".",
"If",
"no",
"encoding",
"is",
"found",
"or",
"if",
"an",
"IOError",
"is",
"encountered",
"then",
"null",
"shall",
"be",
"returned",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/style/sld/XmlCharsetDetector.java#L445-L507 |
137,330 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasCellsTable.java | LasCellsTable.getLasCells | public static List<LasCell> getLasCells( ASpatialDb db, Envelope envelope, Geometry exactGeometry, boolean doPosition,
boolean doIntensity, boolean doReturns, boolean doTime, boolean doColor, int limitTo ) throws Exception {
List<LasCell> lasCells = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_POINTS_COUNT;
if (doPosition)
sql += "," + COLUMN_AVG_ELEV + "," + //
COLUMN_MIN_ELEV + "," + //
COLUMN_MAX_ELEV + "," + //
COLUMN_POSITION_BLOB;//
if (doIntensity)
sql += "," + COLUMN_AVG_INTENSITY + "," + //
COLUMN_MIN_INTENSITY + "," + //
COLUMN_MAX_INTENSITY + "," + //
COLUMN_INTENS_CLASS_BLOB;//
if (doReturns)
sql += "," + COLUMN_RETURNS_BLOB;
if (doTime)
sql += "," + COLUMN_MIN_GPSTIME + "," + //
COLUMN_MAX_GPSTIME + "," + //
COLUMN_GPSTIME_BLOB;
if (doColor)
sql += "," + COLUMN_COLORS_BLOB;
sql += " FROM " + TABLENAME;
if (exactGeometry != null) {
sql += " WHERE " + db.getSpatialindexGeometryWherePiece(TABLENAME, null, exactGeometry);
} else if (envelope != null) {
double x1 = envelope.getMinX();
double y1 = envelope.getMinY();
double x2 = envelope.getMaxX();
double y2 = envelope.getMaxY();
sql += " WHERE " + db.getSpatialindexBBoxWherePiece(TABLENAME, null, x1, y1, x2, y2);
}
if (limitTo > 0) {
sql += " LIMIT " + limitTo;
}
String _sql = sql;
IGeometryParser gp = db.getType().getGeometryParser();
return db.execOnConnection(conn -> {
try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) {
while( rs.next() ) {
LasCell lasCell = resultSetToCell(db, gp, doPosition, doIntensity, doReturns, doTime, doColor, rs);
lasCells.add(lasCell);
}
return lasCells;
}
});
} | java | public static List<LasCell> getLasCells( ASpatialDb db, Envelope envelope, Geometry exactGeometry, boolean doPosition,
boolean doIntensity, boolean doReturns, boolean doTime, boolean doColor, int limitTo ) throws Exception {
List<LasCell> lasCells = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_POINTS_COUNT;
if (doPosition)
sql += "," + COLUMN_AVG_ELEV + "," + //
COLUMN_MIN_ELEV + "," + //
COLUMN_MAX_ELEV + "," + //
COLUMN_POSITION_BLOB;//
if (doIntensity)
sql += "," + COLUMN_AVG_INTENSITY + "," + //
COLUMN_MIN_INTENSITY + "," + //
COLUMN_MAX_INTENSITY + "," + //
COLUMN_INTENS_CLASS_BLOB;//
if (doReturns)
sql += "," + COLUMN_RETURNS_BLOB;
if (doTime)
sql += "," + COLUMN_MIN_GPSTIME + "," + //
COLUMN_MAX_GPSTIME + "," + //
COLUMN_GPSTIME_BLOB;
if (doColor)
sql += "," + COLUMN_COLORS_BLOB;
sql += " FROM " + TABLENAME;
if (exactGeometry != null) {
sql += " WHERE " + db.getSpatialindexGeometryWherePiece(TABLENAME, null, exactGeometry);
} else if (envelope != null) {
double x1 = envelope.getMinX();
double y1 = envelope.getMinY();
double x2 = envelope.getMaxX();
double y2 = envelope.getMaxY();
sql += " WHERE " + db.getSpatialindexBBoxWherePiece(TABLENAME, null, x1, y1, x2, y2);
}
if (limitTo > 0) {
sql += " LIMIT " + limitTo;
}
String _sql = sql;
IGeometryParser gp = db.getType().getGeometryParser();
return db.execOnConnection(conn -> {
try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) {
while( rs.next() ) {
LasCell lasCell = resultSetToCell(db, gp, doPosition, doIntensity, doReturns, doTime, doColor, rs);
lasCells.add(lasCell);
}
return lasCells;
}
});
} | [
"public",
"static",
"List",
"<",
"LasCell",
">",
"getLasCells",
"(",
"ASpatialDb",
"db",
",",
"Envelope",
"envelope",
",",
"Geometry",
"exactGeometry",
",",
"boolean",
"doPosition",
",",
"boolean",
"doIntensity",
",",
"boolean",
"doReturns",
",",
"boolean",
"doTime",
",",
"boolean",
"doColor",
",",
"int",
"limitTo",
")",
"throws",
"Exception",
"{",
"List",
"<",
"LasCell",
">",
"lasCells",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"String",
"sql",
"=",
"\"SELECT \"",
"+",
"COLUMN_GEOM",
"+",
"\",\"",
"+",
"COLUMN_ID",
"+",
"\",\"",
"+",
"COLUMN_SOURCE_ID",
"+",
"\",\"",
"+",
"COLUMN_POINTS_COUNT",
";",
"if",
"(",
"doPosition",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_AVG_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_MIN_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_POSITION_BLOB",
";",
"//",
"if",
"(",
"doIntensity",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_AVG_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_MIN_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_INTENS_CLASS_BLOB",
";",
"//",
"if",
"(",
"doReturns",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_RETURNS_BLOB",
";",
"if",
"(",
"doTime",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_MIN_GPSTIME",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_GPSTIME",
"+",
"\",\"",
"+",
"//",
"COLUMN_GPSTIME_BLOB",
";",
"if",
"(",
"doColor",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_COLORS_BLOB",
";",
"sql",
"+=",
"\" FROM \"",
"+",
"TABLENAME",
";",
"if",
"(",
"exactGeometry",
"!=",
"null",
")",
"{",
"sql",
"+=",
"\" WHERE \"",
"+",
"db",
".",
"getSpatialindexGeometryWherePiece",
"(",
"TABLENAME",
",",
"null",
",",
"exactGeometry",
")",
";",
"}",
"else",
"if",
"(",
"envelope",
"!=",
"null",
")",
"{",
"double",
"x1",
"=",
"envelope",
".",
"getMinX",
"(",
")",
";",
"double",
"y1",
"=",
"envelope",
".",
"getMinY",
"(",
")",
";",
"double",
"x2",
"=",
"envelope",
".",
"getMaxX",
"(",
")",
";",
"double",
"y2",
"=",
"envelope",
".",
"getMaxY",
"(",
")",
";",
"sql",
"+=",
"\" WHERE \"",
"+",
"db",
".",
"getSpatialindexBBoxWherePiece",
"(",
"TABLENAME",
",",
"null",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
";",
"}",
"if",
"(",
"limitTo",
">",
"0",
")",
"{",
"sql",
"+=",
"\" LIMIT \"",
"+",
"limitTo",
";",
"}",
"String",
"_sql",
"=",
"sql",
";",
"IGeometryParser",
"gp",
"=",
"db",
".",
"getType",
"(",
")",
".",
"getGeometryParser",
"(",
")",
";",
"return",
"db",
".",
"execOnConnection",
"(",
"conn",
"->",
"{",
"try",
"(",
"IHMStatement",
"stmt",
"=",
"conn",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"stmt",
".",
"executeQuery",
"(",
"_sql",
")",
")",
"{",
"while",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"LasCell",
"lasCell",
"=",
"resultSetToCell",
"(",
"db",
",",
"gp",
",",
"doPosition",
",",
"doIntensity",
",",
"doReturns",
",",
"doTime",
",",
"doColor",
",",
"rs",
")",
";",
"lasCells",
".",
"add",
"(",
"lasCell",
")",
";",
"}",
"return",
"lasCells",
";",
"}",
"}",
")",
";",
"}"
] | Query the las cell table.
@param db the db to use.
@param envelope an optional {@link Envelope} to query spatially.
@param exactGeometry an optional exact geometry. If available it is used instead of the envelope.
@param doPosition if <code>true</code> position info is extracted.
@param doIntensity if <code>true</code> intensity and classification info is extracted.
@param doReturns if <code>true</code> return info is extracted.
@param doTime if <code>true</code> time info is extracted.
@param doColor if <code>true</code> color info is extracted.
@param limitTo limit the cells to a value if != -1
@return the list of extracted points
@throws Exception | [
"Query",
"the",
"las",
"cell",
"table",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasCellsTable.java#L228-L283 |
137,331 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasCellsTable.java | LasCellsTable.getLasCells | public static List<LasCell> getLasCells( ASpatialDb db, Geometry geometry, boolean doPosition, boolean doIntensity,
boolean doReturns, boolean doTime, boolean doColor ) throws Exception {
List<LasCell> lasCells = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_POINTS_COUNT;
if (doPosition)
sql += "," + COLUMN_AVG_ELEV + "," + //
COLUMN_MIN_ELEV + "," + //
COLUMN_MAX_ELEV + "," + //
COLUMN_POSITION_BLOB;//
if (doIntensity)
sql += "," + COLUMN_AVG_INTENSITY + "," + //
COLUMN_MIN_INTENSITY + "," + //
COLUMN_MAX_INTENSITY + "," + //
COLUMN_INTENS_CLASS_BLOB;//
if (doReturns)
sql += "," + COLUMN_RETURNS_BLOB;
if (doTime)
sql += "," + COLUMN_MIN_GPSTIME + "," + //
COLUMN_MAX_GPSTIME + "," + //
COLUMN_GPSTIME_BLOB;
if (doColor)
sql += "," + COLUMN_COLORS_BLOB;
sql += " FROM " + TABLENAME;
if (geometry != null) {
sql += " WHERE " + db.getSpatialindexGeometryWherePiece(TABLENAME, null, geometry);
}
String _sql = sql;
IGeometryParser gp = db.getType().getGeometryParser();
return db.execOnConnection(conn -> {
try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) {
while( rs.next() ) {
LasCell lasCell = resultSetToCell(db, gp, doPosition, doIntensity, doReturns, doTime, doColor, rs);
lasCells.add(lasCell);
}
return lasCells;
}
});
} | java | public static List<LasCell> getLasCells( ASpatialDb db, Geometry geometry, boolean doPosition, boolean doIntensity,
boolean doReturns, boolean doTime, boolean doColor ) throws Exception {
List<LasCell> lasCells = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_POINTS_COUNT;
if (doPosition)
sql += "," + COLUMN_AVG_ELEV + "," + //
COLUMN_MIN_ELEV + "," + //
COLUMN_MAX_ELEV + "," + //
COLUMN_POSITION_BLOB;//
if (doIntensity)
sql += "," + COLUMN_AVG_INTENSITY + "," + //
COLUMN_MIN_INTENSITY + "," + //
COLUMN_MAX_INTENSITY + "," + //
COLUMN_INTENS_CLASS_BLOB;//
if (doReturns)
sql += "," + COLUMN_RETURNS_BLOB;
if (doTime)
sql += "," + COLUMN_MIN_GPSTIME + "," + //
COLUMN_MAX_GPSTIME + "," + //
COLUMN_GPSTIME_BLOB;
if (doColor)
sql += "," + COLUMN_COLORS_BLOB;
sql += " FROM " + TABLENAME;
if (geometry != null) {
sql += " WHERE " + db.getSpatialindexGeometryWherePiece(TABLENAME, null, geometry);
}
String _sql = sql;
IGeometryParser gp = db.getType().getGeometryParser();
return db.execOnConnection(conn -> {
try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) {
while( rs.next() ) {
LasCell lasCell = resultSetToCell(db, gp, doPosition, doIntensity, doReturns, doTime, doColor, rs);
lasCells.add(lasCell);
}
return lasCells;
}
});
} | [
"public",
"static",
"List",
"<",
"LasCell",
">",
"getLasCells",
"(",
"ASpatialDb",
"db",
",",
"Geometry",
"geometry",
",",
"boolean",
"doPosition",
",",
"boolean",
"doIntensity",
",",
"boolean",
"doReturns",
",",
"boolean",
"doTime",
",",
"boolean",
"doColor",
")",
"throws",
"Exception",
"{",
"List",
"<",
"LasCell",
">",
"lasCells",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"String",
"sql",
"=",
"\"SELECT \"",
"+",
"COLUMN_GEOM",
"+",
"\",\"",
"+",
"COLUMN_ID",
"+",
"\",\"",
"+",
"COLUMN_SOURCE_ID",
"+",
"\",\"",
"+",
"COLUMN_POINTS_COUNT",
";",
"if",
"(",
"doPosition",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_AVG_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_MIN_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_ELEV",
"+",
"\",\"",
"+",
"//",
"COLUMN_POSITION_BLOB",
";",
"//",
"if",
"(",
"doIntensity",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_AVG_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_MIN_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_INTENSITY",
"+",
"\",\"",
"+",
"//",
"COLUMN_INTENS_CLASS_BLOB",
";",
"//",
"if",
"(",
"doReturns",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_RETURNS_BLOB",
";",
"if",
"(",
"doTime",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_MIN_GPSTIME",
"+",
"\",\"",
"+",
"//",
"COLUMN_MAX_GPSTIME",
"+",
"\",\"",
"+",
"//",
"COLUMN_GPSTIME_BLOB",
";",
"if",
"(",
"doColor",
")",
"sql",
"+=",
"\",\"",
"+",
"COLUMN_COLORS_BLOB",
";",
"sql",
"+=",
"\" FROM \"",
"+",
"TABLENAME",
";",
"if",
"(",
"geometry",
"!=",
"null",
")",
"{",
"sql",
"+=",
"\" WHERE \"",
"+",
"db",
".",
"getSpatialindexGeometryWherePiece",
"(",
"TABLENAME",
",",
"null",
",",
"geometry",
")",
";",
"}",
"String",
"_sql",
"=",
"sql",
";",
"IGeometryParser",
"gp",
"=",
"db",
".",
"getType",
"(",
")",
".",
"getGeometryParser",
"(",
")",
";",
"return",
"db",
".",
"execOnConnection",
"(",
"conn",
"->",
"{",
"try",
"(",
"IHMStatement",
"stmt",
"=",
"conn",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"stmt",
".",
"executeQuery",
"(",
"_sql",
")",
")",
"{",
"while",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"LasCell",
"lasCell",
"=",
"resultSetToCell",
"(",
"db",
",",
"gp",
",",
"doPosition",
",",
"doIntensity",
",",
"doReturns",
",",
"doTime",
",",
"doColor",
",",
"rs",
")",
";",
"lasCells",
".",
"add",
"(",
"lasCell",
")",
";",
"}",
"return",
"lasCells",
";",
"}",
"}",
")",
";",
"}"
] | Query the las cell table on a geometry intersection.
@param db the db to use.
@param geometry an optional {@link Geometry} to query spatially.
@param doPosition if <code>true</code> position info is extracted.
@param doIntensity if <code>true</code> intensity and classification info is extracted.
@param doReturns if <code>true</code> return info is extracted.
@param doTime if <code>true</code> time info is extracted.
@param doColor if <code>true</code> color info is extracted.
@return the list of extracted points
@throws Exception | [
"Query",
"the",
"las",
"cell",
"table",
"on",
"a",
"geometry",
"intersection",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasCellsTable.java#L298-L343 |
137,332 | enasequence/sequencetools | src/main/java/uk/ac/ebi/embl/api/validation/fixer/feature/CollectionDateQualifierFix.java | CollectionDateQualifierFix.check | public ValidationResult check(Feature feature)
{
result = new ValidationResult();
if (feature == null)
{
return result;
}
List<Qualifier> collectionDateQualifiers= feature.getQualifiers(Qualifier.COLLECTION_DATE_QUALIFIER_NAME);
if(collectionDateQualifiers.isEmpty())
{
return result;
}
for (Qualifier collectionDateQualifier : collectionDateQualifiers)
{
String collectionDateValue = collectionDateQualifier.getValue();
if (INSDC_DATE_FORMAT_PATTERN_1.matcher(collectionDateValue).matches())
{
collectionDateQualifier.setValue("0"+collectionDateValue);// convert date format "D-MON-YYYY" to "DD-MON-YYYY"
reportMessage(Severity.FIX, collectionDateQualifier.getOrigin(), CollectionDateQualifierFix_ID_1, collectionDateValue,collectionDateQualifier.getValue());
}
if(getEmblEntryValidationPlanProperty().validationScope.get() == ValidationScope.NCBI) {
Matcher matcher = NCBI_DATE_FORMAT_PATTERN.matcher(collectionDateValue);
if (matcher.matches())
{
String monthYear = "-"+matcher.group(2)+"-20"+matcher.group(3);
collectionDateQualifier.setValue(matcher.group(1).length()==1?"0"+matcher.group(1)+monthYear:matcher.group(1)+monthYear);// convert date format "D-MON-YY" or "DD-MON-YY" to "DD-MON-YYYY"
reportMessage(Severity.FIX, collectionDateQualifier.getOrigin(), CollectionDateQualifierFix_ID_1, collectionDateValue,collectionDateQualifier.getValue());
}
}
}
return result;
} | java | public ValidationResult check(Feature feature)
{
result = new ValidationResult();
if (feature == null)
{
return result;
}
List<Qualifier> collectionDateQualifiers= feature.getQualifiers(Qualifier.COLLECTION_DATE_QUALIFIER_NAME);
if(collectionDateQualifiers.isEmpty())
{
return result;
}
for (Qualifier collectionDateQualifier : collectionDateQualifiers)
{
String collectionDateValue = collectionDateQualifier.getValue();
if (INSDC_DATE_FORMAT_PATTERN_1.matcher(collectionDateValue).matches())
{
collectionDateQualifier.setValue("0"+collectionDateValue);// convert date format "D-MON-YYYY" to "DD-MON-YYYY"
reportMessage(Severity.FIX, collectionDateQualifier.getOrigin(), CollectionDateQualifierFix_ID_1, collectionDateValue,collectionDateQualifier.getValue());
}
if(getEmblEntryValidationPlanProperty().validationScope.get() == ValidationScope.NCBI) {
Matcher matcher = NCBI_DATE_FORMAT_PATTERN.matcher(collectionDateValue);
if (matcher.matches())
{
String monthYear = "-"+matcher.group(2)+"-20"+matcher.group(3);
collectionDateQualifier.setValue(matcher.group(1).length()==1?"0"+matcher.group(1)+monthYear:matcher.group(1)+monthYear);// convert date format "D-MON-YY" or "DD-MON-YY" to "DD-MON-YYYY"
reportMessage(Severity.FIX, collectionDateQualifier.getOrigin(), CollectionDateQualifierFix_ID_1, collectionDateValue,collectionDateQualifier.getValue());
}
}
}
return result;
} | [
"public",
"ValidationResult",
"check",
"(",
"Feature",
"feature",
")",
"{",
"result",
"=",
"new",
"ValidationResult",
"(",
")",
";",
"if",
"(",
"feature",
"==",
"null",
")",
"{",
"return",
"result",
";",
"}",
"List",
"<",
"Qualifier",
">",
"collectionDateQualifiers",
"=",
"feature",
".",
"getQualifiers",
"(",
"Qualifier",
".",
"COLLECTION_DATE_QUALIFIER_NAME",
")",
";",
"if",
"(",
"collectionDateQualifiers",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"result",
";",
"}",
"for",
"(",
"Qualifier",
"collectionDateQualifier",
":",
"collectionDateQualifiers",
")",
"{",
"String",
"collectionDateValue",
"=",
"collectionDateQualifier",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"INSDC_DATE_FORMAT_PATTERN_1",
".",
"matcher",
"(",
"collectionDateValue",
")",
".",
"matches",
"(",
")",
")",
"{",
"collectionDateQualifier",
".",
"setValue",
"(",
"\"0\"",
"+",
"collectionDateValue",
")",
";",
"// convert date format \"D-MON-YYYY\" to \"DD-MON-YYYY\"",
"reportMessage",
"(",
"Severity",
".",
"FIX",
",",
"collectionDateQualifier",
".",
"getOrigin",
"(",
")",
",",
"CollectionDateQualifierFix_ID_1",
",",
"collectionDateValue",
",",
"collectionDateQualifier",
".",
"getValue",
"(",
")",
")",
";",
"}",
"if",
"(",
"getEmblEntryValidationPlanProperty",
"(",
")",
".",
"validationScope",
".",
"get",
"(",
")",
"==",
"ValidationScope",
".",
"NCBI",
")",
"{",
"Matcher",
"matcher",
"=",
"NCBI_DATE_FORMAT_PATTERN",
".",
"matcher",
"(",
"collectionDateValue",
")",
";",
"if",
"(",
"matcher",
".",
"matches",
"(",
")",
")",
"{",
"String",
"monthYear",
"=",
"\"-\"",
"+",
"matcher",
".",
"group",
"(",
"2",
")",
"+",
"\"-20\"",
"+",
"matcher",
".",
"group",
"(",
"3",
")",
";",
"collectionDateQualifier",
".",
"setValue",
"(",
"matcher",
".",
"group",
"(",
"1",
")",
".",
"length",
"(",
")",
"==",
"1",
"?",
"\"0\"",
"+",
"matcher",
".",
"group",
"(",
"1",
")",
"+",
"monthYear",
":",
"matcher",
".",
"group",
"(",
"1",
")",
"+",
"monthYear",
")",
";",
"// convert date format \"D-MON-YY\" or \"DD-MON-YY\" to \"DD-MON-YYYY\"",
"reportMessage",
"(",
"Severity",
".",
"FIX",
",",
"collectionDateQualifier",
".",
"getOrigin",
"(",
")",
",",
"CollectionDateQualifierFix_ID_1",
",",
"collectionDateValue",
",",
"collectionDateQualifier",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | "DD-Mmm-YY" | [
"DD",
"-",
"Mmm",
"-",
"YY"
] | 4127f5e1a17540239f5810136153fbd6737fa262 | https://github.com/enasequence/sequencetools/blob/4127f5e1a17540239f5810136153fbd6737fa262/src/main/java/uk/ac/ebi/embl/api/validation/fixer/feature/CollectionDateQualifierFix.java#L38-L73 |
137,333 | TheHortonMachine/hortonmachine | dbs/src/main/java/org/hortonmachine/dbs/utils/OsCheck.java | OsCheck.getOperatingSystemType | public static OSType getOperatingSystemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(
Locale.ENGLISH);
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
detectedOS = OSType.MacOS;
} else if (OS.indexOf("win") >= 0) {
detectedOS = OSType.Windows;
} else if (OS.indexOf("nux") >= 0) {
detectedOS = OSType.Linux;
} else {
detectedOS = OSType.Other;
}
}
return detectedOS;
} | java | public static OSType getOperatingSystemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(
Locale.ENGLISH);
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
detectedOS = OSType.MacOS;
} else if (OS.indexOf("win") >= 0) {
detectedOS = OSType.Windows;
} else if (OS.indexOf("nux") >= 0) {
detectedOS = OSType.Linux;
} else {
detectedOS = OSType.Other;
}
}
return detectedOS;
} | [
"public",
"static",
"OSType",
"getOperatingSystemType",
"(",
")",
"{",
"if",
"(",
"detectedOS",
"==",
"null",
")",
"{",
"String",
"OS",
"=",
"System",
".",
"getProperty",
"(",
"\"os.name\"",
",",
"\"generic\"",
")",
".",
"toLowerCase",
"(",
"Locale",
".",
"ENGLISH",
")",
";",
"if",
"(",
"(",
"OS",
".",
"indexOf",
"(",
"\"mac\"",
")",
">=",
"0",
")",
"||",
"(",
"OS",
".",
"indexOf",
"(",
"\"darwin\"",
")",
">=",
"0",
")",
")",
"{",
"detectedOS",
"=",
"OSType",
".",
"MacOS",
";",
"}",
"else",
"if",
"(",
"OS",
".",
"indexOf",
"(",
"\"win\"",
")",
">=",
"0",
")",
"{",
"detectedOS",
"=",
"OSType",
".",
"Windows",
";",
"}",
"else",
"if",
"(",
"OS",
".",
"indexOf",
"(",
"\"nux\"",
")",
">=",
"0",
")",
"{",
"detectedOS",
"=",
"OSType",
".",
"Linux",
";",
"}",
"else",
"{",
"detectedOS",
"=",
"OSType",
".",
"Other",
";",
"}",
"}",
"return",
"detectedOS",
";",
"}"
] | detect the operating system from the os.name System property and cache
the result
@returns - the operating system detected | [
"detect",
"the",
"operating",
"system",
"from",
"the",
"os",
".",
"name",
"System",
"property",
"and",
"cache",
"the",
"result"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/dbs/src/main/java/org/hortonmachine/dbs/utils/OsCheck.java#L48-L63 |
137,334 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/dxfdwg/libs/dwg/utils/GisModelCurveCalculator.java | GisModelCurveCalculator.calculateGisModelCircle | public static Point2D[] calculateGisModelCircle(Point2D c, double r) {
Point2D[] pts = new Point2D[360];
int angulo = 0;
for (angulo=0; angulo<360; angulo++) {
pts[angulo] = new Point2D.Double(c.getX(), c.getY());
pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
}
return pts;
} | java | public static Point2D[] calculateGisModelCircle(Point2D c, double r) {
Point2D[] pts = new Point2D[360];
int angulo = 0;
for (angulo=0; angulo<360; angulo++) {
pts[angulo] = new Point2D.Double(c.getX(), c.getY());
pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
}
return pts;
} | [
"public",
"static",
"Point2D",
"[",
"]",
"calculateGisModelCircle",
"(",
"Point2D",
"c",
",",
"double",
"r",
")",
"{",
"Point2D",
"[",
"]",
"pts",
"=",
"new",
"Point2D",
"[",
"360",
"]",
";",
"int",
"angulo",
"=",
"0",
";",
"for",
"(",
"angulo",
"=",
"0",
";",
"angulo",
"<",
"360",
";",
"angulo",
"++",
")",
"{",
"pts",
"[",
"angulo",
"]",
"=",
"new",
"Point2D",
".",
"Double",
"(",
"c",
".",
"getX",
"(",
")",
",",
"c",
".",
"getY",
"(",
")",
")",
";",
"pts",
"[",
"angulo",
"]",
".",
"setLocation",
"(",
"pts",
"[",
"angulo",
"]",
".",
"getX",
"(",
")",
"+",
"r",
"*",
"Math",
".",
"sin",
"(",
"angulo",
"*",
"Math",
".",
"PI",
"/",
"(",
"double",
")",
"180.0",
")",
",",
"pts",
"[",
"angulo",
"]",
".",
"getY",
"(",
")",
"+",
"r",
"*",
"Math",
".",
"cos",
"(",
"angulo",
"*",
"Math",
".",
"PI",
"/",
"(",
"double",
")",
"180.0",
")",
")",
";",
"}",
"return",
"pts",
";",
"}"
] | This method calculates an array of Point2D that represents a circle. The distance
between it points is 1 angular unit
@param c Point2D that represents the center of the circle
@param r double value that represents the radius of the circle
@return Point2D[] An array of Point2D that represents the shape of the circle | [
"This",
"method",
"calculates",
"an",
"array",
"of",
"Point2D",
"that",
"represents",
"a",
"circle",
".",
"The",
"distance",
"between",
"it",
"points",
"is",
"1",
"angular",
"unit"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/dxfdwg/libs/dwg/utils/GisModelCurveCalculator.java#L41-L49 |
137,335 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/dxfdwg/libs/dwg/utils/GisModelCurveCalculator.java | GisModelCurveCalculator.calculateGisModelBulge | public static Point2D[] calculateGisModelBulge(Point2D[] newPts, double[] bulges) {
Vector ptspol = new Vector();
Point2D init = new Point2D.Double();
Point2D end = new Point2D.Double();
for (int j=0; j<newPts.length; j++) {
init = newPts[j];
if (j!=newPts.length-1) end = newPts[j+1];
if (bulges[j]==0 || j==newPts.length-1 || (init.getX()==end.getX() && init.getY()==end.getY())) {
ptspol.add(init);
} else {
ArcFromBulgeCalculator arcCalculator = new ArcFromBulgeCalculator(init, end, bulges[j]);
Vector arc = arcCalculator.getPoints(1);
if (bulges[j]<0) {
for (int k=arc.size()-1; k>=0; k--) {
ptspol.add(arc.get(k));
}
ptspol.remove(ptspol.size()-1);
} else {
for (int k=0;k<arc.size();k++) {
ptspol.add(arc.get(k));
}
ptspol.remove(ptspol.size()-1);
}
}
}
Point2D[] points = new Point2D[ptspol.size()];
for (int j=0;j<ptspol.size();j++) {
points[j] = (Point2D)ptspol.get(j);
}
return points;
} | java | public static Point2D[] calculateGisModelBulge(Point2D[] newPts, double[] bulges) {
Vector ptspol = new Vector();
Point2D init = new Point2D.Double();
Point2D end = new Point2D.Double();
for (int j=0; j<newPts.length; j++) {
init = newPts[j];
if (j!=newPts.length-1) end = newPts[j+1];
if (bulges[j]==0 || j==newPts.length-1 || (init.getX()==end.getX() && init.getY()==end.getY())) {
ptspol.add(init);
} else {
ArcFromBulgeCalculator arcCalculator = new ArcFromBulgeCalculator(init, end, bulges[j]);
Vector arc = arcCalculator.getPoints(1);
if (bulges[j]<0) {
for (int k=arc.size()-1; k>=0; k--) {
ptspol.add(arc.get(k));
}
ptspol.remove(ptspol.size()-1);
} else {
for (int k=0;k<arc.size();k++) {
ptspol.add(arc.get(k));
}
ptspol.remove(ptspol.size()-1);
}
}
}
Point2D[] points = new Point2D[ptspol.size()];
for (int j=0;j<ptspol.size();j++) {
points[j] = (Point2D)ptspol.get(j);
}
return points;
} | [
"public",
"static",
"Point2D",
"[",
"]",
"calculateGisModelBulge",
"(",
"Point2D",
"[",
"]",
"newPts",
",",
"double",
"[",
"]",
"bulges",
")",
"{",
"Vector",
"ptspol",
"=",
"new",
"Vector",
"(",
")",
";",
"Point2D",
"init",
"=",
"new",
"Point2D",
".",
"Double",
"(",
")",
";",
"Point2D",
"end",
"=",
"new",
"Point2D",
".",
"Double",
"(",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"newPts",
".",
"length",
";",
"j",
"++",
")",
"{",
"init",
"=",
"newPts",
"[",
"j",
"]",
";",
"if",
"(",
"j",
"!=",
"newPts",
".",
"length",
"-",
"1",
")",
"end",
"=",
"newPts",
"[",
"j",
"+",
"1",
"]",
";",
"if",
"(",
"bulges",
"[",
"j",
"]",
"==",
"0",
"||",
"j",
"==",
"newPts",
".",
"length",
"-",
"1",
"||",
"(",
"init",
".",
"getX",
"(",
")",
"==",
"end",
".",
"getX",
"(",
")",
"&&",
"init",
".",
"getY",
"(",
")",
"==",
"end",
".",
"getY",
"(",
")",
")",
")",
"{",
"ptspol",
".",
"add",
"(",
"init",
")",
";",
"}",
"else",
"{",
"ArcFromBulgeCalculator",
"arcCalculator",
"=",
"new",
"ArcFromBulgeCalculator",
"(",
"init",
",",
"end",
",",
"bulges",
"[",
"j",
"]",
")",
";",
"Vector",
"arc",
"=",
"arcCalculator",
".",
"getPoints",
"(",
"1",
")",
";",
"if",
"(",
"bulges",
"[",
"j",
"]",
"<",
"0",
")",
"{",
"for",
"(",
"int",
"k",
"=",
"arc",
".",
"size",
"(",
")",
"-",
"1",
";",
"k",
">=",
"0",
";",
"k",
"--",
")",
"{",
"ptspol",
".",
"add",
"(",
"arc",
".",
"get",
"(",
"k",
")",
")",
";",
"}",
"ptspol",
".",
"remove",
"(",
"ptspol",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"arc",
".",
"size",
"(",
")",
";",
"k",
"++",
")",
"{",
"ptspol",
".",
"add",
"(",
"arc",
".",
"get",
"(",
"k",
")",
")",
";",
"}",
"ptspol",
".",
"remove",
"(",
"ptspol",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"}",
"}",
"}",
"Point2D",
"[",
"]",
"points",
"=",
"new",
"Point2D",
"[",
"ptspol",
".",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"ptspol",
".",
"size",
"(",
")",
";",
"j",
"++",
")",
"{",
"points",
"[",
"j",
"]",
"=",
"(",
"Point2D",
")",
"ptspol",
".",
"get",
"(",
"j",
")",
";",
"}",
"return",
"points",
";",
"}"
] | This method applies an array of bulges to an array of Point2D that defines a
polyline. The result is a polyline with the input points with the addition of the
points that define the new arcs added to the polyline
@param newPts Base points of the polyline
@param bulges Array of bulge parameters
@return Polyline with a new set of arcs added and defined by the bulge parameters | [
"This",
"method",
"applies",
"an",
"array",
"of",
"bulges",
"to",
"an",
"array",
"of",
"Point2D",
"that",
"defines",
"a",
"polyline",
".",
"The",
"result",
"is",
"a",
"polyline",
"with",
"the",
"input",
"points",
"with",
"the",
"addition",
"of",
"the",
"points",
"that",
"define",
"the",
"new",
"arcs",
"added",
"to",
"the",
"polyline"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/dxfdwg/libs/dwg/utils/GisModelCurveCalculator.java#L187-L217 |
137,336 | codahale/xsalsa20poly1305 | src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java | SecretBox.seal | public byte[] seal(byte[] nonce, byte[] plaintext) {
final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
final Poly1305 poly1305 = new Poly1305();
// initialize XSalsa20
xsalsa20.init(true, new ParametersWithIV(new KeyParameter(key), nonce));
// generate Poly1305 subkey
final byte[] sk = new byte[Keys.KEY_LEN];
xsalsa20.processBytes(sk, 0, Keys.KEY_LEN, sk, 0);
// encrypt plaintext
final byte[] out = new byte[plaintext.length + poly1305.getMacSize()];
xsalsa20.processBytes(plaintext, 0, plaintext.length, out, poly1305.getMacSize());
// hash ciphertext and prepend mac to ciphertext
poly1305.init(new KeyParameter(sk));
poly1305.update(out, poly1305.getMacSize(), plaintext.length);
poly1305.doFinal(out, 0);
return out;
} | java | public byte[] seal(byte[] nonce, byte[] plaintext) {
final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
final Poly1305 poly1305 = new Poly1305();
// initialize XSalsa20
xsalsa20.init(true, new ParametersWithIV(new KeyParameter(key), nonce));
// generate Poly1305 subkey
final byte[] sk = new byte[Keys.KEY_LEN];
xsalsa20.processBytes(sk, 0, Keys.KEY_LEN, sk, 0);
// encrypt plaintext
final byte[] out = new byte[plaintext.length + poly1305.getMacSize()];
xsalsa20.processBytes(plaintext, 0, plaintext.length, out, poly1305.getMacSize());
// hash ciphertext and prepend mac to ciphertext
poly1305.init(new KeyParameter(sk));
poly1305.update(out, poly1305.getMacSize(), plaintext.length);
poly1305.doFinal(out, 0);
return out;
} | [
"public",
"byte",
"[",
"]",
"seal",
"(",
"byte",
"[",
"]",
"nonce",
",",
"byte",
"[",
"]",
"plaintext",
")",
"{",
"final",
"XSalsa20Engine",
"xsalsa20",
"=",
"new",
"XSalsa20Engine",
"(",
")",
";",
"final",
"Poly1305",
"poly1305",
"=",
"new",
"Poly1305",
"(",
")",
";",
"// initialize XSalsa20",
"xsalsa20",
".",
"init",
"(",
"true",
",",
"new",
"ParametersWithIV",
"(",
"new",
"KeyParameter",
"(",
"key",
")",
",",
"nonce",
")",
")",
";",
"// generate Poly1305 subkey",
"final",
"byte",
"[",
"]",
"sk",
"=",
"new",
"byte",
"[",
"Keys",
".",
"KEY_LEN",
"]",
";",
"xsalsa20",
".",
"processBytes",
"(",
"sk",
",",
"0",
",",
"Keys",
".",
"KEY_LEN",
",",
"sk",
",",
"0",
")",
";",
"// encrypt plaintext",
"final",
"byte",
"[",
"]",
"out",
"=",
"new",
"byte",
"[",
"plaintext",
".",
"length",
"+",
"poly1305",
".",
"getMacSize",
"(",
")",
"]",
";",
"xsalsa20",
".",
"processBytes",
"(",
"plaintext",
",",
"0",
",",
"plaintext",
".",
"length",
",",
"out",
",",
"poly1305",
".",
"getMacSize",
"(",
")",
")",
";",
"// hash ciphertext and prepend mac to ciphertext",
"poly1305",
".",
"init",
"(",
"new",
"KeyParameter",
"(",
"sk",
")",
")",
";",
"poly1305",
".",
"update",
"(",
"out",
",",
"poly1305",
".",
"getMacSize",
"(",
")",
",",
"plaintext",
".",
"length",
")",
";",
"poly1305",
".",
"doFinal",
"(",
"out",
",",
"0",
")",
";",
"return",
"out",
";",
"}"
] | Encrypt a plaintext using the given key and nonce.
@param nonce a 24-byte nonce (cf. {@link #nonce(byte[])}, {@link #nonce()})
@param plaintext an arbitrary message
@return the ciphertext | [
"Encrypt",
"a",
"plaintext",
"using",
"the",
"given",
"key",
"and",
"nonce",
"."
] | f3c1ab2f05b17df137ed8fbb66da2b417066729a | https://github.com/codahale/xsalsa20poly1305/blob/f3c1ab2f05b17df137ed8fbb66da2b417066729a/src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java#L71-L92 |
137,337 | codahale/xsalsa20poly1305 | src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java | SecretBox.open | public Optional<byte[]> open(byte[] nonce, byte[] ciphertext) {
final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
final Poly1305 poly1305 = new Poly1305();
// initialize XSalsa20
xsalsa20.init(false, new ParametersWithIV(new KeyParameter(key), nonce));
// generate mac subkey
final byte[] sk = new byte[Keys.KEY_LEN];
xsalsa20.processBytes(sk, 0, sk.length, sk, 0);
// hash ciphertext
poly1305.init(new KeyParameter(sk));
final int len = Math.max(ciphertext.length - poly1305.getMacSize(), 0);
poly1305.update(ciphertext, poly1305.getMacSize(), len);
final byte[] calculatedMAC = new byte[poly1305.getMacSize()];
poly1305.doFinal(calculatedMAC, 0);
// extract mac
final byte[] presentedMAC = new byte[poly1305.getMacSize()];
System.arraycopy(
ciphertext, 0, presentedMAC, 0, Math.min(ciphertext.length, poly1305.getMacSize()));
// compare macs
if (!MessageDigest.isEqual(calculatedMAC, presentedMAC)) {
return Optional.empty();
}
// decrypt ciphertext
final byte[] plaintext = new byte[len];
xsalsa20.processBytes(ciphertext, poly1305.getMacSize(), plaintext.length, plaintext, 0);
return Optional.of(plaintext);
} | java | public Optional<byte[]> open(byte[] nonce, byte[] ciphertext) {
final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
final Poly1305 poly1305 = new Poly1305();
// initialize XSalsa20
xsalsa20.init(false, new ParametersWithIV(new KeyParameter(key), nonce));
// generate mac subkey
final byte[] sk = new byte[Keys.KEY_LEN];
xsalsa20.processBytes(sk, 0, sk.length, sk, 0);
// hash ciphertext
poly1305.init(new KeyParameter(sk));
final int len = Math.max(ciphertext.length - poly1305.getMacSize(), 0);
poly1305.update(ciphertext, poly1305.getMacSize(), len);
final byte[] calculatedMAC = new byte[poly1305.getMacSize()];
poly1305.doFinal(calculatedMAC, 0);
// extract mac
final byte[] presentedMAC = new byte[poly1305.getMacSize()];
System.arraycopy(
ciphertext, 0, presentedMAC, 0, Math.min(ciphertext.length, poly1305.getMacSize()));
// compare macs
if (!MessageDigest.isEqual(calculatedMAC, presentedMAC)) {
return Optional.empty();
}
// decrypt ciphertext
final byte[] plaintext = new byte[len];
xsalsa20.processBytes(ciphertext, poly1305.getMacSize(), plaintext.length, plaintext, 0);
return Optional.of(plaintext);
} | [
"public",
"Optional",
"<",
"byte",
"[",
"]",
">",
"open",
"(",
"byte",
"[",
"]",
"nonce",
",",
"byte",
"[",
"]",
"ciphertext",
")",
"{",
"final",
"XSalsa20Engine",
"xsalsa20",
"=",
"new",
"XSalsa20Engine",
"(",
")",
";",
"final",
"Poly1305",
"poly1305",
"=",
"new",
"Poly1305",
"(",
")",
";",
"// initialize XSalsa20",
"xsalsa20",
".",
"init",
"(",
"false",
",",
"new",
"ParametersWithIV",
"(",
"new",
"KeyParameter",
"(",
"key",
")",
",",
"nonce",
")",
")",
";",
"// generate mac subkey",
"final",
"byte",
"[",
"]",
"sk",
"=",
"new",
"byte",
"[",
"Keys",
".",
"KEY_LEN",
"]",
";",
"xsalsa20",
".",
"processBytes",
"(",
"sk",
",",
"0",
",",
"sk",
".",
"length",
",",
"sk",
",",
"0",
")",
";",
"// hash ciphertext",
"poly1305",
".",
"init",
"(",
"new",
"KeyParameter",
"(",
"sk",
")",
")",
";",
"final",
"int",
"len",
"=",
"Math",
".",
"max",
"(",
"ciphertext",
".",
"length",
"-",
"poly1305",
".",
"getMacSize",
"(",
")",
",",
"0",
")",
";",
"poly1305",
".",
"update",
"(",
"ciphertext",
",",
"poly1305",
".",
"getMacSize",
"(",
")",
",",
"len",
")",
";",
"final",
"byte",
"[",
"]",
"calculatedMAC",
"=",
"new",
"byte",
"[",
"poly1305",
".",
"getMacSize",
"(",
")",
"]",
";",
"poly1305",
".",
"doFinal",
"(",
"calculatedMAC",
",",
"0",
")",
";",
"// extract mac",
"final",
"byte",
"[",
"]",
"presentedMAC",
"=",
"new",
"byte",
"[",
"poly1305",
".",
"getMacSize",
"(",
")",
"]",
";",
"System",
".",
"arraycopy",
"(",
"ciphertext",
",",
"0",
",",
"presentedMAC",
",",
"0",
",",
"Math",
".",
"min",
"(",
"ciphertext",
".",
"length",
",",
"poly1305",
".",
"getMacSize",
"(",
")",
")",
")",
";",
"// compare macs",
"if",
"(",
"!",
"MessageDigest",
".",
"isEqual",
"(",
"calculatedMAC",
",",
"presentedMAC",
")",
")",
"{",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}",
"// decrypt ciphertext",
"final",
"byte",
"[",
"]",
"plaintext",
"=",
"new",
"byte",
"[",
"len",
"]",
";",
"xsalsa20",
".",
"processBytes",
"(",
"ciphertext",
",",
"poly1305",
".",
"getMacSize",
"(",
")",
",",
"plaintext",
".",
"length",
",",
"plaintext",
",",
"0",
")",
";",
"return",
"Optional",
".",
"of",
"(",
"plaintext",
")",
";",
"}"
] | Decrypt a ciphertext using the given key and nonce.
@param nonce a 24-byte nonce
@param ciphertext the encrypted message
@return an {@link Optional} of the original plaintext, or if either the key, nonce, or
ciphertext was modified, an empty {@link Optional}
@see #nonce(byte[])
@see #nonce() | [
"Decrypt",
"a",
"ciphertext",
"using",
"the",
"given",
"key",
"and",
"nonce",
"."
] | f3c1ab2f05b17df137ed8fbb66da2b417066729a | https://github.com/codahale/xsalsa20poly1305/blob/f3c1ab2f05b17df137ed8fbb66da2b417066729a/src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java#L104-L136 |
137,338 | codahale/xsalsa20poly1305 | src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java | SecretBox.nonce | public byte[] nonce() {
final byte[] nonce = new byte[NONCE_SIZE];
final SecureRandom random = new SecureRandom();
random.nextBytes(nonce);
return nonce;
} | java | public byte[] nonce() {
final byte[] nonce = new byte[NONCE_SIZE];
final SecureRandom random = new SecureRandom();
random.nextBytes(nonce);
return nonce;
} | [
"public",
"byte",
"[",
"]",
"nonce",
"(",
")",
"{",
"final",
"byte",
"[",
"]",
"nonce",
"=",
"new",
"byte",
"[",
"NONCE_SIZE",
"]",
";",
"final",
"SecureRandom",
"random",
"=",
"new",
"SecureRandom",
"(",
")",
";",
"random",
".",
"nextBytes",
"(",
"nonce",
")",
";",
"return",
"nonce",
";",
"}"
] | Generates a random nonce.
<p><b>N.B.:</b> Use of this method is probably fine, but because an entropy-exhausted or
compromised {@link SecureRandom} provider might generate duplicate nonces (which would allow an
attacker to potentially decrypt and even forge messages), {@link #nonce(byte[])} is recommended
instead.
@return a 24-byte nonce | [
"Generates",
"a",
"random",
"nonce",
"."
] | f3c1ab2f05b17df137ed8fbb66da2b417066729a | https://github.com/codahale/xsalsa20poly1305/blob/f3c1ab2f05b17df137ed8fbb66da2b417066729a/src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java#L148-L153 |
137,339 | codahale/xsalsa20poly1305 | src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java | SecretBox.nonce | public byte[] nonce(byte[] message) {
final byte[] n1 = new byte[16];
final byte[] n2 = new byte[16];
final SecureRandom random = new SecureRandom();
random.nextBytes(n1);
random.nextBytes(n2);
final Blake2bDigest blake2b = new Blake2bDigest(key, NONCE_SIZE, n1, n2);
blake2b.update(message, message.length, 0);
final byte[] nonce = new byte[NONCE_SIZE];
blake2b.doFinal(nonce, 0);
return nonce;
} | java | public byte[] nonce(byte[] message) {
final byte[] n1 = new byte[16];
final byte[] n2 = new byte[16];
final SecureRandom random = new SecureRandom();
random.nextBytes(n1);
random.nextBytes(n2);
final Blake2bDigest blake2b = new Blake2bDigest(key, NONCE_SIZE, n1, n2);
blake2b.update(message, message.length, 0);
final byte[] nonce = new byte[NONCE_SIZE];
blake2b.doFinal(nonce, 0);
return nonce;
} | [
"public",
"byte",
"[",
"]",
"nonce",
"(",
"byte",
"[",
"]",
"message",
")",
"{",
"final",
"byte",
"[",
"]",
"n1",
"=",
"new",
"byte",
"[",
"16",
"]",
";",
"final",
"byte",
"[",
"]",
"n2",
"=",
"new",
"byte",
"[",
"16",
"]",
";",
"final",
"SecureRandom",
"random",
"=",
"new",
"SecureRandom",
"(",
")",
";",
"random",
".",
"nextBytes",
"(",
"n1",
")",
";",
"random",
".",
"nextBytes",
"(",
"n2",
")",
";",
"final",
"Blake2bDigest",
"blake2b",
"=",
"new",
"Blake2bDigest",
"(",
"key",
",",
"NONCE_SIZE",
",",
"n1",
",",
"n2",
")",
";",
"blake2b",
".",
"update",
"(",
"message",
",",
"message",
".",
"length",
",",
"0",
")",
";",
"final",
"byte",
"[",
"]",
"nonce",
"=",
"new",
"byte",
"[",
"NONCE_SIZE",
"]",
";",
"blake2b",
".",
"doFinal",
"(",
"nonce",
",",
"0",
")",
";",
"return",
"nonce",
";",
"}"
] | Generates a random nonce which is guaranteed to be unique even if the process's PRNG is
exhausted or compromised.
<p>Internally, this creates a Blake2b instance with the given key, a random 16-byte salt, and a
random 16-byte personalization tag. It then hashes the message and returns the resulting
24-byte digest as the nonce.
<p>In the event of a broken or entropy-exhausted {@link SecureRandom} provider, the nonce is
essentially equivalent to a synthetic IV and should be unique for any given key/message pair.
The result will be deterministic, which will allow attackers to detect duplicate messages.
<p>In the event of a compromised {@link SecureRandom} provider, the attacker would need a
complete second-preimage attack against Blake2b in order to produce colliding nonces.
@param message the message to be encrypted
@return a 24-byte nonce | [
"Generates",
"a",
"random",
"nonce",
"which",
"is",
"guaranteed",
"to",
"be",
"unique",
"even",
"if",
"the",
"process",
"s",
"PRNG",
"is",
"exhausted",
"or",
"compromised",
"."
] | f3c1ab2f05b17df137ed8fbb66da2b417066729a | https://github.com/codahale/xsalsa20poly1305/blob/f3c1ab2f05b17df137ed8fbb66da2b417066729a/src/main/java/com/codahale/xsalsa20poly1305/SecretBox.java#L173-L186 |
137,340 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/utils/GDataObject.java | GDataObject.get | public Object get( int row, int col ) {
return (dstore == null) ? null : dstore.get(row, col);
} | java | public Object get( int row, int col ) {
return (dstore == null) ? null : dstore.get(row, col);
} | [
"public",
"Object",
"get",
"(",
"int",
"row",
",",
"int",
"col",
")",
"{",
"return",
"(",
"dstore",
"==",
"null",
")",
"?",
"null",
":",
"dstore",
".",
"get",
"(",
"row",
",",
"col",
")",
";",
"}"
] | Returns the data of this objects row and column cell. | [
"Returns",
"the",
"data",
"of",
"this",
"objects",
"row",
"and",
"column",
"cell",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/utils/GDataObject.java#L187-L189 |
137,341 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.go_downstream | public static boolean go_downstream( int[] colRow, double flowdirection ) {
int n = (int) flowdirection;
if (n == 10) {
return true;
} else if (n < 1 || n > 9) {
return false;
} else {
colRow[1] += DIR[n][0];
colRow[0] += DIR[n][1];
return true;
}
} | java | public static boolean go_downstream( int[] colRow, double flowdirection ) {
int n = (int) flowdirection;
if (n == 10) {
return true;
} else if (n < 1 || n > 9) {
return false;
} else {
colRow[1] += DIR[n][0];
colRow[0] += DIR[n][1];
return true;
}
} | [
"public",
"static",
"boolean",
"go_downstream",
"(",
"int",
"[",
"]",
"colRow",
",",
"double",
"flowdirection",
")",
"{",
"int",
"n",
"=",
"(",
"int",
")",
"flowdirection",
";",
"if",
"(",
"n",
"==",
"10",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"n",
"<",
"1",
"||",
"n",
">",
"9",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"colRow",
"[",
"1",
"]",
"+=",
"DIR",
"[",
"n",
"]",
"[",
"0",
"]",
";",
"colRow",
"[",
"0",
"]",
"+=",
"DIR",
"[",
"n",
"]",
"[",
"1",
"]",
";",
"return",
"true",
";",
"}",
"}"
] | Moves one pixel downstream.
@param colRow
the array containing the column and row of the current pixel.
It will be modified here to represent the next downstream
pixel.
@param flowdirection
the current flowdirection number.
@return true if everything went well. | [
"Moves",
"one",
"pixel",
"downstream",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L105-L117 |
137,342 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.sourcesNet | public static boolean sourcesNet( RandomIter flowIterator, int[] colRow, int num, RandomIter netNum ) {
int[][] dir = {{0, 0, 0}, {1, 0, 5}, {1, -1, 6}, {0, -1, 7}, {-1, -1, 8}, {-1, 0, 1}, {-1, 1, 2}, {0, 1, 3}, {1, 1, 4}};
if (flowIterator.getSampleDouble(colRow[0], colRow[1], 0) <= 10.0
&& flowIterator.getSampleDouble(colRow[0], colRow[1], 0) > 0.0) {
for( int k = 1; k <= 8; k++ ) {
if (flowIterator.getSampleDouble(colRow[0] + dir[k][0], colRow[1] + dir[k][1], 0) == dir[k][2]
&& netNum.getSampleDouble(colRow[0] + dir[k][0], colRow[1] + dir[k][1], 0) == num) {
return false;
}
}
return true;
} else {
return false;
}
} | java | public static boolean sourcesNet( RandomIter flowIterator, int[] colRow, int num, RandomIter netNum ) {
int[][] dir = {{0, 0, 0}, {1, 0, 5}, {1, -1, 6}, {0, -1, 7}, {-1, -1, 8}, {-1, 0, 1}, {-1, 1, 2}, {0, 1, 3}, {1, 1, 4}};
if (flowIterator.getSampleDouble(colRow[0], colRow[1], 0) <= 10.0
&& flowIterator.getSampleDouble(colRow[0], colRow[1], 0) > 0.0) {
for( int k = 1; k <= 8; k++ ) {
if (flowIterator.getSampleDouble(colRow[0] + dir[k][0], colRow[1] + dir[k][1], 0) == dir[k][2]
&& netNum.getSampleDouble(colRow[0] + dir[k][0], colRow[1] + dir[k][1], 0) == num) {
return false;
}
}
return true;
} else {
return false;
}
} | [
"public",
"static",
"boolean",
"sourcesNet",
"(",
"RandomIter",
"flowIterator",
",",
"int",
"[",
"]",
"colRow",
",",
"int",
"num",
",",
"RandomIter",
"netNum",
")",
"{",
"int",
"[",
"]",
"[",
"]",
"dir",
"=",
"{",
"{",
"0",
",",
"0",
",",
"0",
"}",
",",
"{",
"1",
",",
"0",
",",
"5",
"}",
",",
"{",
"1",
",",
"-",
"1",
",",
"6",
"}",
",",
"{",
"0",
",",
"-",
"1",
",",
"7",
"}",
",",
"{",
"-",
"1",
",",
"-",
"1",
",",
"8",
"}",
",",
"{",
"-",
"1",
",",
"0",
",",
"1",
"}",
",",
"{",
"-",
"1",
",",
"1",
",",
"2",
"}",
",",
"{",
"0",
",",
"1",
",",
"3",
"}",
",",
"{",
"1",
",",
"1",
",",
"4",
"}",
"}",
";",
"if",
"(",
"flowIterator",
".",
"getSampleDouble",
"(",
"colRow",
"[",
"0",
"]",
",",
"colRow",
"[",
"1",
"]",
",",
"0",
")",
"<=",
"10.0",
"&&",
"flowIterator",
".",
"getSampleDouble",
"(",
"colRow",
"[",
"0",
"]",
",",
"colRow",
"[",
"1",
"]",
",",
"0",
")",
">",
"0.0",
")",
"{",
"for",
"(",
"int",
"k",
"=",
"1",
";",
"k",
"<=",
"8",
";",
"k",
"++",
")",
"{",
"if",
"(",
"flowIterator",
".",
"getSampleDouble",
"(",
"colRow",
"[",
"0",
"]",
"+",
"dir",
"[",
"k",
"]",
"[",
"0",
"]",
",",
"colRow",
"[",
"1",
"]",
"+",
"dir",
"[",
"k",
"]",
"[",
"1",
"]",
",",
"0",
")",
"==",
"dir",
"[",
"k",
"]",
"[",
"2",
"]",
"&&",
"netNum",
".",
"getSampleDouble",
"(",
"colRow",
"[",
"0",
"]",
"+",
"dir",
"[",
"k",
"]",
"[",
"0",
"]",
",",
"colRow",
"[",
"1",
"]",
"+",
"dir",
"[",
"k",
"]",
"[",
"1",
"]",
",",
"0",
")",
"==",
"num",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Controls if the considered point is a source in the network map.
@param flowIterator
{@link RandomIter iterator} of flowdirections map
@param colRow the col and row of the point to check.
@param num
channel number
@param netNum
{@link RandomIter iterator} of the netnumbering map.
@return | [
"Controls",
"if",
"the",
"considered",
"point",
"is",
"a",
"source",
"in",
"the",
"network",
"map",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L442-L458 |
137,343 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.vectorizeDoubleMatrix | public static double[] vectorizeDoubleMatrix( RenderedImage input ) {
double[] U = new double[input.getWidth() * input.getHeight()];
RandomIter inputRandomIter = RandomIterFactory.create(input, null);
int j = 0;
for( int i = 0; i < input.getHeight() * input.getWidth(); i = i + input.getWidth() ) {
double tmp[] = new double[input.getWidth()];
for( int k = 0; k < input.getWidth(); k++ ) {
tmp[k] = inputRandomIter.getSampleDouble(k, j, 0);
}
System.arraycopy(tmp, 0, U, i, input.getWidth());
j++;
}
return U;
} | java | public static double[] vectorizeDoubleMatrix( RenderedImage input ) {
double[] U = new double[input.getWidth() * input.getHeight()];
RandomIter inputRandomIter = RandomIterFactory.create(input, null);
int j = 0;
for( int i = 0; i < input.getHeight() * input.getWidth(); i = i + input.getWidth() ) {
double tmp[] = new double[input.getWidth()];
for( int k = 0; k < input.getWidth(); k++ ) {
tmp[k] = inputRandomIter.getSampleDouble(k, j, 0);
}
System.arraycopy(tmp, 0, U, i, input.getWidth());
j++;
}
return U;
} | [
"public",
"static",
"double",
"[",
"]",
"vectorizeDoubleMatrix",
"(",
"RenderedImage",
"input",
")",
"{",
"double",
"[",
"]",
"U",
"=",
"new",
"double",
"[",
"input",
".",
"getWidth",
"(",
")",
"*",
"input",
".",
"getHeight",
"(",
")",
"]",
";",
"RandomIter",
"inputRandomIter",
"=",
"RandomIterFactory",
".",
"create",
"(",
"input",
",",
"null",
")",
";",
"int",
"j",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"input",
".",
"getHeight",
"(",
")",
"*",
"input",
".",
"getWidth",
"(",
")",
";",
"i",
"=",
"i",
"+",
"input",
".",
"getWidth",
"(",
")",
")",
"{",
"double",
"tmp",
"[",
"]",
"=",
"new",
"double",
"[",
"input",
".",
"getWidth",
"(",
")",
"]",
";",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"input",
".",
"getWidth",
"(",
")",
";",
"k",
"++",
")",
"{",
"tmp",
"[",
"k",
"]",
"=",
"inputRandomIter",
".",
"getSampleDouble",
"(",
"k",
",",
"j",
",",
"0",
")",
";",
"}",
"System",
".",
"arraycopy",
"(",
"tmp",
",",
"0",
",",
"U",
",",
"i",
",",
"input",
".",
"getWidth",
"(",
")",
")",
";",
"j",
"++",
";",
"}",
"return",
"U",
";",
"}"
] | Takes a input raster and vectorializes it.
@param input
@return | [
"Takes",
"a",
"input",
"raster",
"and",
"vectorializes",
"it",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L466-L482 |
137,344 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.calculateNthMoment | public static double calculateNthMoment( double[] values, int validValues, double mean, double momentOrder,
IHMProgressMonitor pm ) {
double moment = 0.0;
double n = 0.0;
if (momentOrder == 1.0) {
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += values[i];
n++;
}
}
if (n >= 1) {
moment /= n;
}
} else if (momentOrder == 2.0) {
// FIXME this needs to be checked, variance doesn't give negative values
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += (values[i]) * (values[i]);
n++;
}
}
if (n >= 1) {
moment = (moment / n - mean * mean);
}
} else {
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += pow((values[i] - mean), momentOrder);
n++;
}
}
if (n >= 1) {
moment /= n;
}
}
if (n == 0) {
pm.errorMessage("No valid data were processed, setting moment value to zero.");
moment = 0.0;
}
return moment;
} | java | public static double calculateNthMoment( double[] values, int validValues, double mean, double momentOrder,
IHMProgressMonitor pm ) {
double moment = 0.0;
double n = 0.0;
if (momentOrder == 1.0) {
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += values[i];
n++;
}
}
if (n >= 1) {
moment /= n;
}
} else if (momentOrder == 2.0) {
// FIXME this needs to be checked, variance doesn't give negative values
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += (values[i]) * (values[i]);
n++;
}
}
if (n >= 1) {
moment = (moment / n - mean * mean);
}
} else {
for( int i = 0; i < validValues; i++ ) {
if (!isNovalue(values[i])) {
moment += pow((values[i] - mean), momentOrder);
n++;
}
}
if (n >= 1) {
moment /= n;
}
}
if (n == 0) {
pm.errorMessage("No valid data were processed, setting moment value to zero.");
moment = 0.0;
}
return moment;
} | [
"public",
"static",
"double",
"calculateNthMoment",
"(",
"double",
"[",
"]",
"values",
",",
"int",
"validValues",
",",
"double",
"mean",
",",
"double",
"momentOrder",
",",
"IHMProgressMonitor",
"pm",
")",
"{",
"double",
"moment",
"=",
"0.0",
";",
"double",
"n",
"=",
"0.0",
";",
"if",
"(",
"momentOrder",
"==",
"1.0",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"validValues",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isNovalue",
"(",
"values",
"[",
"i",
"]",
")",
")",
"{",
"moment",
"+=",
"values",
"[",
"i",
"]",
";",
"n",
"++",
";",
"}",
"}",
"if",
"(",
"n",
">=",
"1",
")",
"{",
"moment",
"/=",
"n",
";",
"}",
"}",
"else",
"if",
"(",
"momentOrder",
"==",
"2.0",
")",
"{",
"// FIXME this needs to be checked, variance doesn't give negative values",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"validValues",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isNovalue",
"(",
"values",
"[",
"i",
"]",
")",
")",
"{",
"moment",
"+=",
"(",
"values",
"[",
"i",
"]",
")",
"*",
"(",
"values",
"[",
"i",
"]",
")",
";",
"n",
"++",
";",
"}",
"}",
"if",
"(",
"n",
">=",
"1",
")",
"{",
"moment",
"=",
"(",
"moment",
"/",
"n",
"-",
"mean",
"*",
"mean",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"validValues",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isNovalue",
"(",
"values",
"[",
"i",
"]",
")",
")",
"{",
"moment",
"+=",
"pow",
"(",
"(",
"values",
"[",
"i",
"]",
"-",
"mean",
")",
",",
"momentOrder",
")",
";",
"n",
"++",
";",
"}",
"}",
"if",
"(",
"n",
">=",
"1",
")",
"{",
"moment",
"/=",
"n",
";",
"}",
"}",
"if",
"(",
"n",
"==",
"0",
")",
"{",
"pm",
".",
"errorMessage",
"(",
"\"No valid data were processed, setting moment value to zero.\"",
")",
";",
"moment",
"=",
"0.0",
";",
"}",
"return",
"moment",
";",
"}"
] | Calculates the nth moment of a set of values.
@param values the array of values.
@param validValues the number of valid values in the array.
@param mean the mean to use.
@param momentOrder the moment order to calculate.
@param pm the monitor.
@return the nth moment value. | [
"Calculates",
"the",
"nth",
"moment",
"of",
"a",
"set",
"of",
"values",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L644-L688 |
137,345 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.extractSubbasins | public static WritableRaster extractSubbasins( WritableRandomIter flowIter, RandomIter netIter,
WritableRandomIter netNumberIter, int rows, int cols, IHMProgressMonitor pm ) {
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
if (!isNovalue(netIter.getSampleDouble(c, r, 0)))
flowIter.setSample(c, r, 0, FlowNode.OUTLET);
}
}
WritableRaster subbasinWR = CoverageUtilities.createWritableRaster(cols, rows, Integer.class, null, null);
WritableRandomIter subbasinIter = RandomIterFactory.createWritable(subbasinWR, null);
markHillSlopeWithLinkValue(flowIter, netNumberIter, subbasinIter, cols, rows, pm);
try {
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
int netValue = netIter.getSample(c, r, 0);
int netNumberValue = netNumberIter.getSample(c, r, 0);
if (!isNovalue(netValue)) {
subbasinIter.setSample(c, r, 0, netNumberValue);
}
if (NumericsUtilities.dEq(netNumberValue, 0)) {
netNumberIter.setSample(c, r, 0, HMConstants.intNovalue);
}
int subbValue = subbasinIter.getSample(c, r, 0);
if (NumericsUtilities.dEq(subbValue, 0))
subbasinIter.setSample(c, r, 0, HMConstants.intNovalue);
}
}
} finally {
subbasinIter.done();
}
return subbasinWR;
} | java | public static WritableRaster extractSubbasins( WritableRandomIter flowIter, RandomIter netIter,
WritableRandomIter netNumberIter, int rows, int cols, IHMProgressMonitor pm ) {
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
if (!isNovalue(netIter.getSampleDouble(c, r, 0)))
flowIter.setSample(c, r, 0, FlowNode.OUTLET);
}
}
WritableRaster subbasinWR = CoverageUtilities.createWritableRaster(cols, rows, Integer.class, null, null);
WritableRandomIter subbasinIter = RandomIterFactory.createWritable(subbasinWR, null);
markHillSlopeWithLinkValue(flowIter, netNumberIter, subbasinIter, cols, rows, pm);
try {
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
int netValue = netIter.getSample(c, r, 0);
int netNumberValue = netNumberIter.getSample(c, r, 0);
if (!isNovalue(netValue)) {
subbasinIter.setSample(c, r, 0, netNumberValue);
}
if (NumericsUtilities.dEq(netNumberValue, 0)) {
netNumberIter.setSample(c, r, 0, HMConstants.intNovalue);
}
int subbValue = subbasinIter.getSample(c, r, 0);
if (NumericsUtilities.dEq(subbValue, 0))
subbasinIter.setSample(c, r, 0, HMConstants.intNovalue);
}
}
} finally {
subbasinIter.done();
}
return subbasinWR;
} | [
"public",
"static",
"WritableRaster",
"extractSubbasins",
"(",
"WritableRandomIter",
"flowIter",
",",
"RandomIter",
"netIter",
",",
"WritableRandomIter",
"netNumberIter",
",",
"int",
"rows",
",",
"int",
"cols",
",",
"IHMProgressMonitor",
"pm",
")",
"{",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"rows",
";",
"r",
"++",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"cols",
";",
"c",
"++",
")",
"{",
"if",
"(",
"!",
"isNovalue",
"(",
"netIter",
".",
"getSampleDouble",
"(",
"c",
",",
"r",
",",
"0",
")",
")",
")",
"flowIter",
".",
"setSample",
"(",
"c",
",",
"r",
",",
"0",
",",
"FlowNode",
".",
"OUTLET",
")",
";",
"}",
"}",
"WritableRaster",
"subbasinWR",
"=",
"CoverageUtilities",
".",
"createWritableRaster",
"(",
"cols",
",",
"rows",
",",
"Integer",
".",
"class",
",",
"null",
",",
"null",
")",
";",
"WritableRandomIter",
"subbasinIter",
"=",
"RandomIterFactory",
".",
"createWritable",
"(",
"subbasinWR",
",",
"null",
")",
";",
"markHillSlopeWithLinkValue",
"(",
"flowIter",
",",
"netNumberIter",
",",
"subbasinIter",
",",
"cols",
",",
"rows",
",",
"pm",
")",
";",
"try",
"{",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"rows",
";",
"r",
"++",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"cols",
";",
"c",
"++",
")",
"{",
"int",
"netValue",
"=",
"netIter",
".",
"getSample",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"int",
"netNumberValue",
"=",
"netNumberIter",
".",
"getSample",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"if",
"(",
"!",
"isNovalue",
"(",
"netValue",
")",
")",
"{",
"subbasinIter",
".",
"setSample",
"(",
"c",
",",
"r",
",",
"0",
",",
"netNumberValue",
")",
";",
"}",
"if",
"(",
"NumericsUtilities",
".",
"dEq",
"(",
"netNumberValue",
",",
"0",
")",
")",
"{",
"netNumberIter",
".",
"setSample",
"(",
"c",
",",
"r",
",",
"0",
",",
"HMConstants",
".",
"intNovalue",
")",
";",
"}",
"int",
"subbValue",
"=",
"subbasinIter",
".",
"getSample",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"if",
"(",
"NumericsUtilities",
".",
"dEq",
"(",
"subbValue",
",",
"0",
")",
")",
"subbasinIter",
".",
"setSample",
"(",
"c",
",",
"r",
",",
"0",
",",
"HMConstants",
".",
"intNovalue",
")",
";",
"}",
"}",
"}",
"finally",
"{",
"subbasinIter",
".",
"done",
"(",
")",
";",
"}",
"return",
"subbasinWR",
";",
"}"
] | Extract the subbasins of a raster map.
@param flowIter the map of flowdirections.
@param netIter the network map.
@param netNumberIter the netnumber map.
@param rows rows of the region.
@param cols columns of the region.
@param pm
@return the map of extracted subbasins. | [
"Extract",
"the",
"subbasins",
"of",
"a",
"raster",
"map",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L840-L876 |
137,346 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.markHillSlopeWithLinkValue | public static void markHillSlopeWithLinkValue( RandomIter flowIter, RandomIter attributeIter, WritableRandomIter markedIter,
int cols, int rows, IHMProgressMonitor pm ) {
pm.beginTask("Marking the hillslopes with the channel value...", rows);
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
FlowNode flowNode = new FlowNode(flowIter, cols, rows, c, r);
if (flowNode.isHeadingOutside()) {
// ignore single cells on borders that exit anyway
continue;
}
if (flowNode.isMarkedAsOutlet()) {
double attributeValue = flowNode.getDoubleValueFromMap(attributeIter);
flowNode.setDoubleValueInMap(markedIter, attributeValue);
continue;
}
if (flowNode.isValid() && flowNode.isSource()) {
/*
* run down to the net to find the
* attribute map content on the net
*/
double attributeValue = doubleNovalue;
FlowNode runningNode = flowNode.goDownstream();
int runningRow = -1;
int runningCol = -1;
while( runningNode != null && runningNode.isValid() ) {
runningRow = runningNode.row;
runningCol = runningNode.col;
if (runningNode.isMarkedAsOutlet()) {
attributeValue = runningNode.getDoubleValueFromMap(attributeIter);
break;
}
runningNode = runningNode.goDownstream();
}
if (!isNovalue(attributeValue)) {
// run down marking the hills
runningNode = flowNode;
while( runningNode != null && runningNode.isValid() ) {
runningNode.setDoubleValueInMap(markedIter, attributeValue);
if (runningNode.isMarkedAsOutlet()) {
break;
}
runningNode = runningNode.goDownstream();
}
} else {
throw new ModelsIllegalargumentException(
"Could not find a value of the attributes map in the channel after point: " + runningCol + "/"
+ runningRow + ". Are you sure that everything leads to a channel or outlet?",
"MODELSENGINE", pm);
}
}
}
pm.worked(1);
}
pm.done();
} | java | public static void markHillSlopeWithLinkValue( RandomIter flowIter, RandomIter attributeIter, WritableRandomIter markedIter,
int cols, int rows, IHMProgressMonitor pm ) {
pm.beginTask("Marking the hillslopes with the channel value...", rows);
for( int r = 0; r < rows; r++ ) {
for( int c = 0; c < cols; c++ ) {
FlowNode flowNode = new FlowNode(flowIter, cols, rows, c, r);
if (flowNode.isHeadingOutside()) {
// ignore single cells on borders that exit anyway
continue;
}
if (flowNode.isMarkedAsOutlet()) {
double attributeValue = flowNode.getDoubleValueFromMap(attributeIter);
flowNode.setDoubleValueInMap(markedIter, attributeValue);
continue;
}
if (flowNode.isValid() && flowNode.isSource()) {
/*
* run down to the net to find the
* attribute map content on the net
*/
double attributeValue = doubleNovalue;
FlowNode runningNode = flowNode.goDownstream();
int runningRow = -1;
int runningCol = -1;
while( runningNode != null && runningNode.isValid() ) {
runningRow = runningNode.row;
runningCol = runningNode.col;
if (runningNode.isMarkedAsOutlet()) {
attributeValue = runningNode.getDoubleValueFromMap(attributeIter);
break;
}
runningNode = runningNode.goDownstream();
}
if (!isNovalue(attributeValue)) {
// run down marking the hills
runningNode = flowNode;
while( runningNode != null && runningNode.isValid() ) {
runningNode.setDoubleValueInMap(markedIter, attributeValue);
if (runningNode.isMarkedAsOutlet()) {
break;
}
runningNode = runningNode.goDownstream();
}
} else {
throw new ModelsIllegalargumentException(
"Could not find a value of the attributes map in the channel after point: " + runningCol + "/"
+ runningRow + ". Are you sure that everything leads to a channel or outlet?",
"MODELSENGINE", pm);
}
}
}
pm.worked(1);
}
pm.done();
} | [
"public",
"static",
"void",
"markHillSlopeWithLinkValue",
"(",
"RandomIter",
"flowIter",
",",
"RandomIter",
"attributeIter",
",",
"WritableRandomIter",
"markedIter",
",",
"int",
"cols",
",",
"int",
"rows",
",",
"IHMProgressMonitor",
"pm",
")",
"{",
"pm",
".",
"beginTask",
"(",
"\"Marking the hillslopes with the channel value...\"",
",",
"rows",
")",
";",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"rows",
";",
"r",
"++",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"cols",
";",
"c",
"++",
")",
"{",
"FlowNode",
"flowNode",
"=",
"new",
"FlowNode",
"(",
"flowIter",
",",
"cols",
",",
"rows",
",",
"c",
",",
"r",
")",
";",
"if",
"(",
"flowNode",
".",
"isHeadingOutside",
"(",
")",
")",
"{",
"// ignore single cells on borders that exit anyway",
"continue",
";",
"}",
"if",
"(",
"flowNode",
".",
"isMarkedAsOutlet",
"(",
")",
")",
"{",
"double",
"attributeValue",
"=",
"flowNode",
".",
"getDoubleValueFromMap",
"(",
"attributeIter",
")",
";",
"flowNode",
".",
"setDoubleValueInMap",
"(",
"markedIter",
",",
"attributeValue",
")",
";",
"continue",
";",
"}",
"if",
"(",
"flowNode",
".",
"isValid",
"(",
")",
"&&",
"flowNode",
".",
"isSource",
"(",
")",
")",
"{",
"/*\n * run down to the net to find the\n * attribute map content on the net \n */",
"double",
"attributeValue",
"=",
"doubleNovalue",
";",
"FlowNode",
"runningNode",
"=",
"flowNode",
".",
"goDownstream",
"(",
")",
";",
"int",
"runningRow",
"=",
"-",
"1",
";",
"int",
"runningCol",
"=",
"-",
"1",
";",
"while",
"(",
"runningNode",
"!=",
"null",
"&&",
"runningNode",
".",
"isValid",
"(",
")",
")",
"{",
"runningRow",
"=",
"runningNode",
".",
"row",
";",
"runningCol",
"=",
"runningNode",
".",
"col",
";",
"if",
"(",
"runningNode",
".",
"isMarkedAsOutlet",
"(",
")",
")",
"{",
"attributeValue",
"=",
"runningNode",
".",
"getDoubleValueFromMap",
"(",
"attributeIter",
")",
";",
"break",
";",
"}",
"runningNode",
"=",
"runningNode",
".",
"goDownstream",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isNovalue",
"(",
"attributeValue",
")",
")",
"{",
"// run down marking the hills",
"runningNode",
"=",
"flowNode",
";",
"while",
"(",
"runningNode",
"!=",
"null",
"&&",
"runningNode",
".",
"isValid",
"(",
")",
")",
"{",
"runningNode",
".",
"setDoubleValueInMap",
"(",
"markedIter",
",",
"attributeValue",
")",
";",
"if",
"(",
"runningNode",
".",
"isMarkedAsOutlet",
"(",
")",
")",
"{",
"break",
";",
"}",
"runningNode",
"=",
"runningNode",
".",
"goDownstream",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"ModelsIllegalargumentException",
"(",
"\"Could not find a value of the attributes map in the channel after point: \"",
"+",
"runningCol",
"+",
"\"/\"",
"+",
"runningRow",
"+",
"\". Are you sure that everything leads to a channel or outlet?\"",
",",
"\"MODELSENGINE\"",
",",
"pm",
")",
";",
"}",
"}",
"}",
"pm",
".",
"worked",
"(",
"1",
")",
";",
"}",
"pm",
".",
"done",
"(",
")",
";",
"}"
] | Marks a map on the hillslope with the values on the channel of an attribute map.
@param flowIter map of flow direction with the network cells
all marked as {@link FlowNode#NETVALUE}. This is very important!
@param attributeIter map of attributes.
@param markedIter the map to be marked.
@param cols region cols.
@param rows region rows.
@param pm monitor. | [
"Marks",
"a",
"map",
"on",
"the",
"hillslope",
"with",
"the",
"values",
"on",
"the",
"channel",
"of",
"an",
"attribute",
"map",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L889-L944 |
137,347 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.isSourcePixel | public static boolean isSourcePixel( RandomIter flowIter, int col, int row ) {
double flowDirection = flowIter.getSampleDouble(col, row, 0);
if (flowDirection < 9.0 && flowDirection > 0.0) {
for( int k = 1; k <= 8; k++ ) {
if (flowIter.getSampleDouble(col + dirIn[k][1], row + dirIn[k][0], 0) == dirIn[k][2]) {
return false;
}
}
return true;
} else {
return false;
}
} | java | public static boolean isSourcePixel( RandomIter flowIter, int col, int row ) {
double flowDirection = flowIter.getSampleDouble(col, row, 0);
if (flowDirection < 9.0 && flowDirection > 0.0) {
for( int k = 1; k <= 8; k++ ) {
if (flowIter.getSampleDouble(col + dirIn[k][1], row + dirIn[k][0], 0) == dirIn[k][2]) {
return false;
}
}
return true;
} else {
return false;
}
} | [
"public",
"static",
"boolean",
"isSourcePixel",
"(",
"RandomIter",
"flowIter",
",",
"int",
"col",
",",
"int",
"row",
")",
"{",
"double",
"flowDirection",
"=",
"flowIter",
".",
"getSampleDouble",
"(",
"col",
",",
"row",
",",
"0",
")",
";",
"if",
"(",
"flowDirection",
"<",
"9.0",
"&&",
"flowDirection",
">",
"0.0",
")",
"{",
"for",
"(",
"int",
"k",
"=",
"1",
";",
"k",
"<=",
"8",
";",
"k",
"++",
")",
"{",
"if",
"(",
"flowIter",
".",
"getSampleDouble",
"(",
"col",
"+",
"dirIn",
"[",
"k",
"]",
"[",
"1",
"]",
",",
"row",
"+",
"dirIn",
"[",
"k",
"]",
"[",
"0",
"]",
",",
"0",
")",
"==",
"dirIn",
"[",
"k",
"]",
"[",
"2",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Verifies if the point is a source pixel in the supplied flow raster.
@param flowIter the {@link RandomIter iterator} of the flowdirections.
@param col the col of the point to check.
@param row the row of the point to check.
@return true if the point identified by col and row is a source pixel. | [
"Verifies",
"if",
"the",
"point",
"is",
"a",
"source",
"pixel",
"in",
"the",
"supplied",
"flow",
"raster",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L954-L966 |
137,348 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.width_interpolate | public static double width_interpolate( double[][] data, double x, int nx, int ny ) {
int rows = data.length;
double xuno = 0, xdue = 0, yuno = 0, ydue = 0, y = 0;
// if 0, interpolate between 0 and the first value of data
if (x >= 0 && x < data[0][nx]) {
xuno = 0;
xdue = data[0][nx];
yuno = 0;
ydue = data[0][ny];
y = ((ydue - yuno) / (xdue - xuno)) * (x - xuno) + yuno;
}
// if it is less than 0 and bigger than the maximum, throw error
if (x > data[(rows - 1)][nx] || x < 0) {
throw new RuntimeException(MessageFormat.format(
"Error in the interpolation algorithm: entering with x = {0} (min = 0.0 max = {1}", x, data[(rows - 1)][nx]));
}
/* trovo i valori limite entro i quali effettuo l'interpolazione lineare */
for( int i = 0; i < rows - 1; i++ ) {
if (x > data[i][nx] && x <= data[(i + 1)][nx]) {
xuno = data[i][nx];
xdue = data[(i + 1)][nx];
yuno = data[i][ny];
ydue = data[(i + 1)][ny];
y = ((ydue - yuno) / (xdue - xuno)) * (x - xuno) + yuno;
}
}
return y;
} | java | public static double width_interpolate( double[][] data, double x, int nx, int ny ) {
int rows = data.length;
double xuno = 0, xdue = 0, yuno = 0, ydue = 0, y = 0;
// if 0, interpolate between 0 and the first value of data
if (x >= 0 && x < data[0][nx]) {
xuno = 0;
xdue = data[0][nx];
yuno = 0;
ydue = data[0][ny];
y = ((ydue - yuno) / (xdue - xuno)) * (x - xuno) + yuno;
}
// if it is less than 0 and bigger than the maximum, throw error
if (x > data[(rows - 1)][nx] || x < 0) {
throw new RuntimeException(MessageFormat.format(
"Error in the interpolation algorithm: entering with x = {0} (min = 0.0 max = {1}", x, data[(rows - 1)][nx]));
}
/* trovo i valori limite entro i quali effettuo l'interpolazione lineare */
for( int i = 0; i < rows - 1; i++ ) {
if (x > data[i][nx] && x <= data[(i + 1)][nx]) {
xuno = data[i][nx];
xdue = data[(i + 1)][nx];
yuno = data[i][ny];
ydue = data[(i + 1)][ny];
y = ((ydue - yuno) / (xdue - xuno)) * (x - xuno) + yuno;
}
}
return y;
} | [
"public",
"static",
"double",
"width_interpolate",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
",",
"double",
"x",
",",
"int",
"nx",
",",
"int",
"ny",
")",
"{",
"int",
"rows",
"=",
"data",
".",
"length",
";",
"double",
"xuno",
"=",
"0",
",",
"xdue",
"=",
"0",
",",
"yuno",
"=",
"0",
",",
"ydue",
"=",
"0",
",",
"y",
"=",
"0",
";",
"// if 0, interpolate between 0 and the first value of data",
"if",
"(",
"x",
">=",
"0",
"&&",
"x",
"<",
"data",
"[",
"0",
"]",
"[",
"nx",
"]",
")",
"{",
"xuno",
"=",
"0",
";",
"xdue",
"=",
"data",
"[",
"0",
"]",
"[",
"nx",
"]",
";",
"yuno",
"=",
"0",
";",
"ydue",
"=",
"data",
"[",
"0",
"]",
"[",
"ny",
"]",
";",
"y",
"=",
"(",
"(",
"ydue",
"-",
"yuno",
")",
"/",
"(",
"xdue",
"-",
"xuno",
")",
")",
"*",
"(",
"x",
"-",
"xuno",
")",
"+",
"yuno",
";",
"}",
"// if it is less than 0 and bigger than the maximum, throw error",
"if",
"(",
"x",
">",
"data",
"[",
"(",
"rows",
"-",
"1",
")",
"]",
"[",
"nx",
"]",
"||",
"x",
"<",
"0",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"MessageFormat",
".",
"format",
"(",
"\"Error in the interpolation algorithm: entering with x = {0} (min = 0.0 max = {1}\"",
",",
"x",
",",
"data",
"[",
"(",
"rows",
"-",
"1",
")",
"]",
"[",
"nx",
"]",
")",
")",
";",
"}",
"/* trovo i valori limite entro i quali effettuo l'interpolazione lineare */",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"rows",
"-",
"1",
";",
"i",
"++",
")",
"{",
"if",
"(",
"x",
">",
"data",
"[",
"i",
"]",
"[",
"nx",
"]",
"&&",
"x",
"<=",
"data",
"[",
"(",
"i",
"+",
"1",
")",
"]",
"[",
"nx",
"]",
")",
"{",
"xuno",
"=",
"data",
"[",
"i",
"]",
"[",
"nx",
"]",
";",
"xdue",
"=",
"data",
"[",
"(",
"i",
"+",
"1",
")",
"]",
"[",
"nx",
"]",
";",
"yuno",
"=",
"data",
"[",
"i",
"]",
"[",
"ny",
"]",
";",
"ydue",
"=",
"data",
"[",
"(",
"i",
"+",
"1",
")",
"]",
"[",
"ny",
"]",
";",
"y",
"=",
"(",
"(",
"ydue",
"-",
"yuno",
")",
"/",
"(",
"xdue",
"-",
"xuno",
")",
")",
"*",
"(",
"x",
"-",
"xuno",
")",
"+",
"yuno",
";",
"}",
"}",
"return",
"y",
";",
"}"
] | Linear interpolation between two values
@param data
- matrix of values to interpolate
@param x
- value to interpolate
@param nx
- column of data in which you find the x values
@param ny
- column of data in which you find the y values
@return | [
"Linear",
"interpolation",
"between",
"two",
"values"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L998-L1032 |
137,349 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.henderson | public static double henderson( double[][] data, int tp ) {
int rows = data.length;
int j = 1, n = 0;
double dt = 0, muno, mdue, a, b, x, y, ydue, s_uno, s_due, smax = 0, tstar;
for( int i = 1; i < rows; i++ ) {
if (data[i][0] + tp <= data[(rows - 1)][0]) {
/**
* ***trovo parametri geometrici del segmento di retta y=muno
* x+a******
*/
muno = (data[i][1] - data[(i - 1)][1]) / (data[i][0] - data[(i - 1)][0]);
a = data[i][1] - (data[i][0] + tp) * muno;
/**
* ***trovo i valori di x per l'intersezione tra y=(muno x+tp)+a
* e y=mdue x+b ******
*/
for( j = 1; j <= (rows - 1); j++ ) {
mdue = (data[j][1] - data[(j - 1)][1]) / (data[j][0] - data[(j - 1)][0]);
b = data[j][1] - data[j][0] * mdue;
x = (a - b) / (mdue - muno);
y = muno * x + a;
if (x >= data[(j - 1)][0] && x <= data[j][0] && x - tp >= data[(i - 1)][0] && x - tp <= data[i][0]) {
ydue = width_interpolate(data, x - tp, 0, 1);
n++;
s_uno = width_interpolate(data, x - tp, 0, 2);
s_due = width_interpolate(data, x, 0, 2);
if (s_due - s_uno > smax) {
smax = s_due - s_uno;
dt = x - tp;
tstar = x;
}
}
}
}
}
return dt;
} | java | public static double henderson( double[][] data, int tp ) {
int rows = data.length;
int j = 1, n = 0;
double dt = 0, muno, mdue, a, b, x, y, ydue, s_uno, s_due, smax = 0, tstar;
for( int i = 1; i < rows; i++ ) {
if (data[i][0] + tp <= data[(rows - 1)][0]) {
/**
* ***trovo parametri geometrici del segmento di retta y=muno
* x+a******
*/
muno = (data[i][1] - data[(i - 1)][1]) / (data[i][0] - data[(i - 1)][0]);
a = data[i][1] - (data[i][0] + tp) * muno;
/**
* ***trovo i valori di x per l'intersezione tra y=(muno x+tp)+a
* e y=mdue x+b ******
*/
for( j = 1; j <= (rows - 1); j++ ) {
mdue = (data[j][1] - data[(j - 1)][1]) / (data[j][0] - data[(j - 1)][0]);
b = data[j][1] - data[j][0] * mdue;
x = (a - b) / (mdue - muno);
y = muno * x + a;
if (x >= data[(j - 1)][0] && x <= data[j][0] && x - tp >= data[(i - 1)][0] && x - tp <= data[i][0]) {
ydue = width_interpolate(data, x - tp, 0, 1);
n++;
s_uno = width_interpolate(data, x - tp, 0, 2);
s_due = width_interpolate(data, x, 0, 2);
if (s_due - s_uno > smax) {
smax = s_due - s_uno;
dt = x - tp;
tstar = x;
}
}
}
}
}
return dt;
} | [
"public",
"static",
"double",
"henderson",
"(",
"double",
"[",
"]",
"[",
"]",
"data",
",",
"int",
"tp",
")",
"{",
"int",
"rows",
"=",
"data",
".",
"length",
";",
"int",
"j",
"=",
"1",
",",
"n",
"=",
"0",
";",
"double",
"dt",
"=",
"0",
",",
"muno",
",",
"mdue",
",",
"a",
",",
"b",
",",
"x",
",",
"y",
",",
"ydue",
",",
"s_uno",
",",
"s_due",
",",
"smax",
"=",
"0",
",",
"tstar",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"rows",
";",
"i",
"++",
")",
"{",
"if",
"(",
"data",
"[",
"i",
"]",
"[",
"0",
"]",
"+",
"tp",
"<=",
"data",
"[",
"(",
"rows",
"-",
"1",
")",
"]",
"[",
"0",
"]",
")",
"{",
"/**\n * ***trovo parametri geometrici del segmento di retta y=muno\n * x+a******\n */",
"muno",
"=",
"(",
"data",
"[",
"i",
"]",
"[",
"1",
"]",
"-",
"data",
"[",
"(",
"i",
"-",
"1",
")",
"]",
"[",
"1",
"]",
")",
"/",
"(",
"data",
"[",
"i",
"]",
"[",
"0",
"]",
"-",
"data",
"[",
"(",
"i",
"-",
"1",
")",
"]",
"[",
"0",
"]",
")",
";",
"a",
"=",
"data",
"[",
"i",
"]",
"[",
"1",
"]",
"-",
"(",
"data",
"[",
"i",
"]",
"[",
"0",
"]",
"+",
"tp",
")",
"*",
"muno",
";",
"/**\n * ***trovo i valori di x per l'intersezione tra y=(muno x+tp)+a\n * e y=mdue x+b ******\n */",
"for",
"(",
"j",
"=",
"1",
";",
"j",
"<=",
"(",
"rows",
"-",
"1",
")",
";",
"j",
"++",
")",
"{",
"mdue",
"=",
"(",
"data",
"[",
"j",
"]",
"[",
"1",
"]",
"-",
"data",
"[",
"(",
"j",
"-",
"1",
")",
"]",
"[",
"1",
"]",
")",
"/",
"(",
"data",
"[",
"j",
"]",
"[",
"0",
"]",
"-",
"data",
"[",
"(",
"j",
"-",
"1",
")",
"]",
"[",
"0",
"]",
")",
";",
"b",
"=",
"data",
"[",
"j",
"]",
"[",
"1",
"]",
"-",
"data",
"[",
"j",
"]",
"[",
"0",
"]",
"*",
"mdue",
";",
"x",
"=",
"(",
"a",
"-",
"b",
")",
"/",
"(",
"mdue",
"-",
"muno",
")",
";",
"y",
"=",
"muno",
"*",
"x",
"+",
"a",
";",
"if",
"(",
"x",
">=",
"data",
"[",
"(",
"j",
"-",
"1",
")",
"]",
"[",
"0",
"]",
"&&",
"x",
"<=",
"data",
"[",
"j",
"]",
"[",
"0",
"]",
"&&",
"x",
"-",
"tp",
">=",
"data",
"[",
"(",
"i",
"-",
"1",
")",
"]",
"[",
"0",
"]",
"&&",
"x",
"-",
"tp",
"<=",
"data",
"[",
"i",
"]",
"[",
"0",
"]",
")",
"{",
"ydue",
"=",
"width_interpolate",
"(",
"data",
",",
"x",
"-",
"tp",
",",
"0",
",",
"1",
")",
";",
"n",
"++",
";",
"s_uno",
"=",
"width_interpolate",
"(",
"data",
",",
"x",
"-",
"tp",
",",
"0",
",",
"2",
")",
";",
"s_due",
"=",
"width_interpolate",
"(",
"data",
",",
"x",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"s_due",
"-",
"s_uno",
">",
"smax",
")",
"{",
"smax",
"=",
"s_due",
"-",
"s_uno",
";",
"dt",
"=",
"x",
"-",
"tp",
";",
"tstar",
"=",
"x",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"dt",
";",
"}"
] | Interpolates the width function in a given tp.
@param data
@param tp
@return | [
"Interpolates",
"the",
"width",
"function",
"in",
"a",
"given",
"tp",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1041-L1091 |
137,350 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.gamma | public static double gamma( double x ) {
double tmp = (x - 0.5) * log(x + 4.5) - (x + 4.5);
double ser = 1.0 + 76.18009173 / (x + 0) - 86.50532033 / (x + 1) + 24.01409822 / (x + 2) - 1.231739516 / (x + 3)
+ 0.00120858003 / (x + 4) - 0.00000536382 / (x + 5);
double gamma = exp(tmp + log(ser * sqrt(2 * PI)));
return gamma;
} | java | public static double gamma( double x ) {
double tmp = (x - 0.5) * log(x + 4.5) - (x + 4.5);
double ser = 1.0 + 76.18009173 / (x + 0) - 86.50532033 / (x + 1) + 24.01409822 / (x + 2) - 1.231739516 / (x + 3)
+ 0.00120858003 / (x + 4) - 0.00000536382 / (x + 5);
double gamma = exp(tmp + log(ser * sqrt(2 * PI)));
return gamma;
} | [
"public",
"static",
"double",
"gamma",
"(",
"double",
"x",
")",
"{",
"double",
"tmp",
"=",
"(",
"x",
"-",
"0.5",
")",
"*",
"log",
"(",
"x",
"+",
"4.5",
")",
"-",
"(",
"x",
"+",
"4.5",
")",
";",
"double",
"ser",
"=",
"1.0",
"+",
"76.18009173",
"/",
"(",
"x",
"+",
"0",
")",
"-",
"86.50532033",
"/",
"(",
"x",
"+",
"1",
")",
"+",
"24.01409822",
"/",
"(",
"x",
"+",
"2",
")",
"-",
"1.231739516",
"/",
"(",
"x",
"+",
"3",
")",
"+",
"0.00120858003",
"/",
"(",
"x",
"+",
"4",
")",
"-",
"0.00000536382",
"/",
"(",
"x",
"+",
"5",
")",
";",
"double",
"gamma",
"=",
"exp",
"(",
"tmp",
"+",
"log",
"(",
"ser",
"*",
"sqrt",
"(",
"2",
"*",
"PI",
")",
")",
")",
";",
"return",
"gamma",
";",
"}"
] | The Gamma function.
@param x
@return the calculated gamma function. | [
"The",
"Gamma",
"function",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1099-L1105 |
137,351 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.sumDownstream | public static WritableRaster sumDownstream( RandomIter flowIter, RandomIter mapToSumIter, int width, int height,
Double upperThreshold, Double lowerThreshold, IHMProgressMonitor pm ) {
final int[] point = new int[2];
WritableRaster summedMapWR = CoverageUtilities.createWritableRaster(width, height, null, null, null);
WritableRandomIter summedMapIter = RandomIterFactory.createWritable(summedMapWR, null);
double uThres = Double.POSITIVE_INFINITY;
if (upperThreshold != null) {
uThres = upperThreshold;
}
double lThres = Double.NEGATIVE_INFINITY;
if (lowerThreshold != null) {
lThres = lowerThreshold;
}
pm.beginTask("Calculating downstream sum...", height);
for( int r = 0; r < height; r++ ) {
for( int c = 0; c < width; c++ ) {
double mapToSumValue = mapToSumIter.getSampleDouble(c, r, 0);
if (!isNovalue(flowIter.getSampleDouble(c, r, 0)) && //
mapToSumValue < uThres && //
mapToSumValue > lThres //
) {
point[0] = c;
point[1] = r;
while( flowIter.getSampleDouble(point[0], point[1], 0) < 9 && //
!isNovalue(flowIter.getSampleDouble(point[0], point[1], 0))
&& (checkRange(mapToSumIter.getSampleDouble(point[0], point[1], 0), uThres, lThres)) ) {
double sumValue = summedMapIter.getSampleDouble(point[0], point[1], 0)
+ mapToSumIter.getSampleDouble(c, r, 0);
summedMapIter.setSample(point[0], point[1], 0, sumValue);
// FlowNode flowNode = new FlowNode(flowIter, width, height, point[0],
// point[1]);
// FlowNode downStreamNode = flowNode.goDownstream();
// if (downStreamNode != null) {
// if (!downStreamNode.isMarkedAsOutlet()) {
// point[0] = downStreamNode.col;
// point[1] = downStreamNode.row;
// }
// } else {
// return null;
// }
if (!go_downstream(point, flowIter.getSampleDouble(point[0], point[1], 0)))
return null;
}
if (!isNovalue(flowIter.getSampleDouble(point[0], point[1], 0))) {
double summedMapValue = summedMapIter.getSampleDouble(point[0], point[1], 0);
if (!isNovalue(summedMapValue)) {
double sumValue = summedMapValue + mapToSumIter.getSampleDouble(c, r, 0);
summedMapIter.setSample(point[0], point[1], 0, sumValue);
}
}
} else {
summedMapIter.setSample(c, r, 0, doubleNovalue);
}
}
pm.worked(1);
}
pm.done();
return summedMapWR;
} | java | public static WritableRaster sumDownstream( RandomIter flowIter, RandomIter mapToSumIter, int width, int height,
Double upperThreshold, Double lowerThreshold, IHMProgressMonitor pm ) {
final int[] point = new int[2];
WritableRaster summedMapWR = CoverageUtilities.createWritableRaster(width, height, null, null, null);
WritableRandomIter summedMapIter = RandomIterFactory.createWritable(summedMapWR, null);
double uThres = Double.POSITIVE_INFINITY;
if (upperThreshold != null) {
uThres = upperThreshold;
}
double lThres = Double.NEGATIVE_INFINITY;
if (lowerThreshold != null) {
lThres = lowerThreshold;
}
pm.beginTask("Calculating downstream sum...", height);
for( int r = 0; r < height; r++ ) {
for( int c = 0; c < width; c++ ) {
double mapToSumValue = mapToSumIter.getSampleDouble(c, r, 0);
if (!isNovalue(flowIter.getSampleDouble(c, r, 0)) && //
mapToSumValue < uThres && //
mapToSumValue > lThres //
) {
point[0] = c;
point[1] = r;
while( flowIter.getSampleDouble(point[0], point[1], 0) < 9 && //
!isNovalue(flowIter.getSampleDouble(point[0], point[1], 0))
&& (checkRange(mapToSumIter.getSampleDouble(point[0], point[1], 0), uThres, lThres)) ) {
double sumValue = summedMapIter.getSampleDouble(point[0], point[1], 0)
+ mapToSumIter.getSampleDouble(c, r, 0);
summedMapIter.setSample(point[0], point[1], 0, sumValue);
// FlowNode flowNode = new FlowNode(flowIter, width, height, point[0],
// point[1]);
// FlowNode downStreamNode = flowNode.goDownstream();
// if (downStreamNode != null) {
// if (!downStreamNode.isMarkedAsOutlet()) {
// point[0] = downStreamNode.col;
// point[1] = downStreamNode.row;
// }
// } else {
// return null;
// }
if (!go_downstream(point, flowIter.getSampleDouble(point[0], point[1], 0)))
return null;
}
if (!isNovalue(flowIter.getSampleDouble(point[0], point[1], 0))) {
double summedMapValue = summedMapIter.getSampleDouble(point[0], point[1], 0);
if (!isNovalue(summedMapValue)) {
double sumValue = summedMapValue + mapToSumIter.getSampleDouble(c, r, 0);
summedMapIter.setSample(point[0], point[1], 0, sumValue);
}
}
} else {
summedMapIter.setSample(c, r, 0, doubleNovalue);
}
}
pm.worked(1);
}
pm.done();
return summedMapWR;
} | [
"public",
"static",
"WritableRaster",
"sumDownstream",
"(",
"RandomIter",
"flowIter",
",",
"RandomIter",
"mapToSumIter",
",",
"int",
"width",
",",
"int",
"height",
",",
"Double",
"upperThreshold",
",",
"Double",
"lowerThreshold",
",",
"IHMProgressMonitor",
"pm",
")",
"{",
"final",
"int",
"[",
"]",
"point",
"=",
"new",
"int",
"[",
"2",
"]",
";",
"WritableRaster",
"summedMapWR",
"=",
"CoverageUtilities",
".",
"createWritableRaster",
"(",
"width",
",",
"height",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"WritableRandomIter",
"summedMapIter",
"=",
"RandomIterFactory",
".",
"createWritable",
"(",
"summedMapWR",
",",
"null",
")",
";",
"double",
"uThres",
"=",
"Double",
".",
"POSITIVE_INFINITY",
";",
"if",
"(",
"upperThreshold",
"!=",
"null",
")",
"{",
"uThres",
"=",
"upperThreshold",
";",
"}",
"double",
"lThres",
"=",
"Double",
".",
"NEGATIVE_INFINITY",
";",
"if",
"(",
"lowerThreshold",
"!=",
"null",
")",
"{",
"lThres",
"=",
"lowerThreshold",
";",
"}",
"pm",
".",
"beginTask",
"(",
"\"Calculating downstream sum...\"",
",",
"height",
")",
";",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"height",
";",
"r",
"++",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"width",
";",
"c",
"++",
")",
"{",
"double",
"mapToSumValue",
"=",
"mapToSumIter",
".",
"getSampleDouble",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"if",
"(",
"!",
"isNovalue",
"(",
"flowIter",
".",
"getSampleDouble",
"(",
"c",
",",
"r",
",",
"0",
")",
")",
"&&",
"//",
"mapToSumValue",
"<",
"uThres",
"&&",
"//",
"mapToSumValue",
">",
"lThres",
"//",
")",
"{",
"point",
"[",
"0",
"]",
"=",
"c",
";",
"point",
"[",
"1",
"]",
"=",
"r",
";",
"while",
"(",
"flowIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
"<",
"9",
"&&",
"//",
"!",
"isNovalue",
"(",
"flowIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
")",
"&&",
"(",
"checkRange",
"(",
"mapToSumIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
",",
"uThres",
",",
"lThres",
")",
")",
")",
"{",
"double",
"sumValue",
"=",
"summedMapIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
"+",
"mapToSumIter",
".",
"getSampleDouble",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"summedMapIter",
".",
"setSample",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
",",
"sumValue",
")",
";",
"// FlowNode flowNode = new FlowNode(flowIter, width, height, point[0],",
"// point[1]);",
"// FlowNode downStreamNode = flowNode.goDownstream();",
"// if (downStreamNode != null) {",
"// if (!downStreamNode.isMarkedAsOutlet()) {",
"// point[0] = downStreamNode.col;",
"// point[1] = downStreamNode.row;",
"// }",
"// } else {",
"// return null;",
"// }",
"if",
"(",
"!",
"go_downstream",
"(",
"point",
",",
"flowIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
")",
")",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isNovalue",
"(",
"flowIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
")",
")",
"{",
"double",
"summedMapValue",
"=",
"summedMapIter",
".",
"getSampleDouble",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
")",
";",
"if",
"(",
"!",
"isNovalue",
"(",
"summedMapValue",
")",
")",
"{",
"double",
"sumValue",
"=",
"summedMapValue",
"+",
"mapToSumIter",
".",
"getSampleDouble",
"(",
"c",
",",
"r",
",",
"0",
")",
";",
"summedMapIter",
".",
"setSample",
"(",
"point",
"[",
"0",
"]",
",",
"point",
"[",
"1",
"]",
",",
"0",
",",
"sumValue",
")",
";",
"}",
"}",
"}",
"else",
"{",
"summedMapIter",
".",
"setSample",
"(",
"c",
",",
"r",
",",
"0",
",",
"doubleNovalue",
")",
";",
"}",
"}",
"pm",
".",
"worked",
"(",
"1",
")",
";",
"}",
"pm",
".",
"done",
"(",
")",
";",
"return",
"summedMapWR",
";",
"}"
] | Calculates the sum of the values of a specified quantity from every point to the outlet.
<p>During the calculation the drainage directions are followed.</p>
@param flowIter the map of flowdirections.
@param mapToSumIter the map for which to sum downstream.
@param width the width of the resulting map.
@param height the height of the resulting map.
@param upperThreshold the upper threshold, values above that are excluded.
@param lowerThreshold the lower threshold, values below that are excluded.
@param pm the monitor.
@return The map of downstream summed values. | [
"Calculates",
"the",
"sum",
"of",
"the",
"values",
"of",
"a",
"specified",
"quantity",
"from",
"every",
"point",
"to",
"the",
"outlet",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1121-L1186 |
137,352 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.calcInverseSunVector | public static double[] calcInverseSunVector( double[] sunVector ) {
double m = Math.max(Math.abs(sunVector[0]), Math.abs(sunVector[1]));
return new double[]{-sunVector[0] / m, -sunVector[1] / m, -sunVector[2] / m};
} | java | public static double[] calcInverseSunVector( double[] sunVector ) {
double m = Math.max(Math.abs(sunVector[0]), Math.abs(sunVector[1]));
return new double[]{-sunVector[0] / m, -sunVector[1] / m, -sunVector[2] / m};
} | [
"public",
"static",
"double",
"[",
"]",
"calcInverseSunVector",
"(",
"double",
"[",
"]",
"sunVector",
")",
"{",
"double",
"m",
"=",
"Math",
".",
"max",
"(",
"Math",
".",
"abs",
"(",
"sunVector",
"[",
"0",
"]",
")",
",",
"Math",
".",
"abs",
"(",
"sunVector",
"[",
"1",
"]",
")",
")",
";",
"return",
"new",
"double",
"[",
"]",
"{",
"-",
"sunVector",
"[",
"0",
"]",
"/",
"m",
",",
"-",
"sunVector",
"[",
"1",
"]",
"/",
"m",
",",
"-",
"sunVector",
"[",
"2",
"]",
"/",
"m",
"}",
";",
"}"
] | Calculating the inverse of the sun vector.
@param sunVector
@return | [
"Calculating",
"the",
"inverse",
"of",
"the",
"sun",
"vector",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1201-L1204 |
137,353 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.calcNormalSunVector | public static double[] calcNormalSunVector( double[] sunVector ) {
double[] normalSunVector = new double[3];
normalSunVector[2] = Math.sqrt(Math.pow(sunVector[0], 2) + Math.pow(sunVector[1], 2));
normalSunVector[0] = -sunVector[0] * sunVector[2] / normalSunVector[2];
normalSunVector[1] = -sunVector[1] * sunVector[2] / normalSunVector[2];
return normalSunVector;
} | java | public static double[] calcNormalSunVector( double[] sunVector ) {
double[] normalSunVector = new double[3];
normalSunVector[2] = Math.sqrt(Math.pow(sunVector[0], 2) + Math.pow(sunVector[1], 2));
normalSunVector[0] = -sunVector[0] * sunVector[2] / normalSunVector[2];
normalSunVector[1] = -sunVector[1] * sunVector[2] / normalSunVector[2];
return normalSunVector;
} | [
"public",
"static",
"double",
"[",
"]",
"calcNormalSunVector",
"(",
"double",
"[",
"]",
"sunVector",
")",
"{",
"double",
"[",
"]",
"normalSunVector",
"=",
"new",
"double",
"[",
"3",
"]",
";",
"normalSunVector",
"[",
"2",
"]",
"=",
"Math",
".",
"sqrt",
"(",
"Math",
".",
"pow",
"(",
"sunVector",
"[",
"0",
"]",
",",
"2",
")",
"+",
"Math",
".",
"pow",
"(",
"sunVector",
"[",
"1",
"]",
",",
"2",
")",
")",
";",
"normalSunVector",
"[",
"0",
"]",
"=",
"-",
"sunVector",
"[",
"0",
"]",
"*",
"sunVector",
"[",
"2",
"]",
"/",
"normalSunVector",
"[",
"2",
"]",
";",
"normalSunVector",
"[",
"1",
"]",
"=",
"-",
"sunVector",
"[",
"1",
"]",
"*",
"sunVector",
"[",
"2",
"]",
"/",
"normalSunVector",
"[",
"2",
"]",
";",
"return",
"normalSunVector",
";",
"}"
] | Calculating the normal to the sun vector.
@param sunVector
@return | [
"Calculating",
"the",
"normal",
"to",
"the",
"sun",
"vector",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1212-L1218 |
137,354 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.scalarProduct | public static double scalarProduct( double[] a, double[] b ) {
double c = 0;
for( int i = 0; i < a.length; i++ ) {
c = c + a[i] * b[i];
}
return c;
} | java | public static double scalarProduct( double[] a, double[] b ) {
double c = 0;
for( int i = 0; i < a.length; i++ ) {
c = c + a[i] * b[i];
}
return c;
} | [
"public",
"static",
"double",
"scalarProduct",
"(",
"double",
"[",
"]",
"a",
",",
"double",
"[",
"]",
"b",
")",
"{",
"double",
"c",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"length",
";",
"i",
"++",
")",
"{",
"c",
"=",
"c",
"+",
"a",
"[",
"i",
"]",
"*",
"b",
"[",
"i",
"]",
";",
"}",
"return",
"c",
";",
"}"
] | Compute the dot product.
@param a
is a vector.
@param b
is a vector.
@return the dot product of a and b. | [
"Compute",
"the",
"dot",
"product",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1229-L1235 |
137,355 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.calculateFactor | public static WritableRaster calculateFactor( int h, int w, double[] sunVector, double[] inverseSunVector,
double[] normalSunVector, WritableRaster demWR, double dx ) {
double casx = 1e6 * sunVector[0];
double casy = 1e6 * sunVector[1];
int f_i = 0;
int f_j = 0;
if (casx <= 0) {
f_i = 0;
} else {
f_i = w - 1;
}
if (casy <= 0) {
f_j = 0;
} else {
f_j = h - 1;
}
WritableRaster sOmbraWR = CoverageUtilities.createWritableRaster(w, h, null, null, 1.0);
int j = f_j;
for( int i = 0; i < sOmbraWR.getWidth(); i++ ) {
shadow(i, j, sOmbraWR, demWR, dx, normalSunVector, inverseSunVector);
}
int i = f_i;
for( int k = 0; k < sOmbraWR.getHeight(); k++ ) {
shadow(i, k, sOmbraWR, demWR, dx, normalSunVector, inverseSunVector);
}
return sOmbraWR;
} | java | public static WritableRaster calculateFactor( int h, int w, double[] sunVector, double[] inverseSunVector,
double[] normalSunVector, WritableRaster demWR, double dx ) {
double casx = 1e6 * sunVector[0];
double casy = 1e6 * sunVector[1];
int f_i = 0;
int f_j = 0;
if (casx <= 0) {
f_i = 0;
} else {
f_i = w - 1;
}
if (casy <= 0) {
f_j = 0;
} else {
f_j = h - 1;
}
WritableRaster sOmbraWR = CoverageUtilities.createWritableRaster(w, h, null, null, 1.0);
int j = f_j;
for( int i = 0; i < sOmbraWR.getWidth(); i++ ) {
shadow(i, j, sOmbraWR, demWR, dx, normalSunVector, inverseSunVector);
}
int i = f_i;
for( int k = 0; k < sOmbraWR.getHeight(); k++ ) {
shadow(i, k, sOmbraWR, demWR, dx, normalSunVector, inverseSunVector);
}
return sOmbraWR;
} | [
"public",
"static",
"WritableRaster",
"calculateFactor",
"(",
"int",
"h",
",",
"int",
"w",
",",
"double",
"[",
"]",
"sunVector",
",",
"double",
"[",
"]",
"inverseSunVector",
",",
"double",
"[",
"]",
"normalSunVector",
",",
"WritableRaster",
"demWR",
",",
"double",
"dx",
")",
"{",
"double",
"casx",
"=",
"1e6",
"*",
"sunVector",
"[",
"0",
"]",
";",
"double",
"casy",
"=",
"1e6",
"*",
"sunVector",
"[",
"1",
"]",
";",
"int",
"f_i",
"=",
"0",
";",
"int",
"f_j",
"=",
"0",
";",
"if",
"(",
"casx",
"<=",
"0",
")",
"{",
"f_i",
"=",
"0",
";",
"}",
"else",
"{",
"f_i",
"=",
"w",
"-",
"1",
";",
"}",
"if",
"(",
"casy",
"<=",
"0",
")",
"{",
"f_j",
"=",
"0",
";",
"}",
"else",
"{",
"f_j",
"=",
"h",
"-",
"1",
";",
"}",
"WritableRaster",
"sOmbraWR",
"=",
"CoverageUtilities",
".",
"createWritableRaster",
"(",
"w",
",",
"h",
",",
"null",
",",
"null",
",",
"1.0",
")",
";",
"int",
"j",
"=",
"f_j",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"sOmbraWR",
".",
"getWidth",
"(",
")",
";",
"i",
"++",
")",
"{",
"shadow",
"(",
"i",
",",
"j",
",",
"sOmbraWR",
",",
"demWR",
",",
"dx",
",",
"normalSunVector",
",",
"inverseSunVector",
")",
";",
"}",
"int",
"i",
"=",
"f_i",
";",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"sOmbraWR",
".",
"getHeight",
"(",
")",
";",
"k",
"++",
")",
"{",
"shadow",
"(",
"i",
",",
"k",
",",
"sOmbraWR",
",",
"demWR",
",",
"dx",
",",
"normalSunVector",
",",
"inverseSunVector",
")",
";",
"}",
"return",
"sOmbraWR",
";",
"}"
] | Evaluate the shadow map calling the shadow method.
@param h
the height of the raster.
@param w
the width of the raster.
@param sunVector
@param inverseSunVector
@param normalSunVector
@param demWR
the elevation map.
@param dx
the resolution of the elevation map.
@return the shadow map. | [
"Evaluate",
"the",
"shadow",
"map",
"calling",
"the",
"shadow",
"method",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1252-L1282 |
137,356 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.shadow | private static WritableRaster shadow( int i, int j, WritableRaster tmpWR, WritableRaster demWR, double res,
double[] normalSunVector, double[] inverseSunVector ) {
int n = 0;
double zcompare = -Double.MAX_VALUE;
double dx = (inverseSunVector[0] * n);
double dy = (inverseSunVector[1] * n);
int nCols = tmpWR.getWidth();
int nRows = tmpWR.getHeight();
int idx = (int) Math.round(i + dx);
int jdy = (int) Math.round(j + dy);
double vectorToOrigin[] = new double[3];
while( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) {
vectorToOrigin[0] = dx * res;
vectorToOrigin[1] = dy * res;
int tmpY = (int) (j + dy);
if (tmpY < 0) {
tmpY = 0;
} else if (tmpY > nRows) {
tmpY = nRows - 1;
}
int tmpX = (int) (i + dx);
if (tmpX < 0) {
tmpX = 0;
} else if (tmpY > nCols) {
tmpX = nCols - 1;
}
vectorToOrigin[2] = demWR.getSampleDouble(idx, jdy, 0);
// vectorToOrigin[2] = (pitRandomIter.getSampleDouble(idx, jdy, 0) +
// pitRandomIter
// .getSampleDouble(tmpX, tmpY, 0)) / 2;
double zprojection = scalarProduct(vectorToOrigin, normalSunVector);
if ((zprojection < zcompare)) {
tmpWR.setSample(idx, jdy, 0, 0);
} else {
zcompare = zprojection;
}
n = n + 1;
dy = (inverseSunVector[1] * n);
dx = (inverseSunVector[0] * n);
idx = (int) Math.round(i + dx);
jdy = (int) Math.round(j + dy);
}
return tmpWR;
} | java | private static WritableRaster shadow( int i, int j, WritableRaster tmpWR, WritableRaster demWR, double res,
double[] normalSunVector, double[] inverseSunVector ) {
int n = 0;
double zcompare = -Double.MAX_VALUE;
double dx = (inverseSunVector[0] * n);
double dy = (inverseSunVector[1] * n);
int nCols = tmpWR.getWidth();
int nRows = tmpWR.getHeight();
int idx = (int) Math.round(i + dx);
int jdy = (int) Math.round(j + dy);
double vectorToOrigin[] = new double[3];
while( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) {
vectorToOrigin[0] = dx * res;
vectorToOrigin[1] = dy * res;
int tmpY = (int) (j + dy);
if (tmpY < 0) {
tmpY = 0;
} else if (tmpY > nRows) {
tmpY = nRows - 1;
}
int tmpX = (int) (i + dx);
if (tmpX < 0) {
tmpX = 0;
} else if (tmpY > nCols) {
tmpX = nCols - 1;
}
vectorToOrigin[2] = demWR.getSampleDouble(idx, jdy, 0);
// vectorToOrigin[2] = (pitRandomIter.getSampleDouble(idx, jdy, 0) +
// pitRandomIter
// .getSampleDouble(tmpX, tmpY, 0)) / 2;
double zprojection = scalarProduct(vectorToOrigin, normalSunVector);
if ((zprojection < zcompare)) {
tmpWR.setSample(idx, jdy, 0, 0);
} else {
zcompare = zprojection;
}
n = n + 1;
dy = (inverseSunVector[1] * n);
dx = (inverseSunVector[0] * n);
idx = (int) Math.round(i + dx);
jdy = (int) Math.round(j + dy);
}
return tmpWR;
} | [
"private",
"static",
"WritableRaster",
"shadow",
"(",
"int",
"i",
",",
"int",
"j",
",",
"WritableRaster",
"tmpWR",
",",
"WritableRaster",
"demWR",
",",
"double",
"res",
",",
"double",
"[",
"]",
"normalSunVector",
",",
"double",
"[",
"]",
"inverseSunVector",
")",
"{",
"int",
"n",
"=",
"0",
";",
"double",
"zcompare",
"=",
"-",
"Double",
".",
"MAX_VALUE",
";",
"double",
"dx",
"=",
"(",
"inverseSunVector",
"[",
"0",
"]",
"*",
"n",
")",
";",
"double",
"dy",
"=",
"(",
"inverseSunVector",
"[",
"1",
"]",
"*",
"n",
")",
";",
"int",
"nCols",
"=",
"tmpWR",
".",
"getWidth",
"(",
")",
";",
"int",
"nRows",
"=",
"tmpWR",
".",
"getHeight",
"(",
")",
";",
"int",
"idx",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"i",
"+",
"dx",
")",
";",
"int",
"jdy",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"j",
"+",
"dy",
")",
";",
"double",
"vectorToOrigin",
"[",
"]",
"=",
"new",
"double",
"[",
"3",
"]",
";",
"while",
"(",
"idx",
">=",
"0",
"&&",
"idx",
"<=",
"nCols",
"-",
"1",
"&&",
"jdy",
">=",
"0",
"&&",
"jdy",
"<=",
"nRows",
"-",
"1",
")",
"{",
"vectorToOrigin",
"[",
"0",
"]",
"=",
"dx",
"*",
"res",
";",
"vectorToOrigin",
"[",
"1",
"]",
"=",
"dy",
"*",
"res",
";",
"int",
"tmpY",
"=",
"(",
"int",
")",
"(",
"j",
"+",
"dy",
")",
";",
"if",
"(",
"tmpY",
"<",
"0",
")",
"{",
"tmpY",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"tmpY",
">",
"nRows",
")",
"{",
"tmpY",
"=",
"nRows",
"-",
"1",
";",
"}",
"int",
"tmpX",
"=",
"(",
"int",
")",
"(",
"i",
"+",
"dx",
")",
";",
"if",
"(",
"tmpX",
"<",
"0",
")",
"{",
"tmpX",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"tmpY",
">",
"nCols",
")",
"{",
"tmpX",
"=",
"nCols",
"-",
"1",
";",
"}",
"vectorToOrigin",
"[",
"2",
"]",
"=",
"demWR",
".",
"getSampleDouble",
"(",
"idx",
",",
"jdy",
",",
"0",
")",
";",
"// vectorToOrigin[2] = (pitRandomIter.getSampleDouble(idx, jdy, 0) +",
"// pitRandomIter",
"// .getSampleDouble(tmpX, tmpY, 0)) / 2;",
"double",
"zprojection",
"=",
"scalarProduct",
"(",
"vectorToOrigin",
",",
"normalSunVector",
")",
";",
"if",
"(",
"(",
"zprojection",
"<",
"zcompare",
")",
")",
"{",
"tmpWR",
".",
"setSample",
"(",
"idx",
",",
"jdy",
",",
"0",
",",
"0",
")",
";",
"}",
"else",
"{",
"zcompare",
"=",
"zprojection",
";",
"}",
"n",
"=",
"n",
"+",
"1",
";",
"dy",
"=",
"(",
"inverseSunVector",
"[",
"1",
"]",
"*",
"n",
")",
";",
"dx",
"=",
"(",
"inverseSunVector",
"[",
"0",
"]",
"*",
"n",
")",
";",
"idx",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"i",
"+",
"dx",
")",
";",
"jdy",
"=",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"j",
"+",
"dy",
")",
";",
"}",
"return",
"tmpWR",
";",
"}"
] | Evaluate the shadow map.
@param i
the x axis index.
@param j
the y axis index.
@param tmpWR
the output shadow map.
@param demWR
the elevation map.
@param res
the resolution of the elevation map.
@param normalSunVector
@param inverseSunVector
@return | [
"Evaluate",
"the",
"shadow",
"map",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1301-L1345 |
137,357 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.meanDoublematrixColumn | public static double meanDoublematrixColumn( double[][] matrix, int column ) {
double mean;
mean = 0;
int length = matrix.length;
for( int i = 0; i < length; i++ ) {
mean += matrix[i][column];
}
return mean / length;
} | java | public static double meanDoublematrixColumn( double[][] matrix, int column ) {
double mean;
mean = 0;
int length = matrix.length;
for( int i = 0; i < length; i++ ) {
mean += matrix[i][column];
}
return mean / length;
} | [
"public",
"static",
"double",
"meanDoublematrixColumn",
"(",
"double",
"[",
"]",
"[",
"]",
"matrix",
",",
"int",
"column",
")",
"{",
"double",
"mean",
";",
"mean",
"=",
"0",
";",
"int",
"length",
"=",
"matrix",
".",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"mean",
"+=",
"matrix",
"[",
"i",
"]",
"[",
"column",
"]",
";",
"}",
"return",
"mean",
"/",
"length",
";",
"}"
] | Return the mean of a column of a matrix.
@param matrix matrix of the value to calculate.
@param column index of the column to calculate the variance.
@return mean. | [
"Return",
"the",
"mean",
"of",
"a",
"column",
"of",
"a",
"matrix",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1396-L1409 |
137,358 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.varianceDoublematrixColumn | public static double varianceDoublematrixColumn( double[][] matrix, int column, double mean )
{
double variance;
variance = 0;
for( int i = 0; i < matrix.length; i++ ) {
variance += (matrix[i][column] - mean) * (matrix[i][column] - mean);
}
return variance / matrix.length;
} | java | public static double varianceDoublematrixColumn( double[][] matrix, int column, double mean )
{
double variance;
variance = 0;
for( int i = 0; i < matrix.length; i++ ) {
variance += (matrix[i][column] - mean) * (matrix[i][column] - mean);
}
return variance / matrix.length;
} | [
"public",
"static",
"double",
"varianceDoublematrixColumn",
"(",
"double",
"[",
"]",
"[",
"]",
"matrix",
",",
"int",
"column",
",",
"double",
"mean",
")",
"{",
"double",
"variance",
";",
"variance",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"matrix",
".",
"length",
";",
"i",
"++",
")",
"{",
"variance",
"+=",
"(",
"matrix",
"[",
"i",
"]",
"[",
"column",
"]",
"-",
"mean",
")",
"*",
"(",
"matrix",
"[",
"i",
"]",
"[",
"column",
"]",
"-",
"mean",
")",
";",
"}",
"return",
"variance",
"/",
"matrix",
".",
"length",
";",
"}"
] | Return the variance of a column of a matrix.
@param matrix matrix of the value to calculate.
@param column index of the column to calculate the variance.
@param mean the mean value of the column.
@return variance. | [
"Return",
"the",
"variance",
"of",
"a",
"column",
"of",
"a",
"matrix",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1419-L1433 |
137,359 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java | ModelsEngine.sumDoublematrixColumns | public static double sumDoublematrixColumns( int coolIndex, double[][] matrixToSum, double[][] resultMatrix,
int firstRowIndex, int lastRowIndex, IHMProgressMonitor pm ) {
double maximum;
maximum = 0;
if (matrixToSum.length != resultMatrix.length) {
pm.errorMessage(msg.message("trentoP.error.matrix")); //$NON-NLS-1$
throw new ArithmeticException(msg.message("trentoP.error.matrix")); //$NON-NLS-1$
}
if (firstRowIndex < 0 || lastRowIndex < firstRowIndex) {
pm.errorMessage(msg.message("trentoP.error.nCol")); //$NON-NLS-1$
throw new ArithmeticException(msg.message("trentoP.error.nCol")); //$NON-NLS-1$
}
for( int i = 0; i < matrixToSum.length; ++i ) {
resultMatrix[i][coolIndex] = 0; /* Initializes element */
for( int j = firstRowIndex; j <= lastRowIndex; ++j ) {
resultMatrix[i][coolIndex] += matrixToSum[i][j];
}
if (resultMatrix[i][coolIndex] >= maximum) /* Saves maximum value */
{
maximum = resultMatrix[i][coolIndex];
}
}
return maximum;
} | java | public static double sumDoublematrixColumns( int coolIndex, double[][] matrixToSum, double[][] resultMatrix,
int firstRowIndex, int lastRowIndex, IHMProgressMonitor pm ) {
double maximum;
maximum = 0;
if (matrixToSum.length != resultMatrix.length) {
pm.errorMessage(msg.message("trentoP.error.matrix")); //$NON-NLS-1$
throw new ArithmeticException(msg.message("trentoP.error.matrix")); //$NON-NLS-1$
}
if (firstRowIndex < 0 || lastRowIndex < firstRowIndex) {
pm.errorMessage(msg.message("trentoP.error.nCol")); //$NON-NLS-1$
throw new ArithmeticException(msg.message("trentoP.error.nCol")); //$NON-NLS-1$
}
for( int i = 0; i < matrixToSum.length; ++i ) {
resultMatrix[i][coolIndex] = 0; /* Initializes element */
for( int j = firstRowIndex; j <= lastRowIndex; ++j ) {
resultMatrix[i][coolIndex] += matrixToSum[i][j];
}
if (resultMatrix[i][coolIndex] >= maximum) /* Saves maximum value */
{
maximum = resultMatrix[i][coolIndex];
}
}
return maximum;
} | [
"public",
"static",
"double",
"sumDoublematrixColumns",
"(",
"int",
"coolIndex",
",",
"double",
"[",
"]",
"[",
"]",
"matrixToSum",
",",
"double",
"[",
"]",
"[",
"]",
"resultMatrix",
",",
"int",
"firstRowIndex",
",",
"int",
"lastRowIndex",
",",
"IHMProgressMonitor",
"pm",
")",
"{",
"double",
"maximum",
";",
"maximum",
"=",
"0",
";",
"if",
"(",
"matrixToSum",
".",
"length",
"!=",
"resultMatrix",
".",
"length",
")",
"{",
"pm",
".",
"errorMessage",
"(",
"msg",
".",
"message",
"(",
"\"trentoP.error.matrix\"",
")",
")",
";",
"//$NON-NLS-1$",
"throw",
"new",
"ArithmeticException",
"(",
"msg",
".",
"message",
"(",
"\"trentoP.error.matrix\"",
")",
")",
";",
"//$NON-NLS-1$",
"}",
"if",
"(",
"firstRowIndex",
"<",
"0",
"||",
"lastRowIndex",
"<",
"firstRowIndex",
")",
"{",
"pm",
".",
"errorMessage",
"(",
"msg",
".",
"message",
"(",
"\"trentoP.error.nCol\"",
")",
")",
";",
"//$NON-NLS-1$",
"throw",
"new",
"ArithmeticException",
"(",
"msg",
".",
"message",
"(",
"\"trentoP.error.nCol\"",
")",
")",
";",
"//$NON-NLS-1$",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"matrixToSum",
".",
"length",
";",
"++",
"i",
")",
"{",
"resultMatrix",
"[",
"i",
"]",
"[",
"coolIndex",
"]",
"=",
"0",
";",
"/* Initializes element */",
"for",
"(",
"int",
"j",
"=",
"firstRowIndex",
";",
"j",
"<=",
"lastRowIndex",
";",
"++",
"j",
")",
"{",
"resultMatrix",
"[",
"i",
"]",
"[",
"coolIndex",
"]",
"+=",
"matrixToSum",
"[",
"i",
"]",
"[",
"j",
"]",
";",
"}",
"if",
"(",
"resultMatrix",
"[",
"i",
"]",
"[",
"coolIndex",
"]",
">=",
"maximum",
")",
"/* Saves maximum value */",
"{",
"maximum",
"=",
"resultMatrix",
"[",
"i",
"]",
"[",
"coolIndex",
"]",
";",
"}",
"}",
"return",
"maximum",
";",
"}"
] | Sum columns.
<p>
Store in a matrix (at index coulumn), the sum of the column of another
matrix. It's necessary to specify the initial and final index of the
coluns to sum.
</p>
@param coolIndex index of the matrix2 where to put the result.
@param matrixToSum contains the value to sum.
@param resultMatrix where to put the result.
@param firstRowIndex initial index of the colum to sum.
@param lastRowIndex final index of the colum to sum.
@return maximum value of the colum index of the matrix2. | [
"Sum",
"columns",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/ModelsEngine.java#L1452-L1482 |
137,360 | enasequence/sequencetools | src/main/java/uk/ac/ebi/embl/api/entry/location/CompoundLocation.java | CompoundLocation.getRelativePosition | public Long getRelativePosition(Long position) {
long relativePosition = 0L;
for (Location location : locations) {
if (location instanceof RemoteLocation) {
relativePosition += location.getLength();
} else {
if (position < location.getBeginPosition()
|| position > location.getEndPosition()) {
relativePosition += location.getLength();
} else {
if (location.isComplement()) {
relativePosition += (location.getEndPosition()
- position + 1);
} else {
relativePosition += (position
- location.getBeginPosition() + 1);
}
if (isComplement()) {
relativePosition = getLength() - relativePosition + 1;
}
return relativePosition;
}
}
}
return null;
} | java | public Long getRelativePosition(Long position) {
long relativePosition = 0L;
for (Location location : locations) {
if (location instanceof RemoteLocation) {
relativePosition += location.getLength();
} else {
if (position < location.getBeginPosition()
|| position > location.getEndPosition()) {
relativePosition += location.getLength();
} else {
if (location.isComplement()) {
relativePosition += (location.getEndPosition()
- position + 1);
} else {
relativePosition += (position
- location.getBeginPosition() + 1);
}
if (isComplement()) {
relativePosition = getLength() - relativePosition + 1;
}
return relativePosition;
}
}
}
return null;
} | [
"public",
"Long",
"getRelativePosition",
"(",
"Long",
"position",
")",
"{",
"long",
"relativePosition",
"=",
"0L",
";",
"for",
"(",
"Location",
"location",
":",
"locations",
")",
"{",
"if",
"(",
"location",
"instanceof",
"RemoteLocation",
")",
"{",
"relativePosition",
"+=",
"location",
".",
"getLength",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"position",
"<",
"location",
".",
"getBeginPosition",
"(",
")",
"||",
"position",
">",
"location",
".",
"getEndPosition",
"(",
")",
")",
"{",
"relativePosition",
"+=",
"location",
".",
"getLength",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"location",
".",
"isComplement",
"(",
")",
")",
"{",
"relativePosition",
"+=",
"(",
"location",
".",
"getEndPosition",
"(",
")",
"-",
"position",
"+",
"1",
")",
";",
"}",
"else",
"{",
"relativePosition",
"+=",
"(",
"position",
"-",
"location",
".",
"getBeginPosition",
"(",
")",
"+",
"1",
")",
";",
"}",
"if",
"(",
"isComplement",
"(",
")",
")",
"{",
"relativePosition",
"=",
"getLength",
"(",
")",
"-",
"relativePosition",
"+",
"1",
";",
"}",
"return",
"relativePosition",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the sequence position relative to the compound location.
@param position
the local sequence position.
@return the relative position. | [
"Returns",
"the",
"sequence",
"position",
"relative",
"to",
"the",
"compound",
"location",
"."
] | 4127f5e1a17540239f5810136153fbd6737fa262 | https://github.com/enasequence/sequencetools/blob/4127f5e1a17540239f5810136153fbd6737fa262/src/main/java/uk/ac/ebi/embl/api/entry/location/CompoundLocation.java#L109-L134 |
137,361 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.concatOr | protected boolean concatOr( boolean... statements ) {
boolean isTrue = statements[0];
for( int i = 1; i < statements.length; i++ ) {
isTrue = isTrue || statements[i];
}
return isTrue;
} | java | protected boolean concatOr( boolean... statements ) {
boolean isTrue = statements[0];
for( int i = 1; i < statements.length; i++ ) {
isTrue = isTrue || statements[i];
}
return isTrue;
} | [
"protected",
"boolean",
"concatOr",
"(",
"boolean",
"...",
"statements",
")",
"{",
"boolean",
"isTrue",
"=",
"statements",
"[",
"0",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"statements",
".",
"length",
";",
"i",
"++",
")",
"{",
"isTrue",
"=",
"isTrue",
"||",
"statements",
"[",
"i",
"]",
";",
"}",
"return",
"isTrue",
";",
"}"
] | Utility method to concatenate conditions with or.
<p>
This can be useful for readability (in case of negation).
</p>
@param statements a list of statements.
@return the final boolean from the or concatenation. | [
"Utility",
"method",
"to",
"concatenate",
"conditions",
"with",
"or",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L213-L219 |
137,362 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.checkNull | protected void checkNull( Object... objects ) {
for( Object object : objects ) {
if (object == null) {
throw new ModelsIllegalargumentException("Mandatory input argument is missing. Check your syntax...",
this.getClass().getSimpleName(), pm);
}
}
} | java | protected void checkNull( Object... objects ) {
for( Object object : objects ) {
if (object == null) {
throw new ModelsIllegalargumentException("Mandatory input argument is missing. Check your syntax...",
this.getClass().getSimpleName(), pm);
}
}
} | [
"protected",
"void",
"checkNull",
"(",
"Object",
"...",
"objects",
")",
"{",
"for",
"(",
"Object",
"object",
":",
"objects",
")",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"throw",
"new",
"ModelsIllegalargumentException",
"(",
"\"Mandatory input argument is missing. Check your syntax...\"",
",",
"this",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
",",
"pm",
")",
";",
"}",
"}",
"}"
] | Checks if the passed objects are all != null and if one is null, throws Exception.
@param objects the objects to check. | [
"Checks",
"if",
"the",
"passed",
"objects",
"are",
"all",
"!",
"=",
"null",
"and",
"if",
"one",
"is",
"null",
"throws",
"Exception",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L226-L233 |
137,363 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.checkFileExists | protected void checkFileExists( String... existingFilePath ) {
StringBuilder sb = null;
for( String filePath : existingFilePath ) {
File file = new File(filePath);
if (!file.exists()) {
if (sb == null) {
sb = new StringBuilder();
sb.append("The following file doesn't seem to exist: ");
}
sb.append("\n\t").append(file.getAbsolutePath());
}
}
if (sb != null)
throw new ModelsIllegalargumentException(sb.toString(), this.getClass().getSimpleName(), pm);
} | java | protected void checkFileExists( String... existingFilePath ) {
StringBuilder sb = null;
for( String filePath : existingFilePath ) {
File file = new File(filePath);
if (!file.exists()) {
if (sb == null) {
sb = new StringBuilder();
sb.append("The following file doesn't seem to exist: ");
}
sb.append("\n\t").append(file.getAbsolutePath());
}
}
if (sb != null)
throw new ModelsIllegalargumentException(sb.toString(), this.getClass().getSimpleName(), pm);
} | [
"protected",
"void",
"checkFileExists",
"(",
"String",
"...",
"existingFilePath",
")",
"{",
"StringBuilder",
"sb",
"=",
"null",
";",
"for",
"(",
"String",
"filePath",
":",
"existingFilePath",
")",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"filePath",
")",
";",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"sb",
"==",
"null",
")",
"{",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"sb",
".",
"append",
"(",
"\"The following file doesn't seem to exist: \"",
")",
";",
"}",
"sb",
".",
"append",
"(",
"\"\\n\\t\"",
")",
".",
"append",
"(",
"file",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"sb",
"!=",
"null",
")",
"throw",
"new",
"ModelsIllegalargumentException",
"(",
"sb",
".",
"toString",
"(",
")",
",",
"this",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
",",
"pm",
")",
";",
"}"
] | Checks if passed path strings exist on the filesystem. If not, an Exception is thrown.
@param existingFilePath one or more file paths that need to exist. | [
"Checks",
"if",
"passed",
"path",
"strings",
"exist",
"on",
"the",
"filesystem",
".",
"If",
"not",
"an",
"Exception",
"is",
"thrown",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L240-L254 |
137,364 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.checkWorkingFolderInPath | protected String checkWorkingFolderInPath( String filePath ) {
if (filePath.contains(HMConstants.WORKINGFOLDER)) {
return null;
}
return filePath;
} | java | protected String checkWorkingFolderInPath( String filePath ) {
if (filePath.contains(HMConstants.WORKINGFOLDER)) {
return null;
}
return filePath;
} | [
"protected",
"String",
"checkWorkingFolderInPath",
"(",
"String",
"filePath",
")",
"{",
"if",
"(",
"filePath",
".",
"contains",
"(",
"HMConstants",
".",
"WORKINGFOLDER",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"filePath",
";",
"}"
] | Checks if a passed path contains the workingfolder constant. If yes it is set to null.
@param filePath the path to check.
@return the path or null. | [
"Checks",
"if",
"a",
"passed",
"path",
"contains",
"the",
"workingfolder",
"constant",
".",
"If",
"yes",
"it",
"is",
"set",
"to",
"null",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L262-L267 |
137,365 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.getRaster | public GridCoverage2D getRaster( String source ) throws Exception {
if (source == null || source.trim().length() == 0)
return null;
OmsRasterReader reader = new OmsRasterReader();
reader.pm = pm;
reader.file = source;
reader.process();
GridCoverage2D geodata = reader.outRaster;
return geodata;
} | java | public GridCoverage2D getRaster( String source ) throws Exception {
if (source == null || source.trim().length() == 0)
return null;
OmsRasterReader reader = new OmsRasterReader();
reader.pm = pm;
reader.file = source;
reader.process();
GridCoverage2D geodata = reader.outRaster;
return geodata;
} | [
"public",
"GridCoverage2D",
"getRaster",
"(",
"String",
"source",
")",
"throws",
"Exception",
"{",
"if",
"(",
"source",
"==",
"null",
"||",
"source",
".",
"trim",
"(",
")",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"null",
";",
"OmsRasterReader",
"reader",
"=",
"new",
"OmsRasterReader",
"(",
")",
";",
"reader",
".",
"pm",
"=",
"pm",
";",
"reader",
".",
"file",
"=",
"source",
";",
"reader",
".",
"process",
"(",
")",
";",
"GridCoverage2D",
"geodata",
"=",
"reader",
".",
"outRaster",
";",
"return",
"geodata",
";",
"}"
] | Fast default reading of raster from definition.
<p>If the source format is not supported, and {@link Exception} is thrown.</p>
<p>If the source is <code>null</code>, null will be returned.</p>
@param source the definition for the raster source.
@return the read {@link GridCoverage2D}.
@throws Exception | [
"Fast",
"default",
"reading",
"of",
"raster",
"from",
"definition",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L279-L288 |
137,366 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.getVector | public SimpleFeatureCollection getVector( String source ) throws Exception {
if (source == null || source.trim().length() == 0)
return null;
OmsVectorReader reader = new OmsVectorReader();
reader.pm = pm;
reader.file = source;
reader.process();
SimpleFeatureCollection fc = reader.outVector;
return fc;
} | java | public SimpleFeatureCollection getVector( String source ) throws Exception {
if (source == null || source.trim().length() == 0)
return null;
OmsVectorReader reader = new OmsVectorReader();
reader.pm = pm;
reader.file = source;
reader.process();
SimpleFeatureCollection fc = reader.outVector;
return fc;
} | [
"public",
"SimpleFeatureCollection",
"getVector",
"(",
"String",
"source",
")",
"throws",
"Exception",
"{",
"if",
"(",
"source",
"==",
"null",
"||",
"source",
".",
"trim",
"(",
")",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"null",
";",
"OmsVectorReader",
"reader",
"=",
"new",
"OmsVectorReader",
"(",
")",
";",
"reader",
".",
"pm",
"=",
"pm",
";",
"reader",
".",
"file",
"=",
"source",
";",
"reader",
".",
"process",
"(",
")",
";",
"SimpleFeatureCollection",
"fc",
"=",
"reader",
".",
"outVector",
";",
"return",
"fc",
";",
"}"
] | Fast default reading of vector from definition.
<p>If the source format is not supported, and {@link Exception} is thrown.</p>
<p>If the source is <code>null</code>, null will be returned.</p>
@param source the definition to the vector source.
@return the read {@link GridCoverage2D}.
@throws Exception | [
"Fast",
"default",
"reading",
"of",
"vector",
"from",
"definition",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L300-L309 |
137,367 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.dumpRaster | public void dumpRaster( GridCoverage2D raster, String source ) throws Exception {
if (raster == null || source == null)
return;
OmsRasterWriter writer = new OmsRasterWriter();
writer.pm = pm;
writer.inRaster = raster;
writer.file = source;
writer.process();
} | java | public void dumpRaster( GridCoverage2D raster, String source ) throws Exception {
if (raster == null || source == null)
return;
OmsRasterWriter writer = new OmsRasterWriter();
writer.pm = pm;
writer.inRaster = raster;
writer.file = source;
writer.process();
} | [
"public",
"void",
"dumpRaster",
"(",
"GridCoverage2D",
"raster",
",",
"String",
"source",
")",
"throws",
"Exception",
"{",
"if",
"(",
"raster",
"==",
"null",
"||",
"source",
"==",
"null",
")",
"return",
";",
"OmsRasterWriter",
"writer",
"=",
"new",
"OmsRasterWriter",
"(",
")",
";",
"writer",
".",
"pm",
"=",
"pm",
";",
"writer",
".",
"inRaster",
"=",
"raster",
";",
"writer",
".",
"file",
"=",
"source",
";",
"writer",
".",
"process",
"(",
")",
";",
"}"
] | Fast default writing of raster to source.
<p>Mind that if either raster or source are <code>null</code>, the method will
return without warning.</p>
@param raster the {@link GridCoverage2D} to write.
@param source the source to which to write to.
@throws Exception | [
"Fast",
"default",
"writing",
"of",
"raster",
"to",
"source",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L321-L329 |
137,368 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java | HMModel.dumpVector | public void dumpVector( SimpleFeatureCollection vector, String source ) throws Exception {
if (vector == null || source == null)
return;
OmsVectorWriter writer = new OmsVectorWriter();
writer.pm = pm;
writer.file = source;
writer.inVector = vector;
writer.process();
} | java | public void dumpVector( SimpleFeatureCollection vector, String source ) throws Exception {
if (vector == null || source == null)
return;
OmsVectorWriter writer = new OmsVectorWriter();
writer.pm = pm;
writer.file = source;
writer.inVector = vector;
writer.process();
} | [
"public",
"void",
"dumpVector",
"(",
"SimpleFeatureCollection",
"vector",
",",
"String",
"source",
")",
"throws",
"Exception",
"{",
"if",
"(",
"vector",
"==",
"null",
"||",
"source",
"==",
"null",
")",
"return",
";",
"OmsVectorWriter",
"writer",
"=",
"new",
"OmsVectorWriter",
"(",
")",
";",
"writer",
".",
"pm",
"=",
"pm",
";",
"writer",
".",
"file",
"=",
"source",
";",
"writer",
".",
"inVector",
"=",
"vector",
";",
"writer",
".",
"process",
"(",
")",
";",
"}"
] | Fast default writing of vector to source.
<p>Mind that if either vector or source are <code>null</code>, the method will
return without warning.</p>
@param vector the {@link SimpleFeatureCollection} to write.
@param source the source to which to write to.
@throws Exception | [
"Fast",
"default",
"writing",
"of",
"vector",
"to",
"source",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/libs/modules/HMModel.java#L341-L349 |
137,369 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.setParameter | public void setParameter( String key, Object obj ) {
if (key.equals("novalue")) { //$NON-NLS-1$
novalue = obj;
} else if (key.equals("matrixtype")) { //$NON-NLS-1$
Integer dmtype = (Integer) obj;
matrixType = dmtype.intValue();
}
} | java | public void setParameter( String key, Object obj ) {
if (key.equals("novalue")) { //$NON-NLS-1$
novalue = obj;
} else if (key.equals("matrixtype")) { //$NON-NLS-1$
Integer dmtype = (Integer) obj;
matrixType = dmtype.intValue();
}
} | [
"public",
"void",
"setParameter",
"(",
"String",
"key",
",",
"Object",
"obj",
")",
"{",
"if",
"(",
"key",
".",
"equals",
"(",
"\"novalue\"",
")",
")",
"{",
"//$NON-NLS-1$",
"novalue",
"=",
"obj",
";",
"}",
"else",
"if",
"(",
"key",
".",
"equals",
"(",
"\"matrixtype\"",
")",
")",
"{",
"//$NON-NLS-1$",
"Integer",
"dmtype",
"=",
"(",
"Integer",
")",
"obj",
";",
"matrixType",
"=",
"dmtype",
".",
"intValue",
"(",
")",
";",
"}",
"}"
] | utility to set particular parameters | [
"utility",
"to",
"set",
"particular",
"parameters"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L422-L429 |
137,370 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.readHeader | private ByteBuffer readHeader( RandomAccessFile ds ) throws IOException {
/*
* the first byte defines the number of bytes are used to describe the row addresses in the
* header (once it was sizeof(long) in grass but then it was turned to an offset (that
* brought to reading problems in JGrass whenever the offset was != 4).
*/
int first = ds.read();
ByteBuffer fileHeader = ByteBuffer.allocate(1 + first * fileWindow.getRows() + first);
ds.seek(0);
/* Read header */
ds.read(fileHeader.array());
return fileHeader;
} | java | private ByteBuffer readHeader( RandomAccessFile ds ) throws IOException {
/*
* the first byte defines the number of bytes are used to describe the row addresses in the
* header (once it was sizeof(long) in grass but then it was turned to an offset (that
* brought to reading problems in JGrass whenever the offset was != 4).
*/
int first = ds.read();
ByteBuffer fileHeader = ByteBuffer.allocate(1 + first * fileWindow.getRows() + first);
ds.seek(0);
/* Read header */
ds.read(fileHeader.array());
return fileHeader;
} | [
"private",
"ByteBuffer",
"readHeader",
"(",
"RandomAccessFile",
"ds",
")",
"throws",
"IOException",
"{",
"/*\n * the first byte defines the number of bytes are used to describe the row addresses in the\n * header (once it was sizeof(long) in grass but then it was turned to an offset (that\n * brought to reading problems in JGrass whenever the offset was != 4).\n */",
"int",
"first",
"=",
"ds",
".",
"read",
"(",
")",
";",
"ByteBuffer",
"fileHeader",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"1",
"+",
"first",
"*",
"fileWindow",
".",
"getRows",
"(",
")",
"+",
"first",
")",
";",
"ds",
".",
"seek",
"(",
"0",
")",
";",
"/* Read header */",
"ds",
".",
"read",
"(",
"fileHeader",
".",
"array",
"(",
")",
")",
";",
"return",
"fileHeader",
";",
"}"
] | Reads the header part of the file into memory | [
"Reads",
"the",
"header",
"part",
"of",
"the",
"file",
"into",
"memory"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L446-L462 |
137,371 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.getRowAddressesFromHeader | private long[] getRowAddressesFromHeader( ByteBuffer header ) {
/*
* Jump over the no more needed first byte (used in readHeader to define the header size)
*/
byte firstbyte = header.get();
/* Read the data row addresses inside the file */
long[] adrows = new long[fileWindow.getRows() + 1];
if (firstbyte == 4) {
for( int i = 0; i <= fileWindow.getRows(); i++ ) {
adrows[i] = header.getInt();
}
} else if (firstbyte == 8) {
for( int i = 0; i <= fileWindow.getRows(); i++ ) {
adrows[i] = header.getLong();
}
} else {
// problems
}
return adrows;
} | java | private long[] getRowAddressesFromHeader( ByteBuffer header ) {
/*
* Jump over the no more needed first byte (used in readHeader to define the header size)
*/
byte firstbyte = header.get();
/* Read the data row addresses inside the file */
long[] adrows = new long[fileWindow.getRows() + 1];
if (firstbyte == 4) {
for( int i = 0; i <= fileWindow.getRows(); i++ ) {
adrows[i] = header.getInt();
}
} else if (firstbyte == 8) {
for( int i = 0; i <= fileWindow.getRows(); i++ ) {
adrows[i] = header.getLong();
}
} else {
// problems
}
return adrows;
} | [
"private",
"long",
"[",
"]",
"getRowAddressesFromHeader",
"(",
"ByteBuffer",
"header",
")",
"{",
"/*\n * Jump over the no more needed first byte (used in readHeader to define the header size)\n */",
"byte",
"firstbyte",
"=",
"header",
".",
"get",
"(",
")",
";",
"/* Read the data row addresses inside the file */",
"long",
"[",
"]",
"adrows",
"=",
"new",
"long",
"[",
"fileWindow",
".",
"getRows",
"(",
")",
"+",
"1",
"]",
";",
"if",
"(",
"firstbyte",
"==",
"4",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<=",
"fileWindow",
".",
"getRows",
"(",
")",
";",
"i",
"++",
")",
"{",
"adrows",
"[",
"i",
"]",
"=",
"header",
".",
"getInt",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"firstbyte",
"==",
"8",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<=",
"fileWindow",
".",
"getRows",
"(",
")",
";",
"i",
"++",
")",
"{",
"adrows",
"[",
"i",
"]",
"=",
"header",
".",
"getLong",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// problems",
"}",
"return",
"adrows",
";",
"}"
] | Extract the row addresses from the header information of the file | [
"Extract",
"the",
"row",
"addresses",
"from",
"the",
"header",
"information",
"of",
"the",
"file"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L467-L487 |
137,372 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.getMapRow | private void getMapRow( int currentrow, ByteBuffer rowdata, boolean iscompressed ) throws IOException, DataFormatException {
// if (logger.isDebugEnabled())
// {
// logger.debug("ACCESSING THE FILE at row: " + currentrow +
// ", rasterMapType = " + rasterMapType +
// ", numberOfBytesPerValue = " + numberOfBytesPerValue +
// ", iscompressed = " + iscompressed);
// }
if (iscompressed) {
/* Compressed maps */
if (rasterMapType == -2) {
/* Compressed double map */
readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
} else if (rasterMapType == -1) {
/* Compressed floating point map */
readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
} else if (rasterMapType > 0) {
/* Compressed integer map */
readCompressedIntegerRowByNumber(rowdata, currentrow, addressesofrows, cellFile);
} else {
// if (logger.isDebugEnabled())
// logger.error("format not double nor float");
}
} else {
if (rasterMapType < 0) {
/* Uncompressed floating point map */
readUncompressedFPRowByNumber(rowdata, currentrow, cellFile, numberOfBytesPerValue);
} else if (rasterMapType > 0) {
/* Uncompressed integer map */
readUncompressedIntegerRowByNumber(rowdata, currentrow, cellFile);
} else {
// if (logger.isDebugEnabled())
// logger.error("Unknown case, iscompressed=" + iscompressed
// + ", compressed=" + compressed + ", rasterMapType="
// + rasterMapType);
}
}
return;
} | java | private void getMapRow( int currentrow, ByteBuffer rowdata, boolean iscompressed ) throws IOException, DataFormatException {
// if (logger.isDebugEnabled())
// {
// logger.debug("ACCESSING THE FILE at row: " + currentrow +
// ", rasterMapType = " + rasterMapType +
// ", numberOfBytesPerValue = " + numberOfBytesPerValue +
// ", iscompressed = " + iscompressed);
// }
if (iscompressed) {
/* Compressed maps */
if (rasterMapType == -2) {
/* Compressed double map */
readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
} else if (rasterMapType == -1) {
/* Compressed floating point map */
readCompressedFPRowByNumber(rowdata, currentrow, addressesofrows, cellFile, numberOfBytesPerValue);
} else if (rasterMapType > 0) {
/* Compressed integer map */
readCompressedIntegerRowByNumber(rowdata, currentrow, addressesofrows, cellFile);
} else {
// if (logger.isDebugEnabled())
// logger.error("format not double nor float");
}
} else {
if (rasterMapType < 0) {
/* Uncompressed floating point map */
readUncompressedFPRowByNumber(rowdata, currentrow, cellFile, numberOfBytesPerValue);
} else if (rasterMapType > 0) {
/* Uncompressed integer map */
readUncompressedIntegerRowByNumber(rowdata, currentrow, cellFile);
} else {
// if (logger.isDebugEnabled())
// logger.error("Unknown case, iscompressed=" + iscompressed
// + ", compressed=" + compressed + ", rasterMapType="
// + rasterMapType);
}
}
return;
} | [
"private",
"void",
"getMapRow",
"(",
"int",
"currentrow",
",",
"ByteBuffer",
"rowdata",
",",
"boolean",
"iscompressed",
")",
"throws",
"IOException",
",",
"DataFormatException",
"{",
"// if (logger.isDebugEnabled())",
"// {",
"// logger.debug(\"ACCESSING THE FILE at row: \" + currentrow +",
"// \", rasterMapType = \" + rasterMapType +",
"// \", numberOfBytesPerValue = \" + numberOfBytesPerValue +",
"// \", iscompressed = \" + iscompressed);",
"// }",
"if",
"(",
"iscompressed",
")",
"{",
"/* Compressed maps */",
"if",
"(",
"rasterMapType",
"==",
"-",
"2",
")",
"{",
"/* Compressed double map */",
"readCompressedFPRowByNumber",
"(",
"rowdata",
",",
"currentrow",
",",
"addressesofrows",
",",
"cellFile",
",",
"numberOfBytesPerValue",
")",
";",
"}",
"else",
"if",
"(",
"rasterMapType",
"==",
"-",
"1",
")",
"{",
"/* Compressed floating point map */",
"readCompressedFPRowByNumber",
"(",
"rowdata",
",",
"currentrow",
",",
"addressesofrows",
",",
"cellFile",
",",
"numberOfBytesPerValue",
")",
";",
"}",
"else",
"if",
"(",
"rasterMapType",
">",
"0",
")",
"{",
"/* Compressed integer map */",
"readCompressedIntegerRowByNumber",
"(",
"rowdata",
",",
"currentrow",
",",
"addressesofrows",
",",
"cellFile",
")",
";",
"}",
"else",
"{",
"// if (logger.isDebugEnabled())",
"// logger.error(\"format not double nor float\");",
"}",
"}",
"else",
"{",
"if",
"(",
"rasterMapType",
"<",
"0",
")",
"{",
"/* Uncompressed floating point map */",
"readUncompressedFPRowByNumber",
"(",
"rowdata",
",",
"currentrow",
",",
"cellFile",
",",
"numberOfBytesPerValue",
")",
";",
"}",
"else",
"if",
"(",
"rasterMapType",
">",
"0",
")",
"{",
"/* Uncompressed integer map */",
"readUncompressedIntegerRowByNumber",
"(",
"rowdata",
",",
"currentrow",
",",
"cellFile",
")",
";",
"}",
"else",
"{",
"// if (logger.isDebugEnabled())",
"// logger.error(\"Unknown case, iscompressed=\" + iscompressed",
"// + \", compressed=\" + compressed + \", rasterMapType=\"",
"// + rasterMapType);",
"}",
"}",
"return",
";",
"}"
] | read a row of the map from the active region
@param currentrow
@param iscompressed
@return
@throws IOException
@throws DataFormatException | [
"read",
"a",
"row",
"of",
"the",
"map",
"from",
"the",
"active",
"region"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L1012-L1051 |
137,373 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.readCompressedFPRowByNumber | private void readCompressedFPRowByNumber( ByteBuffer rowdata, int rn, long[] adrows, RandomAccessFile thefile, int typeBytes )
throws DataFormatException, IOException {
int offset = (int) (adrows[rn + 1] - adrows[rn]);
/*
* The fact that the file is compressed does not mean that the row is compressed. If the
* first byte is 0 (49), then the row is compressed, otherwise (first byte = 48) the row has
* to be read in simple XDR uncompressed format.
*/
byte[] tmp = new byte[offset - 1];
thefile.seek(adrows[rn]);
int firstbyte = (thefile.read() & 0xff);
if (firstbyte == 49) {
/* The row is compressed. */
// thefile.seek((long) adrows[rn] + 1);
thefile.read(tmp, 0, offset - 1);
Inflater decompresser = new Inflater();
decompresser.setInput(tmp, 0, tmp.length);
decompresser.inflate(rowdata.array());
decompresser.end();
} else if (firstbyte == 48) {
/* The row is NOT compressed */
// thefile.seek((long) (adrows[rn]));
// if (thefile.read() == 48)
// {
// thefile.seek((long) (adrows[rn] + 1));
thefile.read(rowdata.array(), 0, offset - 1);
// }
}
} | java | private void readCompressedFPRowByNumber( ByteBuffer rowdata, int rn, long[] adrows, RandomAccessFile thefile, int typeBytes )
throws DataFormatException, IOException {
int offset = (int) (adrows[rn + 1] - adrows[rn]);
/*
* The fact that the file is compressed does not mean that the row is compressed. If the
* first byte is 0 (49), then the row is compressed, otherwise (first byte = 48) the row has
* to be read in simple XDR uncompressed format.
*/
byte[] tmp = new byte[offset - 1];
thefile.seek(adrows[rn]);
int firstbyte = (thefile.read() & 0xff);
if (firstbyte == 49) {
/* The row is compressed. */
// thefile.seek((long) adrows[rn] + 1);
thefile.read(tmp, 0, offset - 1);
Inflater decompresser = new Inflater();
decompresser.setInput(tmp, 0, tmp.length);
decompresser.inflate(rowdata.array());
decompresser.end();
} else if (firstbyte == 48) {
/* The row is NOT compressed */
// thefile.seek((long) (adrows[rn]));
// if (thefile.read() == 48)
// {
// thefile.seek((long) (adrows[rn] + 1));
thefile.read(rowdata.array(), 0, offset - 1);
// }
}
} | [
"private",
"void",
"readCompressedFPRowByNumber",
"(",
"ByteBuffer",
"rowdata",
",",
"int",
"rn",
",",
"long",
"[",
"]",
"adrows",
",",
"RandomAccessFile",
"thefile",
",",
"int",
"typeBytes",
")",
"throws",
"DataFormatException",
",",
"IOException",
"{",
"int",
"offset",
"=",
"(",
"int",
")",
"(",
"adrows",
"[",
"rn",
"+",
"1",
"]",
"-",
"adrows",
"[",
"rn",
"]",
")",
";",
"/*\n * The fact that the file is compressed does not mean that the row is compressed. If the\n * first byte is 0 (49), then the row is compressed, otherwise (first byte = 48) the row has\n * to be read in simple XDR uncompressed format.\n */",
"byte",
"[",
"]",
"tmp",
"=",
"new",
"byte",
"[",
"offset",
"-",
"1",
"]",
";",
"thefile",
".",
"seek",
"(",
"adrows",
"[",
"rn",
"]",
")",
";",
"int",
"firstbyte",
"=",
"(",
"thefile",
".",
"read",
"(",
")",
"&",
"0xff",
")",
";",
"if",
"(",
"firstbyte",
"==",
"49",
")",
"{",
"/* The row is compressed. */",
"// thefile.seek((long) adrows[rn] + 1);",
"thefile",
".",
"read",
"(",
"tmp",
",",
"0",
",",
"offset",
"-",
"1",
")",
";",
"Inflater",
"decompresser",
"=",
"new",
"Inflater",
"(",
")",
";",
"decompresser",
".",
"setInput",
"(",
"tmp",
",",
"0",
",",
"tmp",
".",
"length",
")",
";",
"decompresser",
".",
"inflate",
"(",
"rowdata",
".",
"array",
"(",
")",
")",
";",
"decompresser",
".",
"end",
"(",
")",
";",
"}",
"else",
"if",
"(",
"firstbyte",
"==",
"48",
")",
"{",
"/* The row is NOT compressed */",
"// thefile.seek((long) (adrows[rn]));",
"// if (thefile.read() == 48)",
"// {",
"// thefile.seek((long) (adrows[rn] + 1));",
"thefile",
".",
"read",
"(",
"rowdata",
".",
"array",
"(",
")",
",",
"0",
",",
"offset",
"-",
"1",
")",
";",
"// }",
"}",
"}"
] | read a row of data from a compressed floating point map
@param rn
@param adrows
@param outFile
@param typeBytes
@return the ByteBuffer containing the data
@throws IOException
@throws DataFormatException | [
"read",
"a",
"row",
"of",
"data",
"from",
"a",
"compressed",
"floating",
"point",
"map"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L1064-L1092 |
137,374 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.readUncompressedFPRowByNumber | private void readUncompressedFPRowByNumber( ByteBuffer rowdata, int rn, RandomAccessFile thefile, int typeBytes )
throws IOException, DataFormatException {
int datanumber = fileWindow.getCols() * typeBytes;
thefile.seek((rn * datanumber));
thefile.read(rowdata.array());
} | java | private void readUncompressedFPRowByNumber( ByteBuffer rowdata, int rn, RandomAccessFile thefile, int typeBytes )
throws IOException, DataFormatException {
int datanumber = fileWindow.getCols() * typeBytes;
thefile.seek((rn * datanumber));
thefile.read(rowdata.array());
} | [
"private",
"void",
"readUncompressedFPRowByNumber",
"(",
"ByteBuffer",
"rowdata",
",",
"int",
"rn",
",",
"RandomAccessFile",
"thefile",
",",
"int",
"typeBytes",
")",
"throws",
"IOException",
",",
"DataFormatException",
"{",
"int",
"datanumber",
"=",
"fileWindow",
".",
"getCols",
"(",
")",
"*",
"typeBytes",
";",
"thefile",
".",
"seek",
"(",
"(",
"rn",
"*",
"datanumber",
")",
")",
";",
"thefile",
".",
"read",
"(",
"rowdata",
".",
"array",
"(",
")",
")",
";",
"}"
] | read a row of data from an uncompressed floating point map
@param rn
@param outFile
@param typeBytes
@return the ByteBuffer containing the data
@throws IOException
@throws DataFormatException | [
"read",
"a",
"row",
"of",
"data",
"from",
"an",
"uncompressed",
"floating",
"point",
"map"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L1104-L1110 |
137,375 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.readCompressedIntegerRowByNumber | private void readCompressedIntegerRowByNumber( ByteBuffer rowdata, int rn, long[] adrows, RandomAccessFile thefile )
throws IOException, DataFormatException {
int offset = (int) (adrows[rn + 1] - adrows[rn]);
thefile.seek(adrows[rn]);
/*
* Read how many bytes the values are ex 1 => if encoded: 1 byte for the value and one byte
* for the count = 2 2 => if encoded: 2 bytes for the value and one byte for the count = 3
* etc... etc
*/
int bytespervalue = (thefile.read() & 0xff);
ByteBuffer cell = ByteBuffer.allocate(bytespervalue);
int cellValue = 0;
/* Create the buffer in which read the compressed row */
byte[] tmp = new byte[offset - 1];
thefile.read(tmp);
ByteBuffer tmpBuffer = ByteBuffer.wrap(tmp);
tmpBuffer.order(ByteOrder.nativeOrder());
/*
* Create the buffer in which read the decompressed row. The final decompressed row will
* always contain 4-byte integer values
*/
if ((offset - 1) == (bytespervalue * fileWindow.getCols())) {
/* There is no compression in this row */
for( int i = 0; i < offset - 1; i = i + bytespervalue ) {
/* Read the value */
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
* need to pad them with 0's. The order of the padding is determined by the
* ByteOrder of the buffer.
*/
if (bytespervalue == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (bytespervalue == 2) {
cellValue = cell.getShort(0);
} else if (bytespervalue == 4) {
cellValue = cell.getInt(0);
}
// if (logger.isDebugEnabled()) logger.debug("tmpint=" + tmpint
// );
rowdata.putInt(cellValue);
}
} else {
/*
* If the row is compressed, then the values appear in pairs (like couples a party). The
* couple is composed of the count and the value value (WARNING: this can be more than
* one byte). Therefore, knowing the length of the compressed row we can calculate the
* number of couples.
*/
int couples = (offset - 1) / (1 + bytespervalue);
for( int i = 0; i < couples; i++ ) {
/* Read the count of values */
int count = (tmpBuffer.get() & 0xff);
/* Read the value */
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
* need to pad them with 0's. The order of the padding is determined by the
* ByteOrder of the buffer.
*/
if (bytespervalue == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (bytespervalue == 2) {
cellValue = cell.getShort(0);
} else if (bytespervalue == 4) {
cellValue = cell.getInt(0);
}
/*
* Now write the cell value the required number of times to the raster row data
* buffer.
*/
for( int j = 0; j < count; j++ ) {
// // if (logger.isDebugEnabled()) logger.debug(" " +
// tmpint);
rowdata.putInt(cellValue);
}
}
}
} | java | private void readCompressedIntegerRowByNumber( ByteBuffer rowdata, int rn, long[] adrows, RandomAccessFile thefile )
throws IOException, DataFormatException {
int offset = (int) (adrows[rn + 1] - adrows[rn]);
thefile.seek(adrows[rn]);
/*
* Read how many bytes the values are ex 1 => if encoded: 1 byte for the value and one byte
* for the count = 2 2 => if encoded: 2 bytes for the value and one byte for the count = 3
* etc... etc
*/
int bytespervalue = (thefile.read() & 0xff);
ByteBuffer cell = ByteBuffer.allocate(bytespervalue);
int cellValue = 0;
/* Create the buffer in which read the compressed row */
byte[] tmp = new byte[offset - 1];
thefile.read(tmp);
ByteBuffer tmpBuffer = ByteBuffer.wrap(tmp);
tmpBuffer.order(ByteOrder.nativeOrder());
/*
* Create the buffer in which read the decompressed row. The final decompressed row will
* always contain 4-byte integer values
*/
if ((offset - 1) == (bytespervalue * fileWindow.getCols())) {
/* There is no compression in this row */
for( int i = 0; i < offset - 1; i = i + bytespervalue ) {
/* Read the value */
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
* need to pad them with 0's. The order of the padding is determined by the
* ByteOrder of the buffer.
*/
if (bytespervalue == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (bytespervalue == 2) {
cellValue = cell.getShort(0);
} else if (bytespervalue == 4) {
cellValue = cell.getInt(0);
}
// if (logger.isDebugEnabled()) logger.debug("tmpint=" + tmpint
// );
rowdata.putInt(cellValue);
}
} else {
/*
* If the row is compressed, then the values appear in pairs (like couples a party). The
* couple is composed of the count and the value value (WARNING: this can be more than
* one byte). Therefore, knowing the length of the compressed row we can calculate the
* number of couples.
*/
int couples = (offset - 1) / (1 + bytespervalue);
for( int i = 0; i < couples; i++ ) {
/* Read the count of values */
int count = (tmpBuffer.get() & 0xff);
/* Read the value */
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
* need to pad them with 0's. The order of the padding is determined by the
* ByteOrder of the buffer.
*/
if (bytespervalue == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (bytespervalue == 2) {
cellValue = cell.getShort(0);
} else if (bytespervalue == 4) {
cellValue = cell.getInt(0);
}
/*
* Now write the cell value the required number of times to the raster row data
* buffer.
*/
for( int j = 0; j < count; j++ ) {
// // if (logger.isDebugEnabled()) logger.debug(" " +
// tmpint);
rowdata.putInt(cellValue);
}
}
}
} | [
"private",
"void",
"readCompressedIntegerRowByNumber",
"(",
"ByteBuffer",
"rowdata",
",",
"int",
"rn",
",",
"long",
"[",
"]",
"adrows",
",",
"RandomAccessFile",
"thefile",
")",
"throws",
"IOException",
",",
"DataFormatException",
"{",
"int",
"offset",
"=",
"(",
"int",
")",
"(",
"adrows",
"[",
"rn",
"+",
"1",
"]",
"-",
"adrows",
"[",
"rn",
"]",
")",
";",
"thefile",
".",
"seek",
"(",
"adrows",
"[",
"rn",
"]",
")",
";",
"/*\n * Read how many bytes the values are ex 1 => if encoded: 1 byte for the value and one byte\n * for the count = 2 2 => if encoded: 2 bytes for the value and one byte for the count = 3\n * etc... etc\n */",
"int",
"bytespervalue",
"=",
"(",
"thefile",
".",
"read",
"(",
")",
"&",
"0xff",
")",
";",
"ByteBuffer",
"cell",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"bytespervalue",
")",
";",
"int",
"cellValue",
"=",
"0",
";",
"/* Create the buffer in which read the compressed row */",
"byte",
"[",
"]",
"tmp",
"=",
"new",
"byte",
"[",
"offset",
"-",
"1",
"]",
";",
"thefile",
".",
"read",
"(",
"tmp",
")",
";",
"ByteBuffer",
"tmpBuffer",
"=",
"ByteBuffer",
".",
"wrap",
"(",
"tmp",
")",
";",
"tmpBuffer",
".",
"order",
"(",
"ByteOrder",
".",
"nativeOrder",
"(",
")",
")",
";",
"/*\n * Create the buffer in which read the decompressed row. The final decompressed row will\n * always contain 4-byte integer values\n */",
"if",
"(",
"(",
"offset",
"-",
"1",
")",
"==",
"(",
"bytespervalue",
"*",
"fileWindow",
".",
"getCols",
"(",
")",
")",
")",
"{",
"/* There is no compression in this row */",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"offset",
"-",
"1",
";",
"i",
"=",
"i",
"+",
"bytespervalue",
")",
"{",
"/* Read the value */",
"tmpBuffer",
".",
"get",
"(",
"cell",
".",
"array",
"(",
")",
")",
";",
"/*\n * Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we\n * need to pad them with 0's. The order of the padding is determined by the\n * ByteOrder of the buffer.\n */",
"if",
"(",
"bytespervalue",
"==",
"1",
")",
"{",
"cellValue",
"=",
"(",
"cell",
".",
"get",
"(",
"0",
")",
"&",
"0xff",
")",
";",
"}",
"else",
"if",
"(",
"bytespervalue",
"==",
"2",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getShort",
"(",
"0",
")",
";",
"}",
"else",
"if",
"(",
"bytespervalue",
"==",
"4",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getInt",
"(",
"0",
")",
";",
"}",
"// if (logger.isDebugEnabled()) logger.debug(\"tmpint=\" + tmpint",
"// );",
"rowdata",
".",
"putInt",
"(",
"cellValue",
")",
";",
"}",
"}",
"else",
"{",
"/*\n * If the row is compressed, then the values appear in pairs (like couples a party). The\n * couple is composed of the count and the value value (WARNING: this can be more than\n * one byte). Therefore, knowing the length of the compressed row we can calculate the\n * number of couples.\n */",
"int",
"couples",
"=",
"(",
"offset",
"-",
"1",
")",
"/",
"(",
"1",
"+",
"bytespervalue",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"couples",
";",
"i",
"++",
")",
"{",
"/* Read the count of values */",
"int",
"count",
"=",
"(",
"tmpBuffer",
".",
"get",
"(",
")",
"&",
"0xff",
")",
";",
"/* Read the value */",
"tmpBuffer",
".",
"get",
"(",
"cell",
".",
"array",
"(",
")",
")",
";",
"/*\n * Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we\n * need to pad them with 0's. The order of the padding is determined by the\n * ByteOrder of the buffer.\n */",
"if",
"(",
"bytespervalue",
"==",
"1",
")",
"{",
"cellValue",
"=",
"(",
"cell",
".",
"get",
"(",
"0",
")",
"&",
"0xff",
")",
";",
"}",
"else",
"if",
"(",
"bytespervalue",
"==",
"2",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getShort",
"(",
"0",
")",
";",
"}",
"else",
"if",
"(",
"bytespervalue",
"==",
"4",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getInt",
"(",
"0",
")",
";",
"}",
"/*\n * Now write the cell value the required number of times to the raster row data\n * buffer.\n */",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"count",
";",
"j",
"++",
")",
"{",
"// // if (logger.isDebugEnabled()) logger.debug(\" \" +",
"// tmpint);",
"rowdata",
".",
"putInt",
"(",
"cellValue",
")",
";",
"}",
"}",
"}",
"}"
] | read a row of data from a compressed integer point map
@param rn
@param adrows
@param outFile
@return the ByteBuffer containing the data
@throws IOException | [
"read",
"a",
"row",
"of",
"data",
"from",
"a",
"compressed",
"integer",
"point",
"map"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L1121-L1206 |
137,376 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java | GrassRasterReader.readUncompressedIntegerRowByNumber | private void readUncompressedIntegerRowByNumber( ByteBuffer rowdata, int rn, RandomAccessFile thefile ) throws IOException,
DataFormatException {
int cellValue = 0;
ByteBuffer cell = ByteBuffer.allocate(rasterMapType);
/* The number of bytes that are inside a row in the file. */
int filerowsize = fileWindow.getCols() * rasterMapType;
/* Position the file pointer to read the row */
thefile.seek((rn * filerowsize));
/* Read the row of data from the file */
ByteBuffer tmpBuffer = ByteBuffer.allocate(filerowsize);
thefile.read(tmpBuffer.array());
/*
* Transform the rasterMapType-size-values to a standard 4 bytes integer value
*/
while( tmpBuffer.hasRemaining() ) {
// read the value
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we need
* to pad them with 0's. The order of the padding is determined by the ByteOrder of the
* buffer.
*/
if (rasterMapType == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (rasterMapType == 2) {
cellValue = cell.getShort(0);
} else if (rasterMapType == 4) {
cellValue = cell.getInt(0);
}
// if (logger.isDebugEnabled()) logger.debug("tmpint=" + cellValue
// );
rowdata.putInt(cellValue);
}
} | java | private void readUncompressedIntegerRowByNumber( ByteBuffer rowdata, int rn, RandomAccessFile thefile ) throws IOException,
DataFormatException {
int cellValue = 0;
ByteBuffer cell = ByteBuffer.allocate(rasterMapType);
/* The number of bytes that are inside a row in the file. */
int filerowsize = fileWindow.getCols() * rasterMapType;
/* Position the file pointer to read the row */
thefile.seek((rn * filerowsize));
/* Read the row of data from the file */
ByteBuffer tmpBuffer = ByteBuffer.allocate(filerowsize);
thefile.read(tmpBuffer.array());
/*
* Transform the rasterMapType-size-values to a standard 4 bytes integer value
*/
while( tmpBuffer.hasRemaining() ) {
// read the value
tmpBuffer.get(cell.array());
/*
* Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we need
* to pad them with 0's. The order of the padding is determined by the ByteOrder of the
* buffer.
*/
if (rasterMapType == 1) {
cellValue = (cell.get(0) & 0xff);
} else if (rasterMapType == 2) {
cellValue = cell.getShort(0);
} else if (rasterMapType == 4) {
cellValue = cell.getInt(0);
}
// if (logger.isDebugEnabled()) logger.debug("tmpint=" + cellValue
// );
rowdata.putInt(cellValue);
}
} | [
"private",
"void",
"readUncompressedIntegerRowByNumber",
"(",
"ByteBuffer",
"rowdata",
",",
"int",
"rn",
",",
"RandomAccessFile",
"thefile",
")",
"throws",
"IOException",
",",
"DataFormatException",
"{",
"int",
"cellValue",
"=",
"0",
";",
"ByteBuffer",
"cell",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"rasterMapType",
")",
";",
"/* The number of bytes that are inside a row in the file. */",
"int",
"filerowsize",
"=",
"fileWindow",
".",
"getCols",
"(",
")",
"*",
"rasterMapType",
";",
"/* Position the file pointer to read the row */",
"thefile",
".",
"seek",
"(",
"(",
"rn",
"*",
"filerowsize",
")",
")",
";",
"/* Read the row of data from the file */",
"ByteBuffer",
"tmpBuffer",
"=",
"ByteBuffer",
".",
"allocate",
"(",
"filerowsize",
")",
";",
"thefile",
".",
"read",
"(",
"tmpBuffer",
".",
"array",
"(",
")",
")",
";",
"/*\n * Transform the rasterMapType-size-values to a standard 4 bytes integer value\n */",
"while",
"(",
"tmpBuffer",
".",
"hasRemaining",
"(",
")",
")",
"{",
"// read the value",
"tmpBuffer",
".",
"get",
"(",
"cell",
".",
"array",
"(",
")",
")",
";",
"/*\n * Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we need\n * to pad them with 0's. The order of the padding is determined by the ByteOrder of the\n * buffer.\n */",
"if",
"(",
"rasterMapType",
"==",
"1",
")",
"{",
"cellValue",
"=",
"(",
"cell",
".",
"get",
"(",
"0",
")",
"&",
"0xff",
")",
";",
"}",
"else",
"if",
"(",
"rasterMapType",
"==",
"2",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getShort",
"(",
"0",
")",
";",
"}",
"else",
"if",
"(",
"rasterMapType",
"==",
"4",
")",
"{",
"cellValue",
"=",
"cell",
".",
"getInt",
"(",
"0",
")",
";",
"}",
"// if (logger.isDebugEnabled()) logger.debug(\"tmpint=\" + cellValue",
"// );",
"rowdata",
".",
"putInt",
"(",
"cellValue",
")",
";",
"}",
"}"
] | read a row of data from an uncompressed integer map
@param rn
@param thefile
@return
@throws IOException
@throws DataFormatException | [
"read",
"a",
"row",
"of",
"data",
"from",
"an",
"uncompressed",
"integer",
"map"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/grasslegacy/io/GrassRasterReader.java#L1217-L1255 |
137,377 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/colors/ColorInterpolator.java | ColorInterpolator.getColorFor | public Color getColorFor( double value ) {
if (value <= min) {
return colors[0];
} else if (value >= max) {
return colors[colors.length - 1];
} else {
for( int i = 1; i < colors.length; i++ ) {
double v1 = values[i - 1];
double v2 = values[i];
if (value < v2) {
double v = (value - v1) / (v2 - v1);
Color interpolateColor = interpolateColor(colors[i - 1], colors[i], (float) v);
return interpolateColor;
}
}
return colors[colors.length - 1];
}
} | java | public Color getColorFor( double value ) {
if (value <= min) {
return colors[0];
} else if (value >= max) {
return colors[colors.length - 1];
} else {
for( int i = 1; i < colors.length; i++ ) {
double v1 = values[i - 1];
double v2 = values[i];
if (value < v2) {
double v = (value - v1) / (v2 - v1);
Color interpolateColor = interpolateColor(colors[i - 1], colors[i], (float) v);
return interpolateColor;
}
}
return colors[colors.length - 1];
}
} | [
"public",
"Color",
"getColorFor",
"(",
"double",
"value",
")",
"{",
"if",
"(",
"value",
"<=",
"min",
")",
"{",
"return",
"colors",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"value",
">=",
"max",
")",
"{",
"return",
"colors",
"[",
"colors",
".",
"length",
"-",
"1",
"]",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"colors",
".",
"length",
";",
"i",
"++",
")",
"{",
"double",
"v1",
"=",
"values",
"[",
"i",
"-",
"1",
"]",
";",
"double",
"v2",
"=",
"values",
"[",
"i",
"]",
";",
"if",
"(",
"value",
"<",
"v2",
")",
"{",
"double",
"v",
"=",
"(",
"value",
"-",
"v1",
")",
"/",
"(",
"v2",
"-",
"v1",
")",
";",
"Color",
"interpolateColor",
"=",
"interpolateColor",
"(",
"colors",
"[",
"i",
"-",
"1",
"]",
",",
"colors",
"[",
"i",
"]",
",",
"(",
"float",
")",
"v",
")",
";",
"return",
"interpolateColor",
";",
"}",
"}",
"return",
"colors",
"[",
"colors",
".",
"length",
"-",
"1",
"]",
";",
"}",
"}"
] | Get the color of the defined table by its value.
@param value the value.
@return the interpolated color. | [
"Get",
"the",
"color",
"of",
"the",
"defined",
"table",
"by",
"its",
"value",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/colors/ColorInterpolator.java#L55-L73 |
137,378 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/colors/ColorInterpolator.java | ColorInterpolator.interpolateColor | public static Color interpolateColor( Color color1, Color color2, float fraction ) {
float int2Float = 1f / 255f;
fraction = Math.min(fraction, 1f);
fraction = Math.max(fraction, 0f);
float r1 = color1.getRed() * int2Float;
float g1 = color1.getGreen() * int2Float;
float b1 = color1.getBlue() * int2Float;
float a1 = color1.getAlpha() * int2Float;
float r2 = color2.getRed() * int2Float;
float g2 = color2.getGreen() * int2Float;
float b2 = color2.getBlue() * int2Float;
float a2 = color2.getAlpha() * int2Float;
float deltaR = r2 - r1;
float deltaG = g2 - g1;
float deltaB = b2 - b1;
float deltaA = a2 - a1;
float red = r1 + (deltaR * fraction);
float green = g1 + (deltaG * fraction);
float blue = b1 + (deltaB * fraction);
float alpha = a1 + (deltaA * fraction);
red = Math.min(red, 1f);
red = Math.max(red, 0f);
green = Math.min(green, 1f);
green = Math.max(green, 0f);
blue = Math.min(blue, 1f);
blue = Math.max(blue, 0f);
alpha = Math.min(alpha, 1f);
alpha = Math.max(alpha, 0f);
return new Color(red, green, blue, alpha);
} | java | public static Color interpolateColor( Color color1, Color color2, float fraction ) {
float int2Float = 1f / 255f;
fraction = Math.min(fraction, 1f);
fraction = Math.max(fraction, 0f);
float r1 = color1.getRed() * int2Float;
float g1 = color1.getGreen() * int2Float;
float b1 = color1.getBlue() * int2Float;
float a1 = color1.getAlpha() * int2Float;
float r2 = color2.getRed() * int2Float;
float g2 = color2.getGreen() * int2Float;
float b2 = color2.getBlue() * int2Float;
float a2 = color2.getAlpha() * int2Float;
float deltaR = r2 - r1;
float deltaG = g2 - g1;
float deltaB = b2 - b1;
float deltaA = a2 - a1;
float red = r1 + (deltaR * fraction);
float green = g1 + (deltaG * fraction);
float blue = b1 + (deltaB * fraction);
float alpha = a1 + (deltaA * fraction);
red = Math.min(red, 1f);
red = Math.max(red, 0f);
green = Math.min(green, 1f);
green = Math.max(green, 0f);
blue = Math.min(blue, 1f);
blue = Math.max(blue, 0f);
alpha = Math.min(alpha, 1f);
alpha = Math.max(alpha, 0f);
return new Color(red, green, blue, alpha);
} | [
"public",
"static",
"Color",
"interpolateColor",
"(",
"Color",
"color1",
",",
"Color",
"color2",
",",
"float",
"fraction",
")",
"{",
"float",
"int2Float",
"=",
"1f",
"/",
"255f",
";",
"fraction",
"=",
"Math",
".",
"min",
"(",
"fraction",
",",
"1f",
")",
";",
"fraction",
"=",
"Math",
".",
"max",
"(",
"fraction",
",",
"0f",
")",
";",
"float",
"r1",
"=",
"color1",
".",
"getRed",
"(",
")",
"*",
"int2Float",
";",
"float",
"g1",
"=",
"color1",
".",
"getGreen",
"(",
")",
"*",
"int2Float",
";",
"float",
"b1",
"=",
"color1",
".",
"getBlue",
"(",
")",
"*",
"int2Float",
";",
"float",
"a1",
"=",
"color1",
".",
"getAlpha",
"(",
")",
"*",
"int2Float",
";",
"float",
"r2",
"=",
"color2",
".",
"getRed",
"(",
")",
"*",
"int2Float",
";",
"float",
"g2",
"=",
"color2",
".",
"getGreen",
"(",
")",
"*",
"int2Float",
";",
"float",
"b2",
"=",
"color2",
".",
"getBlue",
"(",
")",
"*",
"int2Float",
";",
"float",
"a2",
"=",
"color2",
".",
"getAlpha",
"(",
")",
"*",
"int2Float",
";",
"float",
"deltaR",
"=",
"r2",
"-",
"r1",
";",
"float",
"deltaG",
"=",
"g2",
"-",
"g1",
";",
"float",
"deltaB",
"=",
"b2",
"-",
"b1",
";",
"float",
"deltaA",
"=",
"a2",
"-",
"a1",
";",
"float",
"red",
"=",
"r1",
"+",
"(",
"deltaR",
"*",
"fraction",
")",
";",
"float",
"green",
"=",
"g1",
"+",
"(",
"deltaG",
"*",
"fraction",
")",
";",
"float",
"blue",
"=",
"b1",
"+",
"(",
"deltaB",
"*",
"fraction",
")",
";",
"float",
"alpha",
"=",
"a1",
"+",
"(",
"deltaA",
"*",
"fraction",
")",
";",
"red",
"=",
"Math",
".",
"min",
"(",
"red",
",",
"1f",
")",
";",
"red",
"=",
"Math",
".",
"max",
"(",
"red",
",",
"0f",
")",
";",
"green",
"=",
"Math",
".",
"min",
"(",
"green",
",",
"1f",
")",
";",
"green",
"=",
"Math",
".",
"max",
"(",
"green",
",",
"0f",
")",
";",
"blue",
"=",
"Math",
".",
"min",
"(",
"blue",
",",
"1f",
")",
";",
"blue",
"=",
"Math",
".",
"max",
"(",
"blue",
",",
"0f",
")",
";",
"alpha",
"=",
"Math",
".",
"min",
"(",
"alpha",
",",
"1f",
")",
";",
"alpha",
"=",
"Math",
".",
"max",
"(",
"alpha",
",",
"0f",
")",
";",
"return",
"new",
"Color",
"(",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
")",
";",
"}"
] | Interpolate a color at a given fraction between 0 and 1.
@param color1 start color.
@param color2 end color.
@param fraction the fraction to interpolate.
@return the new color. | [
"Interpolate",
"a",
"color",
"at",
"a",
"given",
"fraction",
"between",
"0",
"and",
"1",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/colors/ColorInterpolator.java#L161-L196 |
137,379 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/chart/Scatter.java | Scatter.addSeries | public void addSeries( String seriesName, double[] x, double[] y ) {
XYSeries series = new XYSeries(seriesName);
for( int i = 0; i < x.length; i++ ) {
series.add(x[i], y[i]);
}
dataset.addSeries(series);
} | java | public void addSeries( String seriesName, double[] x, double[] y ) {
XYSeries series = new XYSeries(seriesName);
for( int i = 0; i < x.length; i++ ) {
series.add(x[i], y[i]);
}
dataset.addSeries(series);
} | [
"public",
"void",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"x",
",",
"double",
"[",
"]",
"y",
")",
"{",
"XYSeries",
"series",
"=",
"new",
"XYSeries",
"(",
"seriesName",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"{",
"series",
".",
"add",
"(",
"x",
"[",
"i",
"]",
",",
"y",
"[",
"i",
"]",
")",
";",
"}",
"dataset",
".",
"addSeries",
"(",
"series",
")",
";",
"}"
] | Add a new series by name and data.
@param seriesName the name.
@param x the x data array.
@param y the y data array. | [
"Add",
"a",
"new",
"series",
"by",
"name",
"and",
"data",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/chart/Scatter.java#L80-L86 |
137,380 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java | LasSourcesTable.insertLasSource | public static long insertLasSource( ASpatialDb db, int srid, int levels, double resolution, double factor, Polygon polygon,
String name, double minElev, double maxElev, double minIntens, double maxIntens ) throws Exception {
String sql = "INSERT INTO " + TABLENAME//
+ " (" + COLUMN_GEOM + "," + COLUMN_NAME + "," + COLUMN_RESOLUTION + "," //
+ COLUMN_FACTOR + "," + COLUMN_LEVELS + "," + COLUMN_MINZ + "," + COLUMN_MAXZ + "," + COLUMN_MININTENSITY + ","
+ COLUMN_MAXINTENSITY + //
") VALUES (ST_GeomFromText(?, " + srid + "),?,?,?,?,?,?,?,?)";
return db.execOnConnection(connection -> {
try (IHMPreparedStatement pStmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
pStmt.setString(1, polygon.toText());
pStmt.setString(2, name);
pStmt.setDouble(3, resolution);
pStmt.setDouble(4, factor);
pStmt.setInt(5, levels);
pStmt.setDouble(6, minElev);
pStmt.setDouble(7, maxElev);
pStmt.setDouble(8, minIntens);
pStmt.setDouble(9, maxIntens);
pStmt.executeUpdate();
IHMResultSet rs = pStmt.getGeneratedKeys();
rs.next();
long generatedId = rs.getLong(1);
return generatedId;
}
});
} | java | public static long insertLasSource( ASpatialDb db, int srid, int levels, double resolution, double factor, Polygon polygon,
String name, double minElev, double maxElev, double minIntens, double maxIntens ) throws Exception {
String sql = "INSERT INTO " + TABLENAME//
+ " (" + COLUMN_GEOM + "," + COLUMN_NAME + "," + COLUMN_RESOLUTION + "," //
+ COLUMN_FACTOR + "," + COLUMN_LEVELS + "," + COLUMN_MINZ + "," + COLUMN_MAXZ + "," + COLUMN_MININTENSITY + ","
+ COLUMN_MAXINTENSITY + //
") VALUES (ST_GeomFromText(?, " + srid + "),?,?,?,?,?,?,?,?)";
return db.execOnConnection(connection -> {
try (IHMPreparedStatement pStmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
pStmt.setString(1, polygon.toText());
pStmt.setString(2, name);
pStmt.setDouble(3, resolution);
pStmt.setDouble(4, factor);
pStmt.setInt(5, levels);
pStmt.setDouble(6, minElev);
pStmt.setDouble(7, maxElev);
pStmt.setDouble(8, minIntens);
pStmt.setDouble(9, maxIntens);
pStmt.executeUpdate();
IHMResultSet rs = pStmt.getGeneratedKeys();
rs.next();
long generatedId = rs.getLong(1);
return generatedId;
}
});
} | [
"public",
"static",
"long",
"insertLasSource",
"(",
"ASpatialDb",
"db",
",",
"int",
"srid",
",",
"int",
"levels",
",",
"double",
"resolution",
",",
"double",
"factor",
",",
"Polygon",
"polygon",
",",
"String",
"name",
",",
"double",
"minElev",
",",
"double",
"maxElev",
",",
"double",
"minIntens",
",",
"double",
"maxIntens",
")",
"throws",
"Exception",
"{",
"String",
"sql",
"=",
"\"INSERT INTO \"",
"+",
"TABLENAME",
"//",
"+",
"\" (\"",
"+",
"COLUMN_GEOM",
"+",
"\",\"",
"+",
"COLUMN_NAME",
"+",
"\",\"",
"+",
"COLUMN_RESOLUTION",
"+",
"\",\"",
"//",
"+",
"COLUMN_FACTOR",
"+",
"\",\"",
"+",
"COLUMN_LEVELS",
"+",
"\",\"",
"+",
"COLUMN_MINZ",
"+",
"\",\"",
"+",
"COLUMN_MAXZ",
"+",
"\",\"",
"+",
"COLUMN_MININTENSITY",
"+",
"\",\"",
"+",
"COLUMN_MAXINTENSITY",
"+",
"//",
"\") VALUES (ST_GeomFromText(?, \"",
"+",
"srid",
"+",
"\"),?,?,?,?,?,?,?,?)\"",
";",
"return",
"db",
".",
"execOnConnection",
"(",
"connection",
"->",
"{",
"try",
"(",
"IHMPreparedStatement",
"pStmt",
"=",
"connection",
".",
"prepareStatement",
"(",
"sql",
",",
"Statement",
".",
"RETURN_GENERATED_KEYS",
")",
")",
"{",
"pStmt",
".",
"setString",
"(",
"1",
",",
"polygon",
".",
"toText",
"(",
")",
")",
";",
"pStmt",
".",
"setString",
"(",
"2",
",",
"name",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"3",
",",
"resolution",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"4",
",",
"factor",
")",
";",
"pStmt",
".",
"setInt",
"(",
"5",
",",
"levels",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"6",
",",
"minElev",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"7",
",",
"maxElev",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"8",
",",
"minIntens",
")",
";",
"pStmt",
".",
"setDouble",
"(",
"9",
",",
"maxIntens",
")",
";",
"pStmt",
".",
"executeUpdate",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"pStmt",
".",
"getGeneratedKeys",
"(",
")",
";",
"rs",
".",
"next",
"(",
")",
";",
"long",
"generatedId",
"=",
"rs",
".",
"getLong",
"(",
"1",
")",
";",
"return",
"generatedId",
";",
"}",
"}",
")",
";",
"}"
] | Insert values in the table
@param db the db to use.
@param srid the epsg code.
@param levels the levels that are created for this source.
@param resolution the resolution of trhe base cells.
@param factor the level multiplication factor.
@param polygon the polygon geometry bounds of the source.
@param name the name of the source.
@param minElev the min elevation.
@param maxElev the max elevation.
@param minIntens the min intensity.
@param maxIntens the max intensity.
@return the source id.
@throws Exception | [
"Insert",
"values",
"in",
"the",
"table"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java#L85-L114 |
137,381 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java | LasSourcesTable.updateMinMaxIntensity | public static void updateMinMaxIntensity( ASpatialDb db, long sourceId, double minIntens, double maxIntens )
throws Exception {
String sql = "UPDATE " + TABLENAME//
+ " SET " + COLUMN_MININTENSITY + "=" + minIntens + ", " + COLUMN_MAXINTENSITY + "=" + maxIntens + //
" WHERE " + COLUMN_ID + "=" + sourceId;
db.executeInsertUpdateDeleteSql(sql);
} | java | public static void updateMinMaxIntensity( ASpatialDb db, long sourceId, double minIntens, double maxIntens )
throws Exception {
String sql = "UPDATE " + TABLENAME//
+ " SET " + COLUMN_MININTENSITY + "=" + minIntens + ", " + COLUMN_MAXINTENSITY + "=" + maxIntens + //
" WHERE " + COLUMN_ID + "=" + sourceId;
db.executeInsertUpdateDeleteSql(sql);
} | [
"public",
"static",
"void",
"updateMinMaxIntensity",
"(",
"ASpatialDb",
"db",
",",
"long",
"sourceId",
",",
"double",
"minIntens",
",",
"double",
"maxIntens",
")",
"throws",
"Exception",
"{",
"String",
"sql",
"=",
"\"UPDATE \"",
"+",
"TABLENAME",
"//",
"+",
"\" SET \"",
"+",
"COLUMN_MININTENSITY",
"+",
"\"=\"",
"+",
"minIntens",
"+",
"\", \"",
"+",
"COLUMN_MAXINTENSITY",
"+",
"\"=\"",
"+",
"maxIntens",
"+",
"//",
"\" WHERE \"",
"+",
"COLUMN_ID",
"+",
"\"=\"",
"+",
"sourceId",
";",
"db",
".",
"executeInsertUpdateDeleteSql",
"(",
"sql",
")",
";",
"}"
] | Update the intensity values.
@param db the db.
@param sourceId the source to update.
@param minIntens the min value.
@param maxIntens the max value.
@throws Exception | [
"Update",
"the",
"intensity",
"values",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java#L125-L131 |
137,382 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java | LasSourcesTable.getLasSources | public static List<LasSource> getLasSources( ASpatialDb db ) throws Exception {
List<LasSource> sources = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_NAME + "," + COLUMN_RESOLUTION + "," + COLUMN_FACTOR
+ "," + COLUMN_LEVELS + "," + COLUMN_MINZ + "," + COLUMN_MAXZ + "," + COLUMN_MININTENSITY + ","
+ COLUMN_MAXINTENSITY + " FROM " + TABLENAME;
return db.execOnConnection(connection -> {
IGeometryParser gp = db.getType().getGeometryParser();
try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql)) {
while( rs.next() ) {
LasSource lasSource = new LasSource();
int i = 1;
Geometry geometry = gp.fromResultSet(rs, i++);
if (geometry instanceof Polygon) {
Polygon polygon = (Polygon) geometry;
lasSource.polygon = polygon;
lasSource.id = rs.getLong(i++);
lasSource.name = rs.getString(i++);
lasSource.resolution = rs.getDouble(i++);
lasSource.levelFactor = rs.getDouble(i++);
lasSource.levels = rs.getInt(i++);
lasSource.minElev = rs.getDouble(i++);
lasSource.maxElev = rs.getDouble(i++);
lasSource.minIntens = rs.getDouble(i++);
lasSource.maxIntens = rs.getDouble(i++);
sources.add(lasSource);
}
}
return sources;
}
});
} | java | public static List<LasSource> getLasSources( ASpatialDb db ) throws Exception {
List<LasSource> sources = new ArrayList<>();
String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_NAME + "," + COLUMN_RESOLUTION + "," + COLUMN_FACTOR
+ "," + COLUMN_LEVELS + "," + COLUMN_MINZ + "," + COLUMN_MAXZ + "," + COLUMN_MININTENSITY + ","
+ COLUMN_MAXINTENSITY + " FROM " + TABLENAME;
return db.execOnConnection(connection -> {
IGeometryParser gp = db.getType().getGeometryParser();
try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql)) {
while( rs.next() ) {
LasSource lasSource = new LasSource();
int i = 1;
Geometry geometry = gp.fromResultSet(rs, i++);
if (geometry instanceof Polygon) {
Polygon polygon = (Polygon) geometry;
lasSource.polygon = polygon;
lasSource.id = rs.getLong(i++);
lasSource.name = rs.getString(i++);
lasSource.resolution = rs.getDouble(i++);
lasSource.levelFactor = rs.getDouble(i++);
lasSource.levels = rs.getInt(i++);
lasSource.minElev = rs.getDouble(i++);
lasSource.maxElev = rs.getDouble(i++);
lasSource.minIntens = rs.getDouble(i++);
lasSource.maxIntens = rs.getDouble(i++);
sources.add(lasSource);
}
}
return sources;
}
});
} | [
"public",
"static",
"List",
"<",
"LasSource",
">",
"getLasSources",
"(",
"ASpatialDb",
"db",
")",
"throws",
"Exception",
"{",
"List",
"<",
"LasSource",
">",
"sources",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"String",
"sql",
"=",
"\"SELECT \"",
"+",
"COLUMN_GEOM",
"+",
"\",\"",
"+",
"COLUMN_ID",
"+",
"\",\"",
"+",
"COLUMN_NAME",
"+",
"\",\"",
"+",
"COLUMN_RESOLUTION",
"+",
"\",\"",
"+",
"COLUMN_FACTOR",
"+",
"\",\"",
"+",
"COLUMN_LEVELS",
"+",
"\",\"",
"+",
"COLUMN_MINZ",
"+",
"\",\"",
"+",
"COLUMN_MAXZ",
"+",
"\",\"",
"+",
"COLUMN_MININTENSITY",
"+",
"\",\"",
"+",
"COLUMN_MAXINTENSITY",
"+",
"\" FROM \"",
"+",
"TABLENAME",
";",
"return",
"db",
".",
"execOnConnection",
"(",
"connection",
"->",
"{",
"IGeometryParser",
"gp",
"=",
"db",
".",
"getType",
"(",
")",
".",
"getGeometryParser",
"(",
")",
";",
"try",
"(",
"IHMStatement",
"stmt",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"stmt",
".",
"executeQuery",
"(",
"sql",
")",
")",
"{",
"while",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"LasSource",
"lasSource",
"=",
"new",
"LasSource",
"(",
")",
";",
"int",
"i",
"=",
"1",
";",
"Geometry",
"geometry",
"=",
"gp",
".",
"fromResultSet",
"(",
"rs",
",",
"i",
"++",
")",
";",
"if",
"(",
"geometry",
"instanceof",
"Polygon",
")",
"{",
"Polygon",
"polygon",
"=",
"(",
"Polygon",
")",
"geometry",
";",
"lasSource",
".",
"polygon",
"=",
"polygon",
";",
"lasSource",
".",
"id",
"=",
"rs",
".",
"getLong",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"name",
"=",
"rs",
".",
"getString",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"resolution",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"levelFactor",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"levels",
"=",
"rs",
".",
"getInt",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"minElev",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"maxElev",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"minIntens",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"lasSource",
".",
"maxIntens",
"=",
"rs",
".",
"getDouble",
"(",
"i",
"++",
")",
";",
"sources",
".",
"add",
"(",
"lasSource",
")",
";",
"}",
"}",
"return",
"sources",
";",
"}",
"}",
")",
";",
"}"
] | Query the las sources table.
@param db the db to use.
@return the list of available {@link LasSource}s.
@throws Exception | [
"Query",
"the",
"las",
"sources",
"table",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java#L140-L172 |
137,383 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java | LasSourcesTable.isLasDatabase | public static boolean isLasDatabase( ASpatialDb db ) throws Exception {
if (!db.hasTable(TABLENAME) || !db.hasTable(LasCellsTable.TABLENAME)) {
return false;
}
return true;
} | java | public static boolean isLasDatabase( ASpatialDb db ) throws Exception {
if (!db.hasTable(TABLENAME) || !db.hasTable(LasCellsTable.TABLENAME)) {
return false;
}
return true;
} | [
"public",
"static",
"boolean",
"isLasDatabase",
"(",
"ASpatialDb",
"db",
")",
"throws",
"Exception",
"{",
"if",
"(",
"!",
"db",
".",
"hasTable",
"(",
"TABLENAME",
")",
"||",
"!",
"db",
".",
"hasTable",
"(",
"LasCellsTable",
".",
"TABLENAME",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if the db is a las database readable by HortonMachine.
@param db the database to check.
@return <code>true</code> if the db can be read.
@throws Exception | [
"Checks",
"if",
"the",
"db",
"is",
"a",
"las",
"database",
"readable",
"by",
"HortonMachine",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/las/databases/LasSourcesTable.java#L181-L186 |
137,384 | TheHortonMachine/hortonmachine | apps/src/main/java/org/hortonmachine/nww/utils/selection/ScreenSelector.java | ScreenSelector.limitPointToWorldWindow | protected Point limitPointToWorldWindow( Point point ) {
Rectangle viewport = this.getWwd().getView().getViewport();
int x = point.x;
if (x < viewport.x)
x = viewport.x;
if (x > viewport.x + viewport.width)
x = viewport.x + viewport.width;
int y = point.y;
if (y < viewport.y)
y = viewport.y;
if (y > viewport.y + viewport.height)
y = viewport.y + viewport.height;
return new Point(x, y);
} | java | protected Point limitPointToWorldWindow( Point point ) {
Rectangle viewport = this.getWwd().getView().getViewport();
int x = point.x;
if (x < viewport.x)
x = viewport.x;
if (x > viewport.x + viewport.width)
x = viewport.x + viewport.width;
int y = point.y;
if (y < viewport.y)
y = viewport.y;
if (y > viewport.y + viewport.height)
y = viewport.y + viewport.height;
return new Point(x, y);
} | [
"protected",
"Point",
"limitPointToWorldWindow",
"(",
"Point",
"point",
")",
"{",
"Rectangle",
"viewport",
"=",
"this",
".",
"getWwd",
"(",
")",
".",
"getView",
"(",
")",
".",
"getViewport",
"(",
")",
";",
"int",
"x",
"=",
"point",
".",
"x",
";",
"if",
"(",
"x",
"<",
"viewport",
".",
"x",
")",
"x",
"=",
"viewport",
".",
"x",
";",
"if",
"(",
"x",
">",
"viewport",
".",
"x",
"+",
"viewport",
".",
"width",
")",
"x",
"=",
"viewport",
".",
"x",
"+",
"viewport",
".",
"width",
";",
"int",
"y",
"=",
"point",
".",
"y",
";",
"if",
"(",
"y",
"<",
"viewport",
".",
"y",
")",
"y",
"=",
"viewport",
".",
"y",
";",
"if",
"(",
"y",
">",
"viewport",
".",
"y",
"+",
"viewport",
".",
"height",
")",
"y",
"=",
"viewport",
".",
"y",
"+",
"viewport",
".",
"height",
";",
"return",
"new",
"Point",
"(",
"x",
",",
"y",
")",
";",
"}"
] | Limits the specified point's x and y coordinates to the World Window's
viewport, and returns a new point with the limited coordinates. For
example, if the World Window's viewport rectangle is x=0, y=0, width=100,
height=100 and the point's coordinates are x=50, y=200 this returns a new
point with coordinates x=50, y=100. If the specified point is already
inside the World Window's viewport, this returns a new point with the
same x and y coordinates as the specified point.
@param point
the point to limit.
@return a new Point representing the specified point limited to the World
Window's viewport rectangle. | [
"Limits",
"the",
"specified",
"point",
"s",
"x",
"and",
"y",
"coordinates",
"to",
"the",
"World",
"Window",
"s",
"viewport",
"and",
"returns",
"a",
"new",
"point",
"with",
"the",
"limited",
"coordinates",
".",
"For",
"example",
"if",
"the",
"World",
"Window",
"s",
"viewport",
"rectangle",
"is",
"x",
"=",
"0",
"y",
"=",
"0",
"width",
"=",
"100",
"height",
"=",
"100",
"and",
"the",
"point",
"s",
"coordinates",
"are",
"x",
"=",
"50",
"y",
"=",
"200",
"this",
"returns",
"a",
"new",
"point",
"with",
"coordinates",
"x",
"=",
"50",
"y",
"=",
"100",
".",
"If",
"the",
"specified",
"point",
"is",
"already",
"inside",
"the",
"World",
"Window",
"s",
"viewport",
"this",
"returns",
"a",
"new",
"point",
"with",
"the",
"same",
"x",
"and",
"y",
"coordinates",
"as",
"the",
"specified",
"point",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/apps/src/main/java/org/hortonmachine/nww/utils/selection/ScreenSelector.java#L591-L607 |
137,385 | TheHortonMachine/hortonmachine | gui/src/main/java/org/hortonmachine/gui/utils/ImageViewer.java | ImageViewer.show | public static void show( BufferedImage image, String title, boolean modal ) {
JDialog f = new JDialog();
f.add(new ImageViewer(image), BorderLayout.CENTER);
f.setTitle(title);
f.setIconImage(ImageCache.getInstance().getBufferedImage(ImageCache.HORTONMACHINE_FRAME_ICON));
f.setModal(modal);
f.pack();
int h = image.getHeight();
int w = image.getWidth();
if (h > w) {
f.setSize(new Dimension(600, 800));
} else {
f.setSize(new Dimension(800, 600));
}
f.setLocationRelativeTo(null); // Center on screen
f.setVisible(true);
f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
f.getRootPane().registerKeyboardAction(e -> {
f.dispose();
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
} | java | public static void show( BufferedImage image, String title, boolean modal ) {
JDialog f = new JDialog();
f.add(new ImageViewer(image), BorderLayout.CENTER);
f.setTitle(title);
f.setIconImage(ImageCache.getInstance().getBufferedImage(ImageCache.HORTONMACHINE_FRAME_ICON));
f.setModal(modal);
f.pack();
int h = image.getHeight();
int w = image.getWidth();
if (h > w) {
f.setSize(new Dimension(600, 800));
} else {
f.setSize(new Dimension(800, 600));
}
f.setLocationRelativeTo(null); // Center on screen
f.setVisible(true);
f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
f.getRootPane().registerKeyboardAction(e -> {
f.dispose();
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
} | [
"public",
"static",
"void",
"show",
"(",
"BufferedImage",
"image",
",",
"String",
"title",
",",
"boolean",
"modal",
")",
"{",
"JDialog",
"f",
"=",
"new",
"JDialog",
"(",
")",
";",
"f",
".",
"add",
"(",
"new",
"ImageViewer",
"(",
"image",
")",
",",
"BorderLayout",
".",
"CENTER",
")",
";",
"f",
".",
"setTitle",
"(",
"title",
")",
";",
"f",
".",
"setIconImage",
"(",
"ImageCache",
".",
"getInstance",
"(",
")",
".",
"getBufferedImage",
"(",
"ImageCache",
".",
"HORTONMACHINE_FRAME_ICON",
")",
")",
";",
"f",
".",
"setModal",
"(",
"modal",
")",
";",
"f",
".",
"pack",
"(",
")",
";",
"int",
"h",
"=",
"image",
".",
"getHeight",
"(",
")",
";",
"int",
"w",
"=",
"image",
".",
"getWidth",
"(",
")",
";",
"if",
"(",
"h",
">",
"w",
")",
"{",
"f",
".",
"setSize",
"(",
"new",
"Dimension",
"(",
"600",
",",
"800",
")",
")",
";",
"}",
"else",
"{",
"f",
".",
"setSize",
"(",
"new",
"Dimension",
"(",
"800",
",",
"600",
")",
")",
";",
"}",
"f",
".",
"setLocationRelativeTo",
"(",
"null",
")",
";",
"// Center on screen",
"f",
".",
"setVisible",
"(",
"true",
")",
";",
"f",
".",
"setDefaultCloseOperation",
"(",
"JDialog",
".",
"DISPOSE_ON_CLOSE",
")",
";",
"f",
".",
"getRootPane",
"(",
")",
".",
"registerKeyboardAction",
"(",
"e",
"->",
"{",
"f",
".",
"dispose",
"(",
")",
";",
"}",
",",
"KeyStroke",
".",
"getKeyStroke",
"(",
"KeyEvent",
".",
"VK_ESCAPE",
",",
"0",
")",
",",
"JComponent",
".",
"WHEN_IN_FOCUSED_WINDOW",
")",
";",
"}"
] | Opens a JDialog with the image viewer in it.
@param image the image to show.
@param title the title of the dialog.
@param modal if <code>true</code>, the dialog is modal. | [
"Opens",
"a",
"JDialog",
"with",
"the",
"image",
"viewer",
"in",
"it",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gui/src/main/java/org/hortonmachine/gui/utils/ImageViewer.java#L164-L184 |
137,386 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoImages.java | DaoImages.getImagesList | public static List<Image> getImagesList( IHMConnection connection ) throws Exception {
List<Image> images = new ArrayList<Image>();
String sql = "select " + //
ImageTableFields.COLUMN_ID.getFieldName() + "," + //
ImageTableFields.COLUMN_LON.getFieldName() + "," + //
ImageTableFields.COLUMN_LAT.getFieldName() + "," + //
ImageTableFields.COLUMN_ALTIM.getFieldName() + "," + //
ImageTableFields.COLUMN_TS.getFieldName() + "," + //
ImageTableFields.COLUMN_AZIM.getFieldName() + "," + //
ImageTableFields.COLUMN_TEXT.getFieldName() + "," + //
ImageTableFields.COLUMN_NOTE_ID.getFieldName() + "," + //
ImageTableFields.COLUMN_IMAGEDATA_ID.getFieldName() + //
" from " + TABLE_IMAGES;
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(sql);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
while( rs.next() ) {
long id = rs.getLong(1);
double lon = rs.getDouble(2);
double lat = rs.getDouble(3);
double altim = rs.getDouble(4);
long ts = rs.getLong(5);
double azim = rs.getDouble(6);
String text = rs.getString(7);
long noteId = rs.getLong(8);
long imageDataId = rs.getLong(9);
Image image = new Image(id, text, lon, lat, altim, azim, imageDataId, noteId, ts);
images.add(image);
}
}
return images;
} | java | public static List<Image> getImagesList( IHMConnection connection ) throws Exception {
List<Image> images = new ArrayList<Image>();
String sql = "select " + //
ImageTableFields.COLUMN_ID.getFieldName() + "," + //
ImageTableFields.COLUMN_LON.getFieldName() + "," + //
ImageTableFields.COLUMN_LAT.getFieldName() + "," + //
ImageTableFields.COLUMN_ALTIM.getFieldName() + "," + //
ImageTableFields.COLUMN_TS.getFieldName() + "," + //
ImageTableFields.COLUMN_AZIM.getFieldName() + "," + //
ImageTableFields.COLUMN_TEXT.getFieldName() + "," + //
ImageTableFields.COLUMN_NOTE_ID.getFieldName() + "," + //
ImageTableFields.COLUMN_IMAGEDATA_ID.getFieldName() + //
" from " + TABLE_IMAGES;
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(sql);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
while( rs.next() ) {
long id = rs.getLong(1);
double lon = rs.getDouble(2);
double lat = rs.getDouble(3);
double altim = rs.getDouble(4);
long ts = rs.getLong(5);
double azim = rs.getDouble(6);
String text = rs.getString(7);
long noteId = rs.getLong(8);
long imageDataId = rs.getLong(9);
Image image = new Image(id, text, lon, lat, altim, azim, imageDataId, noteId, ts);
images.add(image);
}
}
return images;
} | [
"public",
"static",
"List",
"<",
"Image",
">",
"getImagesList",
"(",
"IHMConnection",
"connection",
")",
"throws",
"Exception",
"{",
"List",
"<",
"Image",
">",
"images",
"=",
"new",
"ArrayList",
"<",
"Image",
">",
"(",
")",
";",
"String",
"sql",
"=",
"\"select \"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_ID",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_LON",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_LAT",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_ALTIM",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_TS",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_AZIM",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_TEXT",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_NOTE_ID",
".",
"getFieldName",
"(",
")",
"+",
"\",\"",
"+",
"//",
"ImageTableFields",
".",
"COLUMN_IMAGEDATA_ID",
".",
"getFieldName",
"(",
")",
"+",
"//",
"\" from \"",
"+",
"TABLE_IMAGES",
";",
"try",
"(",
"IHMStatement",
"statement",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"statement",
".",
"executeQuery",
"(",
"sql",
")",
";",
")",
"{",
"statement",
".",
"setQueryTimeout",
"(",
"30",
")",
";",
"// set timeout to 30 sec.",
"while",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"long",
"id",
"=",
"rs",
".",
"getLong",
"(",
"1",
")",
";",
"double",
"lon",
"=",
"rs",
".",
"getDouble",
"(",
"2",
")",
";",
"double",
"lat",
"=",
"rs",
".",
"getDouble",
"(",
"3",
")",
";",
"double",
"altim",
"=",
"rs",
".",
"getDouble",
"(",
"4",
")",
";",
"long",
"ts",
"=",
"rs",
".",
"getLong",
"(",
"5",
")",
";",
"double",
"azim",
"=",
"rs",
".",
"getDouble",
"(",
"6",
")",
";",
"String",
"text",
"=",
"rs",
".",
"getString",
"(",
"7",
")",
";",
"long",
"noteId",
"=",
"rs",
".",
"getLong",
"(",
"8",
")",
";",
"long",
"imageDataId",
"=",
"rs",
".",
"getLong",
"(",
"9",
")",
";",
"Image",
"image",
"=",
"new",
"Image",
"(",
"id",
",",
"text",
",",
"lon",
",",
"lat",
",",
"altim",
",",
"azim",
",",
"imageDataId",
",",
"noteId",
",",
"ts",
")",
";",
"images",
".",
"add",
"(",
"image",
")",
";",
"}",
"}",
"return",
"images",
";",
"}"
] | Get the list of Images from the db.
@return list of notes.
@throws IOException if something goes wrong. | [
"Get",
"the",
"list",
"of",
"Images",
"from",
"the",
"db",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoImages.java#L205-L238 |
137,387 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoImages.java | DaoImages.getImageData | public static byte[] getImageData( IHMConnection connection, long imageDataId ) throws Exception {
String sql = "select " + //
ImageDataTableFields.COLUMN_IMAGE.getFieldName() + //
" from " + TABLE_IMAGE_DATA + " where " + //
ImageDataTableFields.COLUMN_ID.getFieldName() + " = " + imageDataId;
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(sql);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
if (rs.next()) {
byte[] bytes = rs.getBytes(1);
return bytes;
}
}
return null;
} | java | public static byte[] getImageData( IHMConnection connection, long imageDataId ) throws Exception {
String sql = "select " + //
ImageDataTableFields.COLUMN_IMAGE.getFieldName() + //
" from " + TABLE_IMAGE_DATA + " where " + //
ImageDataTableFields.COLUMN_ID.getFieldName() + " = " + imageDataId;
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(sql);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
if (rs.next()) {
byte[] bytes = rs.getBytes(1);
return bytes;
}
}
return null;
} | [
"public",
"static",
"byte",
"[",
"]",
"getImageData",
"(",
"IHMConnection",
"connection",
",",
"long",
"imageDataId",
")",
"throws",
"Exception",
"{",
"String",
"sql",
"=",
"\"select \"",
"+",
"//",
"ImageDataTableFields",
".",
"COLUMN_IMAGE",
".",
"getFieldName",
"(",
")",
"+",
"//",
"\" from \"",
"+",
"TABLE_IMAGE_DATA",
"+",
"\" where \"",
"+",
"//",
"ImageDataTableFields",
".",
"COLUMN_ID",
".",
"getFieldName",
"(",
")",
"+",
"\" = \"",
"+",
"imageDataId",
";",
"try",
"(",
"IHMStatement",
"statement",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"statement",
".",
"executeQuery",
"(",
"sql",
")",
";",
")",
"{",
"statement",
".",
"setQueryTimeout",
"(",
"30",
")",
";",
"// set timeout to 30 sec.",
"if",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"byte",
"[",
"]",
"bytes",
"=",
"rs",
".",
"getBytes",
"(",
"1",
")",
";",
"return",
"bytes",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get Image data from data id.
@param connection
@param imageDataId
@return
@throws Exception | [
"Get",
"Image",
"data",
"from",
"data",
"id",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoImages.java#L248-L263 |
137,388 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/IdentityMatrix.java | IdentityMatrix.convert | public static void convert(SquareMatrix sm)
{
for (int r = 0; r < sm.nRows; ++r) {
for (int c = 0; c < sm.nCols; ++c) {
sm.values[r][c] = (r == c) ? 1 : 0;
}
}
} | java | public static void convert(SquareMatrix sm)
{
for (int r = 0; r < sm.nRows; ++r) {
for (int c = 0; c < sm.nCols; ++c) {
sm.values[r][c] = (r == c) ? 1 : 0;
}
}
} | [
"public",
"static",
"void",
"convert",
"(",
"SquareMatrix",
"sm",
")",
"{",
"for",
"(",
"int",
"r",
"=",
"0",
";",
"r",
"<",
"sm",
".",
"nRows",
";",
"++",
"r",
")",
"{",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"sm",
".",
"nCols",
";",
"++",
"c",
")",
"{",
"sm",
".",
"values",
"[",
"r",
"]",
"[",
"c",
"]",
"=",
"(",
"r",
"==",
"c",
")",
"?",
"1",
":",
"0",
";",
"}",
"}",
"}"
] | Convert a square matrix into an identity matrix.
@param sm the square matrix to convert | [
"Convert",
"a",
"square",
"matrix",
"into",
"an",
"identity",
"matrix",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/math/matrixes/IdentityMatrix.java#L24-L31 |
137,389 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java | FeatureUtilities.createFeatureCollection | public static SimpleFeatureCollection createFeatureCollection( SimpleFeature... features ) {
DefaultFeatureCollection fcollection = new DefaultFeatureCollection();
for( SimpleFeature feature : features ) {
fcollection.add(feature);
}
return fcollection;
} | java | public static SimpleFeatureCollection createFeatureCollection( SimpleFeature... features ) {
DefaultFeatureCollection fcollection = new DefaultFeatureCollection();
for( SimpleFeature feature : features ) {
fcollection.add(feature);
}
return fcollection;
} | [
"public",
"static",
"SimpleFeatureCollection",
"createFeatureCollection",
"(",
"SimpleFeature",
"...",
"features",
")",
"{",
"DefaultFeatureCollection",
"fcollection",
"=",
"new",
"DefaultFeatureCollection",
"(",
")",
";",
"for",
"(",
"SimpleFeature",
"feature",
":",
"features",
")",
"{",
"fcollection",
".",
"add",
"(",
"feature",
")",
";",
"}",
"return",
"fcollection",
";",
"}"
] | Create a featurecollection from a vector of features
@param features - the vectore of features
@return the created featurecollection | [
"Create",
"a",
"featurecollection",
"from",
"a",
"vector",
"of",
"features"
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java#L212-L219 |
137,390 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java | FeatureUtilities.getAttributeCaseChecked | public static Object getAttributeCaseChecked( SimpleFeature feature, String field ) {
Object attribute = feature.getAttribute(field);
if (attribute == null) {
attribute = feature.getAttribute(field.toLowerCase());
if (attribute != null)
return attribute;
attribute = feature.getAttribute(field.toUpperCase());
if (attribute != null)
return attribute;
// alright, last try, search for it
SimpleFeatureType featureType = feature.getFeatureType();
field = findAttributeName(featureType, field);
if (field != null) {
return feature.getAttribute(field);
}
}
return attribute;
} | java | public static Object getAttributeCaseChecked( SimpleFeature feature, String field ) {
Object attribute = feature.getAttribute(field);
if (attribute == null) {
attribute = feature.getAttribute(field.toLowerCase());
if (attribute != null)
return attribute;
attribute = feature.getAttribute(field.toUpperCase());
if (attribute != null)
return attribute;
// alright, last try, search for it
SimpleFeatureType featureType = feature.getFeatureType();
field = findAttributeName(featureType, field);
if (field != null) {
return feature.getAttribute(field);
}
}
return attribute;
} | [
"public",
"static",
"Object",
"getAttributeCaseChecked",
"(",
"SimpleFeature",
"feature",
",",
"String",
"field",
")",
"{",
"Object",
"attribute",
"=",
"feature",
".",
"getAttribute",
"(",
"field",
")",
";",
"if",
"(",
"attribute",
"==",
"null",
")",
"{",
"attribute",
"=",
"feature",
".",
"getAttribute",
"(",
"field",
".",
"toLowerCase",
"(",
")",
")",
";",
"if",
"(",
"attribute",
"!=",
"null",
")",
"return",
"attribute",
";",
"attribute",
"=",
"feature",
".",
"getAttribute",
"(",
"field",
".",
"toUpperCase",
"(",
")",
")",
";",
"if",
"(",
"attribute",
"!=",
"null",
")",
"return",
"attribute",
";",
"// alright, last try, search for it",
"SimpleFeatureType",
"featureType",
"=",
"feature",
".",
"getFeatureType",
"(",
")",
";",
"field",
"=",
"findAttributeName",
"(",
"featureType",
",",
"field",
")",
";",
"if",
"(",
"field",
"!=",
"null",
")",
"{",
"return",
"feature",
".",
"getAttribute",
"(",
"field",
")",
";",
"}",
"}",
"return",
"attribute",
";",
"}"
] | Getter for attributes of a feature.
<p>If the attribute is not found, checks are done in non
case sensitive mode.
@param feature the feature from which to get the attribute.
@param field the name of the field.
@return the attribute or null if none found. | [
"Getter",
"for",
"attributes",
"of",
"a",
"feature",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java#L590-L608 |
137,391 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java | FeatureUtilities.findAttributeName | public static String findAttributeName( SimpleFeatureType featureType, String field ) {
List<AttributeDescriptor> attributeDescriptors = featureType.getAttributeDescriptors();
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
String name = attributeDescriptor.getLocalName();
if (name.toLowerCase().equals(field.toLowerCase())) {
return name;
}
}
return null;
} | java | public static String findAttributeName( SimpleFeatureType featureType, String field ) {
List<AttributeDescriptor> attributeDescriptors = featureType.getAttributeDescriptors();
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
String name = attributeDescriptor.getLocalName();
if (name.toLowerCase().equals(field.toLowerCase())) {
return name;
}
}
return null;
} | [
"public",
"static",
"String",
"findAttributeName",
"(",
"SimpleFeatureType",
"featureType",
",",
"String",
"field",
")",
"{",
"List",
"<",
"AttributeDescriptor",
">",
"attributeDescriptors",
"=",
"featureType",
".",
"getAttributeDescriptors",
"(",
")",
";",
"for",
"(",
"AttributeDescriptor",
"attributeDescriptor",
":",
"attributeDescriptors",
")",
"{",
"String",
"name",
"=",
"attributeDescriptor",
".",
"getLocalName",
"(",
")",
";",
"if",
"(",
"name",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"field",
".",
"toLowerCase",
"(",
")",
")",
")",
"{",
"return",
"name",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find the name of an attribute, case insensitive.
@param featureType the feature type to check.
@param field the case insensitive field name.
@return the real name of the field, or <code>null</code>, if none found. | [
"Find",
"the",
"name",
"of",
"an",
"attribute",
"case",
"insensitive",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java#L617-L626 |
137,392 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java | FeatureUtilities.featureCollection2QueryResult | public static QueryResult featureCollection2QueryResult( SimpleFeatureCollection featureCollection ) {
List<AttributeDescriptor> attributeDescriptors = featureCollection.getSchema().getAttributeDescriptors();
QueryResult queryResult = new QueryResult();
int count = 0;
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
if (!(attributeDescriptor instanceof GeometryDescriptor)) {
String fieldName = attributeDescriptor.getLocalName();
String type = attributeDescriptor.getType().getBinding().toString();
queryResult.names.add(fieldName);
queryResult.types.add(type);
count++;
}
}
SimpleFeatureIterator featureIterator = featureCollection.features();
while( featureIterator.hasNext() ) {
SimpleFeature f = featureIterator.next();
Geometry geometry = (Geometry) f.getDefaultGeometry();
queryResult.geometries.add(geometry);
Object[] dataRow = new Object[count];
int index = 0;
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
if (!(attributeDescriptor instanceof GeometryDescriptor)) {
String fieldName = attributeDescriptor.getLocalName();
Object attribute = f.getAttribute(fieldName);
if (attribute == null) {
attribute = "";
}
dataRow[index++] = attribute;
}
}
queryResult.data.add(dataRow);
}
return queryResult;
} | java | public static QueryResult featureCollection2QueryResult( SimpleFeatureCollection featureCollection ) {
List<AttributeDescriptor> attributeDescriptors = featureCollection.getSchema().getAttributeDescriptors();
QueryResult queryResult = new QueryResult();
int count = 0;
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
if (!(attributeDescriptor instanceof GeometryDescriptor)) {
String fieldName = attributeDescriptor.getLocalName();
String type = attributeDescriptor.getType().getBinding().toString();
queryResult.names.add(fieldName);
queryResult.types.add(type);
count++;
}
}
SimpleFeatureIterator featureIterator = featureCollection.features();
while( featureIterator.hasNext() ) {
SimpleFeature f = featureIterator.next();
Geometry geometry = (Geometry) f.getDefaultGeometry();
queryResult.geometries.add(geometry);
Object[] dataRow = new Object[count];
int index = 0;
for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
if (!(attributeDescriptor instanceof GeometryDescriptor)) {
String fieldName = attributeDescriptor.getLocalName();
Object attribute = f.getAttribute(fieldName);
if (attribute == null) {
attribute = "";
}
dataRow[index++] = attribute;
}
}
queryResult.data.add(dataRow);
}
return queryResult;
} | [
"public",
"static",
"QueryResult",
"featureCollection2QueryResult",
"(",
"SimpleFeatureCollection",
"featureCollection",
")",
"{",
"List",
"<",
"AttributeDescriptor",
">",
"attributeDescriptors",
"=",
"featureCollection",
".",
"getSchema",
"(",
")",
".",
"getAttributeDescriptors",
"(",
")",
";",
"QueryResult",
"queryResult",
"=",
"new",
"QueryResult",
"(",
")",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"AttributeDescriptor",
"attributeDescriptor",
":",
"attributeDescriptors",
")",
"{",
"if",
"(",
"!",
"(",
"attributeDescriptor",
"instanceof",
"GeometryDescriptor",
")",
")",
"{",
"String",
"fieldName",
"=",
"attributeDescriptor",
".",
"getLocalName",
"(",
")",
";",
"String",
"type",
"=",
"attributeDescriptor",
".",
"getType",
"(",
")",
".",
"getBinding",
"(",
")",
".",
"toString",
"(",
")",
";",
"queryResult",
".",
"names",
".",
"add",
"(",
"fieldName",
")",
";",
"queryResult",
".",
"types",
".",
"add",
"(",
"type",
")",
";",
"count",
"++",
";",
"}",
"}",
"SimpleFeatureIterator",
"featureIterator",
"=",
"featureCollection",
".",
"features",
"(",
")",
";",
"while",
"(",
"featureIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"SimpleFeature",
"f",
"=",
"featureIterator",
".",
"next",
"(",
")",
";",
"Geometry",
"geometry",
"=",
"(",
"Geometry",
")",
"f",
".",
"getDefaultGeometry",
"(",
")",
";",
"queryResult",
".",
"geometries",
".",
"add",
"(",
"geometry",
")",
";",
"Object",
"[",
"]",
"dataRow",
"=",
"new",
"Object",
"[",
"count",
"]",
";",
"int",
"index",
"=",
"0",
";",
"for",
"(",
"AttributeDescriptor",
"attributeDescriptor",
":",
"attributeDescriptors",
")",
"{",
"if",
"(",
"!",
"(",
"attributeDescriptor",
"instanceof",
"GeometryDescriptor",
")",
")",
"{",
"String",
"fieldName",
"=",
"attributeDescriptor",
".",
"getLocalName",
"(",
")",
";",
"Object",
"attribute",
"=",
"f",
".",
"getAttribute",
"(",
"fieldName",
")",
";",
"if",
"(",
"attribute",
"==",
"null",
")",
"{",
"attribute",
"=",
"\"\"",
";",
"}",
"dataRow",
"[",
"index",
"++",
"]",
"=",
"attribute",
";",
"}",
"}",
"queryResult",
".",
"data",
".",
"add",
"(",
"dataRow",
")",
";",
"}",
"return",
"queryResult",
";",
"}"
] | Utility to convert a featurecollection to a queryresult format.
@param featureCollection the collection to convert.
@return the queryresult object. | [
"Utility",
"to",
"convert",
"a",
"featurecollection",
"to",
"a",
"queryresult",
"format",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/features/FeatureUtilities.java#L981-L1018 |
137,393 | TheHortonMachine/hortonmachine | gears/src/main/java/oms3/compiler/MemorySourceJavaFileObject.java | MemorySourceJavaFileObject.createUriFromName | private static URI createUriFromName(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
return new URI(name);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid name: " + name, e);
}
} | java | private static URI createUriFromName(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
return new URI(name);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid name: " + name, e);
}
} | [
"private",
"static",
"URI",
"createUriFromName",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"name\"",
")",
";",
"}",
"try",
"{",
"return",
"new",
"URI",
"(",
"name",
")",
";",
"}",
"catch",
"(",
"final",
"URISyntaxException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid name: \"",
"+",
"name",
",",
"e",
")",
";",
"}",
"}"
] | Creates a URI from a source file name.
@param name the source file name.
@return the URI.
@throws NullPointerException if <code>name</code>
is null.
@throws IllegalArgumentException if <code>name</code>
is invalid. | [
"Creates",
"a",
"URI",
"from",
"a",
"source",
"file",
"name",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/oms3/compiler/MemorySourceJavaFileObject.java#L44-L53 |
137,394 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoNotes.java | DaoNotes.addNote | public static void addNote( Connection connection, long id, double lon, double lat, double altim, long timestamp, String text,
String form ) throws Exception {
String insertSQL = "INSERT INTO " + TableDescriptions.TABLE_NOTES + "(" + //
TableDescriptions.NotesTableFields.COLUMN_ID.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_LAT.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_LON.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_ALTIM.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_TS.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_TEXT.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_FORM.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_ISDIRTY.getFieldName() + //
") VALUES" + "(?,?,?,?,?,?,?,?)";
try (PreparedStatement writeStatement = connection.prepareStatement(insertSQL)) {
writeStatement.setLong(1, id);
writeStatement.setDouble(2, lat);
writeStatement.setDouble(3, lon);
writeStatement.setDouble(4, altim);
writeStatement.setLong(5, timestamp);
writeStatement.setString(6, text);
writeStatement.setString(7, form);
writeStatement.setInt(8, 1);
writeStatement.executeUpdate();
}
} | java | public static void addNote( Connection connection, long id, double lon, double lat, double altim, long timestamp, String text,
String form ) throws Exception {
String insertSQL = "INSERT INTO " + TableDescriptions.TABLE_NOTES + "(" + //
TableDescriptions.NotesTableFields.COLUMN_ID.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_LAT.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_LON.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_ALTIM.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_TS.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_TEXT.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_FORM.getFieldName() + ", " + //
TableDescriptions.NotesTableFields.COLUMN_ISDIRTY.getFieldName() + //
") VALUES" + "(?,?,?,?,?,?,?,?)";
try (PreparedStatement writeStatement = connection.prepareStatement(insertSQL)) {
writeStatement.setLong(1, id);
writeStatement.setDouble(2, lat);
writeStatement.setDouble(3, lon);
writeStatement.setDouble(4, altim);
writeStatement.setLong(5, timestamp);
writeStatement.setString(6, text);
writeStatement.setString(7, form);
writeStatement.setInt(8, 1);
writeStatement.executeUpdate();
}
} | [
"public",
"static",
"void",
"addNote",
"(",
"Connection",
"connection",
",",
"long",
"id",
",",
"double",
"lon",
",",
"double",
"lat",
",",
"double",
"altim",
",",
"long",
"timestamp",
",",
"String",
"text",
",",
"String",
"form",
")",
"throws",
"Exception",
"{",
"String",
"insertSQL",
"=",
"\"INSERT INTO \"",
"+",
"TableDescriptions",
".",
"TABLE_NOTES",
"+",
"\"(\"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_ID",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_LAT",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_LON",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_ALTIM",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_TS",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_TEXT",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_FORM",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"TableDescriptions",
".",
"NotesTableFields",
".",
"COLUMN_ISDIRTY",
".",
"getFieldName",
"(",
")",
"+",
"//",
"\") VALUES\"",
"+",
"\"(?,?,?,?,?,?,?,?)\"",
";",
"try",
"(",
"PreparedStatement",
"writeStatement",
"=",
"connection",
".",
"prepareStatement",
"(",
"insertSQL",
")",
")",
"{",
"writeStatement",
".",
"setLong",
"(",
"1",
",",
"id",
")",
";",
"writeStatement",
".",
"setDouble",
"(",
"2",
",",
"lat",
")",
";",
"writeStatement",
".",
"setDouble",
"(",
"3",
",",
"lon",
")",
";",
"writeStatement",
".",
"setDouble",
"(",
"4",
",",
"altim",
")",
";",
"writeStatement",
".",
"setLong",
"(",
"5",
",",
"timestamp",
")",
";",
"writeStatement",
".",
"setString",
"(",
"6",
",",
"text",
")",
";",
"writeStatement",
".",
"setString",
"(",
"7",
",",
"form",
")",
";",
"writeStatement",
".",
"setInt",
"(",
"8",
",",
"1",
")",
";",
"writeStatement",
".",
"executeUpdate",
"(",
")",
";",
"}",
"}"
] | Add a new note to the database.
@param id the id
@param lon lon
@param lat lat
@param altim elevation
@param timestamp the UTC timestamp in millis.
@param text a text
@param form the optional json form.
@throws IOException if something goes wrong. | [
"Add",
"a",
"new",
"note",
"to",
"the",
"database",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoNotes.java#L118-L142 |
137,395 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoNotes.java | DaoNotes.getNotesList | public static List<Note> getNotesList( IHMConnection connection, float[] nswe ) throws Exception {
String query = "SELECT " + //
NotesTableFields.COLUMN_ID.getFieldName() + ", " + //
NotesTableFields.COLUMN_LON.getFieldName() + ", " + //
NotesTableFields.COLUMN_LAT.getFieldName() + ", " + //
NotesTableFields.COLUMN_ALTIM.getFieldName() + ", " + //
NotesTableFields.COLUMN_TEXT.getFieldName() + ", " + //
NotesTableFields.COLUMN_TS.getFieldName() + ", " + //
NotesTableFields.COLUMN_DESCRIPTION.getFieldName() + //
" FROM " + TABLE_NOTES;
if (nswe != null) {
query = query + " WHERE (lon BETWEEN XXX AND XXX) AND (lat BETWEEN XXX AND XXX)";
query = query.replaceFirst("XXX", String.valueOf(nswe[2]));
query = query.replaceFirst("XXX", String.valueOf(nswe[3]));
query = query.replaceFirst("XXX", String.valueOf(nswe[1]));
query = query.replaceFirst("XXX", String.valueOf(nswe[0]));
}
List<Note> notes = new ArrayList<>();
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
while( rs.next() ) {
Note note = new Note();
note.id = rs.getLong(1);
note.lon = rs.getDouble(2);
note.lat = rs.getDouble(3);
note.altim = rs.getDouble(4);
note.simpleText = rs.getString(5);
note.timeStamp = rs.getLong(6);
note.description = rs.getString(7);
notes.add(note);
}
}
return notes;
} | java | public static List<Note> getNotesList( IHMConnection connection, float[] nswe ) throws Exception {
String query = "SELECT " + //
NotesTableFields.COLUMN_ID.getFieldName() + ", " + //
NotesTableFields.COLUMN_LON.getFieldName() + ", " + //
NotesTableFields.COLUMN_LAT.getFieldName() + ", " + //
NotesTableFields.COLUMN_ALTIM.getFieldName() + ", " + //
NotesTableFields.COLUMN_TEXT.getFieldName() + ", " + //
NotesTableFields.COLUMN_TS.getFieldName() + ", " + //
NotesTableFields.COLUMN_DESCRIPTION.getFieldName() + //
" FROM " + TABLE_NOTES;
if (nswe != null) {
query = query + " WHERE (lon BETWEEN XXX AND XXX) AND (lat BETWEEN XXX AND XXX)";
query = query.replaceFirst("XXX", String.valueOf(nswe[2]));
query = query.replaceFirst("XXX", String.valueOf(nswe[3]));
query = query.replaceFirst("XXX", String.valueOf(nswe[1]));
query = query.replaceFirst("XXX", String.valueOf(nswe[0]));
}
List<Note> notes = new ArrayList<>();
try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
while( rs.next() ) {
Note note = new Note();
note.id = rs.getLong(1);
note.lon = rs.getDouble(2);
note.lat = rs.getDouble(3);
note.altim = rs.getDouble(4);
note.simpleText = rs.getString(5);
note.timeStamp = rs.getLong(6);
note.description = rs.getString(7);
notes.add(note);
}
}
return notes;
} | [
"public",
"static",
"List",
"<",
"Note",
">",
"getNotesList",
"(",
"IHMConnection",
"connection",
",",
"float",
"[",
"]",
"nswe",
")",
"throws",
"Exception",
"{",
"String",
"query",
"=",
"\"SELECT \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_ID",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_LON",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_LAT",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_ALTIM",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_TEXT",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_TS",
".",
"getFieldName",
"(",
")",
"+",
"\", \"",
"+",
"//",
"NotesTableFields",
".",
"COLUMN_DESCRIPTION",
".",
"getFieldName",
"(",
")",
"+",
"//",
"\" FROM \"",
"+",
"TABLE_NOTES",
";",
"if",
"(",
"nswe",
"!=",
"null",
")",
"{",
"query",
"=",
"query",
"+",
"\" WHERE (lon BETWEEN XXX AND XXX) AND (lat BETWEEN XXX AND XXX)\"",
";",
"query",
"=",
"query",
".",
"replaceFirst",
"(",
"\"XXX\"",
",",
"String",
".",
"valueOf",
"(",
"nswe",
"[",
"2",
"]",
")",
")",
";",
"query",
"=",
"query",
".",
"replaceFirst",
"(",
"\"XXX\"",
",",
"String",
".",
"valueOf",
"(",
"nswe",
"[",
"3",
"]",
")",
")",
";",
"query",
"=",
"query",
".",
"replaceFirst",
"(",
"\"XXX\"",
",",
"String",
".",
"valueOf",
"(",
"nswe",
"[",
"1",
"]",
")",
")",
";",
"query",
"=",
"query",
".",
"replaceFirst",
"(",
"\"XXX\"",
",",
"String",
".",
"valueOf",
"(",
"nswe",
"[",
"0",
"]",
")",
")",
";",
"}",
"List",
"<",
"Note",
">",
"notes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"try",
"(",
"IHMStatement",
"statement",
"=",
"connection",
".",
"createStatement",
"(",
")",
";",
"IHMResultSet",
"rs",
"=",
"statement",
".",
"executeQuery",
"(",
"query",
")",
";",
")",
"{",
"statement",
".",
"setQueryTimeout",
"(",
"30",
")",
";",
"// set timeout to 30 sec.",
"while",
"(",
"rs",
".",
"next",
"(",
")",
")",
"{",
"Note",
"note",
"=",
"new",
"Note",
"(",
")",
";",
"note",
".",
"id",
"=",
"rs",
".",
"getLong",
"(",
"1",
")",
";",
"note",
".",
"lon",
"=",
"rs",
".",
"getDouble",
"(",
"2",
")",
";",
"note",
".",
"lat",
"=",
"rs",
".",
"getDouble",
"(",
"3",
")",
";",
"note",
".",
"altim",
"=",
"rs",
".",
"getDouble",
"(",
"4",
")",
";",
"note",
".",
"simpleText",
"=",
"rs",
".",
"getString",
"(",
"5",
")",
";",
"note",
".",
"timeStamp",
"=",
"rs",
".",
"getLong",
"(",
"6",
")",
";",
"note",
".",
"description",
"=",
"rs",
".",
"getString",
"(",
"7",
")",
";",
"notes",
".",
"add",
"(",
"note",
")",
";",
"}",
"}",
"return",
"notes",
";",
"}"
] | Get the collected notes from the database inside a given bound.
@param connection the db to take from .
@param nswe optional bounds as [n, s, w, e].
@return the list of notes inside the bounds.
@throws Exception | [
"Get",
"the",
"collected",
"notes",
"from",
"the",
"database",
"inside",
"a",
"given",
"bound",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/io/geopaparazzi/geopap4/DaoNotes.java#L152-L188 |
137,396 | TheHortonMachine/hortonmachine | gui/src/main/java/org/hortonmachine/gui/spatialtoolbox/core/ParametersPanel.java | ParametersPanel.isAtLeastOneAssignable | private boolean isAtLeastOneAssignable( String main, Class< ? >... classes ) {
for( Class< ? > clazz : classes ) {
if (clazz.getCanonicalName().equals(main)) {
return true;
}
}
return false;
} | java | private boolean isAtLeastOneAssignable( String main, Class< ? >... classes ) {
for( Class< ? > clazz : classes ) {
if (clazz.getCanonicalName().equals(main)) {
return true;
}
}
return false;
} | [
"private",
"boolean",
"isAtLeastOneAssignable",
"(",
"String",
"main",
",",
"Class",
"<",
"?",
">",
"...",
"classes",
")",
"{",
"for",
"(",
"Class",
"<",
"?",
">",
"clazz",
":",
"classes",
")",
"{",
"if",
"(",
"clazz",
".",
"getCanonicalName",
"(",
")",
".",
"equals",
"(",
"main",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if one class is assignable from at least one of the others.
@param main the canonical name of class to check.
@param classes the other classes.
@return true if at least one of the other classes match. | [
"Checks",
"if",
"one",
"class",
"is",
"assignable",
"from",
"at",
"least",
"one",
"of",
"the",
"others",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gui/src/main/java/org/hortonmachine/gui/spatialtoolbox/core/ParametersPanel.java#L548-L555 |
137,397 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/sorting/QuickSortAlgorithm.java | QuickSortAlgorithm.sort | public void sort( double[] values, double[] valuesToFollow ) {
this.valuesToSortDouble = values;
this.valuesToFollowDouble = valuesToFollow;
number = values.length;
monitor.beginTask("Sorting...", -1);
monitor.worked(1);
quicksort(0, number - 1);
monitor.done();
} | java | public void sort( double[] values, double[] valuesToFollow ) {
this.valuesToSortDouble = values;
this.valuesToFollowDouble = valuesToFollow;
number = values.length;
monitor.beginTask("Sorting...", -1);
monitor.worked(1);
quicksort(0, number - 1);
monitor.done();
} | [
"public",
"void",
"sort",
"(",
"double",
"[",
"]",
"values",
",",
"double",
"[",
"]",
"valuesToFollow",
")",
"{",
"this",
".",
"valuesToSortDouble",
"=",
"values",
";",
"this",
".",
"valuesToFollowDouble",
"=",
"valuesToFollow",
";",
"number",
"=",
"values",
".",
"length",
";",
"monitor",
".",
"beginTask",
"(",
"\"Sorting...\"",
",",
"-",
"1",
")",
";",
"monitor",
".",
"worked",
"(",
"1",
")",
";",
"quicksort",
"(",
"0",
",",
"number",
"-",
"1",
")",
";",
"monitor",
".",
"done",
"(",
")",
";",
"}"
] | Sorts an array of double values and moves with the sort a second array.
@param values the array to sort.
@param valuesToFollow the array that should be sorted following the
indexes of the first array. Can be null. | [
"Sorts",
"an",
"array",
"of",
"double",
"values",
"and",
"moves",
"with",
"the",
"sort",
"a",
"second",
"array",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/sorting/QuickSortAlgorithm.java#L46-L58 |
137,398 | TheHortonMachine/hortonmachine | gears/src/main/java/org/hortonmachine/gears/utils/sorting/QuickSortAlgorithm.java | QuickSortAlgorithm.sort | public void sort( float[] values, float[] valuesToFollow ) {
this.valuesToSortFloat = values;
this.valuesToFollowFloat = valuesToFollow;
number = values.length;
monitor.beginTask("Sorting...", -1);
monitor.worked(1);
quicksortFloat(0, number - 1);
monitor.done();
} | java | public void sort( float[] values, float[] valuesToFollow ) {
this.valuesToSortFloat = values;
this.valuesToFollowFloat = valuesToFollow;
number = values.length;
monitor.beginTask("Sorting...", -1);
monitor.worked(1);
quicksortFloat(0, number - 1);
monitor.done();
} | [
"public",
"void",
"sort",
"(",
"float",
"[",
"]",
"values",
",",
"float",
"[",
"]",
"valuesToFollow",
")",
"{",
"this",
".",
"valuesToSortFloat",
"=",
"values",
";",
"this",
".",
"valuesToFollowFloat",
"=",
"valuesToFollow",
";",
"number",
"=",
"values",
".",
"length",
";",
"monitor",
".",
"beginTask",
"(",
"\"Sorting...\"",
",",
"-",
"1",
")",
";",
"monitor",
".",
"worked",
"(",
"1",
")",
";",
"quicksortFloat",
"(",
"0",
",",
"number",
"-",
"1",
")",
";",
"monitor",
".",
"done",
"(",
")",
";",
"}"
] | Sorts an array of float values and moves with the sort a second array.
@param values the array to sort.
@param valuesToFollow the array that should be sorted following the
indexes of the first array. Can be null. | [
"Sorts",
"an",
"array",
"of",
"float",
"values",
"and",
"moves",
"with",
"the",
"sort",
"a",
"second",
"array",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/org/hortonmachine/gears/utils/sorting/QuickSortAlgorithm.java#L67-L79 |
137,399 | TheHortonMachine/hortonmachine | gears/src/main/java/oms3/ngmf/ui/calc/RandomNormal.java | RandomNormal.nextCentral | public float nextCentral() {
// Average 12 uniformly-distributed random values.
float sum = 0.0f;
for (int j = 0; j < 12; ++j)
sum += gen.nextFloat();
// Subtract 6 to center about 0.
return stddev*(sum - 6) + mean;
} | java | public float nextCentral() {
// Average 12 uniformly-distributed random values.
float sum = 0.0f;
for (int j = 0; j < 12; ++j)
sum += gen.nextFloat();
// Subtract 6 to center about 0.
return stddev*(sum - 6) + mean;
} | [
"public",
"float",
"nextCentral",
"(",
")",
"{",
"// Average 12 uniformly-distributed random values.",
"float",
"sum",
"=",
"0.0f",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"12",
";",
"++",
"j",
")",
"sum",
"+=",
"gen",
".",
"nextFloat",
"(",
")",
";",
"// Subtract 6 to center about 0.",
"return",
"stddev",
"*",
"(",
"sum",
"-",
"6",
")",
"+",
"mean",
";",
"}"
] | Compute the next random value using the Central Limit Theorem,
which states that the averages of sets of uniformly-distributed
random values are normally distributed. | [
"Compute",
"the",
"next",
"random",
"value",
"using",
"the",
"Central",
"Limit",
"Theorem",
"which",
"states",
"that",
"the",
"averages",
"of",
"sets",
"of",
"uniformly",
"-",
"distributed",
"random",
"values",
"are",
"normally",
"distributed",
"."
] | d2b436bbdf951dc1fda56096a42dbc0eae4d35a5 | https://github.com/TheHortonMachine/hortonmachine/blob/d2b436bbdf951dc1fda56096a42dbc0eae4d35a5/gears/src/main/java/oms3/ngmf/ui/calc/RandomNormal.java#L50-L58 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.