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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
158,000
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java
|
JavascriptObject.setProperty
|
protected void setProperty(String propertyName, JavascriptEnum propertyValue) {
jsObject.setMember(propertyName, propertyValue.getEnumValue());
}
|
java
|
protected void setProperty(String propertyName, JavascriptEnum propertyValue) {
jsObject.setMember(propertyName, propertyValue.getEnumValue());
}
|
[
"protected",
"void",
"setProperty",
"(",
"String",
"propertyName",
",",
"JavascriptEnum",
"propertyValue",
")",
"{",
"jsObject",
".",
"setMember",
"(",
"propertyName",
",",
"propertyValue",
".",
"getEnumValue",
"(",
")",
")",
";",
"}"
] |
Sets a property on this Javascript object for which the value is a
JavascriptEnum
The value is set to what is returned by the getEnumValue() method on the JavascriptEnum
@param propertyName The name of the property.
@param propertyValue The value of the property.
|
[
"Sets",
"a",
"property",
"on",
"this",
"Javascript",
"object",
"for",
"which",
"the",
"value",
"is",
"a",
"JavascriptEnum"
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java#L169-L171
|
158,001
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java
|
JavascriptObject.getProperty
|
protected <T> T getProperty(String key, Class<T> type) {
Object returnValue = getProperty(key);
if (returnValue != null) {
return (T) returnValue;
} else {
return null;
}
}
|
java
|
protected <T> T getProperty(String key, Class<T> type) {
Object returnValue = getProperty(key);
if (returnValue != null) {
return (T) returnValue;
} else {
return null;
}
}
|
[
"protected",
"<",
"T",
">",
"T",
"getProperty",
"(",
"String",
"key",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"Object",
"returnValue",
"=",
"getProperty",
"(",
"key",
")",
";",
"if",
"(",
"returnValue",
"!=",
"null",
")",
"{",
"return",
"(",
"T",
")",
"returnValue",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets the property and casts to the appropriate type
@param <T>
@param key The property name
@param type The property type
@return The value of the property
|
[
"Gets",
"the",
"property",
"and",
"casts",
"to",
"the",
"appropriate",
"type"
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java#L192-L199
|
158,002
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java
|
JavascriptObject.invokeJavascriptReturnValue
|
protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) {
Object returnObject = invokeJavascript(function);
if (returnObject instanceof JSObject) {
try {
Constructor<T> constructor = returnType.getConstructor(JSObject.class);
return constructor.newInstance((JSObject) returnObject);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
} else {
return (T) returnObject;
}
}
|
java
|
protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) {
Object returnObject = invokeJavascript(function);
if (returnObject instanceof JSObject) {
try {
Constructor<T> constructor = returnType.getConstructor(JSObject.class);
return constructor.newInstance((JSObject) returnObject);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
} else {
return (T) returnObject;
}
}
|
[
"protected",
"<",
"T",
">",
"T",
"invokeJavascriptReturnValue",
"(",
"String",
"function",
",",
"Class",
"<",
"T",
">",
"returnType",
")",
"{",
"Object",
"returnObject",
"=",
"invokeJavascript",
"(",
"function",
")",
";",
"if",
"(",
"returnObject",
"instanceof",
"JSObject",
")",
"{",
"try",
"{",
"Constructor",
"<",
"T",
">",
"constructor",
"=",
"returnType",
".",
"getConstructor",
"(",
"JSObject",
".",
"class",
")",
";",
"return",
"constructor",
".",
"newInstance",
"(",
"(",
"JSObject",
")",
"returnObject",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"ex",
")",
";",
"}",
"}",
"else",
"{",
"return",
"(",
"T",
")",
"returnObject",
";",
"}",
"}"
] |
Invokes a JavaScript function that takes no arguments.
@param <T>
@param function The function to invoke
@param returnType The type of object to return
@return The result of the function.
|
[
"Invokes",
"a",
"JavaScript",
"function",
"that",
"takes",
"no",
"arguments",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java#L241-L253
|
158,003
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java
|
JavascriptObject.checkUndefined
|
protected Object checkUndefined(Object val) {
if (val instanceof String && ((String) val).equals("undefined")) {
return null;
}
return val;
}
|
java
|
protected Object checkUndefined(Object val) {
if (val instanceof String && ((String) val).equals("undefined")) {
return null;
}
return val;
}
|
[
"protected",
"Object",
"checkUndefined",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"instanceof",
"String",
"&&",
"(",
"(",
"String",
")",
"val",
")",
".",
"equals",
"(",
"\"undefined\"",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"val",
";",
"}"
] |
JSObject will return the String "undefined" at certain times, so we
need to make sure we're not getting a value that looks valid, but isn't.
@param val The value from Javascript to be checked.
@return Either null or the value passed in.
|
[
"JSObject",
"will",
"return",
"the",
"String",
"undefined",
"at",
"certain",
"times",
"so",
"we",
"need",
"to",
"make",
"sure",
"we",
"re",
"not",
"getting",
"a",
"value",
"that",
"looks",
"valid",
"but",
"isn",
"t",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java#L286-L291
|
158,004
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java
|
JavascriptObject.checkBoolean
|
protected Boolean checkBoolean(Object val, Boolean def) {
return (val == null) ? def : (Boolean) val;
}
|
java
|
protected Boolean checkBoolean(Object val, Boolean def) {
return (val == null) ? def : (Boolean) val;
}
|
[
"protected",
"Boolean",
"checkBoolean",
"(",
"Object",
"val",
",",
"Boolean",
"def",
")",
"{",
"return",
"(",
"val",
"==",
"null",
")",
"?",
"def",
":",
"(",
"Boolean",
")",
"val",
";",
"}"
] |
Checks a returned Javascript value where we expect a boolean but could
get null.
@param val The value from Javascript to be checked.
@param def The default return value, which can be null.
@return The actual value, or if null, returns false.
|
[
"Checks",
"a",
"returned",
"Javascript",
"value",
"where",
"we",
"expect",
"a",
"boolean",
"but",
"could",
"get",
"null",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptObject.java#L300-L302
|
158,005
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/event/EventHandlers.java
|
EventHandlers.registerHandler
|
public String registerHandler(GFXEventHandler handler) {
String uuid = UUID.randomUUID().toString();
handlers.put(uuid, handler);
return uuid;
}
|
java
|
public String registerHandler(GFXEventHandler handler) {
String uuid = UUID.randomUUID().toString();
handlers.put(uuid, handler);
return uuid;
}
|
[
"public",
"String",
"registerHandler",
"(",
"GFXEventHandler",
"handler",
")",
"{",
"String",
"uuid",
"=",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
";",
"handlers",
".",
"put",
"(",
"uuid",
",",
"handler",
")",
";",
"return",
"uuid",
";",
"}"
] |
Registers a handler and returns the callback key to be passed to
Javascript.
@param handler Handler to be registered.
@return A String random UUID that can be used as the callback key.
|
[
"Registers",
"a",
"handler",
"and",
"returns",
"the",
"callback",
"key",
"to",
"be",
"passed",
"to",
"Javascript",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/event/EventHandlers.java#L79-L83
|
158,006
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/event/EventHandlers.java
|
EventHandlers.handleStateEvent
|
public void handleStateEvent(String callbackKey) {
if (handlers.containsKey(callbackKey) && handlers.get(callbackKey) instanceof StateEventHandler) {
((StateEventHandler) handlers.get(callbackKey)).handle();
} else {
System.err.println("Error in handle: " + callbackKey + " for state handler ");
}
}
|
java
|
public void handleStateEvent(String callbackKey) {
if (handlers.containsKey(callbackKey) && handlers.get(callbackKey) instanceof StateEventHandler) {
((StateEventHandler) handlers.get(callbackKey)).handle();
} else {
System.err.println("Error in handle: " + callbackKey + " for state handler ");
}
}
|
[
"public",
"void",
"handleStateEvent",
"(",
"String",
"callbackKey",
")",
"{",
"if",
"(",
"handlers",
".",
"containsKey",
"(",
"callbackKey",
")",
"&&",
"handlers",
".",
"get",
"(",
"callbackKey",
")",
"instanceof",
"StateEventHandler",
")",
"{",
"(",
"(",
"StateEventHandler",
")",
"handlers",
".",
"get",
"(",
"callbackKey",
")",
")",
".",
"handle",
"(",
")",
";",
"}",
"else",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"Error in handle: \"",
"+",
"callbackKey",
"+",
"\" for state handler \"",
")",
";",
"}",
"}"
] |
This method is called from Javascript, passing in the previously created
callback key. It uses that to find the correct handler and then passes on
the call. State events in the Google Maps API don't pass any parameters.
@param callbackKey Key generated by the call to registerHandler.
|
[
"This",
"method",
"is",
"called",
"from",
"Javascript",
"passing",
"in",
"the",
"previously",
"created",
"callback",
"key",
".",
"It",
"uses",
"that",
"to",
"find",
"the",
"correct",
"handler",
"and",
"then",
"passes",
"on",
"the",
"call",
".",
"State",
"events",
"in",
"the",
"Google",
"Maps",
"API",
"don",
"t",
"pass",
"any",
"parameters",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/event/EventHandlers.java#L113-L119
|
158,007
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java
|
ArcBuilder.buildClosedArc
|
public static final PolygonOptions buildClosedArc(LatLong center, LatLong start, LatLong end, ArcType arcType) {
MVCArray res = buildArcPoints(center, start, end);
if (ArcType.ROUND.equals(arcType)) {
res.push(center);
}
return new PolygonOptions().paths(res);
}
|
java
|
public static final PolygonOptions buildClosedArc(LatLong center, LatLong start, LatLong end, ArcType arcType) {
MVCArray res = buildArcPoints(center, start, end);
if (ArcType.ROUND.equals(arcType)) {
res.push(center);
}
return new PolygonOptions().paths(res);
}
|
[
"public",
"static",
"final",
"PolygonOptions",
"buildClosedArc",
"(",
"LatLong",
"center",
",",
"LatLong",
"start",
",",
"LatLong",
"end",
",",
"ArcType",
"arcType",
")",
"{",
"MVCArray",
"res",
"=",
"buildArcPoints",
"(",
"center",
",",
"start",
",",
"end",
")",
";",
"if",
"(",
"ArcType",
".",
"ROUND",
".",
"equals",
"(",
"arcType",
")",
")",
"{",
"res",
".",
"push",
"(",
"center",
")",
";",
"}",
"return",
"new",
"PolygonOptions",
"(",
")",
".",
"paths",
"(",
"res",
")",
";",
"}"
] |
Builds the path for a closed arc, returning a PolygonOptions that can be
further customised before use.
@param center
@param start
@param end
@param arcType Pass in either ArcType.CHORD or ArcType.ROUND
@return PolygonOptions with the paths element populated.
|
[
"Builds",
"the",
"path",
"for",
"a",
"closed",
"arc",
"returning",
"a",
"PolygonOptions",
"that",
"can",
"be",
"further",
"customised",
"before",
"use",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java#L34-L40
|
158,008
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java
|
ArcBuilder.buildOpenArc
|
public static final PolylineOptions buildOpenArc(LatLong center, LatLong start, LatLong end) {
MVCArray res = buildArcPoints(center, start, end);
return new PolylineOptions().path(res);
}
|
java
|
public static final PolylineOptions buildOpenArc(LatLong center, LatLong start, LatLong end) {
MVCArray res = buildArcPoints(center, start, end);
return new PolylineOptions().path(res);
}
|
[
"public",
"static",
"final",
"PolylineOptions",
"buildOpenArc",
"(",
"LatLong",
"center",
",",
"LatLong",
"start",
",",
"LatLong",
"end",
")",
"{",
"MVCArray",
"res",
"=",
"buildArcPoints",
"(",
"center",
",",
"start",
",",
"end",
")",
";",
"return",
"new",
"PolylineOptions",
"(",
")",
".",
"path",
"(",
"res",
")",
";",
"}"
] |
Builds the path for an open arc based on a PolylineOptions.
@param center
@param start
@param end
@return PolylineOptions with the paths element populated.
|
[
"Builds",
"the",
"path",
"for",
"an",
"open",
"arc",
"based",
"on",
"a",
"PolylineOptions",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java#L50-L53
|
158,009
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java
|
ArcBuilder.buildArcPoints
|
public static final MVCArray buildArcPoints(LatLong center, double startBearing, double endBearing, double radius) {
int points = DEFAULT_ARC_POINTS;
MVCArray res = new MVCArray();
if (startBearing > endBearing) {
endBearing += 360.0;
}
double deltaBearing = endBearing - startBearing;
deltaBearing = deltaBearing / points;
for (int i = 0; (i < points + 1); i++) {
res.push(center.getDestinationPoint(startBearing + i * deltaBearing, radius));
}
return res;
}
|
java
|
public static final MVCArray buildArcPoints(LatLong center, double startBearing, double endBearing, double radius) {
int points = DEFAULT_ARC_POINTS;
MVCArray res = new MVCArray();
if (startBearing > endBearing) {
endBearing += 360.0;
}
double deltaBearing = endBearing - startBearing;
deltaBearing = deltaBearing / points;
for (int i = 0; (i < points + 1); i++) {
res.push(center.getDestinationPoint(startBearing + i * deltaBearing, radius));
}
return res;
}
|
[
"public",
"static",
"final",
"MVCArray",
"buildArcPoints",
"(",
"LatLong",
"center",
",",
"double",
"startBearing",
",",
"double",
"endBearing",
",",
"double",
"radius",
")",
"{",
"int",
"points",
"=",
"DEFAULT_ARC_POINTS",
";",
"MVCArray",
"res",
"=",
"new",
"MVCArray",
"(",
")",
";",
"if",
"(",
"startBearing",
">",
"endBearing",
")",
"{",
"endBearing",
"+=",
"360.0",
";",
"}",
"double",
"deltaBearing",
"=",
"endBearing",
"-",
"startBearing",
";",
"deltaBearing",
"=",
"deltaBearing",
"/",
"points",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"(",
"i",
"<",
"points",
"+",
"1",
")",
";",
"i",
"++",
")",
"{",
"res",
".",
"push",
"(",
"center",
".",
"getDestinationPoint",
"(",
"startBearing",
"+",
"i",
"*",
"deltaBearing",
",",
"radius",
")",
")",
";",
"}",
"return",
"res",
";",
"}"
] |
Generates the points for an arc based on two bearings from a centre point
and a radius.
@param center The LatLong point of the center.
@param startBearing North is 0 degrees, East is 90 degrees, etc.
@param endBearing North is 0 degrees, East is 90 degrees, etc.
@param radius In metres
@return An array of LatLong points in an MVC array representing the arc.
Using this method directly you will need to push the centre point onto
the array in order to close it, if desired.
|
[
"Generates",
"the",
"points",
"for",
"an",
"arc",
"based",
"on",
"two",
"bearings",
"from",
"a",
"centre",
"point",
"and",
"a",
"radius",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/shapes/ArcBuilder.java#L71-L87
|
158,010
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationResult.java
|
ElevationResult.getLocation
|
public LatLong getLocation() {
if (location == null) {
location = new LatLong((JSObject) (getJSObject().getMember("location")));
}
return location;
}
|
java
|
public LatLong getLocation() {
if (location == null) {
location = new LatLong((JSObject) (getJSObject().getMember("location")));
}
return location;
}
|
[
"public",
"LatLong",
"getLocation",
"(",
")",
"{",
"if",
"(",
"location",
"==",
"null",
")",
"{",
"location",
"=",
"new",
"LatLong",
"(",
"(",
"JSObject",
")",
"(",
"getJSObject",
"(",
")",
".",
"getMember",
"(",
"\"location\"",
")",
")",
")",
";",
"}",
"return",
"location",
";",
"}"
] |
The location for this elevation.
@return
|
[
"The",
"location",
"for",
"this",
"elevation",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationResult.java#L39-L44
|
158,011
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptRuntime.java
|
JavascriptRuntime.getArgString
|
protected String getArgString(Object arg) {
//if (arg instanceof LatLong) {
// return ((LatLong) arg).getVariableName();
//} else
if (arg instanceof JavascriptObject) {
return ((JavascriptObject) arg).getVariableName();
// return ((JavascriptObject) arg).getPropertiesAsString();
} else if( arg instanceof JavascriptEnum ) {
return ((JavascriptEnum) arg).getEnumValue().toString();
} else {
return arg.toString();
}
}
|
java
|
protected String getArgString(Object arg) {
//if (arg instanceof LatLong) {
// return ((LatLong) arg).getVariableName();
//} else
if (arg instanceof JavascriptObject) {
return ((JavascriptObject) arg).getVariableName();
// return ((JavascriptObject) arg).getPropertiesAsString();
} else if( arg instanceof JavascriptEnum ) {
return ((JavascriptEnum) arg).getEnumValue().toString();
} else {
return arg.toString();
}
}
|
[
"protected",
"String",
"getArgString",
"(",
"Object",
"arg",
")",
"{",
"//if (arg instanceof LatLong) {",
"// return ((LatLong) arg).getVariableName();",
"//} else ",
"if",
"(",
"arg",
"instanceof",
"JavascriptObject",
")",
"{",
"return",
"(",
"(",
"JavascriptObject",
")",
"arg",
")",
".",
"getVariableName",
"(",
")",
";",
"// return ((JavascriptObject) arg).getPropertiesAsString();",
"}",
"else",
"if",
"(",
"arg",
"instanceof",
"JavascriptEnum",
")",
"{",
"return",
"(",
"(",
"JavascriptEnum",
")",
"arg",
")",
".",
"getEnumValue",
"(",
")",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"return",
"arg",
".",
"toString",
"(",
")",
";",
"}",
"}"
] |
Takes the specified object and converts the argument to a String.
@param arg The object to convert
@return A String representation of the argument.
|
[
"Takes",
"the",
"specified",
"object",
"and",
"converts",
"the",
"argument",
"to",
"a",
"String",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/JavascriptRuntime.java#L181-L193
|
158,012
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/DirectionsPane.java
|
DirectionsPane.registerEventHandler
|
private String registerEventHandler(GFXEventHandler h) {
//checkInitialized();
if (!registeredOnJS) {
JSObject doc = (JSObject) runtime.execute("document");
doc.setMember("jsHandlers", jsHandlers);
registeredOnJS = true;
}
return jsHandlers.registerHandler(h);
}
|
java
|
private String registerEventHandler(GFXEventHandler h) {
//checkInitialized();
if (!registeredOnJS) {
JSObject doc = (JSObject) runtime.execute("document");
doc.setMember("jsHandlers", jsHandlers);
registeredOnJS = true;
}
return jsHandlers.registerHandler(h);
}
|
[
"private",
"String",
"registerEventHandler",
"(",
"GFXEventHandler",
"h",
")",
"{",
"//checkInitialized();",
"if",
"(",
"!",
"registeredOnJS",
")",
"{",
"JSObject",
"doc",
"=",
"(",
"JSObject",
")",
"runtime",
".",
"execute",
"(",
"\"document\"",
")",
";",
"doc",
".",
"setMember",
"(",
"\"jsHandlers\"",
",",
"jsHandlers",
")",
";",
"registeredOnJS",
"=",
"true",
";",
"}",
"return",
"jsHandlers",
".",
"registerHandler",
"(",
"h",
")",
";",
"}"
] |
Registers an event handler in the repository shared between Javascript
and Java.
@param h Event handler to be registered.
@return Callback key that Javascript will use to find this handler.
|
[
"Registers",
"an",
"event",
"handler",
"in",
"the",
"repository",
"shared",
"between",
"Javascript",
"and",
"Java",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/DirectionsPane.java#L211-L219
|
158,013
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/DirectionsPane.java
|
DirectionsPane.addUIEventHandler
|
public void addUIEventHandler(JavascriptObject obj, UIEventType type, UIEventHandler h) {
String key = registerEventHandler(h);
String mcall = "google.maps.event.addListener(" + obj.getVariableName() + ", '" + type.name() + "', "
+ "function(event) {document.jsHandlers.handleUIEvent('" + key + "', event);});";//.latLng
//System.out.println("addUIEventHandler mcall: " + mcall);
runtime.execute(mcall);
}
|
java
|
public void addUIEventHandler(JavascriptObject obj, UIEventType type, UIEventHandler h) {
String key = registerEventHandler(h);
String mcall = "google.maps.event.addListener(" + obj.getVariableName() + ", '" + type.name() + "', "
+ "function(event) {document.jsHandlers.handleUIEvent('" + key + "', event);});";//.latLng
//System.out.println("addUIEventHandler mcall: " + mcall);
runtime.execute(mcall);
}
|
[
"public",
"void",
"addUIEventHandler",
"(",
"JavascriptObject",
"obj",
",",
"UIEventType",
"type",
",",
"UIEventHandler",
"h",
")",
"{",
"String",
"key",
"=",
"registerEventHandler",
"(",
"h",
")",
";",
"String",
"mcall",
"=",
"\"google.maps.event.addListener(\"",
"+",
"obj",
".",
"getVariableName",
"(",
")",
"+",
"\", '\"",
"+",
"type",
".",
"name",
"(",
")",
"+",
"\"', \"",
"+",
"\"function(event) {document.jsHandlers.handleUIEvent('\"",
"+",
"key",
"+",
"\"', event);});\"",
";",
"//.latLng",
"//System.out.println(\"addUIEventHandler mcall: \" + mcall);",
"runtime",
".",
"execute",
"(",
"mcall",
")",
";",
"}"
] |
Adds a handler for a mouse type event on the map.
@param obj The object that the event should be registered on.
@param type Type of the event to register against.
@param h Handler that will be called when the event occurs.
|
[
"Adds",
"a",
"handler",
"for",
"a",
"mouse",
"type",
"event",
"on",
"the",
"map",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/DirectionsPane.java#L238-L244
|
158,014
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java
|
LatLong.distanceFrom
|
public double distanceFrom(LatLong end) {
double dLat = (end.getLatitude() - getLatitude()) * Math.PI / 180;
double dLon = (end.getLongitude() - getLongitude()) * Math.PI / 180;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(getLatitude() * Math.PI / 180)
* Math.cos(end.getLatitude() * Math.PI / 180)
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = EarthRadiusMeters * c;
return d;
}
|
java
|
public double distanceFrom(LatLong end) {
double dLat = (end.getLatitude() - getLatitude()) * Math.PI / 180;
double dLon = (end.getLongitude() - getLongitude()) * Math.PI / 180;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(getLatitude() * Math.PI / 180)
* Math.cos(end.getLatitude() * Math.PI / 180)
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = EarthRadiusMeters * c;
return d;
}
|
[
"public",
"double",
"distanceFrom",
"(",
"LatLong",
"end",
")",
"{",
"double",
"dLat",
"=",
"(",
"end",
".",
"getLatitude",
"(",
")",
"-",
"getLatitude",
"(",
")",
")",
"*",
"Math",
".",
"PI",
"/",
"180",
";",
"double",
"dLon",
"=",
"(",
"end",
".",
"getLongitude",
"(",
")",
"-",
"getLongitude",
"(",
")",
")",
"*",
"Math",
".",
"PI",
"/",
"180",
";",
"double",
"a",
"=",
"Math",
".",
"sin",
"(",
"dLat",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"dLat",
"/",
"2",
")",
"+",
"Math",
".",
"cos",
"(",
"getLatitude",
"(",
")",
"*",
"Math",
".",
"PI",
"/",
"180",
")",
"*",
"Math",
".",
"cos",
"(",
"end",
".",
"getLatitude",
"(",
")",
"*",
"Math",
".",
"PI",
"/",
"180",
")",
"*",
"Math",
".",
"sin",
"(",
"dLon",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"dLon",
"/",
"2",
")",
";",
"double",
"c",
"=",
"2.0",
"*",
"Math",
".",
"atan2",
"(",
"Math",
".",
"sqrt",
"(",
"a",
")",
",",
"Math",
".",
"sqrt",
"(",
"1",
"-",
"a",
")",
")",
";",
"double",
"d",
"=",
"EarthRadiusMeters",
"*",
"c",
";",
"return",
"d",
";",
"}"
] |
From v3_epoly.js, calculates the distance between this LatLong point and
another.
@param end The end point to calculate the distance to.
@return The distance, in metres, to the end point.
|
[
"From",
"v3_epoly",
".",
"js",
"calculates",
"the",
"distance",
"between",
"this",
"LatLong",
"point",
"and",
"another",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java#L58-L71
|
158,015
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java
|
LatLong.getDestinationPoint
|
public LatLong getDestinationPoint(double bearing, double distance) {
double brng = Math.toRadians(bearing);
double lat1 = latToRadians();
double lon1 = longToRadians();
double lat2 = Math.asin(Math.sin(lat1)
* Math.cos(distance / EarthRadiusMeters)
+ Math.cos(lat1) * Math.sin(distance / EarthRadiusMeters)
* Math.cos(brng));
double lon2 = lon1 + Math.atan2(Math.sin(brng)
* Math.sin(distance / EarthRadiusMeters) * Math.cos(lat1),
Math.cos(distance / EarthRadiusMeters)
- Math.sin(lat1) * Math.sin(lat2));
return new LatLong(Math.toDegrees(lat2), Math.toDegrees(lon2));
}
|
java
|
public LatLong getDestinationPoint(double bearing, double distance) {
double brng = Math.toRadians(bearing);
double lat1 = latToRadians();
double lon1 = longToRadians();
double lat2 = Math.asin(Math.sin(lat1)
* Math.cos(distance / EarthRadiusMeters)
+ Math.cos(lat1) * Math.sin(distance / EarthRadiusMeters)
* Math.cos(brng));
double lon2 = lon1 + Math.atan2(Math.sin(brng)
* Math.sin(distance / EarthRadiusMeters) * Math.cos(lat1),
Math.cos(distance / EarthRadiusMeters)
- Math.sin(lat1) * Math.sin(lat2));
return new LatLong(Math.toDegrees(lat2), Math.toDegrees(lon2));
}
|
[
"public",
"LatLong",
"getDestinationPoint",
"(",
"double",
"bearing",
",",
"double",
"distance",
")",
"{",
"double",
"brng",
"=",
"Math",
".",
"toRadians",
"(",
"bearing",
")",
";",
"double",
"lat1",
"=",
"latToRadians",
"(",
")",
";",
"double",
"lon1",
"=",
"longToRadians",
"(",
")",
";",
"double",
"lat2",
"=",
"Math",
".",
"asin",
"(",
"Math",
".",
"sin",
"(",
"lat1",
")",
"*",
"Math",
".",
"cos",
"(",
"distance",
"/",
"EarthRadiusMeters",
")",
"+",
"Math",
".",
"cos",
"(",
"lat1",
")",
"*",
"Math",
".",
"sin",
"(",
"distance",
"/",
"EarthRadiusMeters",
")",
"*",
"Math",
".",
"cos",
"(",
"brng",
")",
")",
";",
"double",
"lon2",
"=",
"lon1",
"+",
"Math",
".",
"atan2",
"(",
"Math",
".",
"sin",
"(",
"brng",
")",
"*",
"Math",
".",
"sin",
"(",
"distance",
"/",
"EarthRadiusMeters",
")",
"*",
"Math",
".",
"cos",
"(",
"lat1",
")",
",",
"Math",
".",
"cos",
"(",
"distance",
"/",
"EarthRadiusMeters",
")",
"-",
"Math",
".",
"sin",
"(",
"lat1",
")",
"*",
"Math",
".",
"sin",
"(",
"lat2",
")",
")",
";",
"return",
"new",
"LatLong",
"(",
"Math",
".",
"toDegrees",
"(",
"lat2",
")",
",",
"Math",
".",
"toDegrees",
"(",
"lon2",
")",
")",
";",
"}"
] |
Calculates the LatLong position of the end point of a line the specified
distance from this LatLong, along the provided bearing, where North is 0,
East is 90 etc.
@param bearing The bearing, in degrees, with North as 0, East as 90 etc.
@param distance The distance in metres.
@return A new LatLong indicating the end point.
|
[
"Calculates",
"the",
"LatLong",
"position",
"of",
"the",
"end",
"point",
"of",
"a",
"line",
"the",
"specified",
"distance",
"from",
"this",
"LatLong",
"along",
"the",
"provided",
"bearing",
"where",
"North",
"is",
"0",
"East",
"is",
"90",
"etc",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java#L100-L119
|
158,016
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java
|
LatLong.getBearing
|
public double getBearing(LatLong end) {
if (this.equals(end)) {
return 0;
}
double lat1 = latToRadians();
double lon1 = longToRadians();
double lat2 = end.latToRadians();
double lon2 = end.longToRadians();
double angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2),
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(lon1 - lon2));
if (angle < 0.0) {
angle += Math.PI * 2.0;
}
if (angle > Math.PI) {
angle -= Math.PI * 2.0;
}
return Math.toDegrees(angle);
}
|
java
|
public double getBearing(LatLong end) {
if (this.equals(end)) {
return 0;
}
double lat1 = latToRadians();
double lon1 = longToRadians();
double lat2 = end.latToRadians();
double lon2 = end.longToRadians();
double angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2),
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(lon1 - lon2));
if (angle < 0.0) {
angle += Math.PI * 2.0;
}
if (angle > Math.PI) {
angle -= Math.PI * 2.0;
}
return Math.toDegrees(angle);
}
|
[
"public",
"double",
"getBearing",
"(",
"LatLong",
"end",
")",
"{",
"if",
"(",
"this",
".",
"equals",
"(",
"end",
")",
")",
"{",
"return",
"0",
";",
"}",
"double",
"lat1",
"=",
"latToRadians",
"(",
")",
";",
"double",
"lon1",
"=",
"longToRadians",
"(",
")",
";",
"double",
"lat2",
"=",
"end",
".",
"latToRadians",
"(",
")",
";",
"double",
"lon2",
"=",
"end",
".",
"longToRadians",
"(",
")",
";",
"double",
"angle",
"=",
"-",
"Math",
".",
"atan2",
"(",
"Math",
".",
"sin",
"(",
"lon1",
"-",
"lon2",
")",
"*",
"Math",
".",
"cos",
"(",
"lat2",
")",
",",
"Math",
".",
"cos",
"(",
"lat1",
")",
"*",
"Math",
".",
"sin",
"(",
"lat2",
")",
"-",
"Math",
".",
"sin",
"(",
"lat1",
")",
"*",
"Math",
".",
"cos",
"(",
"lat2",
")",
"*",
"Math",
".",
"cos",
"(",
"lon1",
"-",
"lon2",
")",
")",
";",
"if",
"(",
"angle",
"<",
"0.0",
")",
"{",
"angle",
"+=",
"Math",
".",
"PI",
"*",
"2.0",
";",
"}",
"if",
"(",
"angle",
">",
"Math",
".",
"PI",
")",
"{",
"angle",
"-=",
"Math",
".",
"PI",
"*",
"2.0",
";",
"}",
"return",
"Math",
".",
"toDegrees",
"(",
"angle",
")",
";",
"}"
] |
Calculates the bearing, in degrees, of the end LatLong point from this
LatLong point.
@param end The point that the bearing is calculated for.
@return The bearing, in degrees, of the supplied point from this point.
|
[
"Calculates",
"the",
"bearing",
"in",
"degrees",
"of",
"the",
"end",
"LatLong",
"point",
"from",
"this",
"LatLong",
"point",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/javascript/object/LatLong.java#L128-L150
|
158,017
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationService.java
|
ElevationService.getElevationForLocations
|
public void getElevationForLocations(LocationElevationRequest req, ElevationServiceCallback callback) {
this.callback = callback;
JSObject doc = (JSObject) getJSObject().eval("document");
doc.setMember(getVariableName(), this);
StringBuilder r = new StringBuilder(getVariableName())
.append(".")
.append("getElevationForLocations(")
.append(req.getVariableName())
.append(", ")
.append("function(results, status) {alert('rec:'+status);\ndocument.")
.append(getVariableName())
.append(".processResponse(results, status);});");
LOG.trace("ElevationService direct call: " + r.toString());
getJSObject().eval(r.toString());
}
|
java
|
public void getElevationForLocations(LocationElevationRequest req, ElevationServiceCallback callback) {
this.callback = callback;
JSObject doc = (JSObject) getJSObject().eval("document");
doc.setMember(getVariableName(), this);
StringBuilder r = new StringBuilder(getVariableName())
.append(".")
.append("getElevationForLocations(")
.append(req.getVariableName())
.append(", ")
.append("function(results, status) {alert('rec:'+status);\ndocument.")
.append(getVariableName())
.append(".processResponse(results, status);});");
LOG.trace("ElevationService direct call: " + r.toString());
getJSObject().eval(r.toString());
}
|
[
"public",
"void",
"getElevationForLocations",
"(",
"LocationElevationRequest",
"req",
",",
"ElevationServiceCallback",
"callback",
")",
"{",
"this",
".",
"callback",
"=",
"callback",
";",
"JSObject",
"doc",
"=",
"(",
"JSObject",
")",
"getJSObject",
"(",
")",
".",
"eval",
"(",
"\"document\"",
")",
";",
"doc",
".",
"setMember",
"(",
"getVariableName",
"(",
")",
",",
"this",
")",
";",
"StringBuilder",
"r",
"=",
"new",
"StringBuilder",
"(",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\".\"",
")",
".",
"append",
"(",
"\"getElevationForLocations(\"",
")",
".",
"append",
"(",
"req",
".",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\", \"",
")",
".",
"append",
"(",
"\"function(results, status) {alert('rec:'+status);\\ndocument.\"",
")",
".",
"append",
"(",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\".processResponse(results, status);});\"",
")",
";",
"LOG",
".",
"trace",
"(",
"\"ElevationService direct call: \"",
"+",
"r",
".",
"toString",
"(",
")",
")",
";",
"getJSObject",
"(",
")",
".",
"eval",
"(",
"r",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Create a request for elevations for multiple locations.
@param req
@param callback
|
[
"Create",
"a",
"request",
"for",
"elevations",
"for",
"multiple",
"locations",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationService.java#L36-L56
|
158,018
|
rterp/GMapsFX
|
GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationService.java
|
ElevationService.getElevationAlongPath
|
public void getElevationAlongPath(PathElevationRequest req, ElevationServiceCallback callback) {
this.callback = callback;
JSObject doc = (JSObject) getJSObject().eval("document");
doc.setMember(getVariableName(), this);
StringBuilder r = new StringBuilder(getVariableName())
.append(".")
.append("getElevationAlongPath(")
.append(req.getVariableName())
.append(", ")
.append("function(results, status) {document.")
.append(getVariableName())
.append(".processResponse(results, status);});");
getJSObject().eval(r.toString());
}
|
java
|
public void getElevationAlongPath(PathElevationRequest req, ElevationServiceCallback callback) {
this.callback = callback;
JSObject doc = (JSObject) getJSObject().eval("document");
doc.setMember(getVariableName(), this);
StringBuilder r = new StringBuilder(getVariableName())
.append(".")
.append("getElevationAlongPath(")
.append(req.getVariableName())
.append(", ")
.append("function(results, status) {document.")
.append(getVariableName())
.append(".processResponse(results, status);});");
getJSObject().eval(r.toString());
}
|
[
"public",
"void",
"getElevationAlongPath",
"(",
"PathElevationRequest",
"req",
",",
"ElevationServiceCallback",
"callback",
")",
"{",
"this",
".",
"callback",
"=",
"callback",
";",
"JSObject",
"doc",
"=",
"(",
"JSObject",
")",
"getJSObject",
"(",
")",
".",
"eval",
"(",
"\"document\"",
")",
";",
"doc",
".",
"setMember",
"(",
"getVariableName",
"(",
")",
",",
"this",
")",
";",
"StringBuilder",
"r",
"=",
"new",
"StringBuilder",
"(",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\".\"",
")",
".",
"append",
"(",
"\"getElevationAlongPath(\"",
")",
".",
"append",
"(",
"req",
".",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\", \"",
")",
".",
"append",
"(",
"\"function(results, status) {document.\"",
")",
".",
"append",
"(",
"getVariableName",
"(",
")",
")",
".",
"append",
"(",
"\".processResponse(results, status);});\"",
")",
";",
"getJSObject",
"(",
")",
".",
"eval",
"(",
"r",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Create a request for elevations for samples along a path.
@param req
@param callback
|
[
"Create",
"a",
"request",
"for",
"elevations",
"for",
"samples",
"along",
"a",
"path",
"."
] |
4623d3f768e8ad78fc50ee32dd204d236e01059f
|
https://github.com/rterp/GMapsFX/blob/4623d3f768e8ad78fc50ee32dd204d236e01059f/GMapsFX/src/main/java/com/lynden/gmapsfx/service/elevation/ElevationService.java#L63-L81
|
158,019
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/comparators/GeopositionComparator.java
|
GeopositionComparator.distance
|
public static double distance(double lat1, double lon1,
double lat2, double lon2) {
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
|
java
|
public static double distance(double lat1, double lon1,
double lat2, double lon2) {
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
|
[
"public",
"static",
"double",
"distance",
"(",
"double",
"lat1",
",",
"double",
"lon1",
",",
"double",
"lat2",
",",
"double",
"lon2",
")",
"{",
"double",
"dLat",
"=",
"Math",
".",
"toRadians",
"(",
"lat2",
"-",
"lat1",
")",
";",
"double",
"dLon",
"=",
"Math",
".",
"toRadians",
"(",
"lon2",
"-",
"lon1",
")",
";",
"lat1",
"=",
"Math",
".",
"toRadians",
"(",
"lat1",
")",
";",
"lat2",
"=",
"Math",
".",
"toRadians",
"(",
"lat2",
")",
";",
"double",
"a",
"=",
"Math",
".",
"sin",
"(",
"dLat",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"dLat",
"/",
"2",
")",
"+",
"Math",
".",
"sin",
"(",
"dLon",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"dLon",
"/",
"2",
")",
"*",
"Math",
".",
"cos",
"(",
"lat1",
")",
"*",
"Math",
".",
"cos",
"(",
"lat2",
")",
";",
"double",
"c",
"=",
"2",
"*",
"Math",
".",
"atan2",
"(",
"Math",
".",
"sqrt",
"(",
"a",
")",
",",
"Math",
".",
"sqrt",
"(",
"1",
"-",
"a",
")",
")",
";",
"return",
"R",
"*",
"c",
";",
"}"
] |
Returns the distance between the two points in meters.
|
[
"Returns",
"the",
"distance",
"between",
"the",
"two",
"points",
"in",
"meters",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/comparators/GeopositionComparator.java#L72-L83
|
158,020
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/comparators/SoundexComparator.java
|
SoundexComparator.soundex
|
public static String soundex(String str) {
if (str.length() < 1)
return ""; // no soundex key for the empty string (could use 000)
char[] key = new char[4];
key[0] = str.charAt(0);
int pos = 1;
char prev = '0';
for (int ix = 1; ix < str.length() && pos < 4; ix++) {
char ch = str.charAt(ix);
int charno;
if (ch >= 'A' && ch <= 'Z')
charno = ch - 'A';
else if (ch >= 'a' && ch <= 'z')
charno = ch - 'a';
else
continue;
if (number[charno] != '0' && number[charno] != prev)
key[pos++] = number[charno];
prev = number[charno];
}
for ( ; pos < 4; pos++)
key[pos] = '0';
return new String(key);
}
|
java
|
public static String soundex(String str) {
if (str.length() < 1)
return ""; // no soundex key for the empty string (could use 000)
char[] key = new char[4];
key[0] = str.charAt(0);
int pos = 1;
char prev = '0';
for (int ix = 1; ix < str.length() && pos < 4; ix++) {
char ch = str.charAt(ix);
int charno;
if (ch >= 'A' && ch <= 'Z')
charno = ch - 'A';
else if (ch >= 'a' && ch <= 'z')
charno = ch - 'a';
else
continue;
if (number[charno] != '0' && number[charno] != prev)
key[pos++] = number[charno];
prev = number[charno];
}
for ( ; pos < 4; pos++)
key[pos] = '0';
return new String(key);
}
|
[
"public",
"static",
"String",
"soundex",
"(",
"String",
"str",
")",
"{",
"if",
"(",
"str",
".",
"length",
"(",
")",
"<",
"1",
")",
"return",
"\"\"",
";",
"// no soundex key for the empty string (could use 000)",
"char",
"[",
"]",
"key",
"=",
"new",
"char",
"[",
"4",
"]",
";",
"key",
"[",
"0",
"]",
"=",
"str",
".",
"charAt",
"(",
"0",
")",
";",
"int",
"pos",
"=",
"1",
";",
"char",
"prev",
"=",
"'",
"'",
";",
"for",
"(",
"int",
"ix",
"=",
"1",
";",
"ix",
"<",
"str",
".",
"length",
"(",
")",
"&&",
"pos",
"<",
"4",
";",
"ix",
"++",
")",
"{",
"char",
"ch",
"=",
"str",
".",
"charAt",
"(",
"ix",
")",
";",
"int",
"charno",
";",
"if",
"(",
"ch",
">=",
"'",
"'",
"&&",
"ch",
"<=",
"'",
"'",
")",
"charno",
"=",
"ch",
"-",
"'",
"'",
";",
"else",
"if",
"(",
"ch",
">=",
"'",
"'",
"&&",
"ch",
"<=",
"'",
"'",
")",
"charno",
"=",
"ch",
"-",
"'",
"'",
";",
"else",
"continue",
";",
"if",
"(",
"number",
"[",
"charno",
"]",
"!=",
"'",
"'",
"&&",
"number",
"[",
"charno",
"]",
"!=",
"prev",
")",
"key",
"[",
"pos",
"++",
"]",
"=",
"number",
"[",
"charno",
"]",
";",
"prev",
"=",
"number",
"[",
"charno",
"]",
";",
"}",
"for",
"(",
";",
"pos",
"<",
"4",
";",
"pos",
"++",
")",
"key",
"[",
"pos",
"]",
"=",
"'",
"0",
"'",
";",
"return",
"new",
"String",
"(",
"key",
")",
";",
"}"
] |
Produces the Soundex key for the given string.
|
[
"Produces",
"the",
"Soundex",
"key",
"for",
"the",
"given",
"string",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/comparators/SoundexComparator.java#L33-L60
|
158,021
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/comparators/SoundexComparator.java
|
SoundexComparator.buildTable
|
private static char[] buildTable() {
char[] table = new char[26];
for (int ix = 0; ix < table.length; ix++)
table[ix] = '0';
table['B' - 'A'] = '1';
table['P' - 'A'] = '1';
table['F' - 'A'] = '1';
table['V' - 'A'] = '1';
table['C' - 'A'] = '2';
table['S' - 'A'] = '2';
table['K' - 'A'] = '2';
table['G' - 'A'] = '2';
table['J' - 'A'] = '2';
table['Q' - 'A'] = '2';
table['X' - 'A'] = '2';
table['Z' - 'A'] = '2';
table['D' - 'A'] = '3';
table['T' - 'A'] = '3';
table['L' - 'A'] = '4';
table['M' - 'A'] = '5';
table['N' - 'A'] = '5';
table['R' - 'A'] = '6';
return table;
}
|
java
|
private static char[] buildTable() {
char[] table = new char[26];
for (int ix = 0; ix < table.length; ix++)
table[ix] = '0';
table['B' - 'A'] = '1';
table['P' - 'A'] = '1';
table['F' - 'A'] = '1';
table['V' - 'A'] = '1';
table['C' - 'A'] = '2';
table['S' - 'A'] = '2';
table['K' - 'A'] = '2';
table['G' - 'A'] = '2';
table['J' - 'A'] = '2';
table['Q' - 'A'] = '2';
table['X' - 'A'] = '2';
table['Z' - 'A'] = '2';
table['D' - 'A'] = '3';
table['T' - 'A'] = '3';
table['L' - 'A'] = '4';
table['M' - 'A'] = '5';
table['N' - 'A'] = '5';
table['R' - 'A'] = '6';
return table;
}
|
[
"private",
"static",
"char",
"[",
"]",
"buildTable",
"(",
")",
"{",
"char",
"[",
"]",
"table",
"=",
"new",
"char",
"[",
"26",
"]",
";",
"for",
"(",
"int",
"ix",
"=",
"0",
";",
"ix",
"<",
"table",
".",
"length",
";",
"ix",
"++",
")",
"table",
"[",
"ix",
"]",
"=",
"'",
"0",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"table",
"[",
"'",
"'",
"-",
"'",
"'",
"]",
"=",
"'",
"'",
";",
"return",
"table",
";",
"}"
] |
Builds the mapping table.
|
[
"Builds",
"the",
"mapping",
"table",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/comparators/SoundexComparator.java#L65-L88
|
158,022
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/datasources/NTriplesDataSource.java
|
NTriplesDataSource.addStatement
|
private void addStatement(RecordImpl record,
String subject,
String property,
String object) {
Collection<Column> cols = columns.get(property);
if (cols == null) {
if (property.equals(RDF_TYPE) && !types.isEmpty())
addValue(record, subject, property, object);
return;
}
for (Column col : cols) {
String cleaned = object;
if (col.getCleaner() != null)
cleaned = col.getCleaner().clean(object);
if (cleaned != null && !cleaned.equals(""))
addValue(record, subject, col.getProperty(), cleaned);
}
}
|
java
|
private void addStatement(RecordImpl record,
String subject,
String property,
String object) {
Collection<Column> cols = columns.get(property);
if (cols == null) {
if (property.equals(RDF_TYPE) && !types.isEmpty())
addValue(record, subject, property, object);
return;
}
for (Column col : cols) {
String cleaned = object;
if (col.getCleaner() != null)
cleaned = col.getCleaner().clean(object);
if (cleaned != null && !cleaned.equals(""))
addValue(record, subject, col.getProperty(), cleaned);
}
}
|
[
"private",
"void",
"addStatement",
"(",
"RecordImpl",
"record",
",",
"String",
"subject",
",",
"String",
"property",
",",
"String",
"object",
")",
"{",
"Collection",
"<",
"Column",
">",
"cols",
"=",
"columns",
".",
"get",
"(",
"property",
")",
";",
"if",
"(",
"cols",
"==",
"null",
")",
"{",
"if",
"(",
"property",
".",
"equals",
"(",
"RDF_TYPE",
")",
"&&",
"!",
"types",
".",
"isEmpty",
"(",
")",
")",
"addValue",
"(",
"record",
",",
"subject",
",",
"property",
",",
"object",
")",
";",
"return",
";",
"}",
"for",
"(",
"Column",
"col",
":",
"cols",
")",
"{",
"String",
"cleaned",
"=",
"object",
";",
"if",
"(",
"col",
".",
"getCleaner",
"(",
")",
"!=",
"null",
")",
"cleaned",
"=",
"col",
".",
"getCleaner",
"(",
")",
".",
"clean",
"(",
"object",
")",
";",
"if",
"(",
"cleaned",
"!=",
"null",
"&&",
"!",
"cleaned",
".",
"equals",
"(",
"\"\"",
")",
")",
"addValue",
"(",
"record",
",",
"subject",
",",
"col",
".",
"getProperty",
"(",
")",
",",
"cleaned",
")",
";",
"}",
"}"
] |
common utility method for adding a statement to a record
|
[
"common",
"utility",
"method",
"for",
"adding",
"a",
"statement",
"to",
"a",
"record"
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/datasources/NTriplesDataSource.java#L89-L107
|
158,023
|
larsga/Duke
|
duke-lucene/src/main/java/no/priv/garshol/duke/databases/GeoProperty.java
|
GeoProperty.geoSearch
|
public Filter geoSearch(String value) {
GeopositionComparator comp = (GeopositionComparator) prop.getComparator();
double dist = comp.getMaxDistance();
double degrees = DistanceUtils.dist2Degrees(dist, DistanceUtils.EARTH_MEAN_RADIUS_KM * 1000.0);
Shape circle = spatialctx.makeCircle(parsePoint(value), degrees);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
return strategy.makeFilter(args);
}
|
java
|
public Filter geoSearch(String value) {
GeopositionComparator comp = (GeopositionComparator) prop.getComparator();
double dist = comp.getMaxDistance();
double degrees = DistanceUtils.dist2Degrees(dist, DistanceUtils.EARTH_MEAN_RADIUS_KM * 1000.0);
Shape circle = spatialctx.makeCircle(parsePoint(value), degrees);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
return strategy.makeFilter(args);
}
|
[
"public",
"Filter",
"geoSearch",
"(",
"String",
"value",
")",
"{",
"GeopositionComparator",
"comp",
"=",
"(",
"GeopositionComparator",
")",
"prop",
".",
"getComparator",
"(",
")",
";",
"double",
"dist",
"=",
"comp",
".",
"getMaxDistance",
"(",
")",
";",
"double",
"degrees",
"=",
"DistanceUtils",
".",
"dist2Degrees",
"(",
"dist",
",",
"DistanceUtils",
".",
"EARTH_MEAN_RADIUS_KM",
"*",
"1000.0",
")",
";",
"Shape",
"circle",
"=",
"spatialctx",
".",
"makeCircle",
"(",
"parsePoint",
"(",
"value",
")",
",",
"degrees",
")",
";",
"SpatialArgs",
"args",
"=",
"new",
"SpatialArgs",
"(",
"SpatialOperation",
".",
"Intersects",
",",
"circle",
")",
";",
"return",
"strategy",
".",
"makeFilter",
"(",
"args",
")",
";",
"}"
] |
Returns a geoquery.
|
[
"Returns",
"a",
"geoquery",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-lucene/src/main/java/no/priv/garshol/duke/databases/GeoProperty.java#L57-L64
|
158,024
|
larsga/Duke
|
duke-lucene/src/main/java/no/priv/garshol/duke/databases/GeoProperty.java
|
GeoProperty.parsePoint
|
private Point parsePoint(String point) {
int comma = point.indexOf(',');
if (comma == -1)
return null;
float lat = Float.valueOf(point.substring(0, comma));
float lng = Float.valueOf(point.substring(comma + 1));
return spatialctx.makePoint(lng, lat);
}
|
java
|
private Point parsePoint(String point) {
int comma = point.indexOf(',');
if (comma == -1)
return null;
float lat = Float.valueOf(point.substring(0, comma));
float lng = Float.valueOf(point.substring(comma + 1));
return spatialctx.makePoint(lng, lat);
}
|
[
"private",
"Point",
"parsePoint",
"(",
"String",
"point",
")",
"{",
"int",
"comma",
"=",
"point",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"comma",
"==",
"-",
"1",
")",
"return",
"null",
";",
"float",
"lat",
"=",
"Float",
".",
"valueOf",
"(",
"point",
".",
"substring",
"(",
"0",
",",
"comma",
")",
")",
";",
"float",
"lng",
"=",
"Float",
".",
"valueOf",
"(",
"point",
".",
"substring",
"(",
"comma",
"+",
"1",
")",
")",
";",
"return",
"spatialctx",
".",
"makePoint",
"(",
"lng",
",",
"lat",
")",
";",
"}"
] |
Parses coordinates into a Spatial4j point shape.
|
[
"Parses",
"coordinates",
"into",
"a",
"Spatial4j",
"point",
"shape",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-lucene/src/main/java/no/priv/garshol/duke/databases/GeoProperty.java#L69-L77
|
158,025
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.open
|
public static Statement open(String jndiPath) {
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiPath);
Connection conn = ds.getConnection();
return conn.createStatement();
} catch (NamingException e) {
throw new DukeException("No database configuration found via JNDI at " +
jndiPath, e);
} catch (SQLException e) {
throw new DukeException("Error connecting to database via " +
jndiPath, e);
}
}
|
java
|
public static Statement open(String jndiPath) {
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiPath);
Connection conn = ds.getConnection();
return conn.createStatement();
} catch (NamingException e) {
throw new DukeException("No database configuration found via JNDI at " +
jndiPath, e);
} catch (SQLException e) {
throw new DukeException("Error connecting to database via " +
jndiPath, e);
}
}
|
[
"public",
"static",
"Statement",
"open",
"(",
"String",
"jndiPath",
")",
"{",
"try",
"{",
"Context",
"ctx",
"=",
"new",
"InitialContext",
"(",
")",
";",
"DataSource",
"ds",
"=",
"(",
"DataSource",
")",
"ctx",
".",
"lookup",
"(",
"jndiPath",
")",
";",
"Connection",
"conn",
"=",
"ds",
".",
"getConnection",
"(",
")",
";",
"return",
"conn",
".",
"createStatement",
"(",
")",
";",
"}",
"catch",
"(",
"NamingException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"\"No database configuration found via JNDI at \"",
"+",
"jndiPath",
",",
"e",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"\"Error connecting to database via \"",
"+",
"jndiPath",
",",
"e",
")",
";",
"}",
"}"
] |
Get a configured database connection via JNDI.
|
[
"Get",
"a",
"configured",
"database",
"connection",
"via",
"JNDI",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L25-L38
|
158,026
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.open
|
public static Statement open(String driverklass, String jdbcuri,
Properties props) {
try {
Driver driver = (Driver) ObjectUtils.instantiate(driverklass);
Connection conn = driver.connect(jdbcuri, props);
if (conn == null)
throw new DukeException("Couldn't connect to database at " +
jdbcuri);
return conn.createStatement();
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
java
|
public static Statement open(String driverklass, String jdbcuri,
Properties props) {
try {
Driver driver = (Driver) ObjectUtils.instantiate(driverklass);
Connection conn = driver.connect(jdbcuri, props);
if (conn == null)
throw new DukeException("Couldn't connect to database at " +
jdbcuri);
return conn.createStatement();
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
[
"public",
"static",
"Statement",
"open",
"(",
"String",
"driverklass",
",",
"String",
"jdbcuri",
",",
"Properties",
"props",
")",
"{",
"try",
"{",
"Driver",
"driver",
"=",
"(",
"Driver",
")",
"ObjectUtils",
".",
"instantiate",
"(",
"driverklass",
")",
";",
"Connection",
"conn",
"=",
"driver",
".",
"connect",
"(",
"jdbcuri",
",",
"props",
")",
";",
"if",
"(",
"conn",
"==",
"null",
")",
"throw",
"new",
"DukeException",
"(",
"\"Couldn't connect to database at \"",
"+",
"jdbcuri",
")",
";",
"return",
"conn",
".",
"createStatement",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Opens a JDBC connection with the given parameters.
|
[
"Opens",
"a",
"JDBC",
"connection",
"with",
"the",
"given",
"parameters",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L43-L56
|
158,027
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.close
|
public static void close(Statement stmt) {
try {
Connection conn = stmt.getConnection();
try {
if (!stmt.isClosed())
stmt.close();
} catch (UnsupportedOperationException e) {
// not all JDBC drivers implement the isClosed() method.
// ugly, but probably the only way to get around this.
// http://stackoverflow.com/questions/12845385/duke-fast-deduplication-java-lang-unsupportedoperationexception-operation-not
stmt.close();
}
if (conn != null && !conn.isClosed())
conn.close();
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
java
|
public static void close(Statement stmt) {
try {
Connection conn = stmt.getConnection();
try {
if (!stmt.isClosed())
stmt.close();
} catch (UnsupportedOperationException e) {
// not all JDBC drivers implement the isClosed() method.
// ugly, but probably the only way to get around this.
// http://stackoverflow.com/questions/12845385/duke-fast-deduplication-java-lang-unsupportedoperationexception-operation-not
stmt.close();
}
if (conn != null && !conn.isClosed())
conn.close();
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
[
"public",
"static",
"void",
"close",
"(",
"Statement",
"stmt",
")",
"{",
"try",
"{",
"Connection",
"conn",
"=",
"stmt",
".",
"getConnection",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"stmt",
".",
"isClosed",
"(",
")",
")",
"stmt",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedOperationException",
"e",
")",
"{",
"// not all JDBC drivers implement the isClosed() method.",
"// ugly, but probably the only way to get around this.",
"// http://stackoverflow.com/questions/12845385/duke-fast-deduplication-java-lang-unsupportedoperationexception-operation-not",
"stmt",
".",
"close",
"(",
")",
";",
"}",
"if",
"(",
"conn",
"!=",
"null",
"&&",
"!",
"conn",
".",
"isClosed",
"(",
")",
")",
"conn",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Closes the JDBC statement and its associated connection.
|
[
"Closes",
"the",
"JDBC",
"statement",
"and",
"its",
"associated",
"connection",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L61-L78
|
158,028
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.validate
|
public static boolean validate(Statement stmt) {
try {
Connection conn = stmt.getConnection();
if (conn == null)
return false;
if (!conn.isClosed() && conn.isValid(10))
return true;
stmt.close();
conn.close();
} catch (SQLException e) {
// this may well fail. that doesn't matter. we're just making an
// attempt to clean up, and if we can't, that's just too bad.
}
return false;
}
|
java
|
public static boolean validate(Statement stmt) {
try {
Connection conn = stmt.getConnection();
if (conn == null)
return false;
if (!conn.isClosed() && conn.isValid(10))
return true;
stmt.close();
conn.close();
} catch (SQLException e) {
// this may well fail. that doesn't matter. we're just making an
// attempt to clean up, and if we can't, that's just too bad.
}
return false;
}
|
[
"public",
"static",
"boolean",
"validate",
"(",
"Statement",
"stmt",
")",
"{",
"try",
"{",
"Connection",
"conn",
"=",
"stmt",
".",
"getConnection",
"(",
")",
";",
"if",
"(",
"conn",
"==",
"null",
")",
"return",
"false",
";",
"if",
"(",
"!",
"conn",
".",
"isClosed",
"(",
")",
"&&",
"conn",
".",
"isValid",
"(",
"10",
")",
")",
"return",
"true",
";",
"stmt",
".",
"close",
"(",
")",
";",
"conn",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"// this may well fail. that doesn't matter. we're just making an",
"// attempt to clean up, and if we can't, that's just too bad.",
"}",
"return",
"false",
";",
"}"
] |
Verifies that the connection is still alive. Returns true if it
is, false if it is not. If the connection is broken we try
closing everything, too, so that the caller need only open a new
connection.
|
[
"Verifies",
"that",
"the",
"connection",
"is",
"still",
"alive",
".",
"Returns",
"true",
"if",
"it",
"is",
"false",
"if",
"it",
"is",
"not",
".",
"If",
"the",
"connection",
"is",
"broken",
"we",
"try",
"closing",
"everything",
"too",
"so",
"that",
"the",
"caller",
"need",
"only",
"open",
"a",
"new",
"connection",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L86-L102
|
158,029
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.queryForInt
|
public static int queryForInt(Statement stmt, String sql, int nullvalue) {
try {
ResultSet rs = stmt.executeQuery(sql);
try {
if (!rs.next())
return nullvalue;
return rs.getInt(1);
} finally {
rs.close();
}
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
java
|
public static int queryForInt(Statement stmt, String sql, int nullvalue) {
try {
ResultSet rs = stmt.executeQuery(sql);
try {
if (!rs.next())
return nullvalue;
return rs.getInt(1);
} finally {
rs.close();
}
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
[
"public",
"static",
"int",
"queryForInt",
"(",
"Statement",
"stmt",
",",
"String",
"sql",
",",
"int",
"nullvalue",
")",
"{",
"try",
"{",
"ResultSet",
"rs",
"=",
"stmt",
".",
"executeQuery",
"(",
"sql",
")",
";",
"try",
"{",
"if",
"(",
"!",
"rs",
".",
"next",
"(",
")",
")",
"return",
"nullvalue",
";",
"return",
"rs",
".",
"getInt",
"(",
"1",
")",
";",
"}",
"finally",
"{",
"rs",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Runs a query that returns a single int.
|
[
"Runs",
"a",
"query",
"that",
"returns",
"a",
"single",
"int",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L107-L121
|
158,030
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java
|
JDBCUtils.queryHasResult
|
public static boolean queryHasResult(Statement stmt, String sql) {
try {
ResultSet rs = stmt.executeQuery(sql);
try {
return rs.next();
} finally {
rs.close();
}
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
java
|
public static boolean queryHasResult(Statement stmt, String sql) {
try {
ResultSet rs = stmt.executeQuery(sql);
try {
return rs.next();
} finally {
rs.close();
}
} catch (SQLException e) {
throw new DukeException(e);
}
}
|
[
"public",
"static",
"boolean",
"queryHasResult",
"(",
"Statement",
"stmt",
",",
"String",
"sql",
")",
"{",
"try",
"{",
"ResultSet",
"rs",
"=",
"stmt",
".",
"executeQuery",
"(",
"sql",
")",
";",
"try",
"{",
"return",
"rs",
".",
"next",
"(",
")",
";",
"}",
"finally",
"{",
"rs",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Returns true if the query result has at least one row.
|
[
"Returns",
"true",
"if",
"the",
"query",
"result",
"has",
"at",
"least",
"one",
"row",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/JDBCUtils.java#L126-L137
|
158,031
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/StringUtils.java
|
StringUtils.replaceAnyOf
|
public static String replaceAnyOf(String value, String chars,
char replacement) {
char[] tmp = new char[value.length()];
int pos = 0;
for (int ix = 0; ix < tmp.length; ix++) {
char ch = value.charAt(ix);
if (chars.indexOf(ch) != -1)
tmp[pos++] = replacement;
else
tmp[pos++] = ch;
}
return new String(tmp, 0, tmp.length);
}
|
java
|
public static String replaceAnyOf(String value, String chars,
char replacement) {
char[] tmp = new char[value.length()];
int pos = 0;
for (int ix = 0; ix < tmp.length; ix++) {
char ch = value.charAt(ix);
if (chars.indexOf(ch) != -1)
tmp[pos++] = replacement;
else
tmp[pos++] = ch;
}
return new String(tmp, 0, tmp.length);
}
|
[
"public",
"static",
"String",
"replaceAnyOf",
"(",
"String",
"value",
",",
"String",
"chars",
",",
"char",
"replacement",
")",
"{",
"char",
"[",
"]",
"tmp",
"=",
"new",
"char",
"[",
"value",
".",
"length",
"(",
")",
"]",
";",
"int",
"pos",
"=",
"0",
";",
"for",
"(",
"int",
"ix",
"=",
"0",
";",
"ix",
"<",
"tmp",
".",
"length",
";",
"ix",
"++",
")",
"{",
"char",
"ch",
"=",
"value",
".",
"charAt",
"(",
"ix",
")",
";",
"if",
"(",
"chars",
".",
"indexOf",
"(",
"ch",
")",
"!=",
"-",
"1",
")",
"tmp",
"[",
"pos",
"++",
"]",
"=",
"replacement",
";",
"else",
"tmp",
"[",
"pos",
"++",
"]",
"=",
"ch",
";",
"}",
"return",
"new",
"String",
"(",
"tmp",
",",
"0",
",",
"tmp",
".",
"length",
")",
";",
"}"
] |
Replaces all characters in the second parameter found in the first
parameter with the final character.
@param value the string to replace characters in
@param chars the characters to replace
@param replacement the character to insert as replacement
|
[
"Replaces",
"all",
"characters",
"in",
"the",
"second",
"parameter",
"found",
"in",
"the",
"first",
"parameter",
"with",
"the",
"final",
"character",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/StringUtils.java#L13-L25
|
158,032
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/StringUtils.java
|
StringUtils.normalizeWS
|
public static String normalizeWS(String value) {
char[] tmp = new char[value.length()];
int pos = 0;
boolean prevws = false;
for (int ix = 0; ix < tmp.length; ix++) {
char ch = value.charAt(ix);
if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r') {
if (prevws && pos != 0)
tmp[pos++] = ' ';
tmp[pos++] = ch;
prevws = false;
} else
prevws = true;
}
return new String(tmp, 0, pos);
}
|
java
|
public static String normalizeWS(String value) {
char[] tmp = new char[value.length()];
int pos = 0;
boolean prevws = false;
for (int ix = 0; ix < tmp.length; ix++) {
char ch = value.charAt(ix);
if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r') {
if (prevws && pos != 0)
tmp[pos++] = ' ';
tmp[pos++] = ch;
prevws = false;
} else
prevws = true;
}
return new String(tmp, 0, pos);
}
|
[
"public",
"static",
"String",
"normalizeWS",
"(",
"String",
"value",
")",
"{",
"char",
"[",
"]",
"tmp",
"=",
"new",
"char",
"[",
"value",
".",
"length",
"(",
")",
"]",
";",
"int",
"pos",
"=",
"0",
";",
"boolean",
"prevws",
"=",
"false",
";",
"for",
"(",
"int",
"ix",
"=",
"0",
";",
"ix",
"<",
"tmp",
".",
"length",
";",
"ix",
"++",
")",
"{",
"char",
"ch",
"=",
"value",
".",
"charAt",
"(",
"ix",
")",
";",
"if",
"(",
"ch",
"!=",
"'",
"'",
"&&",
"ch",
"!=",
"'",
"'",
"&&",
"ch",
"!=",
"'",
"'",
"&&",
"ch",
"!=",
"'",
"'",
")",
"{",
"if",
"(",
"prevws",
"&&",
"pos",
"!=",
"0",
")",
"tmp",
"[",
"pos",
"++",
"]",
"=",
"'",
"'",
";",
"tmp",
"[",
"pos",
"++",
"]",
"=",
"ch",
";",
"prevws",
"=",
"false",
";",
"}",
"else",
"prevws",
"=",
"true",
";",
"}",
"return",
"new",
"String",
"(",
"tmp",
",",
"0",
",",
"pos",
")",
";",
"}"
] |
Removes trailing and leading whitespace, and also reduces each
sequence of internal whitespace to a single space.
|
[
"Removes",
"trailing",
"and",
"leading",
"whitespace",
"and",
"also",
"reduces",
"each",
"sequence",
"of",
"internal",
"whitespace",
"to",
"a",
"single",
"space",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/StringUtils.java#L31-L47
|
158,033
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/PropertyUtils.java
|
PropertyUtils.get
|
public static String get(Properties props, String name, String defval) {
String value = props.getProperty(name);
if (value == null)
value = defval;
return value;
}
|
java
|
public static String get(Properties props, String name, String defval) {
String value = props.getProperty(name);
if (value == null)
value = defval;
return value;
}
|
[
"public",
"static",
"String",
"get",
"(",
"Properties",
"props",
",",
"String",
"name",
",",
"String",
"defval",
")",
"{",
"String",
"value",
"=",
"props",
".",
"getProperty",
"(",
"name",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"value",
"=",
"defval",
";",
"return",
"value",
";",
"}"
] |
Returns the value of an optional property, if the property is
set. If it is not set defval is returned.
|
[
"Returns",
"the",
"value",
"of",
"an",
"optional",
"property",
"if",
"the",
"property",
"is",
"set",
".",
"If",
"it",
"is",
"not",
"set",
"defval",
"is",
"returned",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/PropertyUtils.java#L28-L33
|
158,034
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/ConfigurationImpl.java
|
ConfigurationImpl.getDataSources
|
public Collection<DataSource> getDataSources(int groupno) {
if (groupno == 1)
return group1;
else if (groupno == 2)
return group2;
else
throw new DukeConfigException("Invalid group number: " + groupno);
}
|
java
|
public Collection<DataSource> getDataSources(int groupno) {
if (groupno == 1)
return group1;
else if (groupno == 2)
return group2;
else
throw new DukeConfigException("Invalid group number: " + groupno);
}
|
[
"public",
"Collection",
"<",
"DataSource",
">",
"getDataSources",
"(",
"int",
"groupno",
")",
"{",
"if",
"(",
"groupno",
"==",
"1",
")",
"return",
"group1",
";",
"else",
"if",
"(",
"groupno",
"==",
"2",
")",
"return",
"group2",
";",
"else",
"throw",
"new",
"DukeConfigException",
"(",
"\"Invalid group number: \"",
"+",
"groupno",
")",
";",
"}"
] |
Returns the data sources belonging to a particular group of data
sources. Data sources are grouped in record linkage mode, but not
in deduplication mode, so only use this method in record linkage
mode.
|
[
"Returns",
"the",
"data",
"sources",
"belonging",
"to",
"a",
"particular",
"group",
"of",
"data",
"sources",
".",
"Data",
"sources",
"are",
"grouped",
"in",
"record",
"linkage",
"mode",
"but",
"not",
"in",
"deduplication",
"mode",
"so",
"only",
"use",
"this",
"method",
"in",
"record",
"linkage",
"mode",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/ConfigurationImpl.java#L59-L66
|
158,035
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/ConfigurationImpl.java
|
ConfigurationImpl.addDataSource
|
public void addDataSource(int groupno, DataSource datasource) {
// the loader takes care of validation
if (groupno == 0)
datasources.add(datasource);
else if (groupno == 1)
group1.add(datasource);
else if (groupno == 2)
group2.add(datasource);
}
|
java
|
public void addDataSource(int groupno, DataSource datasource) {
// the loader takes care of validation
if (groupno == 0)
datasources.add(datasource);
else if (groupno == 1)
group1.add(datasource);
else if (groupno == 2)
group2.add(datasource);
}
|
[
"public",
"void",
"addDataSource",
"(",
"int",
"groupno",
",",
"DataSource",
"datasource",
")",
"{",
"// the loader takes care of validation",
"if",
"(",
"groupno",
"==",
"0",
")",
"datasources",
".",
"add",
"(",
"datasource",
")",
";",
"else",
"if",
"(",
"groupno",
"==",
"1",
")",
"group1",
".",
"add",
"(",
"datasource",
")",
";",
"else",
"if",
"(",
"groupno",
"==",
"2",
")",
"group2",
".",
"add",
"(",
"datasource",
")",
";",
"}"
] |
Adds a data source to the configuration. If in deduplication mode
groupno == 0, otherwise it gives the number of the group to which
the data source belongs.
|
[
"Adds",
"a",
"data",
"source",
"to",
"the",
"configuration",
".",
"If",
"in",
"deduplication",
"mode",
"groupno",
"==",
"0",
"otherwise",
"it",
"gives",
"the",
"number",
"of",
"the",
"group",
"to",
"which",
"the",
"data",
"source",
"belongs",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/ConfigurationImpl.java#L73-L81
|
158,036
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/PropertyImpl.java
|
PropertyImpl.compare
|
public double compare(String v1, String v2) {
// FIXME: it should be possible here to say that, actually, we
// didn't learn anything from comparing these two values, so that
// probability is set to 0.5.
if (comparator == null)
return 0.5; // we ignore properties with no comparator
// first, we call the comparator, to get a measure of how similar
// these two values are. note that this is not the same as what we
// are going to return, which is a probability.
double sim = comparator.compare(v1, v2);
// we have been configured with a high probability (for equal
// values) and a low probability (for different values). given
// sim, which is a measure of the similarity somewhere in between
// equal and different, we now compute our estimate of the
// probability.
// if sim = 1.0, we return high. if sim = 0.0, we return low. for
// values in between we need to compute a little. the obvious
// formula to use would be (sim * (high - low)) + low, which
// spreads the values out equally spaced between high and low.
// however, if the similarity is higher than 0.5 we don't want to
// consider this negative evidence, and so there's a threshold
// there. also, users felt Duke was too eager to merge records,
// and wanted probabilities to fall off faster with lower
// probabilities, and so we square sim in order to achieve this.
if (sim >= 0.5)
return ((high - 0.5) * (sim * sim)) + 0.5;
else
return low;
}
|
java
|
public double compare(String v1, String v2) {
// FIXME: it should be possible here to say that, actually, we
// didn't learn anything from comparing these two values, so that
// probability is set to 0.5.
if (comparator == null)
return 0.5; // we ignore properties with no comparator
// first, we call the comparator, to get a measure of how similar
// these two values are. note that this is not the same as what we
// are going to return, which is a probability.
double sim = comparator.compare(v1, v2);
// we have been configured with a high probability (for equal
// values) and a low probability (for different values). given
// sim, which is a measure of the similarity somewhere in between
// equal and different, we now compute our estimate of the
// probability.
// if sim = 1.0, we return high. if sim = 0.0, we return low. for
// values in between we need to compute a little. the obvious
// formula to use would be (sim * (high - low)) + low, which
// spreads the values out equally spaced between high and low.
// however, if the similarity is higher than 0.5 we don't want to
// consider this negative evidence, and so there's a threshold
// there. also, users felt Duke was too eager to merge records,
// and wanted probabilities to fall off faster with lower
// probabilities, and so we square sim in order to achieve this.
if (sim >= 0.5)
return ((high - 0.5) * (sim * sim)) + 0.5;
else
return low;
}
|
[
"public",
"double",
"compare",
"(",
"String",
"v1",
",",
"String",
"v2",
")",
"{",
"// FIXME: it should be possible here to say that, actually, we",
"// didn't learn anything from comparing these two values, so that",
"// probability is set to 0.5.",
"if",
"(",
"comparator",
"==",
"null",
")",
"return",
"0.5",
";",
"// we ignore properties with no comparator",
"// first, we call the comparator, to get a measure of how similar",
"// these two values are. note that this is not the same as what we",
"// are going to return, which is a probability.",
"double",
"sim",
"=",
"comparator",
".",
"compare",
"(",
"v1",
",",
"v2",
")",
";",
"// we have been configured with a high probability (for equal",
"// values) and a low probability (for different values). given",
"// sim, which is a measure of the similarity somewhere in between",
"// equal and different, we now compute our estimate of the",
"// probability.",
"// if sim = 1.0, we return high. if sim = 0.0, we return low. for",
"// values in between we need to compute a little. the obvious",
"// formula to use would be (sim * (high - low)) + low, which",
"// spreads the values out equally spaced between high and low.",
"// however, if the similarity is higher than 0.5 we don't want to",
"// consider this negative evidence, and so there's a threshold",
"// there. also, users felt Duke was too eager to merge records,",
"// and wanted probabilities to fall off faster with lower",
"// probabilities, and so we square sim in order to achieve this.",
"if",
"(",
"sim",
">=",
"0.5",
")",
"return",
"(",
"(",
"high",
"-",
"0.5",
")",
"*",
"(",
"sim",
"*",
"sim",
")",
")",
"+",
"0.5",
";",
"else",
"return",
"low",
";",
"}"
] |
Returns the probability that the records v1 and v2 came from
represent the same entity, based on high and low probability
settings etc.
|
[
"Returns",
"the",
"probability",
"that",
"the",
"records",
"v1",
"and",
"v2",
"came",
"from",
"represent",
"the",
"same",
"entity",
"based",
"on",
"high",
"and",
"low",
"probability",
"settings",
"etc",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/PropertyImpl.java#L121-L155
|
158,037
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/datasources/SparqlDataSource.java
|
SparqlDataSource.runQuery
|
public SparqlResult runQuery(String endpoint, String query) {
return SparqlClient.execute(endpoint, query, username, password);
}
|
java
|
public SparqlResult runQuery(String endpoint, String query) {
return SparqlClient.execute(endpoint, query, username, password);
}
|
[
"public",
"SparqlResult",
"runQuery",
"(",
"String",
"endpoint",
",",
"String",
"query",
")",
"{",
"return",
"SparqlClient",
".",
"execute",
"(",
"endpoint",
",",
"query",
",",
"username",
",",
"password",
")",
";",
"}"
] |
An extension point so we can control how the query gets executed.
This exists for testing purposes, not because we believe it will
actually be used for real.
|
[
"An",
"extension",
"point",
"so",
"we",
"can",
"control",
"how",
"the",
"query",
"gets",
"executed",
".",
"This",
"exists",
"for",
"testing",
"purposes",
"not",
"because",
"we",
"believe",
"it",
"will",
"actually",
"be",
"used",
"for",
"real",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/datasources/SparqlDataSource.java#L123-L125
|
158,038
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/InMemoryClassDatabase.java
|
InMemoryClassDatabase.merge
|
private void merge(Integer cid1, Integer cid2) {
Collection<String> klass1 = classix.get(cid1);
Collection<String> klass2 = classix.get(cid2);
// if klass1 is the smaller, swap the two
if (klass1.size() < klass2.size()) {
Collection<String> tmp = klass2;
klass2 = klass1;
klass1 = tmp;
Integer itmp = cid2;
cid2 = cid1;
cid1 = itmp;
}
// now perform the actual merge
for (String id : klass2) {
klass1.add(id);
recordix.put(id, cid1);
}
// delete the smaller class, and we're done
classix.remove(cid2);
}
|
java
|
private void merge(Integer cid1, Integer cid2) {
Collection<String> klass1 = classix.get(cid1);
Collection<String> klass2 = classix.get(cid2);
// if klass1 is the smaller, swap the two
if (klass1.size() < klass2.size()) {
Collection<String> tmp = klass2;
klass2 = klass1;
klass1 = tmp;
Integer itmp = cid2;
cid2 = cid1;
cid1 = itmp;
}
// now perform the actual merge
for (String id : klass2) {
klass1.add(id);
recordix.put(id, cid1);
}
// delete the smaller class, and we're done
classix.remove(cid2);
}
|
[
"private",
"void",
"merge",
"(",
"Integer",
"cid1",
",",
"Integer",
"cid2",
")",
"{",
"Collection",
"<",
"String",
">",
"klass1",
"=",
"classix",
".",
"get",
"(",
"cid1",
")",
";",
"Collection",
"<",
"String",
">",
"klass2",
"=",
"classix",
".",
"get",
"(",
"cid2",
")",
";",
"// if klass1 is the smaller, swap the two",
"if",
"(",
"klass1",
".",
"size",
"(",
")",
"<",
"klass2",
".",
"size",
"(",
")",
")",
"{",
"Collection",
"<",
"String",
">",
"tmp",
"=",
"klass2",
";",
"klass2",
"=",
"klass1",
";",
"klass1",
"=",
"tmp",
";",
"Integer",
"itmp",
"=",
"cid2",
";",
"cid2",
"=",
"cid1",
";",
"cid1",
"=",
"itmp",
";",
"}",
"// now perform the actual merge",
"for",
"(",
"String",
"id",
":",
"klass2",
")",
"{",
"klass1",
".",
"add",
"(",
"id",
")",
";",
"recordix",
".",
"put",
"(",
"id",
",",
"cid1",
")",
";",
"}",
"// delete the smaller class, and we're done",
"classix",
".",
"remove",
"(",
"cid2",
")",
";",
"}"
] |
Merges the two classes into a single class. The smaller class is
removed, while the largest class is kept.
|
[
"Merges",
"the",
"two",
"classes",
"into",
"a",
"single",
"class",
".",
"The",
"smaller",
"class",
"is",
"removed",
"while",
"the",
"largest",
"class",
"is",
"kept",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/InMemoryClassDatabase.java#L91-L114
|
158,039
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java
|
KeyValueDatabase.bumpScores
|
private void bumpScores(Map<Long, Score> candidates,
List<Bucket> buckets,
int ix) {
for (; ix < buckets.size(); ix++) {
Bucket b = buckets.get(ix);
if (b.nextfree > CUTOFF_FACTOR_2 * candidates.size())
return;
double score = b.getScore();
for (Score s : candidates.values())
if (b.contains(s.id))
s.score += score;
}
}
|
java
|
private void bumpScores(Map<Long, Score> candidates,
List<Bucket> buckets,
int ix) {
for (; ix < buckets.size(); ix++) {
Bucket b = buckets.get(ix);
if (b.nextfree > CUTOFF_FACTOR_2 * candidates.size())
return;
double score = b.getScore();
for (Score s : candidates.values())
if (b.contains(s.id))
s.score += score;
}
}
|
[
"private",
"void",
"bumpScores",
"(",
"Map",
"<",
"Long",
",",
"Score",
">",
"candidates",
",",
"List",
"<",
"Bucket",
">",
"buckets",
",",
"int",
"ix",
")",
"{",
"for",
"(",
";",
"ix",
"<",
"buckets",
".",
"size",
"(",
")",
";",
"ix",
"++",
")",
"{",
"Bucket",
"b",
"=",
"buckets",
".",
"get",
"(",
"ix",
")",
";",
"if",
"(",
"b",
".",
"nextfree",
">",
"CUTOFF_FACTOR_2",
"*",
"candidates",
".",
"size",
"(",
")",
")",
"return",
";",
"double",
"score",
"=",
"b",
".",
"getScore",
"(",
")",
";",
"for",
"(",
"Score",
"s",
":",
"candidates",
".",
"values",
"(",
")",
")",
"if",
"(",
"b",
".",
"contains",
"(",
"s",
".",
"id",
")",
")",
"s",
".",
"score",
"+=",
"score",
";",
"}",
"}"
] |
Goes through the buckets from ix and out, checking for each
candidate if it's in one of the buckets, and if so, increasing
its score accordingly. No new candidates are added.
|
[
"Goes",
"through",
"the",
"buckets",
"from",
"ix",
"and",
"out",
"checking",
"for",
"each",
"candidate",
"if",
"it",
"s",
"in",
"one",
"of",
"the",
"buckets",
"and",
"if",
"so",
"increasing",
"its",
"score",
"accordingly",
".",
"No",
"new",
"candidates",
"are",
"added",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java#L213-L225
|
158,040
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java
|
KeyValueDatabase.collectCandidates
|
private int collectCandidates(Map<Long, Score> candidates,
List<Bucket> buckets,
int threshold) {
int ix;
for (ix = 0; ix < threshold &&
candidates.size() < (CUTOFF_FACTOR_1 * max_search_hits); ix++) {
Bucket b = buckets.get(ix);
long[] ids = b.records;
double score = b.getScore();
for (int ix2 = 0; ix2 < b.nextfree; ix2++) {
Score s = candidates.get(ids[ix2]);
if (s == null) {
s = new Score(ids[ix2]);
candidates.put(ids[ix2], s);
}
s.score += score;
}
if (DEBUG)
System.out.println("Bucket " + b.nextfree + " -> " + candidates.size());
}
return ix;
}
|
java
|
private int collectCandidates(Map<Long, Score> candidates,
List<Bucket> buckets,
int threshold) {
int ix;
for (ix = 0; ix < threshold &&
candidates.size() < (CUTOFF_FACTOR_1 * max_search_hits); ix++) {
Bucket b = buckets.get(ix);
long[] ids = b.records;
double score = b.getScore();
for (int ix2 = 0; ix2 < b.nextfree; ix2++) {
Score s = candidates.get(ids[ix2]);
if (s == null) {
s = new Score(ids[ix2]);
candidates.put(ids[ix2], s);
}
s.score += score;
}
if (DEBUG)
System.out.println("Bucket " + b.nextfree + " -> " + candidates.size());
}
return ix;
}
|
[
"private",
"int",
"collectCandidates",
"(",
"Map",
"<",
"Long",
",",
"Score",
">",
"candidates",
",",
"List",
"<",
"Bucket",
">",
"buckets",
",",
"int",
"threshold",
")",
"{",
"int",
"ix",
";",
"for",
"(",
"ix",
"=",
"0",
";",
"ix",
"<",
"threshold",
"&&",
"candidates",
".",
"size",
"(",
")",
"<",
"(",
"CUTOFF_FACTOR_1",
"*",
"max_search_hits",
")",
";",
"ix",
"++",
")",
"{",
"Bucket",
"b",
"=",
"buckets",
".",
"get",
"(",
"ix",
")",
";",
"long",
"[",
"]",
"ids",
"=",
"b",
".",
"records",
";",
"double",
"score",
"=",
"b",
".",
"getScore",
"(",
")",
";",
"for",
"(",
"int",
"ix2",
"=",
"0",
";",
"ix2",
"<",
"b",
".",
"nextfree",
";",
"ix2",
"++",
")",
"{",
"Score",
"s",
"=",
"candidates",
".",
"get",
"(",
"ids",
"[",
"ix2",
"]",
")",
";",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"s",
"=",
"new",
"Score",
"(",
"ids",
"[",
"ix2",
"]",
")",
";",
"candidates",
".",
"put",
"(",
"ids",
"[",
"ix2",
"]",
",",
"s",
")",
";",
"}",
"s",
".",
"score",
"+=",
"score",
";",
"}",
"if",
"(",
"DEBUG",
")",
"System",
".",
"out",
".",
"println",
"(",
"\"Bucket \"",
"+",
"b",
".",
"nextfree",
"+",
"\" -> \"",
"+",
"candidates",
".",
"size",
"(",
")",
")",
";",
"}",
"return",
"ix",
";",
"}"
] |
Goes through the first buckets, picking out candidate records and
tallying up their scores.
@return the index of the first bucket we did not process
|
[
"Goes",
"through",
"the",
"first",
"buckets",
"picking",
"out",
"candidate",
"records",
"and",
"tallying",
"up",
"their",
"scores",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java#L232-L254
|
158,041
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java
|
KeyValueDatabase.lookup
|
private List<Bucket> lookup(Record record) {
List<Bucket> buckets = new ArrayList();
for (Property p : config.getLookupProperties()) {
String propname = p.getName();
Collection<String> values = record.getValues(propname);
if (values == null)
continue;
for (String value : values) {
String[] tokens = StringUtils.split(value);
for (int ix = 0; ix < tokens.length; ix++) {
Bucket b = store.lookupToken(propname, tokens[ix]);
if (b == null || b.records == null)
continue;
long[] ids = b.records;
if (DEBUG)
System.out.println(propname + ", " + tokens[ix] + ": " + b.nextfree + " (" + b.getScore() + ")");
buckets.add(b);
}
}
}
return buckets;
}
|
java
|
private List<Bucket> lookup(Record record) {
List<Bucket> buckets = new ArrayList();
for (Property p : config.getLookupProperties()) {
String propname = p.getName();
Collection<String> values = record.getValues(propname);
if (values == null)
continue;
for (String value : values) {
String[] tokens = StringUtils.split(value);
for (int ix = 0; ix < tokens.length; ix++) {
Bucket b = store.lookupToken(propname, tokens[ix]);
if (b == null || b.records == null)
continue;
long[] ids = b.records;
if (DEBUG)
System.out.println(propname + ", " + tokens[ix] + ": " + b.nextfree + " (" + b.getScore() + ")");
buckets.add(b);
}
}
}
return buckets;
}
|
[
"private",
"List",
"<",
"Bucket",
">",
"lookup",
"(",
"Record",
"record",
")",
"{",
"List",
"<",
"Bucket",
">",
"buckets",
"=",
"new",
"ArrayList",
"(",
")",
";",
"for",
"(",
"Property",
"p",
":",
"config",
".",
"getLookupProperties",
"(",
")",
")",
"{",
"String",
"propname",
"=",
"p",
".",
"getName",
"(",
")",
";",
"Collection",
"<",
"String",
">",
"values",
"=",
"record",
".",
"getValues",
"(",
"propname",
")",
";",
"if",
"(",
"values",
"==",
"null",
")",
"continue",
";",
"for",
"(",
"String",
"value",
":",
"values",
")",
"{",
"String",
"[",
"]",
"tokens",
"=",
"StringUtils",
".",
"split",
"(",
"value",
")",
";",
"for",
"(",
"int",
"ix",
"=",
"0",
";",
"ix",
"<",
"tokens",
".",
"length",
";",
"ix",
"++",
")",
"{",
"Bucket",
"b",
"=",
"store",
".",
"lookupToken",
"(",
"propname",
",",
"tokens",
"[",
"ix",
"]",
")",
";",
"if",
"(",
"b",
"==",
"null",
"||",
"b",
".",
"records",
"==",
"null",
")",
"continue",
";",
"long",
"[",
"]",
"ids",
"=",
"b",
".",
"records",
";",
"if",
"(",
"DEBUG",
")",
"System",
".",
"out",
".",
"println",
"(",
"propname",
"+",
"\", \"",
"+",
"tokens",
"[",
"ix",
"]",
"+",
"\": \"",
"+",
"b",
".",
"nextfree",
"+",
"\" (\"",
"+",
"b",
".",
"getScore",
"(",
")",
"+",
"\")\"",
")",
";",
"buckets",
".",
"add",
"(",
"b",
")",
";",
"}",
"}",
"}",
"return",
"buckets",
";",
"}"
] |
Tokenizes lookup fields and returns all matching buckets in the
index.
|
[
"Tokenizes",
"lookup",
"fields",
"and",
"returns",
"all",
"matching",
"buckets",
"in",
"the",
"index",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/databases/KeyValueDatabase.java#L260-L283
|
158,042
|
larsga/Duke
|
duke-server/src/main/java/no/priv/garshol/duke/server/CommonJTimer.java
|
CommonJTimer.spawnThread
|
public void spawnThread(DukeController controller, int check_interval) {
this.controller = controller;
timer = mgr.schedule(this, 0, check_interval * 1000); // convert to ms
}
|
java
|
public void spawnThread(DukeController controller, int check_interval) {
this.controller = controller;
timer = mgr.schedule(this, 0, check_interval * 1000); // convert to ms
}
|
[
"public",
"void",
"spawnThread",
"(",
"DukeController",
"controller",
",",
"int",
"check_interval",
")",
"{",
"this",
".",
"controller",
"=",
"controller",
";",
"timer",
"=",
"mgr",
".",
"schedule",
"(",
"this",
",",
"0",
",",
"check_interval",
"*",
"1000",
")",
";",
"// convert to ms",
"}"
] |
Starts a background thread which calls the controller every
check_interval milliseconds. Returns immediately, leaving the
background thread running.
|
[
"Starts",
"a",
"background",
"thread",
"which",
"calls",
"the",
"controller",
"every",
"check_interval",
"milliseconds",
".",
"Returns",
"immediately",
"leaving",
"the",
"background",
"thread",
"running",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-server/src/main/java/no/priv/garshol/duke/server/CommonJTimer.java#L45-L48
|
158,043
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/AbstractCmdlineTool.java
|
AbstractCmdlineTool.init
|
public String[] init(String[] argv, int min, int max,
Collection<CommandLineParser.Option> options)
throws IOException, SAXException {
// parse command line
parser = new CommandLineParser();
parser.setMinimumArguments(min);
parser.setMaximumArguments(max);
parser.registerOption(new CommandLineParser.BooleanOption("reindex", 'I'));
if (options != null)
for (CommandLineParser.Option option : options)
parser.registerOption(option);
try {
argv = parser.parse(argv);
} catch (CommandLineParser.CommandLineParserException e) {
System.err.println("ERROR: " + e.getMessage());
usage();
System.exit(1);
}
// do we need to reindex?
boolean reindex = parser.getOptionState("reindex");
// load configuration
config = ConfigLoader.load(argv[0]);
database = config.getDatabase(reindex); // overwrite iff reindex
if (database.isInMemory())
reindex = true; // no other way to do it in this case
// reindex, if requested
if (reindex)
reindex(config, database);
return argv;
}
|
java
|
public String[] init(String[] argv, int min, int max,
Collection<CommandLineParser.Option> options)
throws IOException, SAXException {
// parse command line
parser = new CommandLineParser();
parser.setMinimumArguments(min);
parser.setMaximumArguments(max);
parser.registerOption(new CommandLineParser.BooleanOption("reindex", 'I'));
if (options != null)
for (CommandLineParser.Option option : options)
parser.registerOption(option);
try {
argv = parser.parse(argv);
} catch (CommandLineParser.CommandLineParserException e) {
System.err.println("ERROR: " + e.getMessage());
usage();
System.exit(1);
}
// do we need to reindex?
boolean reindex = parser.getOptionState("reindex");
// load configuration
config = ConfigLoader.load(argv[0]);
database = config.getDatabase(reindex); // overwrite iff reindex
if (database.isInMemory())
reindex = true; // no other way to do it in this case
// reindex, if requested
if (reindex)
reindex(config, database);
return argv;
}
|
[
"public",
"String",
"[",
"]",
"init",
"(",
"String",
"[",
"]",
"argv",
",",
"int",
"min",
",",
"int",
"max",
",",
"Collection",
"<",
"CommandLineParser",
".",
"Option",
">",
"options",
")",
"throws",
"IOException",
",",
"SAXException",
"{",
"// parse command line",
"parser",
"=",
"new",
"CommandLineParser",
"(",
")",
";",
"parser",
".",
"setMinimumArguments",
"(",
"min",
")",
";",
"parser",
".",
"setMaximumArguments",
"(",
"max",
")",
";",
"parser",
".",
"registerOption",
"(",
"new",
"CommandLineParser",
".",
"BooleanOption",
"(",
"\"reindex\"",
",",
"'",
"'",
")",
")",
";",
"if",
"(",
"options",
"!=",
"null",
")",
"for",
"(",
"CommandLineParser",
".",
"Option",
"option",
":",
"options",
")",
"parser",
".",
"registerOption",
"(",
"option",
")",
";",
"try",
"{",
"argv",
"=",
"parser",
".",
"parse",
"(",
"argv",
")",
";",
"}",
"catch",
"(",
"CommandLineParser",
".",
"CommandLineParserException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"ERROR: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"usage",
"(",
")",
";",
"System",
".",
"exit",
"(",
"1",
")",
";",
"}",
"// do we need to reindex?",
"boolean",
"reindex",
"=",
"parser",
".",
"getOptionState",
"(",
"\"reindex\"",
")",
";",
"// load configuration",
"config",
"=",
"ConfigLoader",
".",
"load",
"(",
"argv",
"[",
"0",
"]",
")",
";",
"database",
"=",
"config",
".",
"getDatabase",
"(",
"reindex",
")",
";",
"// overwrite iff reindex",
"if",
"(",
"database",
".",
"isInMemory",
"(",
")",
")",
"reindex",
"=",
"true",
";",
"// no other way to do it in this case",
"// reindex, if requested",
"if",
"(",
"reindex",
")",
"reindex",
"(",
"config",
",",
"database",
")",
";",
"return",
"argv",
";",
"}"
] |
These exact lines are shared between three different tools, so
they have been moved here to reduce code duplication.
@return The parsed command-line, with options removed.
|
[
"These",
"exact",
"lines",
"are",
"shared",
"between",
"three",
"different",
"tools",
"so",
"they",
"have",
"been",
"moved",
"here",
"to",
"reduce",
"code",
"duplication",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/AbstractCmdlineTool.java#L26-L60
|
158,044
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java
|
Utils.createTempDirectory
|
public static File createTempDirectory(String prefix) {
File temp = null;
try {
temp = File.createTempFile(prefix != null ? prefix : "temp", Long.toString(System.nanoTime()));
if (!(temp.delete())) {
throw new IOException("Could not delete temp file: "
+ temp.getAbsolutePath());
}
if (!(temp.mkdir())) {
throw new IOException("Could not create temp directory: "
+ temp.getAbsolutePath());
}
} catch (IOException e) {
throw new DukeException("Unable to create temporary directory with prefix " + prefix, e);
}
return temp;
}
|
java
|
public static File createTempDirectory(String prefix) {
File temp = null;
try {
temp = File.createTempFile(prefix != null ? prefix : "temp", Long.toString(System.nanoTime()));
if (!(temp.delete())) {
throw new IOException("Could not delete temp file: "
+ temp.getAbsolutePath());
}
if (!(temp.mkdir())) {
throw new IOException("Could not create temp directory: "
+ temp.getAbsolutePath());
}
} catch (IOException e) {
throw new DukeException("Unable to create temporary directory with prefix " + prefix, e);
}
return temp;
}
|
[
"public",
"static",
"File",
"createTempDirectory",
"(",
"String",
"prefix",
")",
"{",
"File",
"temp",
"=",
"null",
";",
"try",
"{",
"temp",
"=",
"File",
".",
"createTempFile",
"(",
"prefix",
"!=",
"null",
"?",
"prefix",
":",
"\"temp\"",
",",
"Long",
".",
"toString",
"(",
"System",
".",
"nanoTime",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"(",
"temp",
".",
"delete",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not delete temp file: \"",
"+",
"temp",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"temp",
".",
"mkdir",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not create temp directory: \"",
"+",
"temp",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"\"Unable to create temporary directory with prefix \"",
"+",
"prefix",
",",
"e",
")",
";",
"}",
"return",
"temp",
";",
"}"
] |
Creates a temporary folder using the given prefix to generate its name.
@param prefix the prefix string to be used in generating the directory's name; may be <i>null</i>
@return the <code>File</code> to the newly created folder
@throws IOException
|
[
"Creates",
"a",
"temporary",
"folder",
"using",
"the",
"given",
"prefix",
"to",
"generate",
"its",
"name",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/Utils.java#L36-L56
|
158,045
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/ConfigLoader.java
|
ConfigLoader.loadFromString
|
public static Configuration loadFromString(String config)
throws IOException, SAXException {
ConfigurationImpl cfg = new ConfigurationImpl();
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(new ConfigHandler(cfg, null));
Reader reader = new StringReader(config);
parser.parse(new InputSource(reader));
return cfg;
}
|
java
|
public static Configuration loadFromString(String config)
throws IOException, SAXException {
ConfigurationImpl cfg = new ConfigurationImpl();
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(new ConfigHandler(cfg, null));
Reader reader = new StringReader(config);
parser.parse(new InputSource(reader));
return cfg;
}
|
[
"public",
"static",
"Configuration",
"loadFromString",
"(",
"String",
"config",
")",
"throws",
"IOException",
",",
"SAXException",
"{",
"ConfigurationImpl",
"cfg",
"=",
"new",
"ConfigurationImpl",
"(",
")",
";",
"XMLReader",
"parser",
"=",
"XMLReaderFactory",
".",
"createXMLReader",
"(",
")",
";",
"parser",
".",
"setContentHandler",
"(",
"new",
"ConfigHandler",
"(",
"cfg",
",",
"null",
")",
")",
";",
"Reader",
"reader",
"=",
"new",
"StringReader",
"(",
"config",
")",
";",
"parser",
".",
"parse",
"(",
"new",
"InputSource",
"(",
"reader",
")",
")",
";",
"return",
"cfg",
";",
"}"
] |
Loads the configuration XML from the given string.
@since 1.3
|
[
"Loads",
"the",
"configuration",
"XML",
"from",
"the",
"given",
"string",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/ConfigLoader.java#L58-L67
|
158,046
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/matchers/LinkDatabaseMatchListener.java
|
LinkDatabaseMatchListener.endRecord_
|
public void endRecord_() {
// this is where we actually update the link database. basically,
// all we need to do is to retract those links which weren't seen
// this time around, and that can be done via assertLink, since it
// can override existing links.
// get all the existing links
Collection<Link> oldlinks = linkdb.getAllLinksFor(getIdentity(current));
// build a hashmap so we can look up corresponding old links from
// new links
if (oldlinks != null) {
Map<String, Link> oldmap = new HashMap(oldlinks.size());
for (Link l : oldlinks)
oldmap.put(makeKey(l), l);
// removing all the links we found this time around from the set of
// old links. any links remaining after this will be stale, and need
// to be retracted
for (Link newl : new ArrayList<Link>(curlinks)) {
String key = makeKey(newl);
Link oldl = oldmap.get(key);
if (oldl == null)
continue;
if (oldl.overrides(newl))
// previous information overrides this link, so ignore
curlinks.remove(newl);
else if (sameAs(oldl, newl)) {
// there's no new information here, so just ignore this
curlinks.remove(newl);
oldmap.remove(key); // we don't want to retract the old one
} else
// the link is out of date, but will be overwritten, so remove
oldmap.remove(key);
}
// all the inferred links left in oldmap are now old links we
// didn't find on this pass. there is no longer any evidence
// supporting them, and so we can retract them.
for (Link oldl : oldmap.values())
if (oldl.getStatus() == LinkStatus.INFERRED) {
oldl.retract(); // changes to retracted, updates timestamp
curlinks.add(oldl);
}
}
// okay, now we write it all to the database
for (Link l : curlinks)
linkdb.assertLink(l);
}
|
java
|
public void endRecord_() {
// this is where we actually update the link database. basically,
// all we need to do is to retract those links which weren't seen
// this time around, and that can be done via assertLink, since it
// can override existing links.
// get all the existing links
Collection<Link> oldlinks = linkdb.getAllLinksFor(getIdentity(current));
// build a hashmap so we can look up corresponding old links from
// new links
if (oldlinks != null) {
Map<String, Link> oldmap = new HashMap(oldlinks.size());
for (Link l : oldlinks)
oldmap.put(makeKey(l), l);
// removing all the links we found this time around from the set of
// old links. any links remaining after this will be stale, and need
// to be retracted
for (Link newl : new ArrayList<Link>(curlinks)) {
String key = makeKey(newl);
Link oldl = oldmap.get(key);
if (oldl == null)
continue;
if (oldl.overrides(newl))
// previous information overrides this link, so ignore
curlinks.remove(newl);
else if (sameAs(oldl, newl)) {
// there's no new information here, so just ignore this
curlinks.remove(newl);
oldmap.remove(key); // we don't want to retract the old one
} else
// the link is out of date, but will be overwritten, so remove
oldmap.remove(key);
}
// all the inferred links left in oldmap are now old links we
// didn't find on this pass. there is no longer any evidence
// supporting them, and so we can retract them.
for (Link oldl : oldmap.values())
if (oldl.getStatus() == LinkStatus.INFERRED) {
oldl.retract(); // changes to retracted, updates timestamp
curlinks.add(oldl);
}
}
// okay, now we write it all to the database
for (Link l : curlinks)
linkdb.assertLink(l);
}
|
[
"public",
"void",
"endRecord_",
"(",
")",
"{",
"// this is where we actually update the link database. basically,",
"// all we need to do is to retract those links which weren't seen",
"// this time around, and that can be done via assertLink, since it",
"// can override existing links.",
"// get all the existing links",
"Collection",
"<",
"Link",
">",
"oldlinks",
"=",
"linkdb",
".",
"getAllLinksFor",
"(",
"getIdentity",
"(",
"current",
")",
")",
";",
"// build a hashmap so we can look up corresponding old links from",
"// new links",
"if",
"(",
"oldlinks",
"!=",
"null",
")",
"{",
"Map",
"<",
"String",
",",
"Link",
">",
"oldmap",
"=",
"new",
"HashMap",
"(",
"oldlinks",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Link",
"l",
":",
"oldlinks",
")",
"oldmap",
".",
"put",
"(",
"makeKey",
"(",
"l",
")",
",",
"l",
")",
";",
"// removing all the links we found this time around from the set of",
"// old links. any links remaining after this will be stale, and need",
"// to be retracted",
"for",
"(",
"Link",
"newl",
":",
"new",
"ArrayList",
"<",
"Link",
">",
"(",
"curlinks",
")",
")",
"{",
"String",
"key",
"=",
"makeKey",
"(",
"newl",
")",
";",
"Link",
"oldl",
"=",
"oldmap",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"oldl",
"==",
"null",
")",
"continue",
";",
"if",
"(",
"oldl",
".",
"overrides",
"(",
"newl",
")",
")",
"// previous information overrides this link, so ignore",
"curlinks",
".",
"remove",
"(",
"newl",
")",
";",
"else",
"if",
"(",
"sameAs",
"(",
"oldl",
",",
"newl",
")",
")",
"{",
"// there's no new information here, so just ignore this",
"curlinks",
".",
"remove",
"(",
"newl",
")",
";",
"oldmap",
".",
"remove",
"(",
"key",
")",
";",
"// we don't want to retract the old one",
"}",
"else",
"// the link is out of date, but will be overwritten, so remove",
"oldmap",
".",
"remove",
"(",
"key",
")",
";",
"}",
"// all the inferred links left in oldmap are now old links we",
"// didn't find on this pass. there is no longer any evidence",
"// supporting them, and so we can retract them.",
"for",
"(",
"Link",
"oldl",
":",
"oldmap",
".",
"values",
"(",
")",
")",
"if",
"(",
"oldl",
".",
"getStatus",
"(",
")",
"==",
"LinkStatus",
".",
"INFERRED",
")",
"{",
"oldl",
".",
"retract",
"(",
")",
";",
"// changes to retracted, updates timestamp",
"curlinks",
".",
"add",
"(",
"oldl",
")",
";",
"}",
"}",
"// okay, now we write it all to the database",
"for",
"(",
"Link",
"l",
":",
"curlinks",
")",
"linkdb",
".",
"assertLink",
"(",
"l",
")",
";",
"}"
] |
this method is called from the event methods
|
[
"this",
"method",
"is",
"called",
"from",
"the",
"event",
"methods"
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/matchers/LinkDatabaseMatchListener.java#L87-L137
|
158,047
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/ConfigWriter.java
|
ConfigWriter.write
|
public void write(Configuration config)
throws IOException {
pp.startDocument();
pp.startElement("duke", null);
// FIXME: here we should write the objects, but that's not
// possible with the current API. we don't need that for the
// genetic algorithm at the moment, but it would be useful.
pp.startElement("schema", null);
writeElement("threshold", "" + config.getThreshold());
if (config.getMaybeThreshold() != 0.0)
writeElement("maybe-threshold", "" + config.getMaybeThreshold());
for (Property p : config.getProperties())
writeProperty(p);
pp.endElement("schema");
String dbclass = config.getDatabase(false).getClass().getName();
AttributeListImpl atts = new AttributeListImpl();
atts.addAttribute("class", "CDATA", dbclass);
pp.startElement("database", atts);
pp.endElement("database");
if (config.isDeduplicationMode())
for (DataSource src : config.getDataSources())
writeDataSource(src);
else {
pp.startElement("group", null);
for (DataSource src : config.getDataSources(1))
writeDataSource(src);
pp.endElement("group");
pp.startElement("group", null);
for (DataSource src : config.getDataSources(2))
writeDataSource(src);
pp.endElement("group");
}
pp.endElement("duke");
pp.endDocument();
}
|
java
|
public void write(Configuration config)
throws IOException {
pp.startDocument();
pp.startElement("duke", null);
// FIXME: here we should write the objects, but that's not
// possible with the current API. we don't need that for the
// genetic algorithm at the moment, but it would be useful.
pp.startElement("schema", null);
writeElement("threshold", "" + config.getThreshold());
if (config.getMaybeThreshold() != 0.0)
writeElement("maybe-threshold", "" + config.getMaybeThreshold());
for (Property p : config.getProperties())
writeProperty(p);
pp.endElement("schema");
String dbclass = config.getDatabase(false).getClass().getName();
AttributeListImpl atts = new AttributeListImpl();
atts.addAttribute("class", "CDATA", dbclass);
pp.startElement("database", atts);
pp.endElement("database");
if (config.isDeduplicationMode())
for (DataSource src : config.getDataSources())
writeDataSource(src);
else {
pp.startElement("group", null);
for (DataSource src : config.getDataSources(1))
writeDataSource(src);
pp.endElement("group");
pp.startElement("group", null);
for (DataSource src : config.getDataSources(2))
writeDataSource(src);
pp.endElement("group");
}
pp.endElement("duke");
pp.endDocument();
}
|
[
"public",
"void",
"write",
"(",
"Configuration",
"config",
")",
"throws",
"IOException",
"{",
"pp",
".",
"startDocument",
"(",
")",
";",
"pp",
".",
"startElement",
"(",
"\"duke\"",
",",
"null",
")",
";",
"// FIXME: here we should write the objects, but that's not",
"// possible with the current API. we don't need that for the",
"// genetic algorithm at the moment, but it would be useful.",
"pp",
".",
"startElement",
"(",
"\"schema\"",
",",
"null",
")",
";",
"writeElement",
"(",
"\"threshold\"",
",",
"\"\"",
"+",
"config",
".",
"getThreshold",
"(",
")",
")",
";",
"if",
"(",
"config",
".",
"getMaybeThreshold",
"(",
")",
"!=",
"0.0",
")",
"writeElement",
"(",
"\"maybe-threshold\"",
",",
"\"\"",
"+",
"config",
".",
"getMaybeThreshold",
"(",
")",
")",
";",
"for",
"(",
"Property",
"p",
":",
"config",
".",
"getProperties",
"(",
")",
")",
"writeProperty",
"(",
"p",
")",
";",
"pp",
".",
"endElement",
"(",
"\"schema\"",
")",
";",
"String",
"dbclass",
"=",
"config",
".",
"getDatabase",
"(",
"false",
")",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
";",
"AttributeListImpl",
"atts",
"=",
"new",
"AttributeListImpl",
"(",
")",
";",
"atts",
".",
"addAttribute",
"(",
"\"class\"",
",",
"\"CDATA\"",
",",
"dbclass",
")",
";",
"pp",
".",
"startElement",
"(",
"\"database\"",
",",
"atts",
")",
";",
"pp",
".",
"endElement",
"(",
"\"database\"",
")",
";",
"if",
"(",
"config",
".",
"isDeduplicationMode",
"(",
")",
")",
"for",
"(",
"DataSource",
"src",
":",
"config",
".",
"getDataSources",
"(",
")",
")",
"writeDataSource",
"(",
"src",
")",
";",
"else",
"{",
"pp",
".",
"startElement",
"(",
"\"group\"",
",",
"null",
")",
";",
"for",
"(",
"DataSource",
"src",
":",
"config",
".",
"getDataSources",
"(",
"1",
")",
")",
"writeDataSource",
"(",
"src",
")",
";",
"pp",
".",
"endElement",
"(",
"\"group\"",
")",
";",
"pp",
".",
"startElement",
"(",
"\"group\"",
",",
"null",
")",
";",
"for",
"(",
"DataSource",
"src",
":",
"config",
".",
"getDataSources",
"(",
"2",
")",
")",
"writeDataSource",
"(",
"src",
")",
";",
"pp",
".",
"endElement",
"(",
"\"group\"",
")",
";",
"}",
"pp",
".",
"endElement",
"(",
"\"duke\"",
")",
";",
"pp",
".",
"endDocument",
"(",
")",
";",
"}"
] |
Writes the given configuration to the given file.
|
[
"Writes",
"the",
"given",
"configuration",
"to",
"the",
"given",
"file",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/ConfigWriter.java#L28-L72
|
158,048
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/NTriplesParser.java
|
NTriplesParser.parse
|
public static void parse(Reader src, StatementHandler handler)
throws IOException {
new NTriplesParser(src, handler).parse();
}
|
java
|
public static void parse(Reader src, StatementHandler handler)
throws IOException {
new NTriplesParser(src, handler).parse();
}
|
[
"public",
"static",
"void",
"parse",
"(",
"Reader",
"src",
",",
"StatementHandler",
"handler",
")",
"throws",
"IOException",
"{",
"new",
"NTriplesParser",
"(",
"src",
",",
"handler",
")",
".",
"parse",
"(",
")",
";",
"}"
] |
Reads the NTriples file from the reader, pushing statements into
the handler.
|
[
"Reads",
"the",
"NTriples",
"file",
"from",
"the",
"reader",
"pushing",
"statements",
"into",
"the",
"handler",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/NTriplesParser.java#L25-L28
|
158,049
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/comparators/Levenshtein.java
|
Levenshtein.distance
|
public static int distance(String s1, String s2) {
if (s1.length() == 0)
return s2.length();
if (s2.length() == 0)
return s1.length();
int s1len = s1.length();
// we use a flat array for better performance. we address it by
// s1ix + s1len * s2ix. this modification improves performance
// by about 30%, which is definitely worth the extra complexity.
int[] matrix = new int[(s1len + 1) * (s2.length() + 1)];
for (int col = 0; col <= s2.length(); col++)
matrix[col * s1len] = col;
for (int row = 0; row <= s1len; row++)
matrix[row] = row;
for (int ix1 = 0; ix1 < s1len; ix1++) {
char ch1 = s1.charAt(ix1);
for (int ix2 = 0; ix2 < s2.length(); ix2++) {
int cost;
if (ch1 == s2.charAt(ix2))
cost = 0;
else
cost = 1;
int left = matrix[ix1 + ((ix2 + 1) * s1len)] + 1;
int above = matrix[ix1 + 1 + (ix2 * s1len)] + 1;
int aboveleft = matrix[ix1 + (ix2 * s1len)] + cost;
matrix[ix1 + 1 + ((ix2 + 1) * s1len)] =
Math.min(left, Math.min(above, aboveleft));
}
}
// for (int ix1 = 0; ix1 <= s1len; ix1++) {
// for (int ix2 = 0; ix2 <= s2.length(); ix2++) {
// System.out.print(matrix[ix1 + (ix2 * s1len)] + " ");
// }
// System.out.println();
// }
return matrix[s1len + (s2.length() * s1len)];
}
|
java
|
public static int distance(String s1, String s2) {
if (s1.length() == 0)
return s2.length();
if (s2.length() == 0)
return s1.length();
int s1len = s1.length();
// we use a flat array for better performance. we address it by
// s1ix + s1len * s2ix. this modification improves performance
// by about 30%, which is definitely worth the extra complexity.
int[] matrix = new int[(s1len + 1) * (s2.length() + 1)];
for (int col = 0; col <= s2.length(); col++)
matrix[col * s1len] = col;
for (int row = 0; row <= s1len; row++)
matrix[row] = row;
for (int ix1 = 0; ix1 < s1len; ix1++) {
char ch1 = s1.charAt(ix1);
for (int ix2 = 0; ix2 < s2.length(); ix2++) {
int cost;
if (ch1 == s2.charAt(ix2))
cost = 0;
else
cost = 1;
int left = matrix[ix1 + ((ix2 + 1) * s1len)] + 1;
int above = matrix[ix1 + 1 + (ix2 * s1len)] + 1;
int aboveleft = matrix[ix1 + (ix2 * s1len)] + cost;
matrix[ix1 + 1 + ((ix2 + 1) * s1len)] =
Math.min(left, Math.min(above, aboveleft));
}
}
// for (int ix1 = 0; ix1 <= s1len; ix1++) {
// for (int ix2 = 0; ix2 <= s2.length(); ix2++) {
// System.out.print(matrix[ix1 + (ix2 * s1len)] + " ");
// }
// System.out.println();
// }
return matrix[s1len + (s2.length() * s1len)];
}
|
[
"public",
"static",
"int",
"distance",
"(",
"String",
"s1",
",",
"String",
"s2",
")",
"{",
"if",
"(",
"s1",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"s2",
".",
"length",
"(",
")",
";",
"if",
"(",
"s2",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"s1",
".",
"length",
"(",
")",
";",
"int",
"s1len",
"=",
"s1",
".",
"length",
"(",
")",
";",
"// we use a flat array for better performance. we address it by",
"// s1ix + s1len * s2ix. this modification improves performance",
"// by about 30%, which is definitely worth the extra complexity.",
"int",
"[",
"]",
"matrix",
"=",
"new",
"int",
"[",
"(",
"s1len",
"+",
"1",
")",
"*",
"(",
"s2",
".",
"length",
"(",
")",
"+",
"1",
")",
"]",
";",
"for",
"(",
"int",
"col",
"=",
"0",
";",
"col",
"<=",
"s2",
".",
"length",
"(",
")",
";",
"col",
"++",
")",
"matrix",
"[",
"col",
"*",
"s1len",
"]",
"=",
"col",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<=",
"s1len",
";",
"row",
"++",
")",
"matrix",
"[",
"row",
"]",
"=",
"row",
";",
"for",
"(",
"int",
"ix1",
"=",
"0",
";",
"ix1",
"<",
"s1len",
";",
"ix1",
"++",
")",
"{",
"char",
"ch1",
"=",
"s1",
".",
"charAt",
"(",
"ix1",
")",
";",
"for",
"(",
"int",
"ix2",
"=",
"0",
";",
"ix2",
"<",
"s2",
".",
"length",
"(",
")",
";",
"ix2",
"++",
")",
"{",
"int",
"cost",
";",
"if",
"(",
"ch1",
"==",
"s2",
".",
"charAt",
"(",
"ix2",
")",
")",
"cost",
"=",
"0",
";",
"else",
"cost",
"=",
"1",
";",
"int",
"left",
"=",
"matrix",
"[",
"ix1",
"+",
"(",
"(",
"ix2",
"+",
"1",
")",
"*",
"s1len",
")",
"]",
"+",
"1",
";",
"int",
"above",
"=",
"matrix",
"[",
"ix1",
"+",
"1",
"+",
"(",
"ix2",
"*",
"s1len",
")",
"]",
"+",
"1",
";",
"int",
"aboveleft",
"=",
"matrix",
"[",
"ix1",
"+",
"(",
"ix2",
"*",
"s1len",
")",
"]",
"+",
"cost",
";",
"matrix",
"[",
"ix1",
"+",
"1",
"+",
"(",
"(",
"ix2",
"+",
"1",
")",
"*",
"s1len",
")",
"]",
"=",
"Math",
".",
"min",
"(",
"left",
",",
"Math",
".",
"min",
"(",
"above",
",",
"aboveleft",
")",
")",
";",
"}",
"}",
"// for (int ix1 = 0; ix1 <= s1len; ix1++) {",
"// for (int ix2 = 0; ix2 <= s2.length(); ix2++) {",
"// System.out.print(matrix[ix1 + (ix2 * s1len)] + \" \");",
"// }",
"// System.out.println();",
"// }",
"return",
"matrix",
"[",
"s1len",
"+",
"(",
"s2",
".",
"length",
"(",
")",
"*",
"s1len",
")",
"]",
";",
"}"
] |
This is the original, naive implementation, using the Wagner &
Fischer algorithm from 1974. It uses a flattened matrix for
speed, but still computes the entire matrix.
|
[
"This",
"is",
"the",
"original",
"naive",
"implementation",
"using",
"the",
"Wagner",
"&",
"Fischer",
"algorithm",
"from",
"1974",
".",
"It",
"uses",
"a",
"flattened",
"matrix",
"for",
"speed",
"but",
"still",
"computes",
"the",
"entire",
"matrix",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/comparators/Levenshtein.java#L53-L94
|
158,050
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/comparators/Levenshtein.java
|
Levenshtein.compactDistance
|
public static int compactDistance(String s1, String s2) {
if (s1.length() == 0)
return s2.length();
if (s2.length() == 0)
return s1.length();
// the maximum edit distance there is any point in reporting.
int maxdist = Math.min(s1.length(), s2.length()) / 2;
// we allocate just one column instead of the entire matrix, in
// order to save space. this also enables us to implement the
// algorithm somewhat faster. the first cell is always the
// virtual first row.
int s1len = s1.length();
int[] column = new int[s1len + 1];
// first we need to fill in the initial column. we use a separate
// loop for this, because in this case our basis for comparison is
// not the previous column, but a virtual first column.
int ix2 = 0;
char ch2 = s2.charAt(ix2);
column[0] = 1; // virtual first row
for (int ix1 = 1; ix1 <= s1len; ix1++) {
int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;
// Lowest of three: above (column[ix1 - 1]), aboveleft: ix1 - 1,
// left: ix1. Latter cannot possibly be lowest, so is
// ignored.
column[ix1] = Math.min(column[ix1 - 1], ix1 - 1) + cost;
}
// okay, now we have an initialized first column, and we can
// compute the rest of the matrix.
int above = 0;
for (ix2 = 1; ix2 < s2.length(); ix2++) {
ch2 = s2.charAt(ix2);
above = ix2 + 1; // virtual first row
int smallest = s1len * 2; // used to implement cutoff
for (int ix1 = 1; ix1 <= s1len; ix1++) {
int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;
// above: above
// aboveleft: column[ix1 - 1]
// left: column[ix1]
int value = Math.min(Math.min(above, column[ix1 - 1]), column[ix1]) +
cost;
column[ix1 - 1] = above; // write previous
above = value; // keep current
smallest = Math.min(smallest, value);
}
column[s1len] = above;
// check if we can stop because we'll be going over the max distance
if (smallest > maxdist)
return smallest;
}
// ok, we're done
return above;
}
|
java
|
public static int compactDistance(String s1, String s2) {
if (s1.length() == 0)
return s2.length();
if (s2.length() == 0)
return s1.length();
// the maximum edit distance there is any point in reporting.
int maxdist = Math.min(s1.length(), s2.length()) / 2;
// we allocate just one column instead of the entire matrix, in
// order to save space. this also enables us to implement the
// algorithm somewhat faster. the first cell is always the
// virtual first row.
int s1len = s1.length();
int[] column = new int[s1len + 1];
// first we need to fill in the initial column. we use a separate
// loop for this, because in this case our basis for comparison is
// not the previous column, but a virtual first column.
int ix2 = 0;
char ch2 = s2.charAt(ix2);
column[0] = 1; // virtual first row
for (int ix1 = 1; ix1 <= s1len; ix1++) {
int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;
// Lowest of three: above (column[ix1 - 1]), aboveleft: ix1 - 1,
// left: ix1. Latter cannot possibly be lowest, so is
// ignored.
column[ix1] = Math.min(column[ix1 - 1], ix1 - 1) + cost;
}
// okay, now we have an initialized first column, and we can
// compute the rest of the matrix.
int above = 0;
for (ix2 = 1; ix2 < s2.length(); ix2++) {
ch2 = s2.charAt(ix2);
above = ix2 + 1; // virtual first row
int smallest = s1len * 2; // used to implement cutoff
for (int ix1 = 1; ix1 <= s1len; ix1++) {
int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;
// above: above
// aboveleft: column[ix1 - 1]
// left: column[ix1]
int value = Math.min(Math.min(above, column[ix1 - 1]), column[ix1]) +
cost;
column[ix1 - 1] = above; // write previous
above = value; // keep current
smallest = Math.min(smallest, value);
}
column[s1len] = above;
// check if we can stop because we'll be going over the max distance
if (smallest > maxdist)
return smallest;
}
// ok, we're done
return above;
}
|
[
"public",
"static",
"int",
"compactDistance",
"(",
"String",
"s1",
",",
"String",
"s2",
")",
"{",
"if",
"(",
"s1",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"s2",
".",
"length",
"(",
")",
";",
"if",
"(",
"s2",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"s1",
".",
"length",
"(",
")",
";",
"// the maximum edit distance there is any point in reporting.",
"int",
"maxdist",
"=",
"Math",
".",
"min",
"(",
"s1",
".",
"length",
"(",
")",
",",
"s2",
".",
"length",
"(",
")",
")",
"/",
"2",
";",
"// we allocate just one column instead of the entire matrix, in",
"// order to save space. this also enables us to implement the",
"// algorithm somewhat faster. the first cell is always the",
"// virtual first row.",
"int",
"s1len",
"=",
"s1",
".",
"length",
"(",
")",
";",
"int",
"[",
"]",
"column",
"=",
"new",
"int",
"[",
"s1len",
"+",
"1",
"]",
";",
"// first we need to fill in the initial column. we use a separate",
"// loop for this, because in this case our basis for comparison is",
"// not the previous column, but a virtual first column.",
"int",
"ix2",
"=",
"0",
";",
"char",
"ch2",
"=",
"s2",
".",
"charAt",
"(",
"ix2",
")",
";",
"column",
"[",
"0",
"]",
"=",
"1",
";",
"// virtual first row",
"for",
"(",
"int",
"ix1",
"=",
"1",
";",
"ix1",
"<=",
"s1len",
";",
"ix1",
"++",
")",
"{",
"int",
"cost",
"=",
"s1",
".",
"charAt",
"(",
"ix1",
"-",
"1",
")",
"==",
"ch2",
"?",
"0",
":",
"1",
";",
"// Lowest of three: above (column[ix1 - 1]), aboveleft: ix1 - 1,",
"// left: ix1. Latter cannot possibly be lowest, so is",
"// ignored.",
"column",
"[",
"ix1",
"]",
"=",
"Math",
".",
"min",
"(",
"column",
"[",
"ix1",
"-",
"1",
"]",
",",
"ix1",
"-",
"1",
")",
"+",
"cost",
";",
"}",
"// okay, now we have an initialized first column, and we can",
"// compute the rest of the matrix.",
"int",
"above",
"=",
"0",
";",
"for",
"(",
"ix2",
"=",
"1",
";",
"ix2",
"<",
"s2",
".",
"length",
"(",
")",
";",
"ix2",
"++",
")",
"{",
"ch2",
"=",
"s2",
".",
"charAt",
"(",
"ix2",
")",
";",
"above",
"=",
"ix2",
"+",
"1",
";",
"// virtual first row",
"int",
"smallest",
"=",
"s1len",
"*",
"2",
";",
"// used to implement cutoff",
"for",
"(",
"int",
"ix1",
"=",
"1",
";",
"ix1",
"<=",
"s1len",
";",
"ix1",
"++",
")",
"{",
"int",
"cost",
"=",
"s1",
".",
"charAt",
"(",
"ix1",
"-",
"1",
")",
"==",
"ch2",
"?",
"0",
":",
"1",
";",
"// above: above",
"// aboveleft: column[ix1 - 1]",
"// left: column[ix1]",
"int",
"value",
"=",
"Math",
".",
"min",
"(",
"Math",
".",
"min",
"(",
"above",
",",
"column",
"[",
"ix1",
"-",
"1",
"]",
")",
",",
"column",
"[",
"ix1",
"]",
")",
"+",
"cost",
";",
"column",
"[",
"ix1",
"-",
"1",
"]",
"=",
"above",
";",
"// write previous",
"above",
"=",
"value",
";",
"// keep current",
"smallest",
"=",
"Math",
".",
"min",
"(",
"smallest",
",",
"value",
")",
";",
"}",
"column",
"[",
"s1len",
"]",
"=",
"above",
";",
"// check if we can stop because we'll be going over the max distance",
"if",
"(",
"smallest",
">",
"maxdist",
")",
"return",
"smallest",
";",
"}",
"// ok, we're done",
"return",
"above",
";",
"}"
] |
Optimized version of the Wagner & Fischer algorithm that only
keeps a single column in the matrix in memory at a time. It
implements the simple cutoff, but otherwise computes the entire
matrix. It is roughly twice as fast as the original function.
|
[
"Optimized",
"version",
"of",
"the",
"Wagner",
"&",
"Fischer",
"algorithm",
"that",
"only",
"keeps",
"a",
"single",
"column",
"in",
"the",
"matrix",
"in",
"memory",
"at",
"a",
"time",
".",
"It",
"implements",
"the",
"simple",
"cutoff",
"but",
"otherwise",
"computes",
"the",
"entire",
"matrix",
".",
"It",
"is",
"roughly",
"twice",
"as",
"fast",
"as",
"the",
"original",
"function",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/comparators/Levenshtein.java#L228-L288
|
158,051
|
larsga/Duke
|
duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java
|
LuceneDatabase.commit
|
public void commit() {
if (directory == null)
return;
try {
if (reader != null)
reader.close();
// it turns out that IndexWriter.optimize actually slows
// searches down, because it invalidates the cache. therefore
// not calling it any more.
// http://www.searchworkings.org/blog/-/blogs/uwe-says%3A-is-your-reader-atomic
// iwriter.optimize();
iwriter.commit();
openSearchers();
} catch (IOException e) {
throw new DukeException(e);
}
}
|
java
|
public void commit() {
if (directory == null)
return;
try {
if (reader != null)
reader.close();
// it turns out that IndexWriter.optimize actually slows
// searches down, because it invalidates the cache. therefore
// not calling it any more.
// http://www.searchworkings.org/blog/-/blogs/uwe-says%3A-is-your-reader-atomic
// iwriter.optimize();
iwriter.commit();
openSearchers();
} catch (IOException e) {
throw new DukeException(e);
}
}
|
[
"public",
"void",
"commit",
"(",
")",
"{",
"if",
"(",
"directory",
"==",
"null",
")",
"return",
";",
"try",
"{",
"if",
"(",
"reader",
"!=",
"null",
")",
"reader",
".",
"close",
"(",
")",
";",
"// it turns out that IndexWriter.optimize actually slows",
"// searches down, because it invalidates the cache. therefore",
"// not calling it any more.",
"// http://www.searchworkings.org/blog/-/blogs/uwe-says%3A-is-your-reader-atomic",
"// iwriter.optimize();",
"iwriter",
".",
"commit",
"(",
")",
";",
"openSearchers",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"DukeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Flushes all changes to disk.
|
[
"Flushes",
"all",
"changes",
"to",
"disk",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java#L218-L237
|
158,052
|
larsga/Duke
|
duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java
|
LuceneDatabase.findRecordById
|
public Record findRecordById(String id) {
if (directory == null)
init();
Property idprop = config.getIdentityProperties().iterator().next();
for (Record r : lookup(idprop, id))
if (r.getValue(idprop.getName()).equals(id))
return r;
return null; // not found
}
|
java
|
public Record findRecordById(String id) {
if (directory == null)
init();
Property idprop = config.getIdentityProperties().iterator().next();
for (Record r : lookup(idprop, id))
if (r.getValue(idprop.getName()).equals(id))
return r;
return null; // not found
}
|
[
"public",
"Record",
"findRecordById",
"(",
"String",
"id",
")",
"{",
"if",
"(",
"directory",
"==",
"null",
")",
"init",
"(",
")",
";",
"Property",
"idprop",
"=",
"config",
".",
"getIdentityProperties",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
";",
"for",
"(",
"Record",
"r",
":",
"lookup",
"(",
"idprop",
",",
"id",
")",
")",
"if",
"(",
"r",
".",
"getValue",
"(",
"idprop",
".",
"getName",
"(",
")",
")",
".",
"equals",
"(",
"id",
")",
")",
"return",
"r",
";",
"return",
"null",
";",
"// not found",
"}"
] |
Look up record by identity.
|
[
"Look",
"up",
"record",
"by",
"identity",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-lucene/src/main/java/no/priv/garshol/duke/databases/LuceneDatabase.java#L242-L252
|
158,053
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/cleaners/PhoneNumberCleaner.java
|
PhoneNumberCleaner.clean
|
public String clean(String value) {
String orig = value;
// check if there's a + before the first digit
boolean initialplus = findPlus(value);
// remove everything but digits
value = sub.clean(value);
if (value == null)
return null;
// check for initial '00'
boolean zerozero = !initialplus && value.startsWith("00");
if (zerozero)
value = value.substring(2); // strip off the zeros
// look for country code
CountryCode ccode = findCountryCode(value);
if (ccode == null) {
// no country code, let's do what little we can
if (initialplus || zerozero)
return orig; // this number is messed up. dare not touch
return value;
} else {
value = value.substring(ccode.getPrefix().length()); // strip off ccode
if (ccode.getStripZero() && value.startsWith("0"))
value = value.substring(1); // strip the zero
if (ccode.isRightFormat(value))
return "+" + ccode.getPrefix() + " " + value;
else
return orig; // don't dare touch this
}
}
|
java
|
public String clean(String value) {
String orig = value;
// check if there's a + before the first digit
boolean initialplus = findPlus(value);
// remove everything but digits
value = sub.clean(value);
if (value == null)
return null;
// check for initial '00'
boolean zerozero = !initialplus && value.startsWith("00");
if (zerozero)
value = value.substring(2); // strip off the zeros
// look for country code
CountryCode ccode = findCountryCode(value);
if (ccode == null) {
// no country code, let's do what little we can
if (initialplus || zerozero)
return orig; // this number is messed up. dare not touch
return value;
} else {
value = value.substring(ccode.getPrefix().length()); // strip off ccode
if (ccode.getStripZero() && value.startsWith("0"))
value = value.substring(1); // strip the zero
if (ccode.isRightFormat(value))
return "+" + ccode.getPrefix() + " " + value;
else
return orig; // don't dare touch this
}
}
|
[
"public",
"String",
"clean",
"(",
"String",
"value",
")",
"{",
"String",
"orig",
"=",
"value",
";",
"// check if there's a + before the first digit",
"boolean",
"initialplus",
"=",
"findPlus",
"(",
"value",
")",
";",
"// remove everything but digits",
"value",
"=",
"sub",
".",
"clean",
"(",
"value",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"return",
"null",
";",
"// check for initial '00'",
"boolean",
"zerozero",
"=",
"!",
"initialplus",
"&&",
"value",
".",
"startsWith",
"(",
"\"00\"",
")",
";",
"if",
"(",
"zerozero",
")",
"value",
"=",
"value",
".",
"substring",
"(",
"2",
")",
";",
"// strip off the zeros",
"// look for country code",
"CountryCode",
"ccode",
"=",
"findCountryCode",
"(",
"value",
")",
";",
"if",
"(",
"ccode",
"==",
"null",
")",
"{",
"// no country code, let's do what little we can",
"if",
"(",
"initialplus",
"||",
"zerozero",
")",
"return",
"orig",
";",
"// this number is messed up. dare not touch",
"return",
"value",
";",
"}",
"else",
"{",
"value",
"=",
"value",
".",
"substring",
"(",
"ccode",
".",
"getPrefix",
"(",
")",
".",
"length",
"(",
")",
")",
";",
"// strip off ccode",
"if",
"(",
"ccode",
".",
"getStripZero",
"(",
")",
"&&",
"value",
".",
"startsWith",
"(",
"\"0\"",
")",
")",
"value",
"=",
"value",
".",
"substring",
"(",
"1",
")",
";",
"// strip the zero",
"if",
"(",
"ccode",
".",
"isRightFormat",
"(",
"value",
")",
")",
"return",
"\"+\"",
"+",
"ccode",
".",
"getPrefix",
"(",
")",
"+",
"\" \"",
"+",
"value",
";",
"else",
"return",
"orig",
";",
"// don't dare touch this",
"}",
"}"
] |
look for zero after country code, and remove if present
|
[
"look",
"for",
"zero",
"after",
"country",
"code",
"and",
"remove",
"if",
"present"
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/cleaners/PhoneNumberCleaner.java#L32-L66
|
158,054
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/Link.java
|
Link.overrides
|
public boolean overrides(Link other) {
if (other.getStatus() == LinkStatus.ASSERTED &&
status != LinkStatus.ASSERTED)
return false;
else if (status == LinkStatus.ASSERTED &&
other.getStatus() != LinkStatus.ASSERTED)
return true;
// the two links are from equivalent sources of information, so we
// believe the most recent
return timestamp > other.getTimestamp();
}
|
java
|
public boolean overrides(Link other) {
if (other.getStatus() == LinkStatus.ASSERTED &&
status != LinkStatus.ASSERTED)
return false;
else if (status == LinkStatus.ASSERTED &&
other.getStatus() != LinkStatus.ASSERTED)
return true;
// the two links are from equivalent sources of information, so we
// believe the most recent
return timestamp > other.getTimestamp();
}
|
[
"public",
"boolean",
"overrides",
"(",
"Link",
"other",
")",
"{",
"if",
"(",
"other",
".",
"getStatus",
"(",
")",
"==",
"LinkStatus",
".",
"ASSERTED",
"&&",
"status",
"!=",
"LinkStatus",
".",
"ASSERTED",
")",
"return",
"false",
";",
"else",
"if",
"(",
"status",
"==",
"LinkStatus",
".",
"ASSERTED",
"&&",
"other",
".",
"getStatus",
"(",
")",
"!=",
"LinkStatus",
".",
"ASSERTED",
")",
"return",
"true",
";",
"// the two links are from equivalent sources of information, so we",
"// believe the most recent",
"return",
"timestamp",
">",
"other",
".",
"getTimestamp",
"(",
")",
";",
"}"
] |
Returns true if the information in this link should take
precedence over the information in the other link.
|
[
"Returns",
"true",
"if",
"the",
"information",
"in",
"this",
"link",
"should",
"take",
"precedence",
"over",
"the",
"information",
"in",
"the",
"other",
"link",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/Link.java#L92-L104
|
158,055
|
larsga/Duke
|
duke-server/src/main/java/no/priv/garshol/duke/server/DukeController.java
|
DukeController.process
|
public void process() {
// are we ready to process yet, or have we had an error, and are
// waiting a bit longer in the hope that it will resolve itself?
if (error_skips > 0) {
error_skips--;
return;
}
try {
if (logger != null)
logger.debug("Starting processing");
status = "Processing";
lastCheck = System.currentTimeMillis();
// FIXME: how to break off processing if we don't want to keep going?
processor.deduplicate(batch_size);
status = "Sleeping";
if (logger != null)
logger.debug("Finished processing");
} catch (Throwable e) {
status = "Thread blocked on error: " + e;
if (logger != null)
logger.error("Error in processing; waiting", e);
error_skips = error_factor;
}
}
|
java
|
public void process() {
// are we ready to process yet, or have we had an error, and are
// waiting a bit longer in the hope that it will resolve itself?
if (error_skips > 0) {
error_skips--;
return;
}
try {
if (logger != null)
logger.debug("Starting processing");
status = "Processing";
lastCheck = System.currentTimeMillis();
// FIXME: how to break off processing if we don't want to keep going?
processor.deduplicate(batch_size);
status = "Sleeping";
if (logger != null)
logger.debug("Finished processing");
} catch (Throwable e) {
status = "Thread blocked on error: " + e;
if (logger != null)
logger.error("Error in processing; waiting", e);
error_skips = error_factor;
}
}
|
[
"public",
"void",
"process",
"(",
")",
"{",
"// are we ready to process yet, or have we had an error, and are",
"// waiting a bit longer in the hope that it will resolve itself?",
"if",
"(",
"error_skips",
">",
"0",
")",
"{",
"error_skips",
"--",
";",
"return",
";",
"}",
"try",
"{",
"if",
"(",
"logger",
"!=",
"null",
")",
"logger",
".",
"debug",
"(",
"\"Starting processing\"",
")",
";",
"status",
"=",
"\"Processing\"",
";",
"lastCheck",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"// FIXME: how to break off processing if we don't want to keep going?",
"processor",
".",
"deduplicate",
"(",
"batch_size",
")",
";",
"status",
"=",
"\"Sleeping\"",
";",
"if",
"(",
"logger",
"!=",
"null",
")",
"logger",
".",
"debug",
"(",
"\"Finished processing\"",
")",
";",
"}",
"catch",
"(",
"Throwable",
"e",
")",
"{",
"status",
"=",
"\"Thread blocked on error: \"",
"+",
"e",
";",
"if",
"(",
"logger",
"!=",
"null",
")",
"logger",
".",
"error",
"(",
"\"Error in processing; waiting\"",
",",
"e",
")",
";",
"error_skips",
"=",
"error_factor",
";",
"}",
"}"
] |
Runs the record linkage process.
|
[
"Runs",
"the",
"record",
"linkage",
"process",
"."
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-server/src/main/java/no/priv/garshol/duke/server/DukeController.java#L98-L124
|
158,056
|
larsga/Duke
|
duke-server/src/main/java/no/priv/garshol/duke/server/DukeController.java
|
DukeController.reportError
|
void reportError(Throwable throwable) {
if (logger != null)
logger.error("Timer reported error", throwable);
status = "Thread blocked on error: " + throwable;
error_skips = error_factor;
}
|
java
|
void reportError(Throwable throwable) {
if (logger != null)
logger.error("Timer reported error", throwable);
status = "Thread blocked on error: " + throwable;
error_skips = error_factor;
}
|
[
"void",
"reportError",
"(",
"Throwable",
"throwable",
")",
"{",
"if",
"(",
"logger",
"!=",
"null",
")",
"logger",
".",
"error",
"(",
"\"Timer reported error\"",
",",
"throwable",
")",
";",
"status",
"=",
"\"Thread blocked on error: \"",
"+",
"throwable",
";",
"error_skips",
"=",
"error_factor",
";",
"}"
] |
called by timer thread
|
[
"called",
"by",
"timer",
"thread"
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-server/src/main/java/no/priv/garshol/duke/server/DukeController.java#L155-L160
|
158,057
|
larsga/Duke
|
duke-core/src/main/java/no/priv/garshol/duke/utils/ObjectUtils.java
|
ObjectUtils.makePropertyName
|
public static String makePropertyName(String name) {
char[] buf = new char[name.length() + 3];
int pos = 0;
buf[pos++] = 's';
buf[pos++] = 'e';
buf[pos++] = 't';
for (int ix = 0; ix < name.length(); ix++) {
char ch = name.charAt(ix);
if (ix == 0)
ch = Character.toUpperCase(ch);
else if (ch == '-') {
ix++;
if (ix == name.length())
break;
ch = Character.toUpperCase(name.charAt(ix));
}
buf[pos++] = ch;
}
return new String(buf, 0, pos);
}
|
java
|
public static String makePropertyName(String name) {
char[] buf = new char[name.length() + 3];
int pos = 0;
buf[pos++] = 's';
buf[pos++] = 'e';
buf[pos++] = 't';
for (int ix = 0; ix < name.length(); ix++) {
char ch = name.charAt(ix);
if (ix == 0)
ch = Character.toUpperCase(ch);
else if (ch == '-') {
ix++;
if (ix == name.length())
break;
ch = Character.toUpperCase(name.charAt(ix));
}
buf[pos++] = ch;
}
return new String(buf, 0, pos);
}
|
[
"public",
"static",
"String",
"makePropertyName",
"(",
"String",
"name",
")",
"{",
"char",
"[",
"]",
"buf",
"=",
"new",
"char",
"[",
"name",
".",
"length",
"(",
")",
"+",
"3",
"]",
";",
"int",
"pos",
"=",
"0",
";",
"buf",
"[",
"pos",
"++",
"]",
"=",
"'",
"'",
";",
"buf",
"[",
"pos",
"++",
"]",
"=",
"'",
"'",
";",
"buf",
"[",
"pos",
"++",
"]",
"=",
"'",
"'",
";",
"for",
"(",
"int",
"ix",
"=",
"0",
";",
"ix",
"<",
"name",
".",
"length",
"(",
")",
";",
"ix",
"++",
")",
"{",
"char",
"ch",
"=",
"name",
".",
"charAt",
"(",
"ix",
")",
";",
"if",
"(",
"ix",
"==",
"0",
")",
"ch",
"=",
"Character",
".",
"toUpperCase",
"(",
"ch",
")",
";",
"else",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"ix",
"++",
";",
"if",
"(",
"ix",
"==",
"name",
".",
"length",
"(",
")",
")",
"break",
";",
"ch",
"=",
"Character",
".",
"toUpperCase",
"(",
"name",
".",
"charAt",
"(",
"ix",
")",
")",
";",
"}",
"buf",
"[",
"pos",
"++",
"]",
"=",
"ch",
";",
"}",
"return",
"new",
"String",
"(",
"buf",
",",
"0",
",",
"pos",
")",
";",
"}"
] |
public because it's used by other packages that use Duke
|
[
"public",
"because",
"it",
"s",
"used",
"by",
"other",
"packages",
"that",
"use",
"Duke"
] |
6263f9c6e984c26362a76241c7c7ea3bb4469bac
|
https://github.com/larsga/Duke/blob/6263f9c6e984c26362a76241c7c7ea3bb4469bac/duke-core/src/main/java/no/priv/garshol/duke/utils/ObjectUtils.java#L77-L99
|
158,058
|
andremion/Louvre
|
louvre/src/main/java/com/andremion/louvre/util/transition/MediaSharedElementCallback.java
|
MediaSharedElementCallback.mapObsoleteElements
|
@NonNull
private List<String> mapObsoleteElements(List<String> names) {
List<String> elementsToRemove = new ArrayList<>(names.size());
for (String name : names) {
if (name.startsWith("android")) continue;
elementsToRemove.add(name);
}
return elementsToRemove;
}
|
java
|
@NonNull
private List<String> mapObsoleteElements(List<String> names) {
List<String> elementsToRemove = new ArrayList<>(names.size());
for (String name : names) {
if (name.startsWith("android")) continue;
elementsToRemove.add(name);
}
return elementsToRemove;
}
|
[
"@",
"NonNull",
"private",
"List",
"<",
"String",
">",
"mapObsoleteElements",
"(",
"List",
"<",
"String",
">",
"names",
")",
"{",
"List",
"<",
"String",
">",
"elementsToRemove",
"=",
"new",
"ArrayList",
"<>",
"(",
"names",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"String",
"name",
":",
"names",
")",
"{",
"if",
"(",
"name",
".",
"startsWith",
"(",
"\"android\"",
")",
")",
"continue",
";",
"elementsToRemove",
".",
"add",
"(",
"name",
")",
";",
"}",
"return",
"elementsToRemove",
";",
"}"
] |
Maps all views that don't start with "android" namespace.
@param names All shared element names.
@return The obsolete shared element names.
|
[
"Maps",
"all",
"views",
"that",
"don",
"t",
"start",
"with",
"android",
"namespace",
"."
] |
9aeddc88f2e51b8f0f757c290ff26904ae8d6af2
|
https://github.com/andremion/Louvre/blob/9aeddc88f2e51b8f0f757c290ff26904ae8d6af2/louvre/src/main/java/com/andremion/louvre/util/transition/MediaSharedElementCallback.java#L72-L80
|
158,059
|
andremion/Louvre
|
louvre/src/main/java/com/andremion/louvre/util/transition/MediaSharedElementCallback.java
|
MediaSharedElementCallback.removeObsoleteElements
|
private void removeObsoleteElements(List<String> names,
Map<String, View> sharedElements,
List<String> elementsToRemove) {
if (elementsToRemove.size() > 0) {
names.removeAll(elementsToRemove);
for (String elementToRemove : elementsToRemove) {
sharedElements.remove(elementToRemove);
}
}
}
|
java
|
private void removeObsoleteElements(List<String> names,
Map<String, View> sharedElements,
List<String> elementsToRemove) {
if (elementsToRemove.size() > 0) {
names.removeAll(elementsToRemove);
for (String elementToRemove : elementsToRemove) {
sharedElements.remove(elementToRemove);
}
}
}
|
[
"private",
"void",
"removeObsoleteElements",
"(",
"List",
"<",
"String",
">",
"names",
",",
"Map",
"<",
"String",
",",
"View",
">",
"sharedElements",
",",
"List",
"<",
"String",
">",
"elementsToRemove",
")",
"{",
"if",
"(",
"elementsToRemove",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"names",
".",
"removeAll",
"(",
"elementsToRemove",
")",
";",
"for",
"(",
"String",
"elementToRemove",
":",
"elementsToRemove",
")",
"{",
"sharedElements",
".",
"remove",
"(",
"elementToRemove",
")",
";",
"}",
"}",
"}"
] |
Removes obsolete elements from names and shared elements.
@param names Shared element names.
@param sharedElements Shared elements.
@param elementsToRemove The elements that should be removed.
|
[
"Removes",
"obsolete",
"elements",
"from",
"names",
"and",
"shared",
"elements",
"."
] |
9aeddc88f2e51b8f0f757c290ff26904ae8d6af2
|
https://github.com/andremion/Louvre/blob/9aeddc88f2e51b8f0f757c290ff26904ae8d6af2/louvre/src/main/java/com/andremion/louvre/util/transition/MediaSharedElementCallback.java#L89-L98
|
158,060
|
andremion/Louvre
|
louvre/src/main/java/com/andremion/louvre/home/GalleryAdapter.java
|
GalleryAdapter.onBindViewHolder
|
@Override
public void onBindViewHolder(GalleryAdapter.ViewHolder holder, int position, List<Object> payloads) {
if (payloads.isEmpty()) { // If doesn't have any payload then bind the fully item
super.onBindViewHolder(holder, position, payloads);
} else {
for (Object payload : payloads) {
boolean selected = isSelected(position);
if (SELECTION_PAYLOAD.equals(payload)) {
if (VIEW_TYPE_MEDIA == getItemViewType(position)) {
MediaViewHolder viewHolder = (MediaViewHolder) holder;
viewHolder.mCheckView.setChecked(selected);
if (selected) {
AnimationHelper.scaleView(holder.mImageView, SELECTED_SCALE);
} else {
AnimationHelper.scaleView(holder.mImageView, UNSELECTED_SCALE);
}
}
}
}
}
}
|
java
|
@Override
public void onBindViewHolder(GalleryAdapter.ViewHolder holder, int position, List<Object> payloads) {
if (payloads.isEmpty()) { // If doesn't have any payload then bind the fully item
super.onBindViewHolder(holder, position, payloads);
} else {
for (Object payload : payloads) {
boolean selected = isSelected(position);
if (SELECTION_PAYLOAD.equals(payload)) {
if (VIEW_TYPE_MEDIA == getItemViewType(position)) {
MediaViewHolder viewHolder = (MediaViewHolder) holder;
viewHolder.mCheckView.setChecked(selected);
if (selected) {
AnimationHelper.scaleView(holder.mImageView, SELECTED_SCALE);
} else {
AnimationHelper.scaleView(holder.mImageView, UNSELECTED_SCALE);
}
}
}
}
}
}
|
[
"@",
"Override",
"public",
"void",
"onBindViewHolder",
"(",
"GalleryAdapter",
".",
"ViewHolder",
"holder",
",",
"int",
"position",
",",
"List",
"<",
"Object",
">",
"payloads",
")",
"{",
"if",
"(",
"payloads",
".",
"isEmpty",
"(",
")",
")",
"{",
"// If doesn't have any payload then bind the fully item",
"super",
".",
"onBindViewHolder",
"(",
"holder",
",",
"position",
",",
"payloads",
")",
";",
"}",
"else",
"{",
"for",
"(",
"Object",
"payload",
":",
"payloads",
")",
"{",
"boolean",
"selected",
"=",
"isSelected",
"(",
"position",
")",
";",
"if",
"(",
"SELECTION_PAYLOAD",
".",
"equals",
"(",
"payload",
")",
")",
"{",
"if",
"(",
"VIEW_TYPE_MEDIA",
"==",
"getItemViewType",
"(",
"position",
")",
")",
"{",
"MediaViewHolder",
"viewHolder",
"=",
"(",
"MediaViewHolder",
")",
"holder",
";",
"viewHolder",
".",
"mCheckView",
".",
"setChecked",
"(",
"selected",
")",
";",
"if",
"(",
"selected",
")",
"{",
"AnimationHelper",
".",
"scaleView",
"(",
"holder",
".",
"mImageView",
",",
"SELECTED_SCALE",
")",
";",
"}",
"else",
"{",
"AnimationHelper",
".",
"scaleView",
"(",
"holder",
".",
"mImageView",
",",
"UNSELECTED_SCALE",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] |
Binding view holder with payloads is used to handle partial changes in item.
|
[
"Binding",
"view",
"holder",
"with",
"payloads",
"is",
"used",
"to",
"handle",
"partial",
"changes",
"in",
"item",
"."
] |
9aeddc88f2e51b8f0f757c290ff26904ae8d6af2
|
https://github.com/andremion/Louvre/blob/9aeddc88f2e51b8f0f757c290ff26904ae8d6af2/louvre/src/main/java/com/andremion/louvre/home/GalleryAdapter.java#L190-L210
|
158,061
|
airlift/slice
|
src/main/java/io/airlift/slice/UnsafeSliceFactory.java
|
UnsafeSliceFactory.newSlice
|
public Slice newSlice(long address, int size)
{
if (address <= 0) {
throw new IllegalArgumentException("Invalid address: " + address);
}
if (size == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(null, address, size, 0, null);
}
|
java
|
public Slice newSlice(long address, int size)
{
if (address <= 0) {
throw new IllegalArgumentException("Invalid address: " + address);
}
if (size == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(null, address, size, 0, null);
}
|
[
"public",
"Slice",
"newSlice",
"(",
"long",
"address",
",",
"int",
"size",
")",
"{",
"if",
"(",
"address",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid address: \"",
"+",
"address",
")",
";",
"}",
"if",
"(",
"size",
"==",
"0",
")",
"{",
"return",
"Slices",
".",
"EMPTY_SLICE",
";",
"}",
"return",
"new",
"Slice",
"(",
"null",
",",
"address",
",",
"size",
",",
"0",
",",
"null",
")",
";",
"}"
] |
Creates a slice for directly a raw memory address. This is
inherently unsafe as it may be used to access arbitrary memory.
@param address the raw memory address base
@param size the size of the slice
@return the unsafe slice
|
[
"Creates",
"a",
"slice",
"for",
"directly",
"a",
"raw",
"memory",
"address",
".",
"This",
"is",
"inherently",
"unsafe",
"as",
"it",
"may",
"be",
"used",
"to",
"access",
"arbitrary",
"memory",
"."
] |
7166cb0319e3655f8ba15f5a7ccf3d2f721c1242
|
https://github.com/airlift/slice/blob/7166cb0319e3655f8ba15f5a7ccf3d2f721c1242/src/main/java/io/airlift/slice/UnsafeSliceFactory.java#L64-L73
|
158,062
|
airlift/slice
|
src/main/java/io/airlift/slice/UnsafeSliceFactory.java
|
UnsafeSliceFactory.newSlice
|
public Slice newSlice(long address, int size, Object reference)
{
if (address <= 0) {
throw new IllegalArgumentException("Invalid address: " + address);
}
if (reference == null) {
throw new NullPointerException("Object reference is null");
}
if (size == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(null, address, size, size, reference);
}
|
java
|
public Slice newSlice(long address, int size, Object reference)
{
if (address <= 0) {
throw new IllegalArgumentException("Invalid address: " + address);
}
if (reference == null) {
throw new NullPointerException("Object reference is null");
}
if (size == 0) {
return Slices.EMPTY_SLICE;
}
return new Slice(null, address, size, size, reference);
}
|
[
"public",
"Slice",
"newSlice",
"(",
"long",
"address",
",",
"int",
"size",
",",
"Object",
"reference",
")",
"{",
"if",
"(",
"address",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid address: \"",
"+",
"address",
")",
";",
"}",
"if",
"(",
"reference",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Object reference is null\"",
")",
";",
"}",
"if",
"(",
"size",
"==",
"0",
")",
"{",
"return",
"Slices",
".",
"EMPTY_SLICE",
";",
"}",
"return",
"new",
"Slice",
"(",
"null",
",",
"address",
",",
"size",
",",
"size",
",",
"reference",
")",
";",
"}"
] |
Creates a slice for directly a raw memory address. This is
inherently unsafe as it may be used to access arbitrary memory.
The slice will hold the specified object reference to prevent the
garbage collector from freeing it while it is in use by the slice.
@param address the raw memory address base
@param size the size of the slice
@param reference the object reference
@return the unsafe slice
|
[
"Creates",
"a",
"slice",
"for",
"directly",
"a",
"raw",
"memory",
"address",
".",
"This",
"is",
"inherently",
"unsafe",
"as",
"it",
"may",
"be",
"used",
"to",
"access",
"arbitrary",
"memory",
".",
"The",
"slice",
"will",
"hold",
"the",
"specified",
"object",
"reference",
"to",
"prevent",
"the",
"garbage",
"collector",
"from",
"freeing",
"it",
"while",
"it",
"is",
"in",
"use",
"by",
"the",
"slice",
"."
] |
7166cb0319e3655f8ba15f5a7ccf3d2f721c1242
|
https://github.com/airlift/slice/blob/7166cb0319e3655f8ba15f5a7ccf3d2f721c1242/src/main/java/io/airlift/slice/UnsafeSliceFactory.java#L86-L98
|
158,063
|
airlift/slice
|
src/main/java/io/airlift/slice/Murmur3Hash32.java
|
Murmur3Hash32.hash
|
public static int hash(int input)
{
int k1 = mixK1(input);
int h1 = mixH1(DEFAULT_SEED, k1);
return fmix(h1, SizeOf.SIZE_OF_INT);
}
|
java
|
public static int hash(int input)
{
int k1 = mixK1(input);
int h1 = mixH1(DEFAULT_SEED, k1);
return fmix(h1, SizeOf.SIZE_OF_INT);
}
|
[
"public",
"static",
"int",
"hash",
"(",
"int",
"input",
")",
"{",
"int",
"k1",
"=",
"mixK1",
"(",
"input",
")",
";",
"int",
"h1",
"=",
"mixH1",
"(",
"DEFAULT_SEED",
",",
"k1",
")",
";",
"return",
"fmix",
"(",
"h1",
",",
"SizeOf",
".",
"SIZE_OF_INT",
")",
";",
"}"
] |
Special-purpose version for hashing a single int value. Value is treated as little-endian
|
[
"Special",
"-",
"purpose",
"version",
"for",
"hashing",
"a",
"single",
"int",
"value",
".",
"Value",
"is",
"treated",
"as",
"little",
"-",
"endian"
] |
7166cb0319e3655f8ba15f5a7ccf3d2f721c1242
|
https://github.com/airlift/slice/blob/7166cb0319e3655f8ba15f5a7ccf3d2f721c1242/src/main/java/io/airlift/slice/Murmur3Hash32.java#L70-L76
|
158,064
|
airlift/slice
|
src/main/java/io/airlift/slice/SliceUtf8.java
|
SliceUtf8.isAscii
|
public static boolean isAscii(Slice utf8)
{
int length = utf8.length();
int offset = 0;
// Length rounded to 8 bytes
int length8 = length & 0x7FFF_FFF8;
for (; offset < length8; offset += 8) {
if ((utf8.getLongUnchecked(offset) & TOP_MASK64) != 0) {
return false;
}
}
// Enough bytes left for 32 bits?
if (offset + 4 < length) {
if ((utf8.getIntUnchecked(offset) & TOP_MASK32) != 0) {
return false;
}
offset += 4;
}
// Do the rest one by one
for (; offset < length; offset++) {
if ((utf8.getByteUnchecked(offset) & 0x80) != 0) {
return false;
}
}
return true;
}
|
java
|
public static boolean isAscii(Slice utf8)
{
int length = utf8.length();
int offset = 0;
// Length rounded to 8 bytes
int length8 = length & 0x7FFF_FFF8;
for (; offset < length8; offset += 8) {
if ((utf8.getLongUnchecked(offset) & TOP_MASK64) != 0) {
return false;
}
}
// Enough bytes left for 32 bits?
if (offset + 4 < length) {
if ((utf8.getIntUnchecked(offset) & TOP_MASK32) != 0) {
return false;
}
offset += 4;
}
// Do the rest one by one
for (; offset < length; offset++) {
if ((utf8.getByteUnchecked(offset) & 0x80) != 0) {
return false;
}
}
return true;
}
|
[
"public",
"static",
"boolean",
"isAscii",
"(",
"Slice",
"utf8",
")",
"{",
"int",
"length",
"=",
"utf8",
".",
"length",
"(",
")",
";",
"int",
"offset",
"=",
"0",
";",
"// Length rounded to 8 bytes",
"int",
"length8",
"=",
"length",
"&",
"0x7FFF_FFF8",
";",
"for",
"(",
";",
"offset",
"<",
"length8",
";",
"offset",
"+=",
"8",
")",
"{",
"if",
"(",
"(",
"utf8",
".",
"getLongUnchecked",
"(",
"offset",
")",
"&",
"TOP_MASK64",
")",
"!=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Enough bytes left for 32 bits?",
"if",
"(",
"offset",
"+",
"4",
"<",
"length",
")",
"{",
"if",
"(",
"(",
"utf8",
".",
"getIntUnchecked",
"(",
"offset",
")",
"&",
"TOP_MASK32",
")",
"!=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"offset",
"+=",
"4",
";",
"}",
"// Do the rest one by one",
"for",
"(",
";",
"offset",
"<",
"length",
";",
"offset",
"++",
")",
"{",
"if",
"(",
"(",
"utf8",
".",
"getByteUnchecked",
"(",
"offset",
")",
"&",
"0x80",
")",
"!=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Does the slice contain only 7-bit ASCII characters.
|
[
"Does",
"the",
"slice",
"contain",
"only",
"7",
"-",
"bit",
"ASCII",
"characters",
"."
] |
7166cb0319e3655f8ba15f5a7ccf3d2f721c1242
|
https://github.com/airlift/slice/blob/7166cb0319e3655f8ba15f5a7ccf3d2f721c1242/src/main/java/io/airlift/slice/SliceUtf8.java#L67-L95
|
158,065
|
airlift/slice
|
src/main/java/io/airlift/slice/SliceUtf8.java
|
SliceUtf8.lengthOfCodePoint
|
public static int lengthOfCodePoint(int codePoint)
{
if (codePoint < 0) {
throw new InvalidCodePointException(codePoint);
}
if (codePoint < 0x80) {
// normal ASCII
// 0xxx_xxxx
return 1;
}
if (codePoint < 0x800) {
return 2;
}
if (codePoint < 0x1_0000) {
return 3;
}
if (codePoint < 0x11_0000) {
return 4;
}
// Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal
throw new InvalidCodePointException(codePoint);
}
|
java
|
public static int lengthOfCodePoint(int codePoint)
{
if (codePoint < 0) {
throw new InvalidCodePointException(codePoint);
}
if (codePoint < 0x80) {
// normal ASCII
// 0xxx_xxxx
return 1;
}
if (codePoint < 0x800) {
return 2;
}
if (codePoint < 0x1_0000) {
return 3;
}
if (codePoint < 0x11_0000) {
return 4;
}
// Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal
throw new InvalidCodePointException(codePoint);
}
|
[
"public",
"static",
"int",
"lengthOfCodePoint",
"(",
"int",
"codePoint",
")",
"{",
"if",
"(",
"codePoint",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidCodePointException",
"(",
"codePoint",
")",
";",
"}",
"if",
"(",
"codePoint",
"<",
"0x80",
")",
"{",
"// normal ASCII",
"// 0xxx_xxxx",
"return",
"1",
";",
"}",
"if",
"(",
"codePoint",
"<",
"0x800",
")",
"{",
"return",
"2",
";",
"}",
"if",
"(",
"codePoint",
"<",
"0x1_0000",
")",
"{",
"return",
"3",
";",
"}",
"if",
"(",
"codePoint",
"<",
"0x11_0000",
")",
"{",
"return",
"4",
";",
"}",
"// Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal",
"throw",
"new",
"InvalidCodePointException",
"(",
"codePoint",
")",
";",
"}"
] |
Gets the UTF-8 sequence length of the code point.
@throws InvalidCodePointException if code point is not within a valid range
|
[
"Gets",
"the",
"UTF",
"-",
"8",
"sequence",
"length",
"of",
"the",
"code",
"point",
"."
] |
7166cb0319e3655f8ba15f5a7ccf3d2f721c1242
|
https://github.com/airlift/slice/blob/7166cb0319e3655f8ba15f5a7ccf3d2f721c1242/src/main/java/io/airlift/slice/SliceUtf8.java#L906-L927
|
158,066
|
jblas-project/jblas
|
src/main/java/org/jblas/ComplexDouble.java
|
ComplexDouble.divi
|
public ComplexDouble divi(ComplexDouble c, ComplexDouble result) {
double d = c.r * c.r + c.i * c.i;
double newR = (r * c.r + i * c.i) / d;
double newI = (i * c.r - r * c.i) / d;
result.r = newR;
result.i = newI;
return result;
}
|
java
|
public ComplexDouble divi(ComplexDouble c, ComplexDouble result) {
double d = c.r * c.r + c.i * c.i;
double newR = (r * c.r + i * c.i) / d;
double newI = (i * c.r - r * c.i) / d;
result.r = newR;
result.i = newI;
return result;
}
|
[
"public",
"ComplexDouble",
"divi",
"(",
"ComplexDouble",
"c",
",",
"ComplexDouble",
"result",
")",
"{",
"double",
"d",
"=",
"c",
".",
"r",
"*",
"c",
".",
"r",
"+",
"c",
".",
"i",
"*",
"c",
".",
"i",
";",
"double",
"newR",
"=",
"(",
"r",
"*",
"c",
".",
"r",
"+",
"i",
"*",
"c",
".",
"i",
")",
"/",
"d",
";",
"double",
"newI",
"=",
"(",
"i",
"*",
"c",
".",
"r",
"-",
"r",
"*",
"c",
".",
"i",
")",
"/",
"d",
";",
"result",
".",
"r",
"=",
"newR",
";",
"result",
".",
"i",
"=",
"newI",
";",
"return",
"result",
";",
"}"
] |
Divide two complex numbers, in-place
@param c complex number to divide this by
@param result complex number to hold result
@return same as result
|
[
"Divide",
"two",
"complex",
"numbers",
"in",
"-",
"place"
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/ComplexDouble.java#L284-L291
|
158,067
|
jblas-project/jblas
|
src/main/java/org/jblas/util/Permutations.java
|
Permutations.randomPermutation
|
public static int[] randomPermutation(int size) {
Random r = new Random();
int[] result = new int[size];
for (int j = 0; j < size; j++) {
result[j] = j;
}
for (int j = size - 1; j > 0; j--) {
int k = r.nextInt(j);
int temp = result[j];
result[j] = result[k];
result[k] = temp;
}
return result;
}
|
java
|
public static int[] randomPermutation(int size) {
Random r = new Random();
int[] result = new int[size];
for (int j = 0; j < size; j++) {
result[j] = j;
}
for (int j = size - 1; j > 0; j--) {
int k = r.nextInt(j);
int temp = result[j];
result[j] = result[k];
result[k] = temp;
}
return result;
}
|
[
"public",
"static",
"int",
"[",
"]",
"randomPermutation",
"(",
"int",
"size",
")",
"{",
"Random",
"r",
"=",
"new",
"Random",
"(",
")",
";",
"int",
"[",
"]",
"result",
"=",
"new",
"int",
"[",
"size",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"size",
";",
"j",
"++",
")",
"{",
"result",
"[",
"j",
"]",
"=",
"j",
";",
"}",
"for",
"(",
"int",
"j",
"=",
"size",
"-",
"1",
";",
"j",
">",
"0",
";",
"j",
"--",
")",
"{",
"int",
"k",
"=",
"r",
".",
"nextInt",
"(",
"j",
")",
";",
"int",
"temp",
"=",
"result",
"[",
"j",
"]",
";",
"result",
"[",
"j",
"]",
"=",
"result",
"[",
"k",
"]",
";",
"result",
"[",
"k",
"]",
"=",
"temp",
";",
"}",
"return",
"result",
";",
"}"
] |
Create a random permutation of the numbers 0, ..., size - 1.
see Algorithm P, D.E. Knuth: The Art of Computer Programming, Vol. 2, p. 145
|
[
"Create",
"a",
"random",
"permutation",
"of",
"the",
"numbers",
"0",
"...",
"size",
"-",
"1",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/Permutations.java#L54-L70
|
158,068
|
jblas-project/jblas
|
src/main/java/org/jblas/util/Permutations.java
|
Permutations.randomSubset
|
public static int[] randomSubset(int k, int n) {
assert(0 < k && k <= n);
Random r = new Random();
int t = 0, m = 0;
int[] result = new int[k];
while (m < k) {
double u = r.nextDouble();
if ( (n - t) * u < k - m ) {
result[m] = t;
m++;
}
t++;
}
return result;
}
|
java
|
public static int[] randomSubset(int k, int n) {
assert(0 < k && k <= n);
Random r = new Random();
int t = 0, m = 0;
int[] result = new int[k];
while (m < k) {
double u = r.nextDouble();
if ( (n - t) * u < k - m ) {
result[m] = t;
m++;
}
t++;
}
return result;
}
|
[
"public",
"static",
"int",
"[",
"]",
"randomSubset",
"(",
"int",
"k",
",",
"int",
"n",
")",
"{",
"assert",
"(",
"0",
"<",
"k",
"&&",
"k",
"<=",
"n",
")",
";",
"Random",
"r",
"=",
"new",
"Random",
"(",
")",
";",
"int",
"t",
"=",
"0",
",",
"m",
"=",
"0",
";",
"int",
"[",
"]",
"result",
"=",
"new",
"int",
"[",
"k",
"]",
";",
"while",
"(",
"m",
"<",
"k",
")",
"{",
"double",
"u",
"=",
"r",
".",
"nextDouble",
"(",
")",
";",
"if",
"(",
"(",
"n",
"-",
"t",
")",
"*",
"u",
"<",
"k",
"-",
"m",
")",
"{",
"result",
"[",
"m",
"]",
"=",
"t",
";",
"m",
"++",
";",
"}",
"t",
"++",
";",
"}",
"return",
"result",
";",
"}"
] |
Get a random sample of k out of n elements.
See Algorithm S, D. E. Knuth, The Art of Computer Programming, Vol. 2, p.142.
|
[
"Get",
"a",
"random",
"sample",
"of",
"k",
"out",
"of",
"n",
"elements",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/Permutations.java#L77-L92
|
158,069
|
jblas-project/jblas
|
src/main/java/org/jblas/Singular.java
|
Singular.fullSVD
|
public static DoubleMatrix[] fullSVD(DoubleMatrix A) {
int m = A.rows;
int n = A.columns;
DoubleMatrix U = new DoubleMatrix(m, m);
DoubleMatrix S = new DoubleMatrix(min(m, n));
DoubleMatrix V = new DoubleMatrix(n, n);
int info = NativeBlas.dgesvd('A', 'A', m, n, A.dup().data, 0, m, S.data, 0, U.data, 0, m, V.data, 0, n);
if (info > 0) {
throw new LapackConvergenceException("GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
}
return new DoubleMatrix[]{U, S, V.transpose()};
}
|
java
|
public static DoubleMatrix[] fullSVD(DoubleMatrix A) {
int m = A.rows;
int n = A.columns;
DoubleMatrix U = new DoubleMatrix(m, m);
DoubleMatrix S = new DoubleMatrix(min(m, n));
DoubleMatrix V = new DoubleMatrix(n, n);
int info = NativeBlas.dgesvd('A', 'A', m, n, A.dup().data, 0, m, S.data, 0, U.data, 0, m, V.data, 0, n);
if (info > 0) {
throw new LapackConvergenceException("GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
}
return new DoubleMatrix[]{U, S, V.transpose()};
}
|
[
"public",
"static",
"DoubleMatrix",
"[",
"]",
"fullSVD",
"(",
"DoubleMatrix",
"A",
")",
"{",
"int",
"m",
"=",
"A",
".",
"rows",
";",
"int",
"n",
"=",
"A",
".",
"columns",
";",
"DoubleMatrix",
"U",
"=",
"new",
"DoubleMatrix",
"(",
"m",
",",
"m",
")",
";",
"DoubleMatrix",
"S",
"=",
"new",
"DoubleMatrix",
"(",
"min",
"(",
"m",
",",
"n",
")",
")",
";",
"DoubleMatrix",
"V",
"=",
"new",
"DoubleMatrix",
"(",
"n",
",",
"n",
")",
";",
"int",
"info",
"=",
"NativeBlas",
".",
"dgesvd",
"(",
"'",
"'",
",",
"'",
"'",
",",
"m",
",",
"n",
",",
"A",
".",
"dup",
"(",
")",
".",
"data",
",",
"0",
",",
"m",
",",
"S",
".",
"data",
",",
"0",
",",
"U",
".",
"data",
",",
"0",
",",
"m",
",",
"V",
".",
"data",
",",
"0",
",",
"n",
")",
";",
"if",
"(",
"info",
">",
"0",
")",
"{",
"throw",
"new",
"LapackConvergenceException",
"(",
"\"GESVD\"",
",",
"info",
"+",
"\" superdiagonals of an intermediate bidiagonal form failed to converge.\"",
")",
";",
"}",
"return",
"new",
"DoubleMatrix",
"[",
"]",
"{",
"U",
",",
"S",
",",
"V",
".",
"transpose",
"(",
")",
"}",
";",
"}"
] |
Compute a singular-value decomposition of A.
@return A DoubleMatrix[3] array of U, S, V such that A = U * diag(S) * V'
|
[
"Compute",
"a",
"singular",
"-",
"value",
"decomposition",
"of",
"A",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/Singular.java#L21-L36
|
158,070
|
jblas-project/jblas
|
src/main/java/org/jblas/util/LibraryLoader.java
|
LibraryLoader.tryPath
|
private InputStream tryPath(String path) {
Logger.getLogger().debug("Trying path \"" + path + "\".");
return getClass().getResourceAsStream(path);
}
|
java
|
private InputStream tryPath(String path) {
Logger.getLogger().debug("Trying path \"" + path + "\".");
return getClass().getResourceAsStream(path);
}
|
[
"private",
"InputStream",
"tryPath",
"(",
"String",
"path",
")",
"{",
"Logger",
".",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"Trying path \\\"\"",
"+",
"path",
"+",
"\"\\\".\"",
")",
";",
"return",
"getClass",
"(",
")",
".",
"getResourceAsStream",
"(",
"path",
")",
";",
"}"
] |
Try to open a file at the given position.
|
[
"Try",
"to",
"open",
"a",
"file",
"at",
"the",
"given",
"position",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/LibraryLoader.java#L233-L236
|
158,071
|
jblas-project/jblas
|
src/main/java/org/jblas/util/LibraryLoader.java
|
LibraryLoader.loadLibraryFromStream
|
private void loadLibraryFromStream(String libname, InputStream is) {
try {
File tempfile = createTempFile(libname);
OutputStream os = new FileOutputStream(tempfile);
logger.debug("tempfile.getPath() = " + tempfile.getPath());
long savedTime = System.currentTimeMillis();
// Leo says 8k block size is STANDARD ;)
byte buf[] = new byte[8192];
int len;
while ((len = is.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.flush();
InputStream lock = new FileInputStream(tempfile);
os.close();
double seconds = (double) (System.currentTimeMillis() - savedTime) / 1e3;
logger.debug("Copying took " + seconds + " seconds.");
logger.debug("Loading library from " + tempfile.getPath() + ".");
System.load(tempfile.getPath());
lock.close();
} catch (IOException io) {
logger.error("Could not create the temp file: " + io.toString() + ".\n");
} catch (UnsatisfiedLinkError ule) {
logger.error("Couldn't load copied link file: " + ule.toString() + ".\n");
throw ule;
}
}
|
java
|
private void loadLibraryFromStream(String libname, InputStream is) {
try {
File tempfile = createTempFile(libname);
OutputStream os = new FileOutputStream(tempfile);
logger.debug("tempfile.getPath() = " + tempfile.getPath());
long savedTime = System.currentTimeMillis();
// Leo says 8k block size is STANDARD ;)
byte buf[] = new byte[8192];
int len;
while ((len = is.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.flush();
InputStream lock = new FileInputStream(tempfile);
os.close();
double seconds = (double) (System.currentTimeMillis() - savedTime) / 1e3;
logger.debug("Copying took " + seconds + " seconds.");
logger.debug("Loading library from " + tempfile.getPath() + ".");
System.load(tempfile.getPath());
lock.close();
} catch (IOException io) {
logger.error("Could not create the temp file: " + io.toString() + ".\n");
} catch (UnsatisfiedLinkError ule) {
logger.error("Couldn't load copied link file: " + ule.toString() + ".\n");
throw ule;
}
}
|
[
"private",
"void",
"loadLibraryFromStream",
"(",
"String",
"libname",
",",
"InputStream",
"is",
")",
"{",
"try",
"{",
"File",
"tempfile",
"=",
"createTempFile",
"(",
"libname",
")",
";",
"OutputStream",
"os",
"=",
"new",
"FileOutputStream",
"(",
"tempfile",
")",
";",
"logger",
".",
"debug",
"(",
"\"tempfile.getPath() = \"",
"+",
"tempfile",
".",
"getPath",
"(",
")",
")",
";",
"long",
"savedTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"// Leo says 8k block size is STANDARD ;)\r",
"byte",
"buf",
"[",
"]",
"=",
"new",
"byte",
"[",
"8192",
"]",
";",
"int",
"len",
";",
"while",
"(",
"(",
"len",
"=",
"is",
".",
"read",
"(",
"buf",
")",
")",
">",
"0",
")",
"{",
"os",
".",
"write",
"(",
"buf",
",",
"0",
",",
"len",
")",
";",
"}",
"os",
".",
"flush",
"(",
")",
";",
"InputStream",
"lock",
"=",
"new",
"FileInputStream",
"(",
"tempfile",
")",
";",
"os",
".",
"close",
"(",
")",
";",
"double",
"seconds",
"=",
"(",
"double",
")",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"savedTime",
")",
"/",
"1e3",
";",
"logger",
".",
"debug",
"(",
"\"Copying took \"",
"+",
"seconds",
"+",
"\" seconds.\"",
")",
";",
"logger",
".",
"debug",
"(",
"\"Loading library from \"",
"+",
"tempfile",
".",
"getPath",
"(",
")",
"+",
"\".\"",
")",
";",
"System",
".",
"load",
"(",
"tempfile",
".",
"getPath",
"(",
")",
")",
";",
"lock",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"io",
")",
"{",
"logger",
".",
"error",
"(",
"\"Could not create the temp file: \"",
"+",
"io",
".",
"toString",
"(",
")",
"+",
"\".\\n\"",
")",
";",
"}",
"catch",
"(",
"UnsatisfiedLinkError",
"ule",
")",
"{",
"logger",
".",
"error",
"(",
"\"Couldn't load copied link file: \"",
"+",
"ule",
".",
"toString",
"(",
")",
"+",
"\".\\n\"",
")",
";",
"throw",
"ule",
";",
"}",
"}"
] |
Load a system library from a stream. Copies the library to a temp file
and loads from there.
@param libname name of the library (just used in constructing the library name)
@param is InputStream pointing to the library
|
[
"Load",
"a",
"system",
"library",
"from",
"a",
"stream",
".",
"Copies",
"the",
"library",
"to",
"a",
"temp",
"file",
"and",
"loads",
"from",
"there",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/LibraryLoader.java#L249-L282
|
158,072
|
jblas-project/jblas
|
src/main/java/org/jblas/util/SanityChecks.java
|
SanityChecks.checkVectorAddition
|
public static void checkVectorAddition() {
DoubleMatrix x = new DoubleMatrix(3, 1, 1.0, 2.0, 3.0);
DoubleMatrix y = new DoubleMatrix(3, 1, 4.0, 5.0, 6.0);
DoubleMatrix z = new DoubleMatrix(3, 1, 5.0, 7.0, 9.0);
check("checking vector addition", x.add(y).equals(z));
}
|
java
|
public static void checkVectorAddition() {
DoubleMatrix x = new DoubleMatrix(3, 1, 1.0, 2.0, 3.0);
DoubleMatrix y = new DoubleMatrix(3, 1, 4.0, 5.0, 6.0);
DoubleMatrix z = new DoubleMatrix(3, 1, 5.0, 7.0, 9.0);
check("checking vector addition", x.add(y).equals(z));
}
|
[
"public",
"static",
"void",
"checkVectorAddition",
"(",
")",
"{",
"DoubleMatrix",
"x",
"=",
"new",
"DoubleMatrix",
"(",
"3",
",",
"1",
",",
"1.0",
",",
"2.0",
",",
"3.0",
")",
";",
"DoubleMatrix",
"y",
"=",
"new",
"DoubleMatrix",
"(",
"3",
",",
"1",
",",
"4.0",
",",
"5.0",
",",
"6.0",
")",
";",
"DoubleMatrix",
"z",
"=",
"new",
"DoubleMatrix",
"(",
"3",
",",
"1",
",",
"5.0",
",",
"7.0",
",",
"9.0",
")",
";",
"check",
"(",
"\"checking vector addition\"",
",",
"x",
".",
"add",
"(",
"y",
")",
".",
"equals",
"(",
"z",
")",
")",
";",
"}"
] |
Check whether vector addition works. This is pure Java code and should work.
|
[
"Check",
"whether",
"vector",
"addition",
"works",
".",
"This",
"is",
"pure",
"Java",
"code",
"and",
"should",
"work",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/SanityChecks.java#L64-L70
|
158,073
|
jblas-project/jblas
|
src/main/java/org/jblas/util/SanityChecks.java
|
SanityChecks.checkXerbla
|
public static void checkXerbla() {
double[] x = new double[9];
System.out.println("Check whether we're catching XERBLA errors. If you see something like \"** On entry to DGEMM parameter number 4 had an illegal value\", it didn't work!");
try {
NativeBlas.dgemm('N', 'N', 3, -1, 3, 1.0, x, 0, 3, x, 0, 3, 0.0, x, 0, 3);
} catch (IllegalArgumentException e) {
check("checking XERBLA", e.getMessage().contains("XERBLA"));
return;
}
assert (false); // shouldn't happen
}
|
java
|
public static void checkXerbla() {
double[] x = new double[9];
System.out.println("Check whether we're catching XERBLA errors. If you see something like \"** On entry to DGEMM parameter number 4 had an illegal value\", it didn't work!");
try {
NativeBlas.dgemm('N', 'N', 3, -1, 3, 1.0, x, 0, 3, x, 0, 3, 0.0, x, 0, 3);
} catch (IllegalArgumentException e) {
check("checking XERBLA", e.getMessage().contains("XERBLA"));
return;
}
assert (false); // shouldn't happen
}
|
[
"public",
"static",
"void",
"checkXerbla",
"(",
")",
"{",
"double",
"[",
"]",
"x",
"=",
"new",
"double",
"[",
"9",
"]",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"Check whether we're catching XERBLA errors. If you see something like \\\"** On entry to DGEMM parameter number 4 had an illegal value\\\", it didn't work!\"",
")",
";",
"try",
"{",
"NativeBlas",
".",
"dgemm",
"(",
"'",
"'",
",",
"'",
"'",
",",
"3",
",",
"-",
"1",
",",
"3",
",",
"1.0",
",",
"x",
",",
"0",
",",
"3",
",",
"x",
",",
"0",
",",
"3",
",",
"0.0",
",",
"x",
",",
"0",
",",
"3",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"check",
"(",
"\"checking XERBLA\"",
",",
"e",
".",
"getMessage",
"(",
")",
".",
"contains",
"(",
"\"XERBLA\"",
")",
")",
";",
"return",
";",
"}",
"assert",
"(",
"false",
")",
";",
"// shouldn't happen",
"}"
] |
Check whether error handling works. If it works, you should see an
ok, otherwise, you might see the actual error message and then
the program exits.
|
[
"Check",
"whether",
"error",
"handling",
"works",
".",
"If",
"it",
"works",
"you",
"should",
"see",
"an",
"ok",
"otherwise",
"you",
"might",
"see",
"the",
"actual",
"error",
"message",
"and",
"then",
"the",
"program",
"exits",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/SanityChecks.java#L99-L109
|
158,074
|
jblas-project/jblas
|
src/main/java/org/jblas/util/SanityChecks.java
|
SanityChecks.checkEigenvalues
|
public static void checkEigenvalues() {
DoubleMatrix A = new DoubleMatrix(new double[][]{
{3.0, 2.0, 0.0},
{2.0, 3.0, 2.0},
{0.0, 2.0, 3.0}
});
DoubleMatrix E = new DoubleMatrix(3, 1);
NativeBlas.dsyev('N', 'U', 3, A.data, 0, 3, E.data, 0);
check("checking existence of dsyev...", true);
}
|
java
|
public static void checkEigenvalues() {
DoubleMatrix A = new DoubleMatrix(new double[][]{
{3.0, 2.0, 0.0},
{2.0, 3.0, 2.0},
{0.0, 2.0, 3.0}
});
DoubleMatrix E = new DoubleMatrix(3, 1);
NativeBlas.dsyev('N', 'U', 3, A.data, 0, 3, E.data, 0);
check("checking existence of dsyev...", true);
}
|
[
"public",
"static",
"void",
"checkEigenvalues",
"(",
")",
"{",
"DoubleMatrix",
"A",
"=",
"new",
"DoubleMatrix",
"(",
"new",
"double",
"[",
"]",
"[",
"]",
"{",
"{",
"3.0",
",",
"2.0",
",",
"0.0",
"}",
",",
"{",
"2.0",
",",
"3.0",
",",
"2.0",
"}",
",",
"{",
"0.0",
",",
"2.0",
",",
"3.0",
"}",
"}",
")",
";",
"DoubleMatrix",
"E",
"=",
"new",
"DoubleMatrix",
"(",
"3",
",",
"1",
")",
";",
"NativeBlas",
".",
"dsyev",
"(",
"'",
"'",
",",
"'",
"'",
",",
"3",
",",
"A",
".",
"data",
",",
"0",
",",
"3",
",",
"E",
".",
"data",
",",
"0",
")",
";",
"check",
"(",
"\"checking existence of dsyev...\"",
",",
"true",
")",
";",
"}"
] |
Compute eigenvalues. This is a routine not in ATLAS, but in the original
LAPACK.
|
[
"Compute",
"eigenvalues",
".",
"This",
"is",
"a",
"routine",
"not",
"in",
"ATLAS",
"but",
"in",
"the",
"original",
"LAPACK",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/util/SanityChecks.java#L115-L126
|
158,075
|
jblas-project/jblas
|
src/main/java/org/jblas/Decompose.java
|
Decompose.cholesky
|
public static DoubleMatrix cholesky(DoubleMatrix A) {
DoubleMatrix result = A.dup();
int info = NativeBlas.dpotrf('U', A.rows, result.data, 0, A.rows);
if (info < 0) {
throw new LapackArgumentException("DPOTRF", -info);
} else if (info > 0) {
throw new LapackPositivityException("DPOTRF", "Minor " + info + " was negative. Matrix must be positive definite.");
}
clearLower(result);
return result;
}
|
java
|
public static DoubleMatrix cholesky(DoubleMatrix A) {
DoubleMatrix result = A.dup();
int info = NativeBlas.dpotrf('U', A.rows, result.data, 0, A.rows);
if (info < 0) {
throw new LapackArgumentException("DPOTRF", -info);
} else if (info > 0) {
throw new LapackPositivityException("DPOTRF", "Minor " + info + " was negative. Matrix must be positive definite.");
}
clearLower(result);
return result;
}
|
[
"public",
"static",
"DoubleMatrix",
"cholesky",
"(",
"DoubleMatrix",
"A",
")",
"{",
"DoubleMatrix",
"result",
"=",
"A",
".",
"dup",
"(",
")",
";",
"int",
"info",
"=",
"NativeBlas",
".",
"dpotrf",
"(",
"'",
"'",
",",
"A",
".",
"rows",
",",
"result",
".",
"data",
",",
"0",
",",
"A",
".",
"rows",
")",
";",
"if",
"(",
"info",
"<",
"0",
")",
"{",
"throw",
"new",
"LapackArgumentException",
"(",
"\"DPOTRF\"",
",",
"-",
"info",
")",
";",
"}",
"else",
"if",
"(",
"info",
">",
"0",
")",
"{",
"throw",
"new",
"LapackPositivityException",
"(",
"\"DPOTRF\"",
",",
"\"Minor \"",
"+",
"info",
"+",
"\" was negative. Matrix must be positive definite.\"",
")",
";",
"}",
"clearLower",
"(",
"result",
")",
";",
"return",
"result",
";",
"}"
] |
Compute Cholesky decomposition of A
@param A symmetric, positive definite matrix (only upper half is used)
@return upper triangular matrix U such that A = U' * U
|
[
"Compute",
"Cholesky",
"decomposition",
"of",
"A"
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/Decompose.java#L149-L159
|
158,076
|
jblas-project/jblas
|
src/main/java/org/jblas/Decompose.java
|
Decompose.qr
|
public static QRDecomposition<DoubleMatrix> qr(DoubleMatrix A) {
int minmn = min(A.rows, A.columns);
DoubleMatrix result = A.dup();
DoubleMatrix tau = new DoubleMatrix(minmn);
SimpleBlas.geqrf(result, tau);
DoubleMatrix R = new DoubleMatrix(A.rows, A.columns);
for (int i = 0; i < A.rows; i++) {
for (int j = i; j < A.columns; j++) {
R.put(i, j, result.get(i, j));
}
}
DoubleMatrix Q = DoubleMatrix.eye(A.rows);
SimpleBlas.ormqr('L', 'N', result, tau, Q);
return new QRDecomposition<DoubleMatrix>(Q, R);
}
|
java
|
public static QRDecomposition<DoubleMatrix> qr(DoubleMatrix A) {
int minmn = min(A.rows, A.columns);
DoubleMatrix result = A.dup();
DoubleMatrix tau = new DoubleMatrix(minmn);
SimpleBlas.geqrf(result, tau);
DoubleMatrix R = new DoubleMatrix(A.rows, A.columns);
for (int i = 0; i < A.rows; i++) {
for (int j = i; j < A.columns; j++) {
R.put(i, j, result.get(i, j));
}
}
DoubleMatrix Q = DoubleMatrix.eye(A.rows);
SimpleBlas.ormqr('L', 'N', result, tau, Q);
return new QRDecomposition<DoubleMatrix>(Q, R);
}
|
[
"public",
"static",
"QRDecomposition",
"<",
"DoubleMatrix",
">",
"qr",
"(",
"DoubleMatrix",
"A",
")",
"{",
"int",
"minmn",
"=",
"min",
"(",
"A",
".",
"rows",
",",
"A",
".",
"columns",
")",
";",
"DoubleMatrix",
"result",
"=",
"A",
".",
"dup",
"(",
")",
";",
"DoubleMatrix",
"tau",
"=",
"new",
"DoubleMatrix",
"(",
"minmn",
")",
";",
"SimpleBlas",
".",
"geqrf",
"(",
"result",
",",
"tau",
")",
";",
"DoubleMatrix",
"R",
"=",
"new",
"DoubleMatrix",
"(",
"A",
".",
"rows",
",",
"A",
".",
"columns",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"A",
".",
"rows",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"i",
";",
"j",
"<",
"A",
".",
"columns",
";",
"j",
"++",
")",
"{",
"R",
".",
"put",
"(",
"i",
",",
"j",
",",
"result",
".",
"get",
"(",
"i",
",",
"j",
")",
")",
";",
"}",
"}",
"DoubleMatrix",
"Q",
"=",
"DoubleMatrix",
".",
"eye",
"(",
"A",
".",
"rows",
")",
";",
"SimpleBlas",
".",
"ormqr",
"(",
"'",
"'",
",",
"'",
"'",
",",
"result",
",",
"tau",
",",
"Q",
")",
";",
"return",
"new",
"QRDecomposition",
"<",
"DoubleMatrix",
">",
"(",
"Q",
",",
"R",
")",
";",
"}"
] |
QR decomposition.
Decomposes (m,n) matrix A into a (m,m) matrix Q and an (m,n) matrix R such that
Q is orthogonal, R is upper triangular and Q * R = A
Note that if A has more rows than columns, then the lower rows of R will contain
only zeros, such that the corresponding later columns of Q do not enter the computation
at all. For some reason, LAPACK does not properly normalize those columns.
@param A matrix
@return QR decomposition
|
[
"QR",
"decomposition",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/Decompose.java#L200-L214
|
158,077
|
jblas-project/jblas
|
src/main/java/org/jblas/MatrixFunctions.java
|
MatrixFunctions.absi
|
public static DoubleMatrix absi(DoubleMatrix x) {
/*# mapfct('Math.abs') #*/
//RJPP-BEGIN------------------------------------------------------------
for (int i = 0; i < x.length; i++)
x.put(i, (double) Math.abs(x.get(i)));
return x;
//RJPP-END--------------------------------------------------------------
}
|
java
|
public static DoubleMatrix absi(DoubleMatrix x) {
/*# mapfct('Math.abs') #*/
//RJPP-BEGIN------------------------------------------------------------
for (int i = 0; i < x.length; i++)
x.put(i, (double) Math.abs(x.get(i)));
return x;
//RJPP-END--------------------------------------------------------------
}
|
[
"public",
"static",
"DoubleMatrix",
"absi",
"(",
"DoubleMatrix",
"x",
")",
"{",
"/*# mapfct('Math.abs') #*/",
"//RJPP-BEGIN------------------------------------------------------------",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"x",
".",
"put",
"(",
"i",
",",
"(",
"double",
")",
"Math",
".",
"abs",
"(",
"x",
".",
"get",
"(",
"i",
")",
")",
")",
";",
"return",
"x",
";",
"//RJPP-END--------------------------------------------------------------",
"}"
] |
Sets all elements in this matrix to their absolute values. Note
that this operation is in-place.
@see MatrixFunctions#abs(DoubleMatrix)
@return this matrix
|
[
"Sets",
"all",
"elements",
"in",
"this",
"matrix",
"to",
"their",
"absolute",
"values",
".",
"Note",
"that",
"this",
"operation",
"is",
"in",
"-",
"place",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/MatrixFunctions.java#L69-L76
|
158,078
|
jblas-project/jblas
|
src/main/java/org/jblas/MatrixFunctions.java
|
MatrixFunctions.expm
|
public static DoubleMatrix expm(DoubleMatrix A) {
// constants for pade approximation
final double c0 = 1.0;
final double c1 = 0.5;
final double c2 = 0.12;
final double c3 = 0.01833333333333333;
final double c4 = 0.0019927536231884053;
final double c5 = 1.630434782608695E-4;
final double c6 = 1.0351966873706E-5;
final double c7 = 5.175983436853E-7;
final double c8 = 2.0431513566525E-8;
final double c9 = 6.306022705717593E-10;
final double c10 = 1.4837700484041396E-11;
final double c11 = 2.5291534915979653E-13;
final double c12 = 2.8101705462199615E-15;
final double c13 = 1.5440497506703084E-17;
int j = Math.max(0, 1 + (int) Math.floor(Math.log(A.normmax()) / Math.log(2)));
DoubleMatrix As = A.div((double) Math.pow(2, j)); // scaled version of A
int n = A.getRows();
// calculate D and N using special Horner techniques
DoubleMatrix As_2 = As.mmul(As);
DoubleMatrix As_4 = As_2.mmul(As_2);
DoubleMatrix As_6 = As_4.mmul(As_2);
// U = c0*I + c2*A^2 + c4*A^4 + (c6*I + c8*A^2 + c10*A^4 + c12*A^6)*A^6
DoubleMatrix U = DoubleMatrix.eye(n).muli(c0).addi(As_2.mul(c2)).addi(As_4.mul(c4)).addi(
DoubleMatrix.eye(n).muli(c6).addi(As_2.mul(c8)).addi(As_4.mul(c10)).addi(As_6.mul(c12)).mmuli(As_6));
// V = c1*I + c3*A^2 + c5*A^4 + (c7*I + c9*A^2 + c11*A^4 + c13*A^6)*A^6
DoubleMatrix V = DoubleMatrix.eye(n).muli(c1).addi(As_2.mul(c3)).addi(As_4.mul(c5)).addi(
DoubleMatrix.eye(n).muli(c7).addi(As_2.mul(c9)).addi(As_4.mul(c11)).addi(As_6.mul(c13)).mmuli(As_6));
DoubleMatrix AV = As.mmuli(V);
DoubleMatrix N = U.add(AV);
DoubleMatrix D = U.subi(AV);
// solve DF = N for F
DoubleMatrix F = Solve.solve(D, N);
// now square j times
for (int k = 0; k < j; k++) {
F.mmuli(F);
}
return F;
}
|
java
|
public static DoubleMatrix expm(DoubleMatrix A) {
// constants for pade approximation
final double c0 = 1.0;
final double c1 = 0.5;
final double c2 = 0.12;
final double c3 = 0.01833333333333333;
final double c4 = 0.0019927536231884053;
final double c5 = 1.630434782608695E-4;
final double c6 = 1.0351966873706E-5;
final double c7 = 5.175983436853E-7;
final double c8 = 2.0431513566525E-8;
final double c9 = 6.306022705717593E-10;
final double c10 = 1.4837700484041396E-11;
final double c11 = 2.5291534915979653E-13;
final double c12 = 2.8101705462199615E-15;
final double c13 = 1.5440497506703084E-17;
int j = Math.max(0, 1 + (int) Math.floor(Math.log(A.normmax()) / Math.log(2)));
DoubleMatrix As = A.div((double) Math.pow(2, j)); // scaled version of A
int n = A.getRows();
// calculate D and N using special Horner techniques
DoubleMatrix As_2 = As.mmul(As);
DoubleMatrix As_4 = As_2.mmul(As_2);
DoubleMatrix As_6 = As_4.mmul(As_2);
// U = c0*I + c2*A^2 + c4*A^4 + (c6*I + c8*A^2 + c10*A^4 + c12*A^6)*A^6
DoubleMatrix U = DoubleMatrix.eye(n).muli(c0).addi(As_2.mul(c2)).addi(As_4.mul(c4)).addi(
DoubleMatrix.eye(n).muli(c6).addi(As_2.mul(c8)).addi(As_4.mul(c10)).addi(As_6.mul(c12)).mmuli(As_6));
// V = c1*I + c3*A^2 + c5*A^4 + (c7*I + c9*A^2 + c11*A^4 + c13*A^6)*A^6
DoubleMatrix V = DoubleMatrix.eye(n).muli(c1).addi(As_2.mul(c3)).addi(As_4.mul(c5)).addi(
DoubleMatrix.eye(n).muli(c7).addi(As_2.mul(c9)).addi(As_4.mul(c11)).addi(As_6.mul(c13)).mmuli(As_6));
DoubleMatrix AV = As.mmuli(V);
DoubleMatrix N = U.add(AV);
DoubleMatrix D = U.subi(AV);
// solve DF = N for F
DoubleMatrix F = Solve.solve(D, N);
// now square j times
for (int k = 0; k < j; k++) {
F.mmuli(F);
}
return F;
}
|
[
"public",
"static",
"DoubleMatrix",
"expm",
"(",
"DoubleMatrix",
"A",
")",
"{",
"// constants for pade approximation",
"final",
"double",
"c0",
"=",
"1.0",
";",
"final",
"double",
"c1",
"=",
"0.5",
";",
"final",
"double",
"c2",
"=",
"0.12",
";",
"final",
"double",
"c3",
"=",
"0.01833333333333333",
";",
"final",
"double",
"c4",
"=",
"0.0019927536231884053",
";",
"final",
"double",
"c5",
"=",
"1.630434782608695E-4",
";",
"final",
"double",
"c6",
"=",
"1.0351966873706E-5",
";",
"final",
"double",
"c7",
"=",
"5.175983436853E-7",
";",
"final",
"double",
"c8",
"=",
"2.0431513566525E-8",
";",
"final",
"double",
"c9",
"=",
"6.306022705717593E-10",
";",
"final",
"double",
"c10",
"=",
"1.4837700484041396E-11",
";",
"final",
"double",
"c11",
"=",
"2.5291534915979653E-13",
";",
"final",
"double",
"c12",
"=",
"2.8101705462199615E-15",
";",
"final",
"double",
"c13",
"=",
"1.5440497506703084E-17",
";",
"int",
"j",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"1",
"+",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"Math",
".",
"log",
"(",
"A",
".",
"normmax",
"(",
")",
")",
"/",
"Math",
".",
"log",
"(",
"2",
")",
")",
")",
";",
"DoubleMatrix",
"As",
"=",
"A",
".",
"div",
"(",
"(",
"double",
")",
"Math",
".",
"pow",
"(",
"2",
",",
"j",
")",
")",
";",
"// scaled version of A",
"int",
"n",
"=",
"A",
".",
"getRows",
"(",
")",
";",
"// calculate D and N using special Horner techniques",
"DoubleMatrix",
"As_2",
"=",
"As",
".",
"mmul",
"(",
"As",
")",
";",
"DoubleMatrix",
"As_4",
"=",
"As_2",
".",
"mmul",
"(",
"As_2",
")",
";",
"DoubleMatrix",
"As_6",
"=",
"As_4",
".",
"mmul",
"(",
"As_2",
")",
";",
"// U = c0*I + c2*A^2 + c4*A^4 + (c6*I + c8*A^2 + c10*A^4 + c12*A^6)*A^6",
"DoubleMatrix",
"U",
"=",
"DoubleMatrix",
".",
"eye",
"(",
"n",
")",
".",
"muli",
"(",
"c0",
")",
".",
"addi",
"(",
"As_2",
".",
"mul",
"(",
"c2",
")",
")",
".",
"addi",
"(",
"As_4",
".",
"mul",
"(",
"c4",
")",
")",
".",
"addi",
"(",
"DoubleMatrix",
".",
"eye",
"(",
"n",
")",
".",
"muli",
"(",
"c6",
")",
".",
"addi",
"(",
"As_2",
".",
"mul",
"(",
"c8",
")",
")",
".",
"addi",
"(",
"As_4",
".",
"mul",
"(",
"c10",
")",
")",
".",
"addi",
"(",
"As_6",
".",
"mul",
"(",
"c12",
")",
")",
".",
"mmuli",
"(",
"As_6",
")",
")",
";",
"// V = c1*I + c3*A^2 + c5*A^4 + (c7*I + c9*A^2 + c11*A^4 + c13*A^6)*A^6",
"DoubleMatrix",
"V",
"=",
"DoubleMatrix",
".",
"eye",
"(",
"n",
")",
".",
"muli",
"(",
"c1",
")",
".",
"addi",
"(",
"As_2",
".",
"mul",
"(",
"c3",
")",
")",
".",
"addi",
"(",
"As_4",
".",
"mul",
"(",
"c5",
")",
")",
".",
"addi",
"(",
"DoubleMatrix",
".",
"eye",
"(",
"n",
")",
".",
"muli",
"(",
"c7",
")",
".",
"addi",
"(",
"As_2",
".",
"mul",
"(",
"c9",
")",
")",
".",
"addi",
"(",
"As_4",
".",
"mul",
"(",
"c11",
")",
")",
".",
"addi",
"(",
"As_6",
".",
"mul",
"(",
"c13",
")",
")",
".",
"mmuli",
"(",
"As_6",
")",
")",
";",
"DoubleMatrix",
"AV",
"=",
"As",
".",
"mmuli",
"(",
"V",
")",
";",
"DoubleMatrix",
"N",
"=",
"U",
".",
"add",
"(",
"AV",
")",
";",
"DoubleMatrix",
"D",
"=",
"U",
".",
"subi",
"(",
"AV",
")",
";",
"// solve DF = N for F",
"DoubleMatrix",
"F",
"=",
"Solve",
".",
"solve",
"(",
"D",
",",
"N",
")",
";",
"// now square j times",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"j",
";",
"k",
"++",
")",
"{",
"F",
".",
"mmuli",
"(",
"F",
")",
";",
"}",
"return",
"F",
";",
"}"
] |
Calculate matrix exponential of a square matrix.
A scaled Pade approximation algorithm is used.
The algorithm has been directly translated from Golub & Van Loan "Matrix Computations",
algorithm 11.3.1. Special Horner techniques from 11.2 are also used to minimize the number
of matrix multiplications.
@param A square matrix
@return matrix exponential of A
|
[
"Calculate",
"matrix",
"exponential",
"of",
"a",
"square",
"matrix",
"."
] |
2818f231228e655cda80dfd8e0b87709fdfd8a70
|
https://github.com/jblas-project/jblas/blob/2818f231228e655cda80dfd8e0b87709fdfd8a70/src/main/java/org/jblas/MatrixFunctions.java#L406-L451
|
158,079
|
wdtinc/mapbox-vector-tile-java
|
src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/JtsAdapter.java
|
JtsAdapter.toGeomType
|
public static VectorTile.Tile.GeomType toGeomType(Geometry geometry) {
VectorTile.Tile.GeomType result = VectorTile.Tile.GeomType.UNKNOWN;
if(geometry instanceof Point
|| geometry instanceof MultiPoint) {
result = VectorTile.Tile.GeomType.POINT;
} else if(geometry instanceof LineString
|| geometry instanceof MultiLineString) {
result = VectorTile.Tile.GeomType.LINESTRING;
} else if(geometry instanceof Polygon
|| geometry instanceof MultiPolygon) {
result = VectorTile.Tile.GeomType.POLYGON;
}
return result;
}
|
java
|
public static VectorTile.Tile.GeomType toGeomType(Geometry geometry) {
VectorTile.Tile.GeomType result = VectorTile.Tile.GeomType.UNKNOWN;
if(geometry instanceof Point
|| geometry instanceof MultiPoint) {
result = VectorTile.Tile.GeomType.POINT;
} else if(geometry instanceof LineString
|| geometry instanceof MultiLineString) {
result = VectorTile.Tile.GeomType.LINESTRING;
} else if(geometry instanceof Polygon
|| geometry instanceof MultiPolygon) {
result = VectorTile.Tile.GeomType.POLYGON;
}
return result;
}
|
[
"public",
"static",
"VectorTile",
".",
"Tile",
".",
"GeomType",
"toGeomType",
"(",
"Geometry",
"geometry",
")",
"{",
"VectorTile",
".",
"Tile",
".",
"GeomType",
"result",
"=",
"VectorTile",
".",
"Tile",
".",
"GeomType",
".",
"UNKNOWN",
";",
"if",
"(",
"geometry",
"instanceof",
"Point",
"||",
"geometry",
"instanceof",
"MultiPoint",
")",
"{",
"result",
"=",
"VectorTile",
".",
"Tile",
".",
"GeomType",
".",
"POINT",
";",
"}",
"else",
"if",
"(",
"geometry",
"instanceof",
"LineString",
"||",
"geometry",
"instanceof",
"MultiLineString",
")",
"{",
"result",
"=",
"VectorTile",
".",
"Tile",
".",
"GeomType",
".",
"LINESTRING",
";",
"}",
"else",
"if",
"(",
"geometry",
"instanceof",
"Polygon",
"||",
"geometry",
"instanceof",
"MultiPolygon",
")",
"{",
"result",
"=",
"VectorTile",
".",
"Tile",
".",
"GeomType",
".",
"POLYGON",
";",
"}",
"return",
"result",
";",
"}"
] |
Get the MVT type mapping for the provided JTS Geometry.
@param geometry JTS Geometry to get MVT type for
@return MVT type for the given JTS Geometry, may return
{@link com.wdtinc.mapbox_vector_tile.VectorTile.Tile.GeomType#UNKNOWN}
|
[
"Get",
"the",
"MVT",
"type",
"mapping",
"for",
"the",
"provided",
"JTS",
"Geometry",
"."
] |
e5e3df3fc2260709e289f972a1348c0a1ea30339
|
https://github.com/wdtinc/mapbox-vector-tile-java/blob/e5e3df3fc2260709e289f972a1348c0a1ea30339/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/JtsAdapter.java#L184-L201
|
158,080
|
wdtinc/mapbox-vector-tile-java
|
src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/JtsAdapter.java
|
JtsAdapter.equalAsInts
|
private static boolean equalAsInts(Vec2d a, Vec2d b) {
return ((int) a.x) == ((int) b.x) && ((int) a.y) == ((int) b.y);
}
|
java
|
private static boolean equalAsInts(Vec2d a, Vec2d b) {
return ((int) a.x) == ((int) b.x) && ((int) a.y) == ((int) b.y);
}
|
[
"private",
"static",
"boolean",
"equalAsInts",
"(",
"Vec2d",
"a",
",",
"Vec2d",
"b",
")",
"{",
"return",
"(",
"(",
"int",
")",
"a",
".",
"x",
")",
"==",
"(",
"(",
"int",
")",
"b",
".",
"x",
")",
"&&",
"(",
"(",
"int",
")",
"a",
".",
"y",
")",
"==",
"(",
"(",
"int",
")",
"b",
".",
"y",
")",
";",
"}"
] |
Return true if the values of the two vectors are equal when cast as ints.
@param a first vector to compare
@param b second vector to compare
@return true if the values of the two vectors are equal when cast as ints
|
[
"Return",
"true",
"if",
"the",
"values",
"of",
"the",
"two",
"vectors",
"are",
"equal",
"when",
"cast",
"as",
"ints",
"."
] |
e5e3df3fc2260709e289f972a1348c0a1ea30339
|
https://github.com/wdtinc/mapbox-vector-tile-java/blob/e5e3df3fc2260709e289f972a1348c0a1ea30339/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/JtsAdapter.java#L630-L632
|
158,081
|
wdtinc/mapbox-vector-tile-java
|
src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/model/JtsLayer.java
|
JtsLayer.validate
|
private static void validate(String name, Collection<Geometry> geometries, int extent) {
if (name == null) {
throw new IllegalArgumentException("layer name is null");
}
if (geometries == null) {
throw new IllegalArgumentException("geometry collection is null");
}
if (extent <= 0) {
throw new IllegalArgumentException("extent is less than or equal to 0");
}
}
|
java
|
private static void validate(String name, Collection<Geometry> geometries, int extent) {
if (name == null) {
throw new IllegalArgumentException("layer name is null");
}
if (geometries == null) {
throw new IllegalArgumentException("geometry collection is null");
}
if (extent <= 0) {
throw new IllegalArgumentException("extent is less than or equal to 0");
}
}
|
[
"private",
"static",
"void",
"validate",
"(",
"String",
"name",
",",
"Collection",
"<",
"Geometry",
">",
"geometries",
",",
"int",
"extent",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"layer name is null\"",
")",
";",
"}",
"if",
"(",
"geometries",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"geometry collection is null\"",
")",
";",
"}",
"if",
"(",
"extent",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"extent is less than or equal to 0\"",
")",
";",
"}",
"}"
] |
Validate the JtsLayer.
@param name mvt layer name
@param geometries geometries in the tile
@throws IllegalArgumentException when {@code name} or {@code geometries} are null
|
[
"Validate",
"the",
"JtsLayer",
"."
] |
e5e3df3fc2260709e289f972a1348c0a1ea30339
|
https://github.com/wdtinc/mapbox-vector-tile-java/blob/e5e3df3fc2260709e289f972a1348c0a1ea30339/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/model/JtsLayer.java#L121-L131
|
158,082
|
wdtinc/mapbox-vector-tile-java
|
src/main/java/com/wdtinc/mapbox_vector_tile/build/MvtLayerProps.java
|
MvtLayerProps.addKey
|
public int addKey(String key) {
JdkUtils.requireNonNull(key);
int nextIndex = keys.size();
final Integer mapIndex = JdkUtils.putIfAbsent(keys, key, nextIndex);
return mapIndex == null ? nextIndex : mapIndex;
}
|
java
|
public int addKey(String key) {
JdkUtils.requireNonNull(key);
int nextIndex = keys.size();
final Integer mapIndex = JdkUtils.putIfAbsent(keys, key, nextIndex);
return mapIndex == null ? nextIndex : mapIndex;
}
|
[
"public",
"int",
"addKey",
"(",
"String",
"key",
")",
"{",
"JdkUtils",
".",
"requireNonNull",
"(",
"key",
")",
";",
"int",
"nextIndex",
"=",
"keys",
".",
"size",
"(",
")",
";",
"final",
"Integer",
"mapIndex",
"=",
"JdkUtils",
".",
"putIfAbsent",
"(",
"keys",
",",
"key",
",",
"nextIndex",
")",
";",
"return",
"mapIndex",
"==",
"null",
"?",
"nextIndex",
":",
"mapIndex",
";",
"}"
] |
Add the key and return it's index code. If the key already is present, the previous
index code is returned and no insertion is done.
@param key key to add
@return index of the key
|
[
"Add",
"the",
"key",
"and",
"return",
"it",
"s",
"index",
"code",
".",
"If",
"the",
"key",
"already",
"is",
"present",
"the",
"previous",
"index",
"code",
"is",
"returned",
"and",
"no",
"insertion",
"is",
"done",
"."
] |
e5e3df3fc2260709e289f972a1348c0a1ea30339
|
https://github.com/wdtinc/mapbox-vector-tile-java/blob/e5e3df3fc2260709e289f972a1348c0a1ea30339/src/main/java/com/wdtinc/mapbox_vector_tile/build/MvtLayerProps.java#L35-L40
|
158,083
|
liuguangqiang/SwipeBack
|
library/src/main/java/com/liuguangqiang/swipeback/SwipeBackLayout.java
|
SwipeBackLayout.findScrollView
|
private void findScrollView(ViewGroup viewGroup) {
scrollChild = viewGroup;
if (viewGroup.getChildCount() > 0) {
int count = viewGroup.getChildCount();
View child;
for (int i = 0; i < count; i++) {
child = viewGroup.getChildAt(i);
if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) {
scrollChild = child;
return;
}
}
}
}
|
java
|
private void findScrollView(ViewGroup viewGroup) {
scrollChild = viewGroup;
if (viewGroup.getChildCount() > 0) {
int count = viewGroup.getChildCount();
View child;
for (int i = 0; i < count; i++) {
child = viewGroup.getChildAt(i);
if (child instanceof AbsListView || child instanceof ScrollView || child instanceof ViewPager || child instanceof WebView) {
scrollChild = child;
return;
}
}
}
}
|
[
"private",
"void",
"findScrollView",
"(",
"ViewGroup",
"viewGroup",
")",
"{",
"scrollChild",
"=",
"viewGroup",
";",
"if",
"(",
"viewGroup",
".",
"getChildCount",
"(",
")",
">",
"0",
")",
"{",
"int",
"count",
"=",
"viewGroup",
".",
"getChildCount",
"(",
")",
";",
"View",
"child",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"child",
"=",
"viewGroup",
".",
"getChildAt",
"(",
"i",
")",
";",
"if",
"(",
"child",
"instanceof",
"AbsListView",
"||",
"child",
"instanceof",
"ScrollView",
"||",
"child",
"instanceof",
"ViewPager",
"||",
"child",
"instanceof",
"WebView",
")",
"{",
"scrollChild",
"=",
"child",
";",
"return",
";",
"}",
"}",
"}",
"}"
] |
Find out the scrollable child view from a ViewGroup.
@param viewGroup
|
[
"Find",
"out",
"the",
"scrollable",
"child",
"view",
"from",
"a",
"ViewGroup",
"."
] |
0dd68189c58a5b2ead6bd5fe97c2a29cb43639f6
|
https://github.com/liuguangqiang/SwipeBack/blob/0dd68189c58a5b2ead6bd5fe97c2a29cb43639f6/library/src/main/java/com/liuguangqiang/swipeback/SwipeBackLayout.java#L227-L240
|
158,084
|
alkacon/opencms-core
|
src/org/opencms/ui/apps/sessions/CmsSendBroadcastDialog.java
|
CmsSendBroadcastDialog.removeAllBroadcasts
|
private void removeAllBroadcasts(Set<String> sessionIds) {
if (sessionIds == null) {
for (CmsSessionInfo info : OpenCms.getSessionManager().getSessionInfos()) {
OpenCms.getSessionManager().getBroadcastQueue(info.getSessionId().getStringValue()).clear();
}
return;
}
for (String sessionId : sessionIds) {
OpenCms.getSessionManager().getBroadcastQueue(sessionId).clear();
}
}
|
java
|
private void removeAllBroadcasts(Set<String> sessionIds) {
if (sessionIds == null) {
for (CmsSessionInfo info : OpenCms.getSessionManager().getSessionInfos()) {
OpenCms.getSessionManager().getBroadcastQueue(info.getSessionId().getStringValue()).clear();
}
return;
}
for (String sessionId : sessionIds) {
OpenCms.getSessionManager().getBroadcastQueue(sessionId).clear();
}
}
|
[
"private",
"void",
"removeAllBroadcasts",
"(",
"Set",
"<",
"String",
">",
"sessionIds",
")",
"{",
"if",
"(",
"sessionIds",
"==",
"null",
")",
"{",
"for",
"(",
"CmsSessionInfo",
"info",
":",
"OpenCms",
".",
"getSessionManager",
"(",
")",
".",
"getSessionInfos",
"(",
")",
")",
"{",
"OpenCms",
".",
"getSessionManager",
"(",
")",
".",
"getBroadcastQueue",
"(",
"info",
".",
"getSessionId",
"(",
")",
".",
"getStringValue",
"(",
")",
")",
".",
"clear",
"(",
")",
";",
"}",
"return",
";",
"}",
"for",
"(",
"String",
"sessionId",
":",
"sessionIds",
")",
"{",
"OpenCms",
".",
"getSessionManager",
"(",
")",
".",
"getBroadcastQueue",
"(",
"sessionId",
")",
".",
"clear",
"(",
")",
";",
"}",
"}"
] |
Removes all pending broadcasts
@param sessionIds to remove broadcast for (or null for all sessions)
|
[
"Removes",
"all",
"pending",
"broadcasts"
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/apps/sessions/CmsSendBroadcastDialog.java#L169-L180
|
158,085
|
alkacon/opencms-core
|
src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java
|
CmsPatternPanelMonthlyView.onWeekDayChange
|
@UiHandler("m_atDay")
void onWeekDayChange(ValueChangeEvent<String> event) {
if (handleChange()) {
m_controller.setWeekDay(event.getValue());
}
}
|
java
|
@UiHandler("m_atDay")
void onWeekDayChange(ValueChangeEvent<String> event) {
if (handleChange()) {
m_controller.setWeekDay(event.getValue());
}
}
|
[
"@",
"UiHandler",
"(",
"\"m_atDay\"",
")",
"void",
"onWeekDayChange",
"(",
"ValueChangeEvent",
"<",
"String",
">",
"event",
")",
"{",
"if",
"(",
"handleChange",
"(",
")",
")",
"{",
"m_controller",
".",
"setWeekDay",
"(",
"event",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] |
Handles week day changes.
@param event the change event.
|
[
"Handles",
"week",
"day",
"changes",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java#L282-L288
|
158,086
|
alkacon/opencms-core
|
src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java
|
CmsPatternPanelMonthlyView.addCheckBox
|
private void addCheckBox(final String internalValue, String labelMessageKey) {
CmsCheckBox box = new CmsCheckBox(Messages.get().key(labelMessageKey));
box.setInternalValue(internalValue);
box.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (handleChange()) {
m_controller.weeksChange(internalValue, event.getValue());
}
}
});
m_weekPanel.add(box);
m_checkboxes.add(box);
}
|
java
|
private void addCheckBox(final String internalValue, String labelMessageKey) {
CmsCheckBox box = new CmsCheckBox(Messages.get().key(labelMessageKey));
box.setInternalValue(internalValue);
box.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (handleChange()) {
m_controller.weeksChange(internalValue, event.getValue());
}
}
});
m_weekPanel.add(box);
m_checkboxes.add(box);
}
|
[
"private",
"void",
"addCheckBox",
"(",
"final",
"String",
"internalValue",
",",
"String",
"labelMessageKey",
")",
"{",
"CmsCheckBox",
"box",
"=",
"new",
"CmsCheckBox",
"(",
"Messages",
".",
"get",
"(",
")",
".",
"key",
"(",
"labelMessageKey",
")",
")",
";",
"box",
".",
"setInternalValue",
"(",
"internalValue",
")",
";",
"box",
".",
"addValueChangeHandler",
"(",
"new",
"ValueChangeHandler",
"<",
"Boolean",
">",
"(",
")",
"{",
"public",
"void",
"onValueChange",
"(",
"ValueChangeEvent",
"<",
"Boolean",
">",
"event",
")",
"{",
"if",
"(",
"handleChange",
"(",
")",
")",
"{",
"m_controller",
".",
"weeksChange",
"(",
"internalValue",
",",
"event",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"m_weekPanel",
".",
"add",
"(",
"box",
")",
";",
"m_checkboxes",
".",
"add",
"(",
"box",
")",
";",
"}"
] |
Creates a check box and adds it to the week panel and the checkboxes.
@param internalValue the internal value of the checkbox
@param labelMessageKey key for the label of the checkbox
|
[
"Creates",
"a",
"check",
"box",
"and",
"adds",
"it",
"to",
"the",
"week",
"panel",
"and",
"the",
"checkboxes",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java#L295-L311
|
158,087
|
alkacon/opencms-core
|
src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java
|
CmsPatternPanelMonthlyView.checkExactlyTheWeeksCheckBoxes
|
private void checkExactlyTheWeeksCheckBoxes(Collection<WeekOfMonth> weeksToCheck) {
for (CmsCheckBox cb : m_checkboxes) {
cb.setChecked(weeksToCheck.contains(WeekOfMonth.valueOf(cb.getInternalValue())));
}
}
|
java
|
private void checkExactlyTheWeeksCheckBoxes(Collection<WeekOfMonth> weeksToCheck) {
for (CmsCheckBox cb : m_checkboxes) {
cb.setChecked(weeksToCheck.contains(WeekOfMonth.valueOf(cb.getInternalValue())));
}
}
|
[
"private",
"void",
"checkExactlyTheWeeksCheckBoxes",
"(",
"Collection",
"<",
"WeekOfMonth",
">",
"weeksToCheck",
")",
"{",
"for",
"(",
"CmsCheckBox",
"cb",
":",
"m_checkboxes",
")",
"{",
"cb",
".",
"setChecked",
"(",
"weeksToCheck",
".",
"contains",
"(",
"WeekOfMonth",
".",
"valueOf",
"(",
"cb",
".",
"getInternalValue",
"(",
")",
")",
")",
")",
";",
"}",
"}"
] |
Check exactly the week check-boxes representing the given weeks.
@param weeksToCheck the weeks selected.
|
[
"Check",
"exactly",
"the",
"week",
"check",
"-",
"boxes",
"representing",
"the",
"given",
"weeks",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java#L317-L322
|
158,088
|
alkacon/opencms-core
|
src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java
|
CmsPatternPanelMonthlyView.fillWeekPanel
|
private void fillWeekPanel() {
addCheckBox(WeekOfMonth.FIRST.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_1_0);
addCheckBox(WeekOfMonth.SECOND.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_2_0);
addCheckBox(WeekOfMonth.THIRD.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_3_0);
addCheckBox(WeekOfMonth.FOURTH.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_4_0);
addCheckBox(WeekOfMonth.LAST.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_5_0);
}
|
java
|
private void fillWeekPanel() {
addCheckBox(WeekOfMonth.FIRST.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_1_0);
addCheckBox(WeekOfMonth.SECOND.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_2_0);
addCheckBox(WeekOfMonth.THIRD.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_3_0);
addCheckBox(WeekOfMonth.FOURTH.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_4_0);
addCheckBox(WeekOfMonth.LAST.toString(), Messages.GUI_SERIALDATE_WEEKDAYNUMBER_5_0);
}
|
[
"private",
"void",
"fillWeekPanel",
"(",
")",
"{",
"addCheckBox",
"(",
"WeekOfMonth",
".",
"FIRST",
".",
"toString",
"(",
")",
",",
"Messages",
".",
"GUI_SERIALDATE_WEEKDAYNUMBER_1_0",
")",
";",
"addCheckBox",
"(",
"WeekOfMonth",
".",
"SECOND",
".",
"toString",
"(",
")",
",",
"Messages",
".",
"GUI_SERIALDATE_WEEKDAYNUMBER_2_0",
")",
";",
"addCheckBox",
"(",
"WeekOfMonth",
".",
"THIRD",
".",
"toString",
"(",
")",
",",
"Messages",
".",
"GUI_SERIALDATE_WEEKDAYNUMBER_3_0",
")",
";",
"addCheckBox",
"(",
"WeekOfMonth",
".",
"FOURTH",
".",
"toString",
"(",
")",
",",
"Messages",
".",
"GUI_SERIALDATE_WEEKDAYNUMBER_4_0",
")",
";",
"addCheckBox",
"(",
"WeekOfMonth",
".",
"LAST",
".",
"toString",
"(",
")",
",",
"Messages",
".",
"GUI_SERIALDATE_WEEKDAYNUMBER_5_0",
")",
";",
"}"
] |
Fills the week panel with checkboxes.
|
[
"Fills",
"the",
"week",
"panel",
"with",
"checkboxes",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-gwt/org/opencms/acacia/client/widgets/serialdate/CmsPatternPanelMonthlyView.java#L327-L334
|
158,089
|
alkacon/opencms-core
|
src-setup/org/opencms/setup/ui/A_CmsSetupStep.java
|
A_CmsSetupStep.htmlLabel
|
public Label htmlLabel(String html) {
Label label = new Label();
label.setContentMode(ContentMode.HTML);
label.setValue(html);
return label;
}
|
java
|
public Label htmlLabel(String html) {
Label label = new Label();
label.setContentMode(ContentMode.HTML);
label.setValue(html);
return label;
}
|
[
"public",
"Label",
"htmlLabel",
"(",
"String",
"html",
")",
"{",
"Label",
"label",
"=",
"new",
"Label",
"(",
")",
";",
"label",
".",
"setContentMode",
"(",
"ContentMode",
".",
"HTML",
")",
";",
"label",
".",
"setValue",
"(",
"html",
")",
";",
"return",
"label",
";",
"}"
] |
Creates a new HTML-formatted label with the given content.
@param html the label content
|
[
"Creates",
"a",
"new",
"HTML",
"-",
"formatted",
"label",
"with",
"the",
"given",
"content",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-setup/org/opencms/setup/ui/A_CmsSetupStep.java#L80-L87
|
158,090
|
alkacon/opencms-core
|
src-setup/org/opencms/setup/ui/A_CmsSetupStep.java
|
A_CmsSetupStep.readSnippet
|
public String readSnippet(String name) {
String path = CmsStringUtil.joinPaths(
m_context.getSetupBean().getWebAppRfsPath(),
CmsSetupBean.FOLDER_SETUP,
"html",
name);
try (InputStream stream = new FileInputStream(path)) {
byte[] data = CmsFileUtil.readFully(stream, false);
String result = new String(data, "UTF-8");
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
public String readSnippet(String name) {
String path = CmsStringUtil.joinPaths(
m_context.getSetupBean().getWebAppRfsPath(),
CmsSetupBean.FOLDER_SETUP,
"html",
name);
try (InputStream stream = new FileInputStream(path)) {
byte[] data = CmsFileUtil.readFully(stream, false);
String result = new String(data, "UTF-8");
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"String",
"readSnippet",
"(",
"String",
"name",
")",
"{",
"String",
"path",
"=",
"CmsStringUtil",
".",
"joinPaths",
"(",
"m_context",
".",
"getSetupBean",
"(",
")",
".",
"getWebAppRfsPath",
"(",
")",
",",
"CmsSetupBean",
".",
"FOLDER_SETUP",
",",
"\"html\"",
",",
"name",
")",
";",
"try",
"(",
"InputStream",
"stream",
"=",
"new",
"FileInputStream",
"(",
"path",
")",
")",
"{",
"byte",
"[",
"]",
"data",
"=",
"CmsFileUtil",
".",
"readFully",
"(",
"stream",
",",
"false",
")",
";",
"String",
"result",
"=",
"new",
"String",
"(",
"data",
",",
"\"UTF-8\"",
")",
";",
"return",
"result",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Reads an HTML snippet with the given name.
@return the HTML data
|
[
"Reads",
"an",
"HTML",
"snippet",
"with",
"the",
"given",
"name",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-setup/org/opencms/setup/ui/A_CmsSetupStep.java#L94-L108
|
158,091
|
alkacon/opencms-core
|
src/org/opencms/widgets/CmsAddFormatterWidget.java
|
CmsAddFormatterWidget.getSelectOptionValues
|
public static List<String> getSelectOptionValues(CmsObject cms, String rootPath, boolean allRemoved) {
try {
cms = OpenCms.initCmsObject(cms);
cms.getRequestContext().setSiteRoot("");
CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(cms, rootPath);
if (adeConfig.parent() != null) {
adeConfig = adeConfig.parent();
}
List<CmsSelectWidgetOption> options = getFormatterOptionsStatic(cms, adeConfig, rootPath, allRemoved);
List<CmsSelectWidgetOption> typeOptions = getTypeOptionsStatic(cms, adeConfig, allRemoved);
options.addAll(typeOptions);
List<String> result = new ArrayList<String>(options.size());
for (CmsSelectWidgetOption o : options) {
result.add(o.getValue());
}
return result;
} catch (CmsException e) {
// should never happen
LOG.error(e.getLocalizedMessage(), e);
return null;
}
}
|
java
|
public static List<String> getSelectOptionValues(CmsObject cms, String rootPath, boolean allRemoved) {
try {
cms = OpenCms.initCmsObject(cms);
cms.getRequestContext().setSiteRoot("");
CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(cms, rootPath);
if (adeConfig.parent() != null) {
adeConfig = adeConfig.parent();
}
List<CmsSelectWidgetOption> options = getFormatterOptionsStatic(cms, adeConfig, rootPath, allRemoved);
List<CmsSelectWidgetOption> typeOptions = getTypeOptionsStatic(cms, adeConfig, allRemoved);
options.addAll(typeOptions);
List<String> result = new ArrayList<String>(options.size());
for (CmsSelectWidgetOption o : options) {
result.add(o.getValue());
}
return result;
} catch (CmsException e) {
// should never happen
LOG.error(e.getLocalizedMessage(), e);
return null;
}
}
|
[
"public",
"static",
"List",
"<",
"String",
">",
"getSelectOptionValues",
"(",
"CmsObject",
"cms",
",",
"String",
"rootPath",
",",
"boolean",
"allRemoved",
")",
"{",
"try",
"{",
"cms",
"=",
"OpenCms",
".",
"initCmsObject",
"(",
"cms",
")",
";",
"cms",
".",
"getRequestContext",
"(",
")",
".",
"setSiteRoot",
"(",
"\"\"",
")",
";",
"CmsADEConfigData",
"adeConfig",
"=",
"OpenCms",
".",
"getADEManager",
"(",
")",
".",
"lookupConfiguration",
"(",
"cms",
",",
"rootPath",
")",
";",
"if",
"(",
"adeConfig",
".",
"parent",
"(",
")",
"!=",
"null",
")",
"{",
"adeConfig",
"=",
"adeConfig",
".",
"parent",
"(",
")",
";",
"}",
"List",
"<",
"CmsSelectWidgetOption",
">",
"options",
"=",
"getFormatterOptionsStatic",
"(",
"cms",
",",
"adeConfig",
",",
"rootPath",
",",
"allRemoved",
")",
";",
"List",
"<",
"CmsSelectWidgetOption",
">",
"typeOptions",
"=",
"getTypeOptionsStatic",
"(",
"cms",
",",
"adeConfig",
",",
"allRemoved",
")",
";",
"options",
".",
"addAll",
"(",
"typeOptions",
")",
";",
"List",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"options",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"CmsSelectWidgetOption",
"o",
":",
"options",
")",
"{",
"result",
".",
"add",
"(",
"o",
".",
"getValue",
"(",
")",
")",
";",
"}",
"return",
"result",
";",
"}",
"catch",
"(",
"CmsException",
"e",
")",
"{",
"// should never happen",
"LOG",
".",
"error",
"(",
"e",
".",
"getLocalizedMessage",
"(",
")",
",",
"e",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
Returns all values that can be selected in the widget.
@param cms the current CMS object
@param rootPath the root path to the currently edited xml file (sitemap config)
@param allRemoved flag, indicating if all inheritedly available formatters should be disabled
@return all values that can be selected in the widget.
|
[
"Returns",
"all",
"values",
"that",
"can",
"be",
"selected",
"in",
"the",
"widget",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/widgets/CmsAddFormatterWidget.java#L85-L109
|
158,092
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.addRow
|
public void addRow(Component component) {
Component actualComponent = component == null ? m_newComponentFactory.get() : component;
I_CmsEditableGroupRow row = m_rowBuilder.buildRow(this, actualComponent);
m_container.addComponent(row);
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
java
|
public void addRow(Component component) {
Component actualComponent = component == null ? m_newComponentFactory.get() : component;
I_CmsEditableGroupRow row = m_rowBuilder.buildRow(this, actualComponent);
m_container.addComponent(row);
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
[
"public",
"void",
"addRow",
"(",
"Component",
"component",
")",
"{",
"Component",
"actualComponent",
"=",
"component",
"==",
"null",
"?",
"m_newComponentFactory",
".",
"get",
"(",
")",
":",
"component",
";",
"I_CmsEditableGroupRow",
"row",
"=",
"m_rowBuilder",
".",
"buildRow",
"(",
"this",
",",
"actualComponent",
")",
";",
"m_container",
".",
"addComponent",
"(",
"row",
")",
";",
"updatePlaceholder",
"(",
")",
";",
"updateButtonBars",
"(",
")",
";",
"updateGroupValidation",
"(",
")",
";",
"}"
] |
Adds a row for the given component at the end of the group.
@param component the component to wrap in the row to be added
|
[
"Adds",
"a",
"row",
"for",
"the",
"given",
"component",
"at",
"the",
"end",
"of",
"the",
"group",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L251-L259
|
158,093
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.addRowAfter
|
public void addRowAfter(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index >= 0) {
Component component = m_newComponentFactory.get();
I_CmsEditableGroupRow newRow = m_rowBuilder.buildRow(this, component);
m_container.addComponent(newRow, index + 1);
}
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
java
|
public void addRowAfter(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index >= 0) {
Component component = m_newComponentFactory.get();
I_CmsEditableGroupRow newRow = m_rowBuilder.buildRow(this, component);
m_container.addComponent(newRow, index + 1);
}
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
[
"public",
"void",
"addRowAfter",
"(",
"I_CmsEditableGroupRow",
"row",
")",
"{",
"int",
"index",
"=",
"m_container",
".",
"getComponentIndex",
"(",
"row",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"Component",
"component",
"=",
"m_newComponentFactory",
".",
"get",
"(",
")",
";",
"I_CmsEditableGroupRow",
"newRow",
"=",
"m_rowBuilder",
".",
"buildRow",
"(",
"this",
",",
"component",
")",
";",
"m_container",
".",
"addComponent",
"(",
"newRow",
",",
"index",
"+",
"1",
")",
";",
"}",
"updatePlaceholder",
"(",
")",
";",
"updateButtonBars",
"(",
")",
";",
"updateGroupValidation",
"(",
")",
";",
"}"
] |
Adds a new row after the given one.
@param row the row after which a new one should be added
|
[
"Adds",
"a",
"new",
"row",
"after",
"the",
"given",
"one",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L266-L277
|
158,094
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.getRows
|
public List<I_CmsEditableGroupRow> getRows() {
List<I_CmsEditableGroupRow> result = Lists.newArrayList();
for (Component component : m_container) {
if (component instanceof I_CmsEditableGroupRow) {
result.add((I_CmsEditableGroupRow)component);
}
}
return result;
}
|
java
|
public List<I_CmsEditableGroupRow> getRows() {
List<I_CmsEditableGroupRow> result = Lists.newArrayList();
for (Component component : m_container) {
if (component instanceof I_CmsEditableGroupRow) {
result.add((I_CmsEditableGroupRow)component);
}
}
return result;
}
|
[
"public",
"List",
"<",
"I_CmsEditableGroupRow",
">",
"getRows",
"(",
")",
"{",
"List",
"<",
"I_CmsEditableGroupRow",
">",
"result",
"=",
"Lists",
".",
"newArrayList",
"(",
")",
";",
"for",
"(",
"Component",
"component",
":",
"m_container",
")",
"{",
"if",
"(",
"component",
"instanceof",
"I_CmsEditableGroupRow",
")",
"{",
"result",
".",
"add",
"(",
"(",
"I_CmsEditableGroupRow",
")",
"component",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Gets all rows.
@return the list of all rows
|
[
"Gets",
"all",
"rows",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L324-L333
|
158,095
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.moveDown
|
public void moveDown(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if ((index >= 0) && (index < (m_container.getComponentCount() - 1))) {
m_container.removeComponent(row);
m_container.addComponent(row, index + 1);
}
updateButtonBars();
}
|
java
|
public void moveDown(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if ((index >= 0) && (index < (m_container.getComponentCount() - 1))) {
m_container.removeComponent(row);
m_container.addComponent(row, index + 1);
}
updateButtonBars();
}
|
[
"public",
"void",
"moveDown",
"(",
"I_CmsEditableGroupRow",
"row",
")",
"{",
"int",
"index",
"=",
"m_container",
".",
"getComponentIndex",
"(",
"row",
")",
";",
"if",
"(",
"(",
"index",
">=",
"0",
")",
"&&",
"(",
"index",
"<",
"(",
"m_container",
".",
"getComponentCount",
"(",
")",
"-",
"1",
")",
")",
")",
"{",
"m_container",
".",
"removeComponent",
"(",
"row",
")",
";",
"m_container",
".",
"addComponent",
"(",
"row",
",",
"index",
"+",
"1",
")",
";",
"}",
"updateButtonBars",
"(",
")",
";",
"}"
] |
Moves the given row down.
@param row the row to move
|
[
"Moves",
"the",
"given",
"row",
"down",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L350-L358
|
158,096
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.moveUp
|
public void moveUp(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index > 0) {
m_container.removeComponent(row);
m_container.addComponent(row, index - 1);
}
updateButtonBars();
}
|
java
|
public void moveUp(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index > 0) {
m_container.removeComponent(row);
m_container.addComponent(row, index - 1);
}
updateButtonBars();
}
|
[
"public",
"void",
"moveUp",
"(",
"I_CmsEditableGroupRow",
"row",
")",
"{",
"int",
"index",
"=",
"m_container",
".",
"getComponentIndex",
"(",
"row",
")",
";",
"if",
"(",
"index",
">",
"0",
")",
"{",
"m_container",
".",
"removeComponent",
"(",
"row",
")",
";",
"m_container",
".",
"addComponent",
"(",
"row",
",",
"index",
"-",
"1",
")",
";",
"}",
"updateButtonBars",
"(",
")",
";",
"}"
] |
Moves the given row up.
@param row the row to move
|
[
"Moves",
"the",
"given",
"row",
"up",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L365-L373
|
158,097
|
alkacon/opencms-core
|
src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java
|
CmsEditableGroup.remove
|
public void remove(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index >= 0) {
m_container.removeComponent(row);
}
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
java
|
public void remove(I_CmsEditableGroupRow row) {
int index = m_container.getComponentIndex(row);
if (index >= 0) {
m_container.removeComponent(row);
}
updatePlaceholder();
updateButtonBars();
updateGroupValidation();
}
|
[
"public",
"void",
"remove",
"(",
"I_CmsEditableGroupRow",
"row",
")",
"{",
"int",
"index",
"=",
"m_container",
".",
"getComponentIndex",
"(",
"row",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"m_container",
".",
"removeComponent",
"(",
"row",
")",
";",
"}",
"updatePlaceholder",
"(",
")",
";",
"updateButtonBars",
"(",
")",
";",
"updateGroupValidation",
"(",
")",
";",
"}"
] |
Removes the given row.
@param row the row to remove
|
[
"Removes",
"the",
"given",
"row",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/ui/components/editablegroup/CmsEditableGroup.java#L380-L389
|
158,098
|
alkacon/opencms-core
|
src/org/opencms/file/CmsObject.java
|
CmsObject.adjustLinks
|
public void adjustLinks(String sourceFolder, String targetFolder) throws CmsException {
String rootSourceFolder = addSiteRoot(sourceFolder);
String rootTargetFolder = addSiteRoot(targetFolder);
String siteRoot = getRequestContext().getSiteRoot();
getRequestContext().setSiteRoot("");
try {
CmsLinkRewriter linkRewriter = new CmsLinkRewriter(this, rootSourceFolder, rootTargetFolder);
linkRewriter.rewriteLinks();
} finally {
getRequestContext().setSiteRoot(siteRoot);
}
}
|
java
|
public void adjustLinks(String sourceFolder, String targetFolder) throws CmsException {
String rootSourceFolder = addSiteRoot(sourceFolder);
String rootTargetFolder = addSiteRoot(targetFolder);
String siteRoot = getRequestContext().getSiteRoot();
getRequestContext().setSiteRoot("");
try {
CmsLinkRewriter linkRewriter = new CmsLinkRewriter(this, rootSourceFolder, rootTargetFolder);
linkRewriter.rewriteLinks();
} finally {
getRequestContext().setSiteRoot(siteRoot);
}
}
|
[
"public",
"void",
"adjustLinks",
"(",
"String",
"sourceFolder",
",",
"String",
"targetFolder",
")",
"throws",
"CmsException",
"{",
"String",
"rootSourceFolder",
"=",
"addSiteRoot",
"(",
"sourceFolder",
")",
";",
"String",
"rootTargetFolder",
"=",
"addSiteRoot",
"(",
"targetFolder",
")",
";",
"String",
"siteRoot",
"=",
"getRequestContext",
"(",
")",
".",
"getSiteRoot",
"(",
")",
";",
"getRequestContext",
"(",
")",
".",
"setSiteRoot",
"(",
"\"\"",
")",
";",
"try",
"{",
"CmsLinkRewriter",
"linkRewriter",
"=",
"new",
"CmsLinkRewriter",
"(",
"this",
",",
"rootSourceFolder",
",",
"rootTargetFolder",
")",
";",
"linkRewriter",
".",
"rewriteLinks",
"(",
")",
";",
"}",
"finally",
"{",
"getRequestContext",
"(",
")",
".",
"setSiteRoot",
"(",
"siteRoot",
")",
";",
"}",
"}"
] |
Adjusts all links in the target folder that point to the source folder
so that they are kept "relative" in the target folder where possible.
If a link is found from the target folder to the source folder,
then the target folder is checked if a target of the same name
is found also "relative" inside the target Folder, and if so,
the link is changed to that "relative" target. This is mainly used to keep
relative links inside a copied folder structure intact.
Example: Image we have folder /folderA/ that contains files
/folderA/x1 and /folderA/y1. x1 has a link to y1 and y1 to x1.
Now someone copies /folderA/ to /folderB/. So we end up with
/folderB/x2 and /folderB/y2. Because of the link mechanism in OpenCms,
x2 will have a link to y1 and y2 to x1. By using this method,
the links from x2 to y1 will be replaced by a link x2 to y2,
and y2 to x1 with y2 to x2.
Link replacement works for links in XML files as well as relation only
type links.
@param sourceFolder the source folder
@param targetFolder the target folder
@throws CmsException if something goes wrong
|
[
"Adjusts",
"all",
"links",
"in",
"the",
"target",
"folder",
"that",
"point",
"to",
"the",
"source",
"folder",
"so",
"that",
"they",
"are",
"kept",
"relative",
"in",
"the",
"target",
"folder",
"where",
"possible",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src/org/opencms/file/CmsObject.java#L253-L265
|
158,099
|
alkacon/opencms-core
|
src-gwt/org/opencms/gwt/client/ui/input/colorpicker/CmsColorSelector.java
|
CmsColorSelector.setRGB
|
public void setRGB(int red, int green, int blue) throws Exception {
CmsColor color = new CmsColor();
color.setRGB(red, green, blue);
m_red = red;
m_green = green;
m_blue = blue;
m_hue = color.getHue();
m_saturation = color.getSaturation();
m_brightness = color.getValue();
m_tbRed.setText(Integer.toString(m_red));
m_tbGreen.setText(Integer.toString(m_green));
m_tbBlue.setText(Integer.toString(m_blue));
m_tbHue.setText(Integer.toString(m_hue));
m_tbSaturation.setText(Integer.toString(m_saturation));
m_tbBrightness.setText(Integer.toString(m_brightness));
m_tbHexColor.setText(color.getHex());
setPreview(color.getHex());
updateSliders();
}
|
java
|
public void setRGB(int red, int green, int blue) throws Exception {
CmsColor color = new CmsColor();
color.setRGB(red, green, blue);
m_red = red;
m_green = green;
m_blue = blue;
m_hue = color.getHue();
m_saturation = color.getSaturation();
m_brightness = color.getValue();
m_tbRed.setText(Integer.toString(m_red));
m_tbGreen.setText(Integer.toString(m_green));
m_tbBlue.setText(Integer.toString(m_blue));
m_tbHue.setText(Integer.toString(m_hue));
m_tbSaturation.setText(Integer.toString(m_saturation));
m_tbBrightness.setText(Integer.toString(m_brightness));
m_tbHexColor.setText(color.getHex());
setPreview(color.getHex());
updateSliders();
}
|
[
"public",
"void",
"setRGB",
"(",
"int",
"red",
",",
"int",
"green",
",",
"int",
"blue",
")",
"throws",
"Exception",
"{",
"CmsColor",
"color",
"=",
"new",
"CmsColor",
"(",
")",
";",
"color",
".",
"setRGB",
"(",
"red",
",",
"green",
",",
"blue",
")",
";",
"m_red",
"=",
"red",
";",
"m_green",
"=",
"green",
";",
"m_blue",
"=",
"blue",
";",
"m_hue",
"=",
"color",
".",
"getHue",
"(",
")",
";",
"m_saturation",
"=",
"color",
".",
"getSaturation",
"(",
")",
";",
"m_brightness",
"=",
"color",
".",
"getValue",
"(",
")",
";",
"m_tbRed",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_red",
")",
")",
";",
"m_tbGreen",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_green",
")",
")",
";",
"m_tbBlue",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_blue",
")",
")",
";",
"m_tbHue",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_hue",
")",
")",
";",
"m_tbSaturation",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_saturation",
")",
")",
";",
"m_tbBrightness",
".",
"setText",
"(",
"Integer",
".",
"toString",
"(",
"m_brightness",
")",
")",
";",
"m_tbHexColor",
".",
"setText",
"(",
"color",
".",
"getHex",
"(",
")",
")",
";",
"setPreview",
"(",
"color",
".",
"getHex",
"(",
")",
")",
";",
"updateSliders",
"(",
")",
";",
"}"
] |
Sets the Red, Green, and Blue color variables. This will automatically populate the Hue, Saturation and Brightness and Hexadecimal fields, too.
The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.
@param red strength - valid range is 0-255
@param green strength - valid range is 0-255
@param blue strength - valid range is 0-255
@throws java.lang.Exception Exception if the Red, Green or Blue variables are out of range.
|
[
"Sets",
"the",
"Red",
"Green",
"and",
"Blue",
"color",
"variables",
".",
"This",
"will",
"automatically",
"populate",
"the",
"Hue",
"Saturation",
"and",
"Brightness",
"and",
"Hexadecimal",
"fields",
"too",
"."
] |
bc104acc75d2277df5864da939a1f2de5fdee504
|
https://github.com/alkacon/opencms-core/blob/bc104acc75d2277df5864da939a1f2de5fdee504/src-gwt/org/opencms/gwt/client/ui/input/colorpicker/CmsColorSelector.java#L787-L809
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.