repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
johnlcox/motif | motif/src/main/java/com/leacox/motif/matching/FluentMatchingR.java | FluentMatchingR.getMatch | public R getMatch() {
for (Pattern<T, R> pattern : patterns) {
if (pattern.matches(value)) {
return pattern.apply(value);
}
}
throw new MatchException("No match found for " + value);
} | java | public R getMatch() {
for (Pattern<T, R> pattern : patterns) {
if (pattern.matches(value)) {
return pattern.apply(value);
}
}
throw new MatchException("No match found for " + value);
} | [
"public",
"R",
"getMatch",
"(",
")",
"{",
"for",
"(",
"Pattern",
"<",
"T",
",",
"R",
">",
"pattern",
":",
"patterns",
")",
"{",
"if",
"(",
"pattern",
".",
"matches",
"(",
"value",
")",
")",
"{",
"return",
"pattern",
".",
"apply",
"(",
"value",
")... | Runs through the possible matches and executes the specified action of the first match and
returns the result.
@throws MatchException if no match is found. | [
"Runs",
"through",
"the",
"possible",
"matches",
"and",
"executes",
"the",
"specified",
"action",
"of",
"the",
"first",
"match",
"and",
"returns",
"the",
"result",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/motif/src/main/java/com/leacox/motif/matching/FluentMatchingR.java#L115-L123 | train |
opentelecoms-org/zrtp-java | src/zorg/platform/blackberry/BBRandomGenerator.java | BBRandomGenerator.seedUsingPcmAudio | public void seedUsingPcmAudio(byte[] data) {
byte[] key = new byte[64];
for (int i = 0; i < key.length; i++) {
int x = 0;
//Pick 4 random bytes from the PCM audio data, from each of the bytes
//take the two least significant bits and concatenate them to form
//the i-th byte in the seed key
for (int j = 0; j < 4; j++) {
x = (x << 2) | (3 & data[RandomSource.getInt(data.length)]);
}
key[i] = (byte) x;
}
seed(key);
initialized = true;
} | java | public void seedUsingPcmAudio(byte[] data) {
byte[] key = new byte[64];
for (int i = 0; i < key.length; i++) {
int x = 0;
//Pick 4 random bytes from the PCM audio data, from each of the bytes
//take the two least significant bits and concatenate them to form
//the i-th byte in the seed key
for (int j = 0; j < 4; j++) {
x = (x << 2) | (3 & data[RandomSource.getInt(data.length)]);
}
key[i] = (byte) x;
}
seed(key);
initialized = true;
} | [
"public",
"void",
"seedUsingPcmAudio",
"(",
"byte",
"[",
"]",
"data",
")",
"{",
"byte",
"[",
"]",
"key",
"=",
"new",
"byte",
"[",
"64",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"key",
".",
"length",
";",
"i",
"++",
")",
"{",... | Seed the random generator with 2 least significant bits of randomly picked
bytes within the provided PCM audio data
@param data PCM audio data | [
"Seed",
"the",
"random",
"generator",
"with",
"2",
"least",
"significant",
"bits",
"of",
"randomly",
"picked",
"bytes",
"within",
"the",
"provided",
"PCM",
"audio",
"data"
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/platform/blackberry/BBRandomGenerator.java#L63-L77 | train |
opentelecoms-org/zrtp-java | src/zorg/platform/blackberry/BBRandomGenerator.java | BBRandomGenerator.getInt | public int getInt() {
try {
byte[] rand = fipsGenerator.getBytes(4);
int result = rand[0];
for (int i = 1; i < 4; i++) {
result = (result << 8) | rand[i];
}
return result;
} catch (Throwable ex) {
BBPlatform.getPlatform().getLogger().logException("RandomGenerator.getInt() Falling back to RandomSource " + ex.getMessage());
return RandomSource.getInt();
}
} | java | public int getInt() {
try {
byte[] rand = fipsGenerator.getBytes(4);
int result = rand[0];
for (int i = 1; i < 4; i++) {
result = (result << 8) | rand[i];
}
return result;
} catch (Throwable ex) {
BBPlatform.getPlatform().getLogger().logException("RandomGenerator.getInt() Falling back to RandomSource " + ex.getMessage());
return RandomSource.getInt();
}
} | [
"public",
"int",
"getInt",
"(",
")",
"{",
"try",
"{",
"byte",
"[",
"]",
"rand",
"=",
"fipsGenerator",
".",
"getBytes",
"(",
"4",
")",
";",
"int",
"result",
"=",
"rand",
"[",
"0",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"4",... | Returns a random integer
@return A random value of type int | [
"Returns",
"a",
"random",
"integer"
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/platform/blackberry/BBRandomGenerator.java#L94-L106 | train |
opentelecoms-org/zrtp-java | src/zorg/platform/blackberry/BBRandomGenerator.java | BBRandomGenerator.getBytes | public void getBytes(byte[] buffer) {
try {
fipsGenerator.getBytes(buffer);
} catch (Throwable ex) {
BBPlatform.getPlatform().getLogger().logException("RandomGenerator.getBytes() Falling back to RandomSource... " + ex.getMessage());
RandomSource.getBytes(buffer);
}
} | java | public void getBytes(byte[] buffer) {
try {
fipsGenerator.getBytes(buffer);
} catch (Throwable ex) {
BBPlatform.getPlatform().getLogger().logException("RandomGenerator.getBytes() Falling back to RandomSource... " + ex.getMessage());
RandomSource.getBytes(buffer);
}
} | [
"public",
"void",
"getBytes",
"(",
"byte",
"[",
"]",
"buffer",
")",
"{",
"try",
"{",
"fipsGenerator",
".",
"getBytes",
"(",
"buffer",
")",
";",
"}",
"catch",
"(",
"Throwable",
"ex",
")",
"{",
"BBPlatform",
".",
"getPlatform",
"(",
")",
".",
"getLogger"... | Generates random bytes filling the given buffer entirely
@param buffer The byte array to fill with random bytes | [
"Generates",
"random",
"bytes",
"filling",
"the",
"given",
"buffer",
"entirely"
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/platform/blackberry/BBRandomGenerator.java#L113-L120 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Path.java | Path.checkBuf | protected void checkBuf (int pointCount, boolean checkMove) {
if (checkMove && typeSize == 0) {
throw new IllegalPathStateException("First segment must be a SEG_MOVETO");
}
if (typeSize == types.length) {
byte[] tmp = new byte[typeSize + BUFFER_CAPACITY];
System.arraycopy(types, 0, tmp, 0, typeSize);
types = tmp;
}
if (pointSize + pointCount > points.length) {
float[] tmp = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)];
System.arraycopy(points, 0, tmp, 0, pointSize);
points = tmp;
}
} | java | protected void checkBuf (int pointCount, boolean checkMove) {
if (checkMove && typeSize == 0) {
throw new IllegalPathStateException("First segment must be a SEG_MOVETO");
}
if (typeSize == types.length) {
byte[] tmp = new byte[typeSize + BUFFER_CAPACITY];
System.arraycopy(types, 0, tmp, 0, typeSize);
types = tmp;
}
if (pointSize + pointCount > points.length) {
float[] tmp = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)];
System.arraycopy(points, 0, tmp, 0, pointSize);
points = tmp;
}
} | [
"protected",
"void",
"checkBuf",
"(",
"int",
"pointCount",
",",
"boolean",
"checkMove",
")",
"{",
"if",
"(",
"checkMove",
"&&",
"typeSize",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalPathStateException",
"(",
"\"First segment must be a SEG_MOVETO\"",
")",
";",
... | Checks points and types buffer size to add pointCount points. If necessary realloc buffers
to enlarge size.
@param pointCount the point count to be added in buffer | [
"Checks",
"points",
"and",
"types",
"buffer",
"size",
"to",
"add",
"pointCount",
"points",
".",
"If",
"necessary",
"realloc",
"buffers",
"to",
"enlarge",
"size",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Path.java#L264-L278 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Path.java | Path.isInside | protected boolean isInside (int cross) {
return (rule == WIND_NON_ZERO) ? Crossing.isInsideNonZero(cross) :
Crossing.isInsideEvenOdd(cross);
} | java | protected boolean isInside (int cross) {
return (rule == WIND_NON_ZERO) ? Crossing.isInsideNonZero(cross) :
Crossing.isInsideEvenOdd(cross);
} | [
"protected",
"boolean",
"isInside",
"(",
"int",
"cross",
")",
"{",
"return",
"(",
"rule",
"==",
"WIND_NON_ZERO",
")",
"?",
"Crossing",
".",
"isInsideNonZero",
"(",
"cross",
")",
":",
"Crossing",
".",
"isInsideEvenOdd",
"(",
"cross",
")",
";",
"}"
] | Checks cross count according to path rule to define is it point inside shape or not.
@param cross the point cross count.
@return true if point is inside path, or false otherwise. | [
"Checks",
"cross",
"count",
"according",
"to",
"path",
"rule",
"to",
"define",
"is",
"it",
"point",
"inside",
"shape",
"or",
"not",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Path.java#L286-L289 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/GeometryUtil.java | GeometryUtil.subQuad | public static void subQuad (double[] coef, double t0, boolean left) {
if (left) {
coef[2] = (1 - t0) * coef[0] + t0 * coef[2];
coef[3] = (1 - t0) * coef[1] + t0 * coef[3];
} else {
coef[2] = (1 - t0) * coef[2] + t0 * coef[4];
coef[3] = (1 - t0) * coef[3] + t0 * coef[5];
}
} | java | public static void subQuad (double[] coef, double t0, boolean left) {
if (left) {
coef[2] = (1 - t0) * coef[0] + t0 * coef[2];
coef[3] = (1 - t0) * coef[1] + t0 * coef[3];
} else {
coef[2] = (1 - t0) * coef[2] + t0 * coef[4];
coef[3] = (1 - t0) * coef[3] + t0 * coef[5];
}
} | [
"public",
"static",
"void",
"subQuad",
"(",
"double",
"[",
"]",
"coef",
",",
"double",
"t0",
",",
"boolean",
"left",
")",
"{",
"if",
"(",
"left",
")",
"{",
"coef",
"[",
"2",
"]",
"=",
"(",
"1",
"-",
"t0",
")",
"*",
"coef",
"[",
"0",
"]",
"+",... | t0 - ? | [
"t0",
"-",
"?"
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/GeometryUtil.java#L362-L370 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/ProbeHandlerThread.java | ProbeHandlerThread.sendResponse | private boolean sendResponse(String respondToURL, String payloadType, ResponseWrapper payload) {
// This method will likely need some thought and care in the error handling
// and error reporting
// It's a had job at the moment.
String responseStr = null;
String contentType = null; // MIME type
boolean success = true;
switch (payloadType) {
case "XML": {
responseStr = payload.toXML();
contentType = "application/xml";
break;
}
case "JSON": {
responseStr = payload.toJSON();
contentType = "application/json";
break;
}
default:
responseStr = payload.toJSON();
}
try {
HttpPost postRequest = new HttpPost(respondToURL);
StringEntity input = new StringEntity(responseStr);
input.setContentType(contentType);
postRequest.setEntity(input);
LOGGER.debug("Sending response");
LOGGER.debug("Response payload:");
LOGGER.debug(responseStr);
CloseableHttpResponse httpResponse = httpClient.execute(postRequest);
try {
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode > 300) {
throw new RuntimeException("Failed : HTTP error code : " + httpResponse.getStatusLine().getStatusCode());
}
if (statusCode != 204) {
BufferedReader br = new BufferedReader(new InputStreamReader((httpResponse.getEntity().getContent())));
LOGGER.debug("Successful response from response target - " + respondToURL);
String output;
LOGGER.debug("Output from Listener .... \n");
while ((output = br.readLine()) != null) {
LOGGER.debug(output);
}
br.close();
}
} finally {
httpResponse.close();
}
LOGGER.info("Successfully handled probeID: " + probe.getProbeId() + " sending response to: " + respondToURL);
} catch (MalformedURLException e) {
success = false;
LOGGER.error( "MalformedURLException occured for probeID [" + payload.getProbeID() + "]" + "\nThe respondTo URL was a no good. respondTo URL is: " + respondToURL);
} catch (IOException e) {
success = false;
LOGGER.error( "An IOException occured for probeID [" + payload.getProbeID() + "]" + " - " + e.getLocalizedMessage());
LOGGER.debug( "Stack trace for IOException for probeID [" + payload.getProbeID() + "]", e);
} catch (Exception e) {
success = false;
LOGGER.error( "Some other error occured for probeID [" + payload.getProbeID() + "]" + ". respondTo URL is: " + respondToURL + " - " + e.getLocalizedMessage());
LOGGER.debug( "Stack trace for probeID [" + payload.getProbeID() + "]", e);
}
return success;
} | java | private boolean sendResponse(String respondToURL, String payloadType, ResponseWrapper payload) {
// This method will likely need some thought and care in the error handling
// and error reporting
// It's a had job at the moment.
String responseStr = null;
String contentType = null; // MIME type
boolean success = true;
switch (payloadType) {
case "XML": {
responseStr = payload.toXML();
contentType = "application/xml";
break;
}
case "JSON": {
responseStr = payload.toJSON();
contentType = "application/json";
break;
}
default:
responseStr = payload.toJSON();
}
try {
HttpPost postRequest = new HttpPost(respondToURL);
StringEntity input = new StringEntity(responseStr);
input.setContentType(contentType);
postRequest.setEntity(input);
LOGGER.debug("Sending response");
LOGGER.debug("Response payload:");
LOGGER.debug(responseStr);
CloseableHttpResponse httpResponse = httpClient.execute(postRequest);
try {
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode > 300) {
throw new RuntimeException("Failed : HTTP error code : " + httpResponse.getStatusLine().getStatusCode());
}
if (statusCode != 204) {
BufferedReader br = new BufferedReader(new InputStreamReader((httpResponse.getEntity().getContent())));
LOGGER.debug("Successful response from response target - " + respondToURL);
String output;
LOGGER.debug("Output from Listener .... \n");
while ((output = br.readLine()) != null) {
LOGGER.debug(output);
}
br.close();
}
} finally {
httpResponse.close();
}
LOGGER.info("Successfully handled probeID: " + probe.getProbeId() + " sending response to: " + respondToURL);
} catch (MalformedURLException e) {
success = false;
LOGGER.error( "MalformedURLException occured for probeID [" + payload.getProbeID() + "]" + "\nThe respondTo URL was a no good. respondTo URL is: " + respondToURL);
} catch (IOException e) {
success = false;
LOGGER.error( "An IOException occured for probeID [" + payload.getProbeID() + "]" + " - " + e.getLocalizedMessage());
LOGGER.debug( "Stack trace for IOException for probeID [" + payload.getProbeID() + "]", e);
} catch (Exception e) {
success = false;
LOGGER.error( "Some other error occured for probeID [" + payload.getProbeID() + "]" + ". respondTo URL is: " + respondToURL + " - " + e.getLocalizedMessage());
LOGGER.debug( "Stack trace for probeID [" + payload.getProbeID() + "]", e);
}
return success;
} | [
"private",
"boolean",
"sendResponse",
"(",
"String",
"respondToURL",
",",
"String",
"payloadType",
",",
"ResponseWrapper",
"payload",
")",
"{",
"// This method will likely need some thought and care in the error handling",
"// and error reporting",
"// It's a had job at the moment.",... | If the probe yields responses from the handler, then send this method will
send the responses to the given respondTo addresses.
@param respondToURL - address to send the response to
@param payloadType - JSON or XML
@param payload - the actual service records to return
@return true if the send was successful | [
"If",
"the",
"probe",
"yields",
"responses",
"from",
"the",
"handler",
"then",
"send",
"this",
"method",
"will",
"send",
"the",
"responses",
"to",
"the",
"given",
"respondTo",
"addresses",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/ProbeHandlerThread.java#L94-L170 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/ProbeHandlerThread.java | ProbeHandlerThread.run | public void run() {
ResponseWrapper response = null;
LOGGER.info("Received probe id: " + probe.getProbeId());
// Only handle probes that we haven't handled before
// The Probe Generator needs to send a stream of identical UDP packets
// to compensate for UDP reliability issues. Therefore, the Responder
// will likely get more than 1 identical probe. We should ignore
// duplicates.
if (!isProbeHandled(probe.getProbeId())) {
if (this.noBrowser && probe.isNaked()) {
LOGGER.warn("Responder set to noBrowser mode. Discarding naked probe with id [" + probe.getProbeId() + "]");
} else {
for (ProbeHandlerPlugin handler : handlers) {
response = handler.handleProbeEvent(probe);
if (!response.isEmpty()) {
LOGGER.debug("Response to probe [" + probe.getProbeId() + "] includes " + response.numberOfServices());
Iterator<RespondToURL> respondToURLs = probe.getRespondToURLs().iterator();
if (probe.getRespondToURLs().isEmpty())
LOGGER.warn("Processed probe [" + probe.getProbeId() + "] with no respondTo address. That's odd.");
if (respondToURLs.hasNext()) {
RespondToURL respondToURL = respondToURLs.next();
// we are ignoring the label for now
boolean success = sendResponse(respondToURL.url, probe.getRespondToPayloadType(), response);
if (!success) {
LOGGER.warn("Issue sending probe [" + probe.getProbeId() + "] response to [" + respondToURL.url + "]");
}
}
} else {
LOGGER.error("Response to probe [" + probe.getProbeId() + "] is empty. Not sending empty response.");
}
}
}
markProbeAsHandled(probe.getProbeId());
responder.probeProcessed();
} else {
LOGGER.info("Discarding duplicate/handled probe with id: " + probe.getProbeId());
}
} | java | public void run() {
ResponseWrapper response = null;
LOGGER.info("Received probe id: " + probe.getProbeId());
// Only handle probes that we haven't handled before
// The Probe Generator needs to send a stream of identical UDP packets
// to compensate for UDP reliability issues. Therefore, the Responder
// will likely get more than 1 identical probe. We should ignore
// duplicates.
if (!isProbeHandled(probe.getProbeId())) {
if (this.noBrowser && probe.isNaked()) {
LOGGER.warn("Responder set to noBrowser mode. Discarding naked probe with id [" + probe.getProbeId() + "]");
} else {
for (ProbeHandlerPlugin handler : handlers) {
response = handler.handleProbeEvent(probe);
if (!response.isEmpty()) {
LOGGER.debug("Response to probe [" + probe.getProbeId() + "] includes " + response.numberOfServices());
Iterator<RespondToURL> respondToURLs = probe.getRespondToURLs().iterator();
if (probe.getRespondToURLs().isEmpty())
LOGGER.warn("Processed probe [" + probe.getProbeId() + "] with no respondTo address. That's odd.");
if (respondToURLs.hasNext()) {
RespondToURL respondToURL = respondToURLs.next();
// we are ignoring the label for now
boolean success = sendResponse(respondToURL.url, probe.getRespondToPayloadType(), response);
if (!success) {
LOGGER.warn("Issue sending probe [" + probe.getProbeId() + "] response to [" + respondToURL.url + "]");
}
}
} else {
LOGGER.error("Response to probe [" + probe.getProbeId() + "] is empty. Not sending empty response.");
}
}
}
markProbeAsHandled(probe.getProbeId());
responder.probeProcessed();
} else {
LOGGER.info("Discarding duplicate/handled probe with id: " + probe.getProbeId());
}
} | [
"public",
"void",
"run",
"(",
")",
"{",
"ResponseWrapper",
"response",
"=",
"null",
";",
"LOGGER",
".",
"info",
"(",
"\"Received probe id: \"",
"+",
"probe",
".",
"getProbeId",
"(",
")",
")",
";",
"// Only handle probes that we haven't handled before",
"// The Probe... | Handle the probe. | [
"Handle",
"the",
"probe",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/ProbeHandlerThread.java#L197-L246 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Crossing.java | Crossing.fixRoots | protected static int fixRoots (float[] res, int rc) {
int tc = 0;
for (int i = 0; i < rc; i++) {
out: {
for (int j = i + 1; j < rc; j++) {
if (isZero(res[i] - res[j])) {
break out;
}
}
res[tc++] = res[i];
}
}
return tc;
} | java | protected static int fixRoots (float[] res, int rc) {
int tc = 0;
for (int i = 0; i < rc; i++) {
out: {
for (int j = i + 1; j < rc; j++) {
if (isZero(res[i] - res[j])) {
break out;
}
}
res[tc++] = res[i];
}
}
return tc;
} | [
"protected",
"static",
"int",
"fixRoots",
"(",
"float",
"[",
"]",
"res",
",",
"int",
"rc",
")",
"{",
"int",
"tc",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"rc",
";",
"i",
"++",
")",
"{",
"out",
":",
"{",
"for",
"(",
... | Excludes double roots. Roots are double if they lies enough close with each other.
@param res the roots
@param rc the roots count
@return new roots count | [
"Excludes",
"double",
"roots",
".",
"Roots",
"are",
"double",
"if",
"they",
"lies",
"enough",
"close",
"with",
"each",
"other",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Crossing.java#L111-L124 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Crossing.java | Crossing.intersectQuad | public static int intersectQuad (float x1, float y1, float cx, float cy, float x2,
float y2, float rx1, float ry1, float rx2, float ry2) {
// LEFT/RIGHT/UP ------------------------------------------------------
if ((rx2 < x1 && rx2 < cx && rx2 < x2) || (rx1 > x1 && rx1 > cx && rx1 > x2) ||
(ry1 > y1 && ry1 > cy && ry1 > y2)) {
return 0;
}
// DOWN ---------------------------------------------------------------
if (ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2) {
if (x1 < x2) {
return x1 < rx1 && rx1 < x2 ? 1 : 0;
}
return x2 < rx1 && rx1 < x1 ? -1 : 0;
}
// INSIDE -------------------------------------------------------------
QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2);
float px1 = rx1 - x1;
float py1 = ry1 - y1;
float px2 = rx2 - x1;
float py2 = ry2 - y1;
float[] res1 = new float[3];
float[] res2 = new float[3];
int rc1 = c.solvePoint(res1, px1);
int rc2 = c.solvePoint(res2, px2);
// INSIDE-LEFT/RIGHT
if (rc1 == 0 && rc2 == 0) {
return 0;
}
// Build bound --------------------------------------------------------
float minX = px1 - DELTA;
float maxX = px2 + DELTA;
float[] bound = new float[28];
int bc = 0;
// Add roots
bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
// Add extremal points
rc2 = c.solveExtreme(res2);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
// Add start and end
if (rx1 < x1 && x1 < rx2) {
bound[bc++] = 0f;
bound[bc++] = 0f;
bound[bc++] = 0f;
bound[bc++] = 4;
}
if (rx1 < x2 && x2 < rx2) {
bound[bc++] = 1f;
bound[bc++] = c.ax;
bound[bc++] = c.ay;
bound[bc++] = 5;
}
// End build bound ----------------------------------------------------
int cross = crossBound(bound, bc, py1, py2);
if (cross != UNKNOWN) {
return cross;
}
return c.cross(res1, rc1, py1, py2);
} | java | public static int intersectQuad (float x1, float y1, float cx, float cy, float x2,
float y2, float rx1, float ry1, float rx2, float ry2) {
// LEFT/RIGHT/UP ------------------------------------------------------
if ((rx2 < x1 && rx2 < cx && rx2 < x2) || (rx1 > x1 && rx1 > cx && rx1 > x2) ||
(ry1 > y1 && ry1 > cy && ry1 > y2)) {
return 0;
}
// DOWN ---------------------------------------------------------------
if (ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2) {
if (x1 < x2) {
return x1 < rx1 && rx1 < x2 ? 1 : 0;
}
return x2 < rx1 && rx1 < x1 ? -1 : 0;
}
// INSIDE -------------------------------------------------------------
QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2);
float px1 = rx1 - x1;
float py1 = ry1 - y1;
float px2 = rx2 - x1;
float py2 = ry2 - y1;
float[] res1 = new float[3];
float[] res2 = new float[3];
int rc1 = c.solvePoint(res1, px1);
int rc2 = c.solvePoint(res2, px2);
// INSIDE-LEFT/RIGHT
if (rc1 == 0 && rc2 == 0) {
return 0;
}
// Build bound --------------------------------------------------------
float minX = px1 - DELTA;
float maxX = px2 + DELTA;
float[] bound = new float[28];
int bc = 0;
// Add roots
bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1);
// Add extremal points
rc2 = c.solveExtreme(res2);
bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2);
// Add start and end
if (rx1 < x1 && x1 < rx2) {
bound[bc++] = 0f;
bound[bc++] = 0f;
bound[bc++] = 0f;
bound[bc++] = 4;
}
if (rx1 < x2 && x2 < rx2) {
bound[bc++] = 1f;
bound[bc++] = c.ax;
bound[bc++] = c.ay;
bound[bc++] = 5;
}
// End build bound ----------------------------------------------------
int cross = crossBound(bound, bc, py1, py2);
if (cross != UNKNOWN) {
return cross;
}
return c.cross(res1, rc1, py1, py2);
} | [
"public",
"static",
"int",
"intersectQuad",
"(",
"float",
"x1",
",",
"float",
"y1",
",",
"float",
"cx",
",",
"float",
"cy",
",",
"float",
"x2",
",",
"float",
"y2",
",",
"float",
"rx1",
",",
"float",
"ry1",
",",
"float",
"rx2",
",",
"float",
"ry2",
... | Returns how many times rectangle stripe cross quad curve or the are
intersect | [
"Returns",
"how",
"many",
"times",
"rectangle",
"stripe",
"cross",
"quad",
"curve",
"or",
"the",
"are",
"intersect"
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Crossing.java#L557-L621 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Crossing.java | Crossing.intersectPath | public static int intersectPath (PathIterator p, float x, float y, float w, float h) {
int cross = 0;
int count;
float mx, my, cx, cy;
mx = my = cx = cy = 0f;
float[] coords = new float[6];
float rx1 = x;
float ry1 = y;
float rx2 = x + w;
float ry2 = y + h;
while (!p.isDone()) {
count = 0;
switch (p.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
if (cx != mx || cy != my) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
}
mx = cx = coords[0];
my = cy = coords[1];
break;
case PathIterator.SEG_LINETO:
count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_QUADTO:
count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3],
rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_CUBICTO:
count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3],
cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_CLOSE:
if (cy != my || cx != mx) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
}
cx = mx;
cy = my;
break;
}
if (count == CROSSING) {
return CROSSING;
}
cross += count;
p.next();
}
if (cy != my) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
if (count == CROSSING) {
return CROSSING;
}
cross += count;
}
return cross;
} | java | public static int intersectPath (PathIterator p, float x, float y, float w, float h) {
int cross = 0;
int count;
float mx, my, cx, cy;
mx = my = cx = cy = 0f;
float[] coords = new float[6];
float rx1 = x;
float ry1 = y;
float rx2 = x + w;
float ry2 = y + h;
while (!p.isDone()) {
count = 0;
switch (p.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
if (cx != mx || cy != my) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
}
mx = cx = coords[0];
my = cy = coords[1];
break;
case PathIterator.SEG_LINETO:
count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_QUADTO:
count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3],
rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_CUBICTO:
count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3],
cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
break;
case PathIterator.SEG_CLOSE:
if (cy != my || cx != mx) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
}
cx = mx;
cy = my;
break;
}
if (count == CROSSING) {
return CROSSING;
}
cross += count;
p.next();
}
if (cy != my) {
count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
if (count == CROSSING) {
return CROSSING;
}
cross += count;
}
return cross;
} | [
"public",
"static",
"int",
"intersectPath",
"(",
"PathIterator",
"p",
",",
"float",
"x",
",",
"float",
"y",
",",
"float",
"w",
",",
"float",
"h",
")",
"{",
"int",
"cross",
"=",
"0",
";",
"int",
"count",
";",
"float",
"mx",
",",
"my",
",",
"cx",
"... | Returns how many times rectangle stripe cross path or the are intersect | [
"Returns",
"how",
"many",
"times",
"rectangle",
"stripe",
"cross",
"path",
"or",
"the",
"are",
"intersect"
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Crossing.java#L701-L756 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Crossing.java | Crossing.intersectShape | public static int intersectShape (IShape s, float x, float y, float w, float h) {
if (!s.bounds().intersects(x, y, w, h)) {
return 0;
}
return intersectPath(s.pathIterator(null), x, y, w, h);
} | java | public static int intersectShape (IShape s, float x, float y, float w, float h) {
if (!s.bounds().intersects(x, y, w, h)) {
return 0;
}
return intersectPath(s.pathIterator(null), x, y, w, h);
} | [
"public",
"static",
"int",
"intersectShape",
"(",
"IShape",
"s",
",",
"float",
"x",
",",
"float",
"y",
",",
"float",
"w",
",",
"float",
"h",
")",
"{",
"if",
"(",
"!",
"s",
".",
"bounds",
"(",
")",
".",
"intersects",
"(",
"x",
",",
"y",
",",
"w"... | Returns how many times rectangle stripe cross shape or the are intersect | [
"Returns",
"how",
"many",
"times",
"rectangle",
"stripe",
"cross",
"shape",
"or",
"the",
"are",
"intersect"
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Crossing.java#L761-L766 | train |
di2e/Argo | CommonUtils/src/main/java/ws/argo/common/cache/ExpiringService.java | ExpiringService.isExpired | public boolean isExpired() {
if (_service.getTtl() == 0) {
return false;
}
long t = this.cacheStartTime.getTime();
Date validTime = new Date(t + (_service.getTtl() * ONE_MINUTE_IN_MILLIS));
Date now = new Date();
return (now.getTime() > validTime.getTime());
} | java | public boolean isExpired() {
if (_service.getTtl() == 0) {
return false;
}
long t = this.cacheStartTime.getTime();
Date validTime = new Date(t + (_service.getTtl() * ONE_MINUTE_IN_MILLIS));
Date now = new Date();
return (now.getTime() > validTime.getTime());
} | [
"public",
"boolean",
"isExpired",
"(",
")",
"{",
"if",
"(",
"_service",
".",
"getTtl",
"(",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"long",
"t",
"=",
"this",
".",
"cacheStartTime",
".",
"getTime",
"(",
")",
";",
"Date",
"validTime",
... | Determine if the service record is expired. The service record include a
TTL that tells the client how many minutes the client can count on the
information in the service record. If the cache times out, then those
service records that have expired should be expunged from the cache.
@return true if the service record should be expired from the cache | [
"Determine",
"if",
"the",
"service",
"record",
"is",
"expired",
".",
"The",
"service",
"record",
"include",
"a",
"TTL",
"that",
"tells",
"the",
"client",
"how",
"many",
"minutes",
"the",
"client",
"can",
"count",
"on",
"the",
"information",
"in",
"the",
"s... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CommonUtils/src/main/java/ws/argo/common/cache/ExpiringService.java#L56-L65 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToTransform | public Matrix4 setToTransform (IVector3 translation, IQuaternion rotation) {
return setToRotation(rotation).setTranslation(translation);
} | java | public Matrix4 setToTransform (IVector3 translation, IQuaternion rotation) {
return setToRotation(rotation).setTranslation(translation);
} | [
"public",
"Matrix4",
"setToTransform",
"(",
"IVector3",
"translation",
",",
"IQuaternion",
"rotation",
")",
"{",
"return",
"setToRotation",
"(",
"rotation",
")",
".",
"setTranslation",
"(",
"translation",
")",
";",
"}"
] | Sets this to a matrix that first rotates, then translates.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"matrix",
"that",
"first",
"rotates",
"then",
"translates",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L103-L105 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToTranslation | public Matrix4 setToTranslation (IVector3 translation) {
return setToTranslation(translation.x(), translation.y(), translation.z());
} | java | public Matrix4 setToTranslation (IVector3 translation) {
return setToTranslation(translation.x(), translation.y(), translation.z());
} | [
"public",
"Matrix4",
"setToTranslation",
"(",
"IVector3",
"translation",
")",
"{",
"return",
"setToTranslation",
"(",
"translation",
".",
"x",
"(",
")",
",",
"translation",
".",
"y",
"(",
")",
",",
"translation",
".",
"z",
"(",
")",
")",
";",
"}"
] | Sets this to a translation matrix.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"translation",
"matrix",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L139-L141 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToRotationScale | public Matrix4 setToRotationScale (IMatrix3 rotScale) {
return set(rotScale.m00(), rotScale.m01(), rotScale.m02(), 0f,
rotScale.m10(), rotScale.m11(), rotScale.m12(), 0f,
rotScale.m20(), rotScale.m21(), rotScale.m22(), 0f,
0, 0, 0, 1);
} | java | public Matrix4 setToRotationScale (IMatrix3 rotScale) {
return set(rotScale.m00(), rotScale.m01(), rotScale.m02(), 0f,
rotScale.m10(), rotScale.m11(), rotScale.m12(), 0f,
rotScale.m20(), rotScale.m21(), rotScale.m22(), 0f,
0, 0, 0, 1);
} | [
"public",
"Matrix4",
"setToRotationScale",
"(",
"IMatrix3",
"rotScale",
")",
"{",
"return",
"set",
"(",
"rotScale",
".",
"m00",
"(",
")",
",",
"rotScale",
".",
"m01",
"(",
")",
",",
"rotScale",
".",
"m02",
"(",
")",
",",
"0f",
",",
"rotScale",
".",
"... | Sets this to a rotation plus scale matrix.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"rotation",
"plus",
"scale",
"matrix",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L243-L248 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToPerspective | public Matrix4 setToPerspective (double fovy, double aspect, double near, double far) {
double f = 1f / Math.tan(fovy / 2f), dscale = 1f / (near - far);
return set(f/aspect, 0f, 0f, 0f,
0f, f, 0f, 0f,
0f, 0f, (far+near) * dscale, 2f * far * near * dscale,
0f, 0f, -1f, 0f);
} | java | public Matrix4 setToPerspective (double fovy, double aspect, double near, double far) {
double f = 1f / Math.tan(fovy / 2f), dscale = 1f / (near - far);
return set(f/aspect, 0f, 0f, 0f,
0f, f, 0f, 0f,
0f, 0f, (far+near) * dscale, 2f * far * near * dscale,
0f, 0f, -1f, 0f);
} | [
"public",
"Matrix4",
"setToPerspective",
"(",
"double",
"fovy",
",",
"double",
"aspect",
",",
"double",
"near",
",",
"double",
"far",
")",
"{",
"double",
"f",
"=",
"1f",
"/",
"Math",
".",
"tan",
"(",
"fovy",
"/",
"2f",
")",
",",
"dscale",
"=",
"1f",
... | Sets this to a perspective projection matrix. The formula comes from the OpenGL
documentation for the gluPerspective function.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"perspective",
"projection",
"matrix",
".",
"The",
"formula",
"comes",
"from",
"the",
"OpenGL",
"documentation",
"for",
"the",
"gluPerspective",
"function",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L373-L379 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToFrustum | public Matrix4 setToFrustum (
double left, double right, double bottom, double top, double near, double far) {
return setToFrustum(left, right, bottom, top, near, far, Vector3.UNIT_Z);
} | java | public Matrix4 setToFrustum (
double left, double right, double bottom, double top, double near, double far) {
return setToFrustum(left, right, bottom, top, near, far, Vector3.UNIT_Z);
} | [
"public",
"Matrix4",
"setToFrustum",
"(",
"double",
"left",
",",
"double",
"right",
",",
"double",
"bottom",
",",
"double",
"top",
",",
"double",
"near",
",",
"double",
"far",
")",
"{",
"return",
"setToFrustum",
"(",
"left",
",",
"right",
",",
"bottom",
... | Sets this to a perspective projection matrix. The formula comes from the OpenGL
documentation for the glFrustum function.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"perspective",
"projection",
"matrix",
".",
"The",
"formula",
"comes",
"from",
"the",
"OpenGL",
"documentation",
"for",
"the",
"glFrustum",
"function",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L387-L390 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToFrustum | public Matrix4 setToFrustum (
double left, double right, double bottom, double top,
double near, double far, IVector3 nearFarNormal) {
double rrl = 1f / (right - left);
double rtb = 1f / (top - bottom);
double rnf = 1f / (near - far);
double n2 = 2f * near;
double s = (far + near) / (near*nearFarNormal.z() - far*nearFarNormal.z());
return set(n2 * rrl, 0f, (right + left) * rrl, 0f,
0f, n2 * rtb, (top + bottom) * rtb, 0f,
s * nearFarNormal.x(), s * nearFarNormal.y(), (far + near) * rnf, n2 * far * rnf,
0f, 0f, -1f, 0f);
} | java | public Matrix4 setToFrustum (
double left, double right, double bottom, double top,
double near, double far, IVector3 nearFarNormal) {
double rrl = 1f / (right - left);
double rtb = 1f / (top - bottom);
double rnf = 1f / (near - far);
double n2 = 2f * near;
double s = (far + near) / (near*nearFarNormal.z() - far*nearFarNormal.z());
return set(n2 * rrl, 0f, (right + left) * rrl, 0f,
0f, n2 * rtb, (top + bottom) * rtb, 0f,
s * nearFarNormal.x(), s * nearFarNormal.y(), (far + near) * rnf, n2 * far * rnf,
0f, 0f, -1f, 0f);
} | [
"public",
"Matrix4",
"setToFrustum",
"(",
"double",
"left",
",",
"double",
"right",
",",
"double",
"bottom",
",",
"double",
"top",
",",
"double",
"near",
",",
"double",
"far",
",",
"IVector3",
"nearFarNormal",
")",
"{",
"double",
"rrl",
"=",
"1f",
"/",
"... | Sets this to a perspective projection matrix.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"perspective",
"projection",
"matrix",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L397-L409 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Matrix4.java | Matrix4.setToOrtho | public Matrix4 setToOrtho (
double left, double right, double bottom, double top,
double near, double far, IVector3 nearFarNormal) {
double rlr = 1f / (left - right);
double rbt = 1f / (bottom - top);
double rnf = 1f / (near - far);
double s = 2f / (near*nearFarNormal.z() - far*nearFarNormal.z());
return set(-2f * rlr, 0f, 0f, (right + left) * rlr,
0f, -2f * rbt, 0f, (top + bottom) * rbt,
s * nearFarNormal.x(), s * nearFarNormal.y(), 2f * rnf, (far + near) * rnf,
0f, 0f, 0f, 1f);
} | java | public Matrix4 setToOrtho (
double left, double right, double bottom, double top,
double near, double far, IVector3 nearFarNormal) {
double rlr = 1f / (left - right);
double rbt = 1f / (bottom - top);
double rnf = 1f / (near - far);
double s = 2f / (near*nearFarNormal.z() - far*nearFarNormal.z());
return set(-2f * rlr, 0f, 0f, (right + left) * rlr,
0f, -2f * rbt, 0f, (top + bottom) * rbt,
s * nearFarNormal.x(), s * nearFarNormal.y(), 2f * rnf, (far + near) * rnf,
0f, 0f, 0f, 1f);
} | [
"public",
"Matrix4",
"setToOrtho",
"(",
"double",
"left",
",",
"double",
"right",
",",
"double",
"bottom",
",",
"double",
"top",
",",
"double",
"near",
",",
"double",
"far",
",",
"IVector3",
"nearFarNormal",
")",
"{",
"double",
"rlr",
"=",
"1f",
"/",
"("... | Sets this to an orthographic projection matrix.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"an",
"orthographic",
"projection",
"matrix",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Matrix4.java#L427-L438 | train |
samskivert/pythagoras | src/main/java/pythagoras/i/Points.java | Points.distanceSq | public static int distanceSq (int x1, int y1, int x2, int y2) {
x2 -= x1;
y2 -= y1;
return x2 * x2 + y2 * y2;
} | java | public static int distanceSq (int x1, int y1, int x2, int y2) {
x2 -= x1;
y2 -= y1;
return x2 * x2 + y2 * y2;
} | [
"public",
"static",
"int",
"distanceSq",
"(",
"int",
"x1",
",",
"int",
"y1",
",",
"int",
"x2",
",",
"int",
"y2",
")",
"{",
"x2",
"-=",
"x1",
";",
"y2",
"-=",
"y1",
";",
"return",
"x2",
"*",
"x2",
"+",
"y2",
"*",
"y2",
";",
"}"
] | Returns the squared Euclidian distance between the specified two points. | [
"Returns",
"the",
"squared",
"Euclidian",
"distance",
"between",
"the",
"specified",
"two",
"points",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/i/Points.java#L15-L19 | train |
samskivert/pythagoras | src/main/java/pythagoras/i/Points.java | Points.distance | public static int distance (int x1, int y1, int x2, int y2) {
return (int)Math.sqrt(distanceSq(x1, y1, x2, y2));
} | java | public static int distance (int x1, int y1, int x2, int y2) {
return (int)Math.sqrt(distanceSq(x1, y1, x2, y2));
} | [
"public",
"static",
"int",
"distance",
"(",
"int",
"x1",
",",
"int",
"y1",
",",
"int",
"x2",
",",
"int",
"y2",
")",
"{",
"return",
"(",
"int",
")",
"Math",
".",
"sqrt",
"(",
"distanceSq",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
")",
... | Returns the Euclidian distance between the specified two points, truncated to the nearest
integer. | [
"Returns",
"the",
"Euclidian",
"distance",
"between",
"the",
"specified",
"two",
"points",
"truncated",
"to",
"the",
"nearest",
"integer",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/i/Points.java#L25-L27 | train |
samskivert/pythagoras | src/main/java/pythagoras/i/Points.java | Points.manhattanDistance | public static int manhattanDistance (int x1, int y1, int x2, int y2)
{
return Math.abs(x2 - x1) + Math.abs(y2 - y1);
} | java | public static int manhattanDistance (int x1, int y1, int x2, int y2)
{
return Math.abs(x2 - x1) + Math.abs(y2 - y1);
} | [
"public",
"static",
"int",
"manhattanDistance",
"(",
"int",
"x1",
",",
"int",
"y1",
",",
"int",
"x2",
",",
"int",
"y2",
")",
"{",
"return",
"Math",
".",
"abs",
"(",
"x2",
"-",
"x1",
")",
"+",
"Math",
".",
"abs",
"(",
"y2",
"-",
"y1",
")",
";",
... | Returns the Manhattan distance between the specified two points. | [
"Returns",
"the",
"Manhattan",
"distance",
"between",
"the",
"specified",
"two",
"points",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/i/Points.java#L32-L35 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/MathUtil.java | MathUtil.roundNearest | public static double roundNearest (double v, double target) {
target = Math.abs(target);
if (v >= 0) {
return target * Math.floor((v + 0.5f * target) / target);
} else {
return target * Math.ceil((v - 0.5f * target) / target);
}
} | java | public static double roundNearest (double v, double target) {
target = Math.abs(target);
if (v >= 0) {
return target * Math.floor((v + 0.5f * target) / target);
} else {
return target * Math.ceil((v - 0.5f * target) / target);
}
} | [
"public",
"static",
"double",
"roundNearest",
"(",
"double",
"v",
",",
"double",
"target",
")",
"{",
"target",
"=",
"Math",
".",
"abs",
"(",
"target",
")",
";",
"if",
"(",
"v",
">=",
"0",
")",
"{",
"return",
"target",
"*",
"Math",
".",
"floor",
"("... | Rounds a value to the nearest multiple of a target. | [
"Rounds",
"a",
"value",
"to",
"the",
"nearest",
"multiple",
"of",
"a",
"target",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/MathUtil.java#L61-L68 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java | ProbeSender.sendProbe | public List<Probe> sendProbe(Probe probe) throws ProbeSenderException {
List<Probe> actualProbesToSend;
try {
actualProbesToSend = splitProbe(probe);
} catch (MalformedURLException | JAXBException | UnsupportedPayloadType e) {
throw new ProbeSenderException("Issue splitting the probe.", e);
}
for (Probe probeSegment : actualProbesToSend) {
// String payload
try {
probeTransport.sendProbe(probeSegment);
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return actualProbesToSend;
} | java | public List<Probe> sendProbe(Probe probe) throws ProbeSenderException {
List<Probe> actualProbesToSend;
try {
actualProbesToSend = splitProbe(probe);
} catch (MalformedURLException | JAXBException | UnsupportedPayloadType e) {
throw new ProbeSenderException("Issue splitting the probe.", e);
}
for (Probe probeSegment : actualProbesToSend) {
// String payload
try {
probeTransport.sendProbe(probeSegment);
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return actualProbesToSend;
} | [
"public",
"List",
"<",
"Probe",
">",
"sendProbe",
"(",
"Probe",
"probe",
")",
"throws",
"ProbeSenderException",
"{",
"List",
"<",
"Probe",
">",
"actualProbesToSend",
";",
"try",
"{",
"actualProbesToSend",
"=",
"splitProbe",
"(",
"probe",
")",
";",
"}",
"catc... | Send the probe. It will take the provided probe and then disassemble it
into a number of smaller probes based on the max payload size of the
transport provided.
@param probe the probe to send
@return the list of actual probes sent (which were created when the
provided probe was spit into smaller ones that complied with the
max payload size of the transport)
@throws ProbeSenderException if something goes wrong | [
"Send",
"the",
"probe",
".",
"It",
"will",
"take",
"the",
"provided",
"probe",
"and",
"then",
"disassemble",
"it",
"into",
"a",
"number",
"of",
"smaller",
"probes",
"based",
"on",
"the",
"max",
"payload",
"size",
"of",
"the",
"transport",
"provided",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java#L67-L88 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java | ProbeSender.splitProbe | private List<Probe> splitProbe(Probe probe) throws ProbeSenderException, JAXBException, MalformedURLException, UnsupportedPayloadType {
List<Probe> actualProbeList = new ArrayList<Probe>();
int maxPayloadSize = this.probeTransport.maxPayloadSize();
LinkedList<ProbeIdEntry> combinedList = probe.getCombinedIdentifierList();
// use a strategy to split up the probe into biggest possible chunks
// all respondTo address must be included - if that's a problem then throw
// an exception - the user will need to do some thinking.
// start by taking one siid or scid off put it into a temp probe, check the
// payload size of the probe and repeat until target probe is right size.
// put the target probe in the list, make the temp probe the target probe
// and start the process again.
// Not sure how to do this with wireline compression involved.
if (probe.asXML().length() < maxPayloadSize) {
actualProbeList.add(probe);
} else {
Probe frame = Probe.frameProbeFrom(probe);
Probe splitProbe = new Probe(frame);
int payloadLength = splitProbe.asXML().length();
ProbeIdEntry nextId = combinedList.peek();
if (payloadLength + nextId.getId().length() + 40 >= maxPayloadSize) {
throw new ProbeSenderException("Basic frame violates maxPayloadSize of transport. Likely due to too many respondTo address.");
}
while (!combinedList.isEmpty()) {
payloadLength = splitProbe.asXML().length();
nextId = combinedList.peek();
if (payloadLength + nextId.getId().length() + 40 >= maxPayloadSize) {
actualProbeList.add(splitProbe);
splitProbe = new Probe(frame);
}
ProbeIdEntry id = combinedList.pop();
switch (id.getType()) {
case "scid":
splitProbe.addServiceContractID(id.getId());
break;
case "siid":
splitProbe.addServiceInstanceID(id.getId());
break;
default:
break;
}
}
actualProbeList.add(splitProbe);
}
return actualProbeList;
} | java | private List<Probe> splitProbe(Probe probe) throws ProbeSenderException, JAXBException, MalformedURLException, UnsupportedPayloadType {
List<Probe> actualProbeList = new ArrayList<Probe>();
int maxPayloadSize = this.probeTransport.maxPayloadSize();
LinkedList<ProbeIdEntry> combinedList = probe.getCombinedIdentifierList();
// use a strategy to split up the probe into biggest possible chunks
// all respondTo address must be included - if that's a problem then throw
// an exception - the user will need to do some thinking.
// start by taking one siid or scid off put it into a temp probe, check the
// payload size of the probe and repeat until target probe is right size.
// put the target probe in the list, make the temp probe the target probe
// and start the process again.
// Not sure how to do this with wireline compression involved.
if (probe.asXML().length() < maxPayloadSize) {
actualProbeList.add(probe);
} else {
Probe frame = Probe.frameProbeFrom(probe);
Probe splitProbe = new Probe(frame);
int payloadLength = splitProbe.asXML().length();
ProbeIdEntry nextId = combinedList.peek();
if (payloadLength + nextId.getId().length() + 40 >= maxPayloadSize) {
throw new ProbeSenderException("Basic frame violates maxPayloadSize of transport. Likely due to too many respondTo address.");
}
while (!combinedList.isEmpty()) {
payloadLength = splitProbe.asXML().length();
nextId = combinedList.peek();
if (payloadLength + nextId.getId().length() + 40 >= maxPayloadSize) {
actualProbeList.add(splitProbe);
splitProbe = new Probe(frame);
}
ProbeIdEntry id = combinedList.pop();
switch (id.getType()) {
case "scid":
splitProbe.addServiceContractID(id.getId());
break;
case "siid":
splitProbe.addServiceInstanceID(id.getId());
break;
default:
break;
}
}
actualProbeList.add(splitProbe);
}
return actualProbeList;
} | [
"private",
"List",
"<",
"Probe",
">",
"splitProbe",
"(",
"Probe",
"probe",
")",
"throws",
"ProbeSenderException",
",",
"JAXBException",
",",
"MalformedURLException",
",",
"UnsupportedPayloadType",
"{",
"List",
"<",
"Probe",
">",
"actualProbeList",
"=",
"new",
"Arr... | This method will take the given probe to send and then chop it up into
smaller probes that will fit under the maximum packet size specified by the
transport. This is important because Argo wants the UDP packets to not get
chopped up by the network routers of at all possible. This makes the
overall reliability of the protocol a little higher.
@param probe the offered probe instance
@return the list of probes the original one was split into (might be the
same as the original probe)
@throws ProbeSenderException if there was some issue creating the xml
@throws JAXBException if there was some issue creating the xml
@throws UnsupportedPayloadType this should never happen in this method
@throws MalformedURLException this should never happen in this method | [
"This",
"method",
"will",
"take",
"the",
"given",
"probe",
"to",
"send",
"and",
"then",
"chop",
"it",
"up",
"into",
"smaller",
"probes",
"that",
"will",
"fit",
"under",
"the",
"maximum",
"packet",
"size",
"specified",
"by",
"the",
"transport",
".",
"This",... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java#L114-L172 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java | ProbeSender.getDescription | public String getDescription() {
StringBuffer buf = new StringBuffer();
buf.append("ProbeSender for ");
buf.append(probeTransport.toString());
return buf.toString();
} | java | public String getDescription() {
StringBuffer buf = new StringBuffer();
buf.append("ProbeSender for ");
buf.append(probeTransport.toString());
return buf.toString();
} | [
"public",
"String",
"getDescription",
"(",
")",
"{",
"StringBuffer",
"buf",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"buf",
".",
"append",
"(",
"\"ProbeSender for \"",
")",
";",
"buf",
".",
"append",
"(",
"probeTransport",
".",
"toString",
"(",
")",
")",... | Return the description of the ProbeSender.
@return description | [
"Return",
"the",
"description",
"of",
"the",
"ProbeSender",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSender.java#L179-L184 | train |
opentelecoms-org/zrtp-java | src/zorg/ZRTPCache.java | ZRTPCache.getMyZid | public byte[] getMyZid() {
ZrtpCacheEntry ce = cache.get(LOCAL_ZID_KEY);
if (ce != null) {
return ce.getData();
} else {
byte[] zid = new byte[12];
platform.getCrypto().getRandomGenerator().getBytes(zid);
cache.put(LOCAL_ZID_KEY, zid, null);
platform.getLogger().log("[ZRTP] created new ZID=", zid);
return zid;
}
} | java | public byte[] getMyZid() {
ZrtpCacheEntry ce = cache.get(LOCAL_ZID_KEY);
if (ce != null) {
return ce.getData();
} else {
byte[] zid = new byte[12];
platform.getCrypto().getRandomGenerator().getBytes(zid);
cache.put(LOCAL_ZID_KEY, zid, null);
platform.getLogger().log("[ZRTP] created new ZID=", zid);
return zid;
}
} | [
"public",
"byte",
"[",
"]",
"getMyZid",
"(",
")",
"{",
"ZrtpCacheEntry",
"ce",
"=",
"cache",
".",
"get",
"(",
"LOCAL_ZID_KEY",
")",
";",
"if",
"(",
"ce",
"!=",
"null",
")",
"{",
"return",
"ce",
".",
"getData",
"(",
")",
";",
"}",
"else",
"{",
"by... | Retrieves this clients cached ZID. If there's no cached ZID, i.e. on
first run, a random ZID is created and stored.
@return this client's ZID. | [
"Retrieves",
"this",
"clients",
"cached",
"ZID",
".",
"If",
"there",
"s",
"no",
"cached",
"ZID",
"i",
".",
"e",
".",
"on",
"first",
"run",
"a",
"random",
"ZID",
"is",
"created",
"and",
"stored",
"."
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/ZRTPCache.java#L67-L78 | train |
opentelecoms-org/zrtp-java | src/zorg/ZRTPCache.java | ZRTPCache.selectEntry | public void selectEntry(byte[] remoteZID) {
platform.getLogger().log(
"ZRTPCache: selectEntry("
+ platform.getUtils().byteToHexString(remoteZID) + ")");
String zidString = new String(remoteZID);
if (currentZid != null && currentZid.equals(zidString)) {
return;
}
currentZid = null;
currentRs1 = null;
currentRs2 = null;
currentTrust = false;
currentNumber = null;
ZrtpCacheEntry ce = cache.get(zidString);
if (ce == null) {
currentZid = zidString;
return;
}
byte[] data = ce.getData();
if (data.length == 40 || data.length == 72) {
// backward compatibility: insert trust flag = false
byte[] newData = new byte[1 + data.length];
newData[0] = 0;
System.arraycopy(data, 0, newData, 1, data.length);
data = newData;
}
if (data.length != 41 && data.length != 73) {
platform.getLogger()
.logWarning("Invalid shared secret cache entry");
currentZid = zidString;
return;
}
long expiry = 0;
for (int i = 8; i != 0;) {
expiry = (expiry << 8) + (data[--i] & 0xffL);
}
long now = System.currentTimeMillis();
if (expiry > now) {
currentTrust = (data[8] != 0);
currentRs1 = new byte[32];
System.arraycopy(data, 9, currentRs1, 0, 32);
if (data.length == 73) {
currentRs2 = new byte[32];
System.arraycopy(data, 41, currentRs2, 0, 32);
}
}
currentNumber = ce.getNumber();
currentZid = zidString;
// //// TEST
if (UPDATE_FOR_CACHE_MISMATCH_SIMULATION) {
if (currentRs1 != null)
currentRs1 = platform.getCrypto().getRandomGenerator()
.getBytes(currentRs1.length);
if (currentRs2 != null)
currentRs2 = platform.getCrypto().getRandomGenerator()
.getBytes(currentRs2.length);
if (currentRs1 != null || currentRs2 != null) {
updateEntry(expiry, currentTrust, currentRs1, currentRs2,
currentNumber);
}
UPDATE_FOR_CACHE_MISMATCH_SIMULATION = false;
}
// //// TEST
currentTrust &= (platform.getAddressBook()
.isInAddressBook(currentNumber));
} | java | public void selectEntry(byte[] remoteZID) {
platform.getLogger().log(
"ZRTPCache: selectEntry("
+ platform.getUtils().byteToHexString(remoteZID) + ")");
String zidString = new String(remoteZID);
if (currentZid != null && currentZid.equals(zidString)) {
return;
}
currentZid = null;
currentRs1 = null;
currentRs2 = null;
currentTrust = false;
currentNumber = null;
ZrtpCacheEntry ce = cache.get(zidString);
if (ce == null) {
currentZid = zidString;
return;
}
byte[] data = ce.getData();
if (data.length == 40 || data.length == 72) {
// backward compatibility: insert trust flag = false
byte[] newData = new byte[1 + data.length];
newData[0] = 0;
System.arraycopy(data, 0, newData, 1, data.length);
data = newData;
}
if (data.length != 41 && data.length != 73) {
platform.getLogger()
.logWarning("Invalid shared secret cache entry");
currentZid = zidString;
return;
}
long expiry = 0;
for (int i = 8; i != 0;) {
expiry = (expiry << 8) + (data[--i] & 0xffL);
}
long now = System.currentTimeMillis();
if (expiry > now) {
currentTrust = (data[8] != 0);
currentRs1 = new byte[32];
System.arraycopy(data, 9, currentRs1, 0, 32);
if (data.length == 73) {
currentRs2 = new byte[32];
System.arraycopy(data, 41, currentRs2, 0, 32);
}
}
currentNumber = ce.getNumber();
currentZid = zidString;
// //// TEST
if (UPDATE_FOR_CACHE_MISMATCH_SIMULATION) {
if (currentRs1 != null)
currentRs1 = platform.getCrypto().getRandomGenerator()
.getBytes(currentRs1.length);
if (currentRs2 != null)
currentRs2 = platform.getCrypto().getRandomGenerator()
.getBytes(currentRs2.length);
if (currentRs1 != null || currentRs2 != null) {
updateEntry(expiry, currentTrust, currentRs1, currentRs2,
currentNumber);
}
UPDATE_FOR_CACHE_MISMATCH_SIMULATION = false;
}
// //// TEST
currentTrust &= (platform.getAddressBook()
.isInAddressBook(currentNumber));
} | [
"public",
"void",
"selectEntry",
"(",
"byte",
"[",
"]",
"remoteZID",
")",
"{",
"platform",
".",
"getLogger",
"(",
")",
".",
"log",
"(",
"\"ZRTPCache: selectEntry(\"",
"+",
"platform",
".",
"getUtils",
"(",
")",
".",
"byteToHexString",
"(",
"remoteZID",
")",
... | Selects a cache entry base on remote ZID
@param remoteZID
the remote ZID of the requested entry. | [
"Selects",
"a",
"cache",
"entry",
"base",
"on",
"remote",
"ZID"
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/ZRTPCache.java#L118-L185 | train |
opentelecoms-org/zrtp-java | src/zorg/ZRTPCache.java | ZRTPCache.updateEntry | public void updateEntry(long expiryTime, boolean trust,
byte[] retainedSecret, byte[] rs2, String number) {
if (platform.isVerboseLogging()) {
platform.getLogger().log(
"ZRTPCache: updateEntry("
+ expiryTime
+ ", "
+ trust
+ ", "
+ platform.getUtils().byteToHexString(
retainedSecret) + ", "
+ platform.getUtils().byteToHexString(rs2) + ","
+ number + ")");
}
if (expiryTime == 0) {
cache.remove(currentZid);
currentTrust = false;
currentRs1 = null;
currentRs2 = null;
currentNumber = null;
} else {
byte[] data = new byte[(rs2 == null) ? 41 : 73];
for (int i = 0; i != 8; ++i) {
data[i] = (byte) (expiryTime & 0xff);
expiryTime >>>= 8;
}
data[8] = (byte) (trust ? 1 : 0);
System.arraycopy(retainedSecret, 0, data, 9, 32);
if (rs2 != null) {
System.arraycopy(rs2, 0, data, 41, 32);
}
cache.put(currentZid, data, number);
currentTrust = trust;
currentRs1 = retainedSecret;
currentRs2 = rs2;
currentNumber = number;
}
} | java | public void updateEntry(long expiryTime, boolean trust,
byte[] retainedSecret, byte[] rs2, String number) {
if (platform.isVerboseLogging()) {
platform.getLogger().log(
"ZRTPCache: updateEntry("
+ expiryTime
+ ", "
+ trust
+ ", "
+ platform.getUtils().byteToHexString(
retainedSecret) + ", "
+ platform.getUtils().byteToHexString(rs2) + ","
+ number + ")");
}
if (expiryTime == 0) {
cache.remove(currentZid);
currentTrust = false;
currentRs1 = null;
currentRs2 = null;
currentNumber = null;
} else {
byte[] data = new byte[(rs2 == null) ? 41 : 73];
for (int i = 0; i != 8; ++i) {
data[i] = (byte) (expiryTime & 0xff);
expiryTime >>>= 8;
}
data[8] = (byte) (trust ? 1 : 0);
System.arraycopy(retainedSecret, 0, data, 9, 32);
if (rs2 != null) {
System.arraycopy(rs2, 0, data, 41, 32);
}
cache.put(currentZid, data, number);
currentTrust = trust;
currentRs1 = retainedSecret;
currentRs2 = rs2;
currentNumber = number;
}
} | [
"public",
"void",
"updateEntry",
"(",
"long",
"expiryTime",
",",
"boolean",
"trust",
",",
"byte",
"[",
"]",
"retainedSecret",
",",
"byte",
"[",
"]",
"rs2",
",",
"String",
"number",
")",
"{",
"if",
"(",
"platform",
".",
"isVerboseLogging",
"(",
")",
")",
... | Updates the entry for the selected remote ZID.
@param retainedSecret
the new retained secret.
@param expiryTime
the expiry time, 0 means the entry should be erased.
@param keepRs2
specifies whether the old rs2 should be kept rather than
copying old rs1 into rs2.
@param number
Phone Number associated with the current zid | [
"Updates",
"the",
"entry",
"for",
"the",
"selected",
"remote",
"ZID",
"."
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/ZRTPCache.java#L200-L237 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java | Cache.descriptionsForResponseIDs | public List<String> descriptionsForResponseIDs(List<String> _ids, boolean payload, boolean pretty) {
List<String> descriptions = new ArrayList<String>();
for (ServiceWrapper s : _cache) {
if (_ids.isEmpty() || _responseIds.contains(s.getResponseId())) {
StringBuffer buf = serviceDesciption(payload, pretty, s);
descriptions.add(buf.toString());
}
}
return descriptions;
} | java | public List<String> descriptionsForResponseIDs(List<String> _ids, boolean payload, boolean pretty) {
List<String> descriptions = new ArrayList<String>();
for (ServiceWrapper s : _cache) {
if (_ids.isEmpty() || _responseIds.contains(s.getResponseId())) {
StringBuffer buf = serviceDesciption(payload, pretty, s);
descriptions.add(buf.toString());
}
}
return descriptions;
} | [
"public",
"List",
"<",
"String",
">",
"descriptionsForResponseIDs",
"(",
"List",
"<",
"String",
">",
"_ids",
",",
"boolean",
"payload",
",",
"boolean",
"pretty",
")",
"{",
"List",
"<",
"String",
">",
"descriptions",
"=",
"new",
"ArrayList",
"<",
"String",
... | Return the list of description strings for a list of response ids.
@param _ids list of response ids
@param payload print the whole payload
@param pretty make it pretty
@return the string of all the specified response payloads | [
"Return",
"the",
"list",
"of",
"description",
"strings",
"for",
"a",
"list",
"of",
"response",
"ids",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java#L91-L102 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java | Cache.descriptionsForProbeIDs | public List<String> descriptionsForProbeIDs(List<String> _ids, boolean payload, boolean pretty) {
List<String> descriptions = new ArrayList<String>();
for (ServiceWrapper s : _cache) {
if (_ids.isEmpty() || _probeIds.contains(s.getProbeId())) {
StringBuffer buf = serviceDesciption(payload, pretty, s);
descriptions.add(buf.toString());
}
}
return descriptions;
} | java | public List<String> descriptionsForProbeIDs(List<String> _ids, boolean payload, boolean pretty) {
List<String> descriptions = new ArrayList<String>();
for (ServiceWrapper s : _cache) {
if (_ids.isEmpty() || _probeIds.contains(s.getProbeId())) {
StringBuffer buf = serviceDesciption(payload, pretty, s);
descriptions.add(buf.toString());
}
}
return descriptions;
} | [
"public",
"List",
"<",
"String",
">",
"descriptionsForProbeIDs",
"(",
"List",
"<",
"String",
">",
"_ids",
",",
"boolean",
"payload",
",",
"boolean",
"pretty",
")",
"{",
"List",
"<",
"String",
">",
"descriptions",
"=",
"new",
"ArrayList",
"<",
"String",
">"... | Return the list of description strings for a list of probe ids.
@param _ids list of response ids
@param payload print the whole payload
@param pretty pretty make it pretty
@return the string of all the specified response payloads | [
"Return",
"the",
"list",
"of",
"description",
"strings",
"for",
"a",
"list",
"of",
"probe",
"ids",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java#L112-L123 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java | Cache.asJSON | public String asJSON(boolean pretty) {
JSONSerializer ser = new JSONSerializer();
Gson gson = new Gson();
Gson prettyJson = new GsonBuilder().setPrettyPrinting().create();
JsonArray cacheArray = new JsonArray();
String cacheAsString;
for (ServiceWrapper s : _cache) {
String json = ser.marshalService(s);
JsonObject jsonService = gson.fromJson(json, JsonObject.class);
cacheArray.add(jsonService);
}
if (pretty) {
cacheAsString = prettyJson.toJson(cacheArray);
} else {
cacheAsString = gson.toJson(cacheArray);
}
return cacheAsString;
} | java | public String asJSON(boolean pretty) {
JSONSerializer ser = new JSONSerializer();
Gson gson = new Gson();
Gson prettyJson = new GsonBuilder().setPrettyPrinting().create();
JsonArray cacheArray = new JsonArray();
String cacheAsString;
for (ServiceWrapper s : _cache) {
String json = ser.marshalService(s);
JsonObject jsonService = gson.fromJson(json, JsonObject.class);
cacheArray.add(jsonService);
}
if (pretty) {
cacheAsString = prettyJson.toJson(cacheArray);
} else {
cacheAsString = gson.toJson(cacheArray);
}
return cacheAsString;
} | [
"public",
"String",
"asJSON",
"(",
"boolean",
"pretty",
")",
"{",
"JSONSerializer",
"ser",
"=",
"new",
"JSONSerializer",
"(",
")",
";",
"Gson",
"gson",
"=",
"new",
"Gson",
"(",
")",
";",
"Gson",
"prettyJson",
"=",
"new",
"GsonBuilder",
"(",
")",
".",
"... | Return the cache as JSON.
@param pretty make it pretty
@return the string as JSON | [
"Return",
"the",
"cache",
"as",
"JSON",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/commands/util/Cache.java#L151-L173 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/transport/probe/standard/MulticastTransport.java | MulticastTransport.sendProbe | @Override
public void sendProbe(Probe probe) throws TransportException {
LOGGER.info("Sending probe [" + probe.getProbeID() + "] on network inteface [" + networkInterface.getName() + "] at port [" + multicastAddress + ":" + multicastPort + "]");
LOGGER.debug("Probe requesting TTL of [" + probe.getHopLimit() + "]");
try {
String msg = probe.asXML();
LOGGER.debug("Probe payload (always XML): \n" + msg);
byte[] msgBytes;
msgBytes = msg.getBytes(StandardCharsets.UTF_8);
// send discovery string
InetAddress group = InetAddress.getByName(multicastAddress);
DatagramPacket packet = new DatagramPacket(msgBytes, msgBytes.length, group, multicastPort);
outboundSocket.setTimeToLive(probe.getHopLimit());
outboundSocket.send(packet);
LOGGER.debug("Probe sent on port [" + multicastAddress + ":" + multicastPort + "]");
} catch (IOException e) {
throw new TransportException("Unable to send probe. Issue sending UDP packets.", e);
} catch (JAXBException e) {
throw new TransportException("Unable to send probe because it could not be serialized to XML", e);
}
} | java | @Override
public void sendProbe(Probe probe) throws TransportException {
LOGGER.info("Sending probe [" + probe.getProbeID() + "] on network inteface [" + networkInterface.getName() + "] at port [" + multicastAddress + ":" + multicastPort + "]");
LOGGER.debug("Probe requesting TTL of [" + probe.getHopLimit() + "]");
try {
String msg = probe.asXML();
LOGGER.debug("Probe payload (always XML): \n" + msg);
byte[] msgBytes;
msgBytes = msg.getBytes(StandardCharsets.UTF_8);
// send discovery string
InetAddress group = InetAddress.getByName(multicastAddress);
DatagramPacket packet = new DatagramPacket(msgBytes, msgBytes.length, group, multicastPort);
outboundSocket.setTimeToLive(probe.getHopLimit());
outboundSocket.send(packet);
LOGGER.debug("Probe sent on port [" + multicastAddress + ":" + multicastPort + "]");
} catch (IOException e) {
throw new TransportException("Unable to send probe. Issue sending UDP packets.", e);
} catch (JAXBException e) {
throw new TransportException("Unable to send probe because it could not be serialized to XML", e);
}
} | [
"@",
"Override",
"public",
"void",
"sendProbe",
"(",
"Probe",
"probe",
")",
"throws",
"TransportException",
"{",
"LOGGER",
".",
"info",
"(",
"\"Sending probe [\"",
"+",
"probe",
".",
"getProbeID",
"(",
")",
"+",
"\"] on network inteface [\"",
"+",
"networkInterfac... | Actually send the probe out on the wire.
@param probe the Probe instance that has been pre-configured
@throws TransportException if something bad happened when sending the
probe | [
"Actually",
"send",
"the",
"probe",
"out",
"on",
"the",
"wire",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/transport/probe/standard/MulticastTransport.java#L226-L254 | train |
di2e/Argo | ArgoWirelineFormat/src/main/java/ws/argo/wireline/response/XMLSerializer.java | XMLSerializer.unmarshal | public ResponseWrapper unmarshal(String payload) throws ResponseParseException {
Services xmlServices = parseResponsePayload(payload);
ResponseWrapper response = constructResponseWrapperFromResponse(xmlServices);
return response;
} | java | public ResponseWrapper unmarshal(String payload) throws ResponseParseException {
Services xmlServices = parseResponsePayload(payload);
ResponseWrapper response = constructResponseWrapperFromResponse(xmlServices);
return response;
} | [
"public",
"ResponseWrapper",
"unmarshal",
"(",
"String",
"payload",
")",
"throws",
"ResponseParseException",
"{",
"Services",
"xmlServices",
"=",
"parseResponsePayload",
"(",
"payload",
")",
";",
"ResponseWrapper",
"response",
"=",
"constructResponseWrapperFromResponse",
... | Translate the wireline string into an instance of a ResponseWrapper object.
@param payload the wireline string
@return a new instance of a {@link ResponseWrapper}.
@throws ResponseParseException if some issues occurred parsing the response | [
"Translate",
"the",
"wireline",
"string",
"into",
"an",
"instance",
"of",
"a",
"ResponseWrapper",
"object",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ArgoWirelineFormat/src/main/java/ws/argo/wireline/response/XMLSerializer.java#L176-L184 | train |
di2e/Argo | ArgoWirelineFormat/src/main/java/ws/argo/wireline/response/XMLSerializer.java | XMLSerializer.unmarshalService | public ServiceWrapper unmarshalService(String payload) throws ResponseParseException {
Service xmlService = parseServicePayload(payload);
ServiceWrapper service = constructServiceWrapperFromService(xmlService);
return service;
} | java | public ServiceWrapper unmarshalService(String payload) throws ResponseParseException {
Service xmlService = parseServicePayload(payload);
ServiceWrapper service = constructServiceWrapperFromService(xmlService);
return service;
} | [
"public",
"ServiceWrapper",
"unmarshalService",
"(",
"String",
"payload",
")",
"throws",
"ResponseParseException",
"{",
"Service",
"xmlService",
"=",
"parseServicePayload",
"(",
"payload",
")",
";",
"ServiceWrapper",
"service",
"=",
"constructServiceWrapperFromService",
"... | Translate the wireline string to an instance of a ServiceWrapper object.
@param payload the wireline string
@return a new instance of a {@link ServiceWrapper}.
@throws ResponseParseException if some issues occurred parsing the response | [
"Translate",
"the",
"wireline",
"string",
"to",
"an",
"instance",
"of",
"a",
"ServiceWrapper",
"object",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ArgoWirelineFormat/src/main/java/ws/argo/wireline/response/XMLSerializer.java#L193-L201 | train |
konmik/satellite | valuemap/src/main/java/valuemap/ValueMap.java | ValueMap.get | public <T> T get(String key, T defaultValue) {
if (map.containsKey(key)) {
Object value = map.get(key);
return (T)(value instanceof byte[] ? unmarshall((byte[])value) : value);
}
return defaultValue;
} | java | public <T> T get(String key, T defaultValue) {
if (map.containsKey(key)) {
Object value = map.get(key);
return (T)(value instanceof byte[] ? unmarshall((byte[])value) : value);
}
return defaultValue;
} | [
"public",
"<",
"T",
">",
"T",
"get",
"(",
"String",
"key",
",",
"T",
"defaultValue",
")",
"{",
"if",
"(",
"map",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"Object",
"value",
"=",
"map",
".",
"get",
"(",
"key",
")",
";",
"return",
"(",
"T",... | Returns the value of the mapping with the specified key, or the given default value. | [
"Returns",
"the",
"value",
"of",
"the",
"mapping",
"with",
"the",
"specified",
"key",
"or",
"the",
"given",
"default",
"value",
"."
] | 7b0d3194bf84b3db4c233a131890a23e2d5825b9 | https://github.com/konmik/satellite/blob/7b0d3194bf84b3db4c233a131890a23e2d5825b9/valuemap/src/main/java/valuemap/ValueMap.java#L91-L97 | train |
di2e/Argo | PluginFramework/src/main/java/ws/argo/probe/Probe.java | Probe.setRespondToPayloadType | public void setRespondToPayloadType(String respondToPayloadType) throws UnsupportedPayloadType {
// Sanity check on the payload type values. Should be XML or JSON
// If the probe goes out with a bad value here, then the Responder may have
// problems
if (respondToPayloadType == null || respondToPayloadType.isEmpty() || (!respondToPayloadType.equals(ProbeWrapper.JSON) && !respondToPayloadType.equals(ProbeWrapper.XML)))
throw new UnsupportedPayloadType("Attempting to set payload type to: " + respondToPayloadType + ". Cannot be null or empty and must be " + ProbeWrapper.JSON + " or " + ProbeWrapper.XML);
_probe.setRespondToPayloadType(respondToPayloadType);
} | java | public void setRespondToPayloadType(String respondToPayloadType) throws UnsupportedPayloadType {
// Sanity check on the payload type values. Should be XML or JSON
// If the probe goes out with a bad value here, then the Responder may have
// problems
if (respondToPayloadType == null || respondToPayloadType.isEmpty() || (!respondToPayloadType.equals(ProbeWrapper.JSON) && !respondToPayloadType.equals(ProbeWrapper.XML)))
throw new UnsupportedPayloadType("Attempting to set payload type to: " + respondToPayloadType + ". Cannot be null or empty and must be " + ProbeWrapper.JSON + " or " + ProbeWrapper.XML);
_probe.setRespondToPayloadType(respondToPayloadType);
} | [
"public",
"void",
"setRespondToPayloadType",
"(",
"String",
"respondToPayloadType",
")",
"throws",
"UnsupportedPayloadType",
"{",
"// Sanity check on the payload type values. Should be XML or JSON",
"// If the probe goes out with a bad value here, then the Responder may have",
"// problems",... | set the payload type for the response from the Responder. It only support
XML and JSON.
@param respondToPayloadType a payload type string - XML or JSON
@throws UnsupportedPayloadType if you don't pass in XML or JSON | [
"set",
"the",
"payload",
"type",
"for",
"the",
"response",
"from",
"the",
"Responder",
".",
"It",
"only",
"support",
"XML",
"and",
"JSON",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/PluginFramework/src/main/java/ws/argo/probe/Probe.java#L194-L202 | train |
di2e/Argo | PluginFramework/src/main/java/ws/argo/probe/Probe.java | Probe.getCombinedIdentifierList | public LinkedList<ProbeIdEntry> getCombinedIdentifierList() {
LinkedList<ProbeIdEntry> combinedList = new LinkedList<ProbeIdEntry>();
for (String id : this.getProbeWrapper().getServiceContractIDs()) {
combinedList.add(new ProbeIdEntry("scid", id));
}
for (String id : this.getProbeWrapper().getServiceInstanceIDs()) {
combinedList.add(new ProbeIdEntry("siid", id));
}
return combinedList;
} | java | public LinkedList<ProbeIdEntry> getCombinedIdentifierList() {
LinkedList<ProbeIdEntry> combinedList = new LinkedList<ProbeIdEntry>();
for (String id : this.getProbeWrapper().getServiceContractIDs()) {
combinedList.add(new ProbeIdEntry("scid", id));
}
for (String id : this.getProbeWrapper().getServiceInstanceIDs()) {
combinedList.add(new ProbeIdEntry("siid", id));
}
return combinedList;
} | [
"public",
"LinkedList",
"<",
"ProbeIdEntry",
">",
"getCombinedIdentifierList",
"(",
")",
"{",
"LinkedList",
"<",
"ProbeIdEntry",
">",
"combinedList",
"=",
"new",
"LinkedList",
"<",
"ProbeIdEntry",
">",
"(",
")",
";",
"for",
"(",
"String",
"id",
":",
"this",
... | Create and return a LinkedList of a combination of both scids and siids.
This is a method that is used primarily in the creation of split packets.
@return combined LikedList | [
"Create",
"and",
"return",
"a",
"LinkedList",
"of",
"a",
"combination",
"of",
"both",
"scids",
"and",
"siids",
".",
"This",
"is",
"a",
"method",
"that",
"is",
"used",
"primarily",
"in",
"the",
"creation",
"of",
"split",
"packets",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/PluginFramework/src/main/java/ws/argo/probe/Probe.java#L283-L293 | train |
opentelecoms-org/zrtp-java | src/zorg/LegacyClientUtils.java | LegacyClientUtils.checkClientId | public static boolean checkClientId(boolean isLegacyAttributeList, String farEndClientID) {
if (ZRTP.CLIENT_ID_LEGACY.equals(farEndClientID))
return true;
if (ZRTP.CLIENT_ID_RFC.equals(farEndClientID))
return false;
boolean isPrintable = true;
for (int i = 0; i < farEndClientID.length(); i++) {
int singleChar = farEndClientID.charAt(i);
if (singleChar < 32 || singleChar >= 127) {
isPrintable = false;
}
}
return !isPrintable && isLegacyAttributeList;
} | java | public static boolean checkClientId(boolean isLegacyAttributeList, String farEndClientID) {
if (ZRTP.CLIENT_ID_LEGACY.equals(farEndClientID))
return true;
if (ZRTP.CLIENT_ID_RFC.equals(farEndClientID))
return false;
boolean isPrintable = true;
for (int i = 0; i < farEndClientID.length(); i++) {
int singleChar = farEndClientID.charAt(i);
if (singleChar < 32 || singleChar >= 127) {
isPrintable = false;
}
}
return !isPrintable && isLegacyAttributeList;
} | [
"public",
"static",
"boolean",
"checkClientId",
"(",
"boolean",
"isLegacyAttributeList",
",",
"String",
"farEndClientID",
")",
"{",
"if",
"(",
"ZRTP",
".",
"CLIENT_ID_LEGACY",
".",
"equals",
"(",
"farEndClientID",
")",
")",
"return",
"true",
";",
"if",
"(",
"Z... | Legacy Client send ZRTP.CLIENT_ID_LEGACY or a non-printable ClientId | [
"Legacy",
"Client",
"send",
"ZRTP",
".",
"CLIENT_ID_LEGACY",
"or",
"a",
"non",
"-",
"printable",
"ClientId"
] | 10a0c77866c5d1b1504df161db9a447f5069ed54 | https://github.com/opentelecoms-org/zrtp-java/blob/10a0c77866c5d1b1504df161db9a447f5069ed54/src/zorg/LegacyClientUtils.java#L49-L65 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Rectangles.java | Rectangles.pointRectDistanceSq | public static float pointRectDistanceSq (IRectangle r, IPoint p) {
Point p2 = closestInteriorPoint(r, p);
return Points.distanceSq(p.x(), p.y(), p2.x, p2.y);
} | java | public static float pointRectDistanceSq (IRectangle r, IPoint p) {
Point p2 = closestInteriorPoint(r, p);
return Points.distanceSq(p.x(), p.y(), p2.x, p2.y);
} | [
"public",
"static",
"float",
"pointRectDistanceSq",
"(",
"IRectangle",
"r",
",",
"IPoint",
"p",
")",
"{",
"Point",
"p2",
"=",
"closestInteriorPoint",
"(",
"r",
",",
"p",
")",
";",
"return",
"Points",
".",
"distanceSq",
"(",
"p",
".",
"x",
"(",
")",
","... | Returns the squared Euclidean distance between the given point and the nearest point inside
the bounds of the given rectangle. If the supplied point is inside the rectangle, the
distance will be zero. | [
"Returns",
"the",
"squared",
"Euclidean",
"distance",
"between",
"the",
"given",
"point",
"and",
"the",
"nearest",
"point",
"inside",
"the",
"bounds",
"of",
"the",
"given",
"rectangle",
".",
"If",
"the",
"supplied",
"point",
"is",
"inside",
"the",
"rectangle",... | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Rectangles.java#L58-L61 | train |
di2e/Argo | CommonUtils/src/main/java/ws/argo/common/cache/ResponseCache.java | ResponseCache.cacheAll | public void cacheAll(ArrayList<ExpiringService> list) {
for (ExpiringService service : list) {
cache.put(service.getService().getId(), service);
}
} | java | public void cacheAll(ArrayList<ExpiringService> list) {
for (ExpiringService service : list) {
cache.put(service.getService().getId(), service);
}
} | [
"public",
"void",
"cacheAll",
"(",
"ArrayList",
"<",
"ExpiringService",
">",
"list",
")",
"{",
"for",
"(",
"ExpiringService",
"service",
":",
"list",
")",
"{",
"cache",
".",
"put",
"(",
"service",
".",
"getService",
"(",
")",
".",
"getId",
"(",
")",
",... | Put a list of services in the cache.
@param list the list of service to put in the cache | [
"Put",
"a",
"list",
"of",
"services",
"in",
"the",
"cache",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CommonUtils/src/main/java/ws/argo/common/cache/ResponseCache.java#L58-L64 | train |
di2e/Argo | CommonUtils/src/main/java/ws/argo/common/cache/ResponseCache.java | ResponseCache.asJSON | public String asJSON() {
Gson gson = new Gson();
clearExpired();
Cache jsonCache = new Cache();
for (ExpiringService svc : cache.values()) {
jsonCache.cache.add(svc.getService());
}
String json = gson.toJson(jsonCache);
return json;
} | java | public String asJSON() {
Gson gson = new Gson();
clearExpired();
Cache jsonCache = new Cache();
for (ExpiringService svc : cache.values()) {
jsonCache.cache.add(svc.getService());
}
String json = gson.toJson(jsonCache);
return json;
} | [
"public",
"String",
"asJSON",
"(",
")",
"{",
"Gson",
"gson",
"=",
"new",
"Gson",
"(",
")",
";",
"clearExpired",
"(",
")",
";",
"Cache",
"jsonCache",
"=",
"new",
"Cache",
"(",
")",
";",
"for",
"(",
"ExpiringService",
"svc",
":",
"cache",
".",
"values"... | Return the JSON string of the response cache. Leverage the Gson nature of
the domain wireline classes
@return the JSON string | [
"Return",
"the",
"JSON",
"string",
"of",
"the",
"response",
"cache",
".",
"Leverage",
"the",
"Gson",
"nature",
"of",
"the",
"domain",
"wireline",
"classes"
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CommonUtils/src/main/java/ws/argo/common/cache/ResponseCache.java#L76-L89 | train |
di2e/Argo | ArgoWirelineFormat/src/main/java/ws/argo/wireline/probe/ProbeWrapper.java | ProbeWrapper.addRespondToURL | public void addRespondToURL(String label, String url) {
RespondToURL respondToURL = new RespondToURL();
respondToURL.label = label;
respondToURL.url = url;
respondToURLs.add(respondToURL);
} | java | public void addRespondToURL(String label, String url) {
RespondToURL respondToURL = new RespondToURL();
respondToURL.label = label;
respondToURL.url = url;
respondToURLs.add(respondToURL);
} | [
"public",
"void",
"addRespondToURL",
"(",
"String",
"label",
",",
"String",
"url",
")",
"{",
"RespondToURL",
"respondToURL",
"=",
"new",
"RespondToURL",
"(",
")",
";",
"respondToURL",
".",
"label",
"=",
"label",
";",
"respondToURL",
".",
"url",
"=",
"url",
... | Add a response URL to the probe.
@param label the string label for the respondTo address
@param url the actual URL string | [
"Add",
"a",
"response",
"URL",
"to",
"the",
"probe",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ArgoWirelineFormat/src/main/java/ws/argo/wireline/probe/ProbeWrapper.java#L257-L265 | train |
di2e/Argo | ArgoWirelineFormat/src/main/java/ws/argo/wireline/probe/ProbeWrapper.java | ProbeWrapper.asString | public String asString() {
StringBuffer buf = new StringBuffer();
buf.append(" PID: [ ").append(this.id).append(" ]");;
buf.append(" CID: [ ").append(this.clientId).append(" ]");;
buf.append(" DES: [ ").append(this.desVersion).append(" ]");;
buf.append(" SCIDS: [ " );
for (String scid : serviceContractIDs) {
buf.append(scid).append(" ");
}
buf.append("]");
buf.append(" SIIDS: [ " );
for (String siid : serviceInstanceIDs) {
buf.append(siid).append(" ");
}
buf.append("]");
buf.append(" RESPOND_TO: [ " );
for (RespondToURL rt : respondToURLs) {
buf.append(rt.label).append(", ").append(rt.url).append(" ");
}
buf.append("]");
buf.append(" PAYLOAD_TYPE: [ ").append(respondToPayloadType).append(" ]");
return buf.toString();
} | java | public String asString() {
StringBuffer buf = new StringBuffer();
buf.append(" PID: [ ").append(this.id).append(" ]");;
buf.append(" CID: [ ").append(this.clientId).append(" ]");;
buf.append(" DES: [ ").append(this.desVersion).append(" ]");;
buf.append(" SCIDS: [ " );
for (String scid : serviceContractIDs) {
buf.append(scid).append(" ");
}
buf.append("]");
buf.append(" SIIDS: [ " );
for (String siid : serviceInstanceIDs) {
buf.append(siid).append(" ");
}
buf.append("]");
buf.append(" RESPOND_TO: [ " );
for (RespondToURL rt : respondToURLs) {
buf.append(rt.label).append(", ").append(rt.url).append(" ");
}
buf.append("]");
buf.append(" PAYLOAD_TYPE: [ ").append(respondToPayloadType).append(" ]");
return buf.toString();
} | [
"public",
"String",
"asString",
"(",
")",
"{",
"StringBuffer",
"buf",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"buf",
".",
"append",
"(",
"\" PID: [ \"",
")",
".",
"append",
"(",
"this",
".",
"id",
")",
".",
"append",
"(",
"\" ]\"",
")",
";",
";",
... | This will return the single-line textual representation. This was crafted
for the command line client. Your mileage may vary.
@return the single line description | [
"This",
"will",
"return",
"the",
"single",
"-",
"line",
"textual",
"representation",
".",
"This",
"was",
"crafted",
"for",
"the",
"command",
"line",
"client",
".",
"Your",
"mileage",
"may",
"vary",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ArgoWirelineFormat/src/main/java/ws/argo/wireline/probe/ProbeWrapper.java#L319-L342 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/RectangularShape.java | RectangularShape.setFrame | public void setFrame (XY loc, IDimension size) {
setFrame(loc.x(), loc.y(), size.width(), size.height());
} | java | public void setFrame (XY loc, IDimension size) {
setFrame(loc.x(), loc.y(), size.width(), size.height());
} | [
"public",
"void",
"setFrame",
"(",
"XY",
"loc",
",",
"IDimension",
"size",
")",
"{",
"setFrame",
"(",
"loc",
".",
"x",
"(",
")",
",",
"loc",
".",
"y",
"(",
")",
",",
"size",
".",
"width",
"(",
")",
",",
"size",
".",
"height",
"(",
")",
")",
"... | Sets the location and size of the framing rectangle of this shape to the supplied values. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"to",
"the",
"supplied",
"values",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/RectangularShape.java#L21-L23 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/RectangularShape.java | RectangularShape.setFrame | public void setFrame (IRectangle r) {
setFrame(r.x(), r.y(), r.width(), r.height());
} | java | public void setFrame (IRectangle r) {
setFrame(r.x(), r.y(), r.width(), r.height());
} | [
"public",
"void",
"setFrame",
"(",
"IRectangle",
"r",
")",
"{",
"setFrame",
"(",
"r",
".",
"x",
"(",
")",
",",
"r",
".",
"y",
"(",
")",
",",
"r",
".",
"width",
"(",
")",
",",
"r",
".",
"height",
"(",
")",
")",
";",
"}"
] | Sets the location and size of the framing rectangle of this shape to be equal to the
supplied rectangle. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"to",
"be",
"equal",
"to",
"the",
"supplied",
"rectangle",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/RectangularShape.java#L29-L31 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/RectangularShape.java | RectangularShape.setFrameFromDiagonal | public void setFrameFromDiagonal (XY p1, XY p2) {
setFrameFromDiagonal(p1.x(), p1.y(), p2.x(), p2.y());
} | java | public void setFrameFromDiagonal (XY p1, XY p2) {
setFrameFromDiagonal(p1.x(), p1.y(), p2.x(), p2.y());
} | [
"public",
"void",
"setFrameFromDiagonal",
"(",
"XY",
"p1",
",",
"XY",
"p2",
")",
"{",
"setFrameFromDiagonal",
"(",
"p1",
".",
"x",
"(",
")",
",",
"p1",
".",
"y",
"(",
")",
",",
"p2",
".",
"x",
"(",
")",
",",
"p2",
".",
"y",
"(",
")",
")",
";"... | Sets the location and size of the framing rectangle of this shape based on the supplied
diagonal line. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"based",
"on",
"the",
"supplied",
"diagonal",
"line",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/RectangularShape.java#L60-L62 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/RectangularShape.java | RectangularShape.setFrameFromCenter | public void setFrameFromCenter (XY center, XY corner) {
setFrameFromCenter(center.x(), center.y(), corner.x(), corner.y());
} | java | public void setFrameFromCenter (XY center, XY corner) {
setFrameFromCenter(center.x(), center.y(), corner.x(), corner.y());
} | [
"public",
"void",
"setFrameFromCenter",
"(",
"XY",
"center",
",",
"XY",
"corner",
")",
"{",
"setFrameFromCenter",
"(",
"center",
".",
"x",
"(",
")",
",",
"center",
".",
"y",
"(",
")",
",",
"corner",
".",
"x",
"(",
")",
",",
"corner",
".",
"y",
"(",... | Sets the location and size of the framing rectangle of this shape based on the supplied
center and corner points. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"based",
"on",
"the",
"supplied",
"center",
"and",
"corner",
"points",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/RectangularShape.java#L79-L81 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Points.java | Points.inverseTransform | public static Point inverseTransform (double x, double y, double sx, double sy, double rotation,
double tx, double ty, Point result) {
x -= tx; y -= ty; // untranslate
double sinnega = Math.sin(-rotation), cosnega = Math.cos(-rotation);
double nx = (x * cosnega - y * sinnega); // unrotate
double ny = (x * sinnega + y * cosnega);
return result.set(nx / sx, ny / sy); // unscale
} | java | public static Point inverseTransform (double x, double y, double sx, double sy, double rotation,
double tx, double ty, Point result) {
x -= tx; y -= ty; // untranslate
double sinnega = Math.sin(-rotation), cosnega = Math.cos(-rotation);
double nx = (x * cosnega - y * sinnega); // unrotate
double ny = (x * sinnega + y * cosnega);
return result.set(nx / sx, ny / sy); // unscale
} | [
"public",
"static",
"Point",
"inverseTransform",
"(",
"double",
"x",
",",
"double",
"y",
",",
"double",
"sx",
",",
"double",
"sy",
",",
"double",
"rotation",
",",
"double",
"tx",
",",
"double",
"ty",
",",
"Point",
"result",
")",
"{",
"x",
"-=",
"tx",
... | Inverse transforms a point as specified, storing the result in the point provided.
@return a reference to the result point, for chaining. | [
"Inverse",
"transforms",
"a",
"point",
"as",
"specified",
"storing",
"the",
"result",
"in",
"the",
"point",
"provided",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Points.java#L64-L71 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileProbeHandlerPlugin.java | ConfigFileProbeHandlerPlugin.setServiceList | public void setServiceList(ArrayList<ServiceWrapper> services) {
writeLock.lock();
try {
LOGGER.info("Updating service list by " + Thread.currentThread().getName());
this.serviceList = services;
} finally {
writeLock.unlock();
}
} | java | public void setServiceList(ArrayList<ServiceWrapper> services) {
writeLock.lock();
try {
LOGGER.info("Updating service list by " + Thread.currentThread().getName());
this.serviceList = services;
} finally {
writeLock.unlock();
}
} | [
"public",
"void",
"setServiceList",
"(",
"ArrayList",
"<",
"ServiceWrapper",
">",
"services",
")",
"{",
"writeLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"LOGGER",
".",
"info",
"(",
"\"Updating service list by \"",
"+",
"Thread",
".",
"currentThread",
"(",
... | As the Responder is multi-threaded, make sure that the access to the
services list which might change out if the user changes it, is
synchronized to make sure nothing weird happens.
<p>There is lock on this that will always allow a read unless another thread
is updating the service list.
@param services - the ArrayList of ServiceInfoBeans | [
"As",
"the",
"Responder",
"is",
"multi",
"-",
"threaded",
"make",
"sure",
"that",
"the",
"access",
"to",
"the",
"services",
"list",
"which",
"might",
"change",
"out",
"if",
"the",
"user",
"changes",
"it",
"is",
"synchronized",
"to",
"make",
"sure",
"nothin... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileProbeHandlerPlugin.java#L87-L95 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileProbeHandlerPlugin.java | ConfigFileProbeHandlerPlugin.initializeWithPropertiesFilename | public void initializeWithPropertiesFilename(String filename) throws ProbeHandlerConfigException {
InputStream is;
// try to load the properties file off the classpath first
if (ConfigFileProbeHandlerPlugin.class.getResource(filename) != null) {
is = ConfigFileProbeHandlerPlugin.class.getResourceAsStream(filename);
} else {
try {
is = new FileInputStream(filename);
} catch (FileNotFoundException e) {
throw new ProbeHandlerConfigException("Error loading handler config for [" + this.getClass().getName() + "]", e);
}
}
try {
config.load(is);
} catch (IOException e) {
throw new ProbeHandlerConfigException("Error loading handler config for [" + this.getClass().getName() + "]", e);
} finally {
try {
is.close();
} catch (IOException e) {
throw new ProbeHandlerConfigException("Error closing handler config for {" + this.getClass().getName() + "]", e);
}
}
// Launch the timer task that will look for changes to the config file
try {
configFileScan = new Timer();
configFileScan.scheduleAtFixedRate(new ConfigFileMonitorTask(this), 100, 10000);
} catch (ConfigurationException e) {
throw new ProbeHandlerConfigException("Error initializing monitor task.", e);
}
} | java | public void initializeWithPropertiesFilename(String filename) throws ProbeHandlerConfigException {
InputStream is;
// try to load the properties file off the classpath first
if (ConfigFileProbeHandlerPlugin.class.getResource(filename) != null) {
is = ConfigFileProbeHandlerPlugin.class.getResourceAsStream(filename);
} else {
try {
is = new FileInputStream(filename);
} catch (FileNotFoundException e) {
throw new ProbeHandlerConfigException("Error loading handler config for [" + this.getClass().getName() + "]", e);
}
}
try {
config.load(is);
} catch (IOException e) {
throw new ProbeHandlerConfigException("Error loading handler config for [" + this.getClass().getName() + "]", e);
} finally {
try {
is.close();
} catch (IOException e) {
throw new ProbeHandlerConfigException("Error closing handler config for {" + this.getClass().getName() + "]", e);
}
}
// Launch the timer task that will look for changes to the config file
try {
configFileScan = new Timer();
configFileScan.scheduleAtFixedRate(new ConfigFileMonitorTask(this), 100, 10000);
} catch (ConfigurationException e) {
throw new ProbeHandlerConfigException("Error initializing monitor task.", e);
}
} | [
"public",
"void",
"initializeWithPropertiesFilename",
"(",
"String",
"filename",
")",
"throws",
"ProbeHandlerConfigException",
"{",
"InputStream",
"is",
";",
"// try to load the properties file off the classpath first",
"if",
"(",
"ConfigFileProbeHandlerPlugin",
".",
"class",
"... | Initialize the handler. | [
"Initialize",
"the",
"handler",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileProbeHandlerPlugin.java#L163-L198 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java | ArgoClientContext.initializeTransports | private void initializeTransports(ArrayList<TransportConfig> transportConfigs) {
for (TransportConfig config : transportConfigs) {
ClientProbeSenders transport = new ClientProbeSenders(config);
try {
transport.initialize(this);
_clientSenders.add(transport);
} catch (TransportConfigException e) {
LOGGER.warn( "Transport [" + config.getName() + "] failed to initialize.", e);
Console.error("Unable to initialize the Transport [" + config.getName() + "]. Ignoring.");
}
}
} | java | private void initializeTransports(ArrayList<TransportConfig> transportConfigs) {
for (TransportConfig config : transportConfigs) {
ClientProbeSenders transport = new ClientProbeSenders(config);
try {
transport.initialize(this);
_clientSenders.add(transport);
} catch (TransportConfigException e) {
LOGGER.warn( "Transport [" + config.getName() + "] failed to initialize.", e);
Console.error("Unable to initialize the Transport [" + config.getName() + "]. Ignoring.");
}
}
} | [
"private",
"void",
"initializeTransports",
"(",
"ArrayList",
"<",
"TransportConfig",
">",
"transportConfigs",
")",
"{",
"for",
"(",
"TransportConfig",
"config",
":",
"transportConfigs",
")",
"{",
"ClientProbeSenders",
"transport",
"=",
"new",
"ClientProbeSenders",
"("... | Initializes the Transports.
@param transportConfigs the list if the transport configurations to use | [
"Initializes",
"the",
"Transports",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java#L74-L86 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java | ArgoClientContext.initializeLocalhostNI | private void initializeLocalhostNI() {
InetAddress localhost;
try {
localhost = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(localhost);
if (ni != null)
getNIList().add(ni.getName());
} catch (UnknownHostException | SocketException e) {
Console.severe("Cannot get the Network Interface for localhost");
Console.severe(e.getMessage());
}
} | java | private void initializeLocalhostNI() {
InetAddress localhost;
try {
localhost = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(localhost);
if (ni != null)
getNIList().add(ni.getName());
} catch (UnknownHostException | SocketException e) {
Console.severe("Cannot get the Network Interface for localhost");
Console.severe(e.getMessage());
}
} | [
"private",
"void",
"initializeLocalhostNI",
"(",
")",
"{",
"InetAddress",
"localhost",
";",
"try",
"{",
"localhost",
"=",
"InetAddress",
".",
"getLocalHost",
"(",
")",
";",
"NetworkInterface",
"ni",
"=",
"NetworkInterface",
".",
"getByInetAddress",
"(",
"localhost... | Sets up the network interface list with at least the localhost NI. | [
"Sets",
"up",
"the",
"network",
"interface",
"list",
"with",
"at",
"least",
"the",
"localhost",
"NI",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java#L156-L170 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java | ArgoClientContext.getAvailableNetworkInterfaces | public List<String> getAvailableNetworkInterfaces(boolean requiresMulticast) throws SocketException {
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
List<String> multicastNIs = new ArrayList<String>();
// Console.info("Available Multicast-enabled Network Interfaces");
while (nis.hasMoreElements()) {
NetworkInterface ni = nis.nextElement();
if (ni.isUp() && !ni.isLoopback()) {
if (requiresMulticast) {
if (ni.supportsMulticast())
multicastNIs.add(ni.getName());
} else {
multicastNIs.add(ni.getName());
}
}
}
return multicastNIs;
} | java | public List<String> getAvailableNetworkInterfaces(boolean requiresMulticast) throws SocketException {
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
List<String> multicastNIs = new ArrayList<String>();
// Console.info("Available Multicast-enabled Network Interfaces");
while (nis.hasMoreElements()) {
NetworkInterface ni = nis.nextElement();
if (ni.isUp() && !ni.isLoopback()) {
if (requiresMulticast) {
if (ni.supportsMulticast())
multicastNIs.add(ni.getName());
} else {
multicastNIs.add(ni.getName());
}
}
}
return multicastNIs;
} | [
"public",
"List",
"<",
"String",
">",
"getAvailableNetworkInterfaces",
"(",
"boolean",
"requiresMulticast",
")",
"throws",
"SocketException",
"{",
"Enumeration",
"<",
"NetworkInterface",
">",
"nis",
"=",
"NetworkInterface",
".",
"getNetworkInterfaces",
"(",
")",
";",
... | This gets a list of all the available network interface names.
@param requiresMulticast return only NIs that are multicast capable
@return the list of the currently available network interface names
@throws SocketException if the
{@linkplain NetworkInterface#getNetworkInterfaces()} call fails | [
"This",
"gets",
"a",
"list",
"of",
"all",
"the",
"available",
"network",
"interface",
"names",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java#L181-L202 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java | ArgoClientContext.getClientTransportNamed | public ClientProbeSenders getClientTransportNamed(String transportName) {
ClientProbeSenders found = null;
for (ClientProbeSenders t : _clientSenders) {
if (t.getName().equalsIgnoreCase(transportName)) {
found = t;
break;
}
}
return found;
} | java | public ClientProbeSenders getClientTransportNamed(String transportName) {
ClientProbeSenders found = null;
for (ClientProbeSenders t : _clientSenders) {
if (t.getName().equalsIgnoreCase(transportName)) {
found = t;
break;
}
}
return found;
} | [
"public",
"ClientProbeSenders",
"getClientTransportNamed",
"(",
"String",
"transportName",
")",
"{",
"ClientProbeSenders",
"found",
"=",
"null",
";",
"for",
"(",
"ClientProbeSenders",
"t",
":",
"_clientSenders",
")",
"{",
"if",
"(",
"t",
".",
"getName",
"(",
")"... | Returns the client transport specified by given name.
@param transportName client transport name
@return the ClientTransport that matches the name | [
"Returns",
"the",
"client",
"transport",
"specified",
"by",
"given",
"name",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ArgoClientContext.java#L209-L221 | train |
johnlcox/motif | motif/src/main/java/com/leacox/motif/cases/Case3Cases.java | Case3Cases.case3 | public static <T extends Case3<A, B, C>, A, B, C> DecomposableMatchBuilder0<T> case3(
Class<T> clazz, MatchesExact<A> a, MatchesExact<B> b, MatchesExact<C> c) {
List<Matcher<Object>> matchers =
Lists.of(ArgumentMatchers.eq(a.t), ArgumentMatchers.eq(b.t), ArgumentMatchers.eq(c.t));
return new DecomposableMatchBuilder0<T>(matchers, new Case3FieldExtractor<>(clazz));
} | java | public static <T extends Case3<A, B, C>, A, B, C> DecomposableMatchBuilder0<T> case3(
Class<T> clazz, MatchesExact<A> a, MatchesExact<B> b, MatchesExact<C> c) {
List<Matcher<Object>> matchers =
Lists.of(ArgumentMatchers.eq(a.t), ArgumentMatchers.eq(b.t), ArgumentMatchers.eq(c.t));
return new DecomposableMatchBuilder0<T>(matchers, new Case3FieldExtractor<>(clazz));
} | [
"public",
"static",
"<",
"T",
"extends",
"Case3",
"<",
"A",
",",
"B",
",",
"C",
">",
",",
"A",
",",
"B",
",",
"C",
">",
"DecomposableMatchBuilder0",
"<",
"T",
">",
"case3",
"(",
"Class",
"<",
"T",
">",
"clazz",
",",
"MatchesExact",
"<",
"A",
">",... | Matches a case class of three elements. | [
"Matches",
"a",
"case",
"class",
"of",
"three",
"elements",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/motif/src/main/java/com/leacox/motif/cases/Case3Cases.java#L48-L53 | train |
di2e/Argo | clui/src/main/java/net/dharwin/common/tools/cli/api/Command.java | Command.execute | public CommandResult execute(T context) {
try {
return innerExecute(context);
} catch (Exception e) {
Console.error(e.getMessage());
return CommandResult.ERROR;
}
} | java | public CommandResult execute(T context) {
try {
return innerExecute(context);
} catch (Exception e) {
Console.error(e.getMessage());
return CommandResult.ERROR;
}
} | [
"public",
"CommandResult",
"execute",
"(",
"T",
"context",
")",
"{",
"try",
"{",
"return",
"innerExecute",
"(",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"Console",
".",
"error",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
"... | Executes the command. The command line arguments contains all of the
key-value pairs and switches, but does not include the command name that
came from the original arguments.
@param context the context object from the application
@return The result of the execution of this command. | [
"Executes",
"the",
"command",
".",
"The",
"command",
"line",
"arguments",
"contains",
"all",
"of",
"the",
"key",
"-",
"value",
"pairs",
"and",
"switches",
"but",
"does",
"not",
"include",
"the",
"command",
"name",
"that",
"came",
"from",
"the",
"original",
... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/clui/src/main/java/net/dharwin/common/tools/cli/api/Command.java#L50-L57 | train |
johnlcox/motif | examples/src/main/java/com/leacox/motif/example/FactorialExample.java | FactorialExample.factMatching | public long factMatching(long n) {
return match(n)
.when(caseLong(0)).get(() -> 1L)
.when(caseLong(any())).get(i -> i * factMatching(i - 1))
.getMatch();
} | java | public long factMatching(long n) {
return match(n)
.when(caseLong(0)).get(() -> 1L)
.when(caseLong(any())).get(i -> i * factMatching(i - 1))
.getMatch();
} | [
"public",
"long",
"factMatching",
"(",
"long",
"n",
")",
"{",
"return",
"match",
"(",
"n",
")",
".",
"when",
"(",
"caseLong",
"(",
"0",
")",
")",
".",
"get",
"(",
"(",
")",
"->",
"1L",
")",
".",
"when",
"(",
"caseLong",
"(",
"any",
"(",
")",
... | An implementation of factorial using motif pattern matching. | [
"An",
"implementation",
"of",
"factorial",
"using",
"motif",
"pattern",
"matching",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/examples/src/main/java/com/leacox/motif/example/FactorialExample.java#L43-L48 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Transforms.java | Transforms.createTransformedShape | public static IShape createTransformedShape (Transform t, IShape src) {
if (src == null) {
return null;
}
if (src instanceof Path) {
return ((Path)src).createTransformedShape(t);
}
PathIterator path = src.pathIterator(t);
Path dst = new Path(path.windingRule());
dst.append(path, false);
return dst;
} | java | public static IShape createTransformedShape (Transform t, IShape src) {
if (src == null) {
return null;
}
if (src instanceof Path) {
return ((Path)src).createTransformedShape(t);
}
PathIterator path = src.pathIterator(t);
Path dst = new Path(path.windingRule());
dst.append(path, false);
return dst;
} | [
"public",
"static",
"IShape",
"createTransformedShape",
"(",
"Transform",
"t",
",",
"IShape",
"src",
")",
"{",
"if",
"(",
"src",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"src",
"instanceof",
"Path",
")",
"{",
"return",
"(",
"(",
... | Creates and returns a new shape that is the supplied shape transformed by this transform's
matrix. | [
"Creates",
"and",
"returns",
"a",
"new",
"shape",
"that",
"is",
"the",
"supplied",
"shape",
"transformed",
"by",
"this",
"transform",
"s",
"matrix",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Transforms.java#L16-L27 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/CrossingHelper.java | CrossingHelper.sort | private static void sort (double[] coords1, int length1,
double[] coords2, int length2, int[] array) {
int temp;
int length = length1 + length2;
double x1, y1, x2, y2;
for (int i = 1; i < length; i++) {
if (array[i - 1] < length1) {
x1 = coords1[2 * array[i - 1]];
y1 = coords1[2 * array[i - 1] + 1];
} else {
x1 = coords2[2 * (array[i - 1] - length1)];
y1 = coords2[2 * (array[i - 1] - length1) + 1];
}
if (array[i] < length1) {
x2 = coords1[2 * array[i]];
y2 = coords1[2 * array[i] + 1];
} else {
x2 = coords2[2 * (array[i] - length1)];
y2 = coords2[2 * (array[i] - length1) + 1];
}
int j = i;
while (j > 0 && compare(x1, y1, x2, y2) <= 0) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
j--;
if (j > 0) {
if (array[j - 1] < length1) {
x1 = coords1[2 * array[j - 1]];
y1 = coords1[2 * array[j - 1] + 1];
} else {
x1 = coords2[2 * (array[j - 1] - length1)];
y1 = coords2[2 * (array[j - 1] - length1) + 1];
}
if (array[j] < length1) {
x2 = coords1[2 * array[j]];
y2 = coords1[2 * array[j] + 1];
} else {
x2 = coords2[2 * (array[j] - length1)];
y2 = coords2[2 * (array[j] - length1) + 1];
}
}
}
}
} | java | private static void sort (double[] coords1, int length1,
double[] coords2, int length2, int[] array) {
int temp;
int length = length1 + length2;
double x1, y1, x2, y2;
for (int i = 1; i < length; i++) {
if (array[i - 1] < length1) {
x1 = coords1[2 * array[i - 1]];
y1 = coords1[2 * array[i - 1] + 1];
} else {
x1 = coords2[2 * (array[i - 1] - length1)];
y1 = coords2[2 * (array[i - 1] - length1) + 1];
}
if (array[i] < length1) {
x2 = coords1[2 * array[i]];
y2 = coords1[2 * array[i] + 1];
} else {
x2 = coords2[2 * (array[i] - length1)];
y2 = coords2[2 * (array[i] - length1) + 1];
}
int j = i;
while (j > 0 && compare(x1, y1, x2, y2) <= 0) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
j--;
if (j > 0) {
if (array[j - 1] < length1) {
x1 = coords1[2 * array[j - 1]];
y1 = coords1[2 * array[j - 1] + 1];
} else {
x1 = coords2[2 * (array[j - 1] - length1)];
y1 = coords2[2 * (array[j - 1] - length1) + 1];
}
if (array[j] < length1) {
x2 = coords1[2 * array[j]];
y2 = coords1[2 * array[j] + 1];
} else {
x2 = coords2[2 * (array[j] - length1)];
y2 = coords2[2 * (array[j] - length1) + 1];
}
}
}
}
} | [
"private",
"static",
"void",
"sort",
"(",
"double",
"[",
"]",
"coords1",
",",
"int",
"length1",
",",
"double",
"[",
"]",
"coords2",
",",
"int",
"length2",
",",
"int",
"[",
"]",
"array",
")",
"{",
"int",
"temp",
";",
"int",
"length",
"=",
"length1",
... | the array sorting | [
"the",
"array",
"sorting"
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/CrossingHelper.java#L208-L253 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/RectangularShape.java | RectangularShape.setFrameFromDiagonal | public void setFrameFromDiagonal (float x1, float y1, float x2, float y2) {
float rx, ry, rw, rh;
if (x1 < x2) {
rx = x1;
rw = x2 - x1;
} else {
rx = x2;
rw = x1 - x2;
}
if (y1 < y2) {
ry = y1;
rh = y2 - y1;
} else {
ry = y2;
rh = y1 - y2;
}
setFrame(rx, ry, rw, rh);
} | java | public void setFrameFromDiagonal (float x1, float y1, float x2, float y2) {
float rx, ry, rw, rh;
if (x1 < x2) {
rx = x1;
rw = x2 - x1;
} else {
rx = x2;
rw = x1 - x2;
}
if (y1 < y2) {
ry = y1;
rh = y2 - y1;
} else {
ry = y2;
rh = y1 - y2;
}
setFrame(rx, ry, rw, rh);
} | [
"public",
"void",
"setFrameFromDiagonal",
"(",
"float",
"x1",
",",
"float",
"y1",
",",
"float",
"x2",
",",
"float",
"y2",
")",
"{",
"float",
"rx",
",",
"ry",
",",
"rw",
",",
"rh",
";",
"if",
"(",
"x1",
"<",
"x2",
")",
"{",
"rx",
"=",
"x1",
";",... | Sets the location and size of the framing rectangle of this shape based on the specified
diagonal line. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"based",
"on",
"the",
"specified",
"diagonal",
"line",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/RectangularShape.java#L37-L54 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/RectangularShape.java | RectangularShape.setFrameFromCenter | public void setFrameFromCenter (float centerX, float centerY,
float cornerX, float cornerY) {
float width = Math.abs(cornerX - centerX);
float height = Math.abs(cornerY - centerY);
setFrame(centerX - width, centerY - height, width * 2, height * 2);
} | java | public void setFrameFromCenter (float centerX, float centerY,
float cornerX, float cornerY) {
float width = Math.abs(cornerX - centerX);
float height = Math.abs(cornerY - centerY);
setFrame(centerX - width, centerY - height, width * 2, height * 2);
} | [
"public",
"void",
"setFrameFromCenter",
"(",
"float",
"centerX",
",",
"float",
"centerY",
",",
"float",
"cornerX",
",",
"float",
"cornerY",
")",
"{",
"float",
"width",
"=",
"Math",
".",
"abs",
"(",
"cornerX",
"-",
"centerX",
")",
";",
"float",
"height",
... | Sets the location and size of the framing rectangle of this shape based on the specified
center and corner points. | [
"Sets",
"the",
"location",
"and",
"size",
"of",
"the",
"framing",
"rectangle",
"of",
"this",
"shape",
"based",
"on",
"the",
"specified",
"center",
"and",
"corner",
"points",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/RectangularShape.java#L68-L73 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/listener/ProbeResponseResource.java | ProbeResponseResource.handleJSONProbeResponse | @POST
@Path("/probeResponse")
@Consumes("application/json")
public String handleJSONProbeResponse(String probeResponseJSON) {
JSONSerializer serializer = new JSONSerializer();
ResponseWrapper response;
try {
response = serializer.unmarshal(probeResponseJSON);
} catch (ResponseParseException e) {
String errorResponseString = "Incoming Response could not be parsed. Error message is: " + e.getMessage();
Console.error(errorResponseString);
Console.error("Wireline message that could no be parsed is:");
Console.error(probeResponseJSON);
return errorResponseString;
}
for (ServiceWrapper service : response.getServices()) {
service.setResponseID(response.getResponseID());
service.setProbeID(response.getProbeID());
cache.cache(new ExpiringService(service));
}
String statusString = "Successfully cached " + response.getServices().size() + " services";
updateCacheListener(statusString);
return statusString;
} | java | @POST
@Path("/probeResponse")
@Consumes("application/json")
public String handleJSONProbeResponse(String probeResponseJSON) {
JSONSerializer serializer = new JSONSerializer();
ResponseWrapper response;
try {
response = serializer.unmarshal(probeResponseJSON);
} catch (ResponseParseException e) {
String errorResponseString = "Incoming Response could not be parsed. Error message is: " + e.getMessage();
Console.error(errorResponseString);
Console.error("Wireline message that could no be parsed is:");
Console.error(probeResponseJSON);
return errorResponseString;
}
for (ServiceWrapper service : response.getServices()) {
service.setResponseID(response.getResponseID());
service.setProbeID(response.getProbeID());
cache.cache(new ExpiringService(service));
}
String statusString = "Successfully cached " + response.getServices().size() + " services";
updateCacheListener(statusString);
return statusString;
} | [
"@",
"POST",
"@",
"Path",
"(",
"\"/probeResponse\"",
")",
"@",
"Consumes",
"(",
"\"application/json\"",
")",
"public",
"String",
"handleJSONProbeResponse",
"(",
"String",
"probeResponseJSON",
")",
"{",
"JSONSerializer",
"serializer",
"=",
"new",
"JSONSerializer",
"(... | Inbound JSON responses get processed here.
@param probeResponseJSON - the actual wireline response payload
@return some innocuous string | [
"Inbound",
"JSON",
"responses",
"get",
"processed",
"here",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/listener/ProbeResponseResource.java#L69-L97 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Circle.java | Circle.set | public Circle set (ICircle c) {
return set(c.x(), c.y(), c.radius());
} | java | public Circle set (ICircle c) {
return set(c.x(), c.y(), c.radius());
} | [
"public",
"Circle",
"set",
"(",
"ICircle",
"c",
")",
"{",
"return",
"set",
"(",
"c",
".",
"x",
"(",
")",
",",
"c",
".",
"y",
"(",
")",
",",
"c",
".",
"radius",
"(",
")",
")",
";",
"}"
] | Sets the properties of this circle to be equal to those of the supplied circle.
@return a reference to this this, for chaining. | [
"Sets",
"the",
"properties",
"of",
"this",
"circle",
"to",
"be",
"equal",
"to",
"those",
"of",
"the",
"supplied",
"circle",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Circle.java#L54-L56 | train |
samskivert/pythagoras | src/main/java/pythagoras/d/Circle.java | Circle.set | public Circle set (double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
return this;
} | java | public Circle set (double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
return this;
} | [
"public",
"Circle",
"set",
"(",
"double",
"x",
",",
"double",
"y",
",",
"double",
"radius",
")",
"{",
"this",
".",
"x",
"=",
"x",
";",
"this",
".",
"y",
"=",
"y",
";",
"this",
".",
"radius",
"=",
"radius",
";",
"return",
"this",
";",
"}"
] | Sets the properties of this circle to the supplied values.
@return a reference to this this, for chaining. | [
"Sets",
"the",
"properties",
"of",
"this",
"circle",
"to",
"the",
"supplied",
"values",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/d/Circle.java#L60-L65 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix4.java | Matrix4.setToRotation | public Matrix4 setToRotation (float angle, float x, float y, float z) {
float c = FloatMath.cos(angle), s = FloatMath.sin(angle), omc = 1f - c;
float xs = x*s, ys = y*s, zs = z*s, xy = x*y, xz = x*z, yz = y*z;
return set(x*x*omc + c, xy*omc - zs, xz*omc + ys, 0f,
xy*omc + zs, y*y*omc + c, yz*omc - xs, 0f,
xz*omc - ys, yz*omc + xs, z*z*omc + c, 0f,
0f, 0f, 0f, 1f);
} | java | public Matrix4 setToRotation (float angle, float x, float y, float z) {
float c = FloatMath.cos(angle), s = FloatMath.sin(angle), omc = 1f - c;
float xs = x*s, ys = y*s, zs = z*s, xy = x*y, xz = x*z, yz = y*z;
return set(x*x*omc + c, xy*omc - zs, xz*omc + ys, 0f,
xy*omc + zs, y*y*omc + c, yz*omc - xs, 0f,
xz*omc - ys, yz*omc + xs, z*z*omc + c, 0f,
0f, 0f, 0f, 1f);
} | [
"public",
"Matrix4",
"setToRotation",
"(",
"float",
"angle",
",",
"float",
"x",
",",
"float",
"y",
",",
"float",
"z",
")",
"{",
"float",
"c",
"=",
"FloatMath",
".",
"cos",
"(",
"angle",
")",
",",
"s",
"=",
"FloatMath",
".",
"sin",
"(",
"angle",
")"... | Sets this to a rotation matrix. The formula comes from the OpenGL documentation for the
glRotatef function.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"rotation",
"matrix",
".",
"The",
"formula",
"comes",
"from",
"the",
"OpenGL",
"documentation",
"for",
"the",
"glRotatef",
"function",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Matrix4.java#L212-L219 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix4.java | Matrix4.setToReflection | public Matrix4 setToReflection (float x, float y, float z, float w) {
float x2 = -2f*x, y2 = -2f*y, z2 = -2f*z;
float xy2 = x2*y, xz2 = x2*z, yz2 = y2*z;
float x2y2z2 = x*x + y*y + z*z;
return set(1f + x2*x, xy2, xz2, x2*w*x2y2z2,
xy2, 1f + y2*y, yz2, y2*w*x2y2z2,
xz2, yz2, 1f + z2*z, z2*w*x2y2z2,
0f, 0f, 0f, 1f);
} | java | public Matrix4 setToReflection (float x, float y, float z, float w) {
float x2 = -2f*x, y2 = -2f*y, z2 = -2f*z;
float xy2 = x2*y, xz2 = x2*z, yz2 = y2*z;
float x2y2z2 = x*x + y*y + z*z;
return set(1f + x2*x, xy2, xz2, x2*w*x2y2z2,
xy2, 1f + y2*y, yz2, y2*w*x2y2z2,
xz2, yz2, 1f + z2*z, z2*w*x2y2z2,
0f, 0f, 0f, 1f);
} | [
"public",
"Matrix4",
"setToReflection",
"(",
"float",
"x",
",",
"float",
"y",
",",
"float",
"z",
",",
"float",
"w",
")",
"{",
"float",
"x2",
"=",
"-",
"2f",
"*",
"x",
",",
"y2",
"=",
"-",
"2f",
"*",
"y",
",",
"z2",
"=",
"-",
"2f",
"*",
"z",
... | Sets this to a reflection across the specified plane.
@return a reference to this matrix, for chaining. | [
"Sets",
"this",
"to",
"a",
"reflection",
"across",
"the",
"specified",
"plane",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Matrix4.java#L326-L334 | train |
samskivert/pythagoras | src/main/java/pythagoras/f/Matrix4.java | Matrix4.set | public Matrix4 set (float[] values) {
return set(values[0], values[1], values[2], values[3],
values[4], values[5], values[6], values[7],
values[8], values[9], values[10], values[11],
values[12], values[13], values[14], values[15]);
} | java | public Matrix4 set (float[] values) {
return set(values[0], values[1], values[2], values[3],
values[4], values[5], values[6], values[7],
values[8], values[9], values[10], values[11],
values[12], values[13], values[14], values[15]);
} | [
"public",
"Matrix4",
"set",
"(",
"float",
"[",
"]",
"values",
")",
"{",
"return",
"set",
"(",
"values",
"[",
"0",
"]",
",",
"values",
"[",
"1",
"]",
",",
"values",
"[",
"2",
"]",
",",
"values",
"[",
"3",
"]",
",",
"values",
"[",
"4",
"]",
","... | Copies the elements of a row-major array.
@return a reference to this matrix, for chaining. | [
"Copies",
"the",
"elements",
"of",
"a",
"row",
"-",
"major",
"array",
"."
] | b8fea743ee8a7d742ad9c06ee4f11f50571fbd32 | https://github.com/samskivert/pythagoras/blob/b8fea743ee8a7d742ad9c06ee4f11f50571fbd32/src/main/java/pythagoras/f/Matrix4.java#L457-L462 | train |
konmik/satellite | satellite/src/main/java/satellite/Restartable.java | Restartable.launch | public void launch(Object arg) {
ReconnectableMap.INSTANCE.dismiss(key);
out.put("restore", true);
out.put("arg", arg);
launches.onNext(arg);
} | java | public void launch(Object arg) {
ReconnectableMap.INSTANCE.dismiss(key);
out.put("restore", true);
out.put("arg", arg);
launches.onNext(arg);
} | [
"public",
"void",
"launch",
"(",
"Object",
"arg",
")",
"{",
"ReconnectableMap",
".",
"INSTANCE",
".",
"dismiss",
"(",
"key",
")",
";",
"out",
".",
"put",
"(",
"\"restore\"",
",",
"true",
")",
";",
"out",
".",
"put",
"(",
"\"arg\"",
",",
"arg",
")",
... | Launches an observable providing an argument.
Dismisses the previous observable instance if it is not completed yet.
Note that to make use of arguments, both
{@link #channel(DeliveryMethod, ObservableFactory)} and
{@link #launch(Object)} variants should be used.
@param arg an argument for the new observable.
It must satisfy {@link android.os.Parcel#writeValue(Object)}
method argument requirements. | [
"Launches",
"an",
"observable",
"providing",
"an",
"argument",
".",
"Dismisses",
"the",
"previous",
"observable",
"instance",
"if",
"it",
"is",
"not",
"completed",
"yet",
"."
] | 7b0d3194bf84b3db4c233a131890a23e2d5825b9 | https://github.com/konmik/satellite/blob/7b0d3194bf84b3db4c233a131890a23e2d5825b9/satellite/src/main/java/satellite/Restartable.java#L123-L128 | train |
johnlcox/motif | motif/src/main/java/com/leacox/motif/extract/util/Lists.java | Lists.of | public static <E> List<E> of(E e1, E e2, E e3, E e4) {
List<E> list = new ArrayList<>();
list.add(e1);
list.add(e2);
list.add(e3);
list.add(e4);
return list;
} | java | public static <E> List<E> of(E e1, E e2, E e3, E e4) {
List<E> list = new ArrayList<>();
list.add(e1);
list.add(e2);
list.add(e3);
list.add(e4);
return list;
} | [
"public",
"static",
"<",
"E",
">",
"List",
"<",
"E",
">",
"of",
"(",
"E",
"e1",
",",
"E",
"e2",
",",
"E",
"e3",
",",
"E",
"e4",
")",
"{",
"List",
"<",
"E",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"list",
".",
"add",
"("... | Returns a list of the given elements, in order. | [
"Returns",
"a",
"list",
"of",
"the",
"given",
"elements",
"in",
"order",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/motif/src/main/java/com/leacox/motif/extract/util/Lists.java#L75-L82 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileMonitorTask.java | ConfigFileMonitorTask.run | public void run() {
LOGGER.debug("begin scan for config file changes ...");
try {
Date lastModified = new Date(_xmlConfigFile.lastModified());
if (_lastTimeRead == null || lastModified.after(_lastTimeRead)) {
LOGGER.info("loading config file changes ...");
this.loadServiceConfigFile();
_lastTimeRead = new Date();
}
} catch (ConfigurationException e) {
e.printStackTrace();
LOGGER.error( "Error loading configuation file: ", e );
}
LOGGER.debug("finish scan for config file changes");
} | java | public void run() {
LOGGER.debug("begin scan for config file changes ...");
try {
Date lastModified = new Date(_xmlConfigFile.lastModified());
if (_lastTimeRead == null || lastModified.after(_lastTimeRead)) {
LOGGER.info("loading config file changes ...");
this.loadServiceConfigFile();
_lastTimeRead = new Date();
}
} catch (ConfigurationException e) {
e.printStackTrace();
LOGGER.error( "Error loading configuation file: ", e );
}
LOGGER.debug("finish scan for config file changes");
} | [
"public",
"void",
"run",
"(",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"begin scan for config file changes ...\"",
")",
";",
"try",
"{",
"Date",
"lastModified",
"=",
"new",
"Date",
"(",
"_xmlConfigFile",
".",
"lastModified",
"(",
")",
")",
";",
"if",
"(",
... | When the timer goes off, look for changes to the specified xml config file.
For comparison, we are only interested in the last time we read the file. A
null value for lastTimeRead means that we never read the file before. | [
"When",
"the",
"timer",
"goes",
"off",
"look",
"for",
"changes",
"to",
"the",
"specified",
"xml",
"config",
"file",
".",
"For",
"comparison",
"we",
"are",
"only",
"interested",
"in",
"the",
"last",
"time",
"we",
"read",
"the",
"file",
".",
"A",
"null",
... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileMonitorTask.java#L86-L101 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileMonitorTask.java | ConfigFileMonitorTask.loadServiceConfigFile | private void loadServiceConfigFile() throws ConfigurationException {
Properties properties = _plugin.getConfiguration();
Configuration config = ConfigurationConverter.getConfiguration(properties);
String xmlConfigFilename = config.getString("xmlConfigFilename");
_config = new ServiceListConfiguration(xmlConfigFilename);
// ServicesConfiguration services = parseConfigFile(xmlConfigFilename);
// ArrayList<ServiceWrapper> serviceList = constructServiceList(services);
ArrayList<ServiceWrapper> serviceList = _config.getServiceList();
LOGGER.debug("Setting the service list in the plugin");
_plugin.setServiceList(serviceList);
} | java | private void loadServiceConfigFile() throws ConfigurationException {
Properties properties = _plugin.getConfiguration();
Configuration config = ConfigurationConverter.getConfiguration(properties);
String xmlConfigFilename = config.getString("xmlConfigFilename");
_config = new ServiceListConfiguration(xmlConfigFilename);
// ServicesConfiguration services = parseConfigFile(xmlConfigFilename);
// ArrayList<ServiceWrapper> serviceList = constructServiceList(services);
ArrayList<ServiceWrapper> serviceList = _config.getServiceList();
LOGGER.debug("Setting the service list in the plugin");
_plugin.setServiceList(serviceList);
} | [
"private",
"void",
"loadServiceConfigFile",
"(",
")",
"throws",
"ConfigurationException",
"{",
"Properties",
"properties",
"=",
"_plugin",
".",
"getConfiguration",
"(",
")",
";",
"Configuration",
"config",
"=",
"ConfigurationConverter",
".",
"getConfiguration",
"(",
"... | actually load the xml configuration file. If anything goes wrong throws an
exception. This created a list of service records. When done, set the
service record list in the plugin. The plugin set function should be
synchronized so that it won't squash any concurrent access to the old set
of services.
@throws JAXBException if there is some issue with the XML
@throws FileNotFoundException if the file name does not exist
@throws ConfigurationException if something went wrong | [
"actually",
"load",
"the",
"xml",
"configuration",
"file",
".",
"If",
"anything",
"goes",
"wrong",
"throws",
"an",
"exception",
".",
"This",
"created",
"a",
"list",
"of",
"service",
"records",
".",
"When",
"done",
"set",
"the",
"service",
"record",
"list",
... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/plugin/configfile/ConfigFileMonitorTask.java#L114-L131 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java | ClientProbeSenders.initialize | public void initialize(ArgoClientContext context) throws TransportConfigException {
transportProps = processPropertiesFile(config.getPropertiesFilename());
createProbeSenders(context);
} | java | public void initialize(ArgoClientContext context) throws TransportConfigException {
transportProps = processPropertiesFile(config.getPropertiesFilename());
createProbeSenders(context);
} | [
"public",
"void",
"initialize",
"(",
"ArgoClientContext",
"context",
")",
"throws",
"TransportConfigException",
"{",
"transportProps",
"=",
"processPropertiesFile",
"(",
"config",
".",
"getPropertiesFilename",
"(",
")",
")",
";",
"createProbeSenders",
"(",
"context",
... | Initialize the actual ProbeSenders.
@param context the context of the client application for parameters
@throws TransportConfigException if something goes wonky reading specific
configs for each transport | [
"Initialize",
"the",
"actual",
"ProbeSenders",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java#L50-L55 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java | ClientProbeSenders.getDescription | public String getDescription() {
StringBuffer buf = new StringBuffer();
String transportName = config.getName();
for (ProbeSender sender : senders) {
buf.append(transportName).append(" -- ").append(isEnabled() ? "Enabled" : "Disabled")
.append(" -- ").append(sender.getDescription());
}
return buf.toString();
} | java | public String getDescription() {
StringBuffer buf = new StringBuffer();
String transportName = config.getName();
for (ProbeSender sender : senders) {
buf.append(transportName).append(" -- ").append(isEnabled() ? "Enabled" : "Disabled")
.append(" -- ").append(sender.getDescription());
}
return buf.toString();
} | [
"public",
"String",
"getDescription",
"(",
")",
"{",
"StringBuffer",
"buf",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"String",
"transportName",
"=",
"config",
".",
"getName",
"(",
")",
";",
"for",
"(",
"ProbeSender",
"sender",
":",
"senders",
")",
"{",
... | return the text description of the transport and its associated
ProbeSenders.
@return text description (one liner) | [
"return",
"the",
"text",
"description",
"of",
"the",
"transport",
"and",
"its",
"associated",
"ProbeSenders",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java#L79-L88 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java | ClientProbeSenders.showConfiguration | public String showConfiguration() {
StringBuffer buf = new StringBuffer();
buf.append("\n Client Transport Configuration\n");
buf.append(" Name ...................... ").append(config.getName()).append("\n");
buf.append(" Is Enabled................. ").append(isEnabled()).append("\n");
buf.append(" Required Multicast ........ ").append(config.requiresMulticast()).append("\n");
buf.append(" Uses NI ................... ").append(config.usesNetworkInterface()).append("\n");
buf.append(" Classname ................. ").append(config.getClassname()).append("\n");
buf.append(" Properties filename ....... ").append(config.getPropertiesFilename()).append("\n\n");
buf.append(" Number of ProbeSenders .... ").append(this.getSenders().size()).append("\n");
buf.append(" ProbeSenders .............. \n");
for (ProbeSender s : getSenders()) {
buf.append(" .... ").append(s.getDescription()).append("\n");
}
buf.append(" -------------------------------\n");
return buf.toString();
} | java | public String showConfiguration() {
StringBuffer buf = new StringBuffer();
buf.append("\n Client Transport Configuration\n");
buf.append(" Name ...................... ").append(config.getName()).append("\n");
buf.append(" Is Enabled................. ").append(isEnabled()).append("\n");
buf.append(" Required Multicast ........ ").append(config.requiresMulticast()).append("\n");
buf.append(" Uses NI ................... ").append(config.usesNetworkInterface()).append("\n");
buf.append(" Classname ................. ").append(config.getClassname()).append("\n");
buf.append(" Properties filename ....... ").append(config.getPropertiesFilename()).append("\n\n");
buf.append(" Number of ProbeSenders .... ").append(this.getSenders().size()).append("\n");
buf.append(" ProbeSenders .............. \n");
for (ProbeSender s : getSenders()) {
buf.append(" .... ").append(s.getDescription()).append("\n");
}
buf.append(" -------------------------------\n");
return buf.toString();
} | [
"public",
"String",
"showConfiguration",
"(",
")",
"{",
"StringBuffer",
"buf",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"buf",
".",
"append",
"(",
"\"\\n Client Transport Configuration\\n\"",
")",
";",
"buf",
".",
"append",
"(",
"\" Name ........................ | Show the configuration for a Client Transport.
@return the configuration description of the ClientTransport | [
"Show",
"the",
"configuration",
"for",
"a",
"Client",
"Transport",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java#L95-L113 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java | ClientProbeSenders.close | public void close() {
for (ProbeSender sender : getSenders()) {
try {
sender.close();
} catch (TransportException e) {
LOGGER.warn( "Issue closing the ProbeSender [" + sender.getDescription() + "]", e);
}
}
} | java | public void close() {
for (ProbeSender sender : getSenders()) {
try {
sender.close();
} catch (TransportException e) {
LOGGER.warn( "Issue closing the ProbeSender [" + sender.getDescription() + "]", e);
}
}
} | [
"public",
"void",
"close",
"(",
")",
"{",
"for",
"(",
"ProbeSender",
"sender",
":",
"getSenders",
"(",
")",
")",
"{",
"try",
"{",
"sender",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"TransportException",
"e",
")",
"{",
"LOGGER",
".",
"warn",
... | This closes any of the underlying resources that a ProbeSender might be
using, such as a connection to a server somewhere. | [
"This",
"closes",
"any",
"of",
"the",
"underlying",
"resources",
"that",
"a",
"ProbeSender",
"might",
"be",
"using",
"such",
"as",
"a",
"connection",
"to",
"a",
"server",
"somewhere",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java#L119-L127 | train |
di2e/Argo | CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java | ClientProbeSenders.createProbeSenders | private void createProbeSenders(ArgoClientContext context) throws TransportConfigException {
senders = new ArrayList<ProbeSender>();
if (config.usesNetworkInterface()) {
try {
for (String niName : context.getAvailableNetworkInterfaces(config.requiresMulticast())) {
try {
Transport transport = instantiateTransportClass(config.getClassname());
transport.initialize(transportProps, niName);
ProbeSender sender = new ProbeSender(transport);
senders.add(sender);
} catch (TransportConfigException e) {
LOGGER.warn( e.getLocalizedMessage());
}
}
} catch (SocketException e) {
throw new TransportConfigException("Error getting available network interfaces", e);
}
} else {
Transport transport = instantiateTransportClass(config.getClassname());
transport.initialize(transportProps, "");
ProbeSender sender = new ProbeSender(transport);
senders.add(sender);
}
} | java | private void createProbeSenders(ArgoClientContext context) throws TransportConfigException {
senders = new ArrayList<ProbeSender>();
if (config.usesNetworkInterface()) {
try {
for (String niName : context.getAvailableNetworkInterfaces(config.requiresMulticast())) {
try {
Transport transport = instantiateTransportClass(config.getClassname());
transport.initialize(transportProps, niName);
ProbeSender sender = new ProbeSender(transport);
senders.add(sender);
} catch (TransportConfigException e) {
LOGGER.warn( e.getLocalizedMessage());
}
}
} catch (SocketException e) {
throw new TransportConfigException("Error getting available network interfaces", e);
}
} else {
Transport transport = instantiateTransportClass(config.getClassname());
transport.initialize(transportProps, "");
ProbeSender sender = new ProbeSender(transport);
senders.add(sender);
}
} | [
"private",
"void",
"createProbeSenders",
"(",
"ArgoClientContext",
"context",
")",
"throws",
"TransportConfigException",
"{",
"senders",
"=",
"new",
"ArrayList",
"<",
"ProbeSender",
">",
"(",
")",
";",
"if",
"(",
"config",
".",
"usesNetworkInterface",
"(",
")",
... | Create the actual ProbeSender instances given the configuration
information. If the transport depends on Network Interfaces, then create a
ProbeSender for each NI we can find on this machine.
@param context the main client configuration information
@throws TransportConfigException if there is some issue initializing the
transport. | [
"Create",
"the",
"actual",
"ProbeSender",
"instances",
"given",
"the",
"configuration",
"information",
".",
"If",
"the",
"transport",
"depends",
"on",
"Network",
"Interfaces",
"then",
"create",
"a",
"ProbeSender",
"for",
"each",
"NI",
"we",
"can",
"find",
"on",
... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/CLClient/src/main/java/ws/argo/CLClient/ClientProbeSenders.java#L161-L186 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.getTypeVariables | protected List<TypeVariableName> getTypeVariables(TypeName t) {
return match(t)
.when(typeOf(TypeVariableName.class)).get(
v -> {
if (v.bounds.isEmpty()) {
return ImmutableList.of(v);
} else {
return Stream.concat(
Stream.of(v), v.bounds.stream()
.map(b -> getTypeVariables(b))
.flatMap(b -> b.stream()))
.collect(Collectors.toList());
}
})
.when(typeOf(ParameterizedTypeName.class)).get(
p -> p.typeArguments.stream()
.map(v -> getTypeVariables(v))
.flatMap(l -> l.stream())
.collect(Collectors.toList()))
.orElse(Collections.emptyList())
.getMatch();
} | java | protected List<TypeVariableName> getTypeVariables(TypeName t) {
return match(t)
.when(typeOf(TypeVariableName.class)).get(
v -> {
if (v.bounds.isEmpty()) {
return ImmutableList.of(v);
} else {
return Stream.concat(
Stream.of(v), v.bounds.stream()
.map(b -> getTypeVariables(b))
.flatMap(b -> b.stream()))
.collect(Collectors.toList());
}
})
.when(typeOf(ParameterizedTypeName.class)).get(
p -> p.typeArguments.stream()
.map(v -> getTypeVariables(v))
.flatMap(l -> l.stream())
.collect(Collectors.toList()))
.orElse(Collections.emptyList())
.getMatch();
} | [
"protected",
"List",
"<",
"TypeVariableName",
">",
"getTypeVariables",
"(",
"TypeName",
"t",
")",
"{",
"return",
"match",
"(",
"t",
")",
".",
"when",
"(",
"typeOf",
"(",
"TypeVariableName",
".",
"class",
")",
")",
".",
"get",
"(",
"v",
"->",
"{",
"if",... | Returns a list of type variables for a given type.
<p>There are several cases for what the returned type variables will be:
<ul>
<li>If {@code t} is a type variable itself, and has no bounds, then a singleton list
containing only {@code t} will be returned.</li>
<li>If {@code t} is a type variable with bounds, then the returned list will first contain
{@code t} followed by the type variables for the bounds</li>
<li>If {@code t} is a parameterized type, then the returned list will contain the type
variables of the parameterized type arguments</li>
<li>Otherwise an empty list is returned</li>
</ul> | [
"Returns",
"a",
"list",
"of",
"type",
"variables",
"for",
"a",
"given",
"type",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L75-L96 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.createTypeArityList | protected List<TypeNameWithArity> createTypeArityList(
TypeName t, String extractVariableName, int maxArity) {
TypeName u = match(t)
.when(typeOf(TypeVariableName.class))
.get(x -> (TypeName) TypeVariableName.get("E" + x.name, x))
.orElse(x -> x)
.getMatch();
List<TypeNameWithArity> typeArityList = new ArrayList<>();
//typeArityList.add(TypeNameWithArity.of(t, 0));
typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_EXACT, t), 0));
typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_ANY, t), 1));
//typeArityList.add(TypeNameWithArity.of(TypeName.get(MatchesAny.class), 1));
IntStream.rangeClosed(0, maxArity).forEach(
extractArity -> {
TypeName[] typeVariables = createTypeVariables(u, extractVariableName, extractArity);
typeArityList.add(
TypeNameWithArity.of(
ParameterizedTypeName
.get(
ClassName.get(getDecomposableBuilderByArity(extractArity)),
typeVariables), extractArity));
});
return typeArityList;
} | java | protected List<TypeNameWithArity> createTypeArityList(
TypeName t, String extractVariableName, int maxArity) {
TypeName u = match(t)
.when(typeOf(TypeVariableName.class))
.get(x -> (TypeName) TypeVariableName.get("E" + x.name, x))
.orElse(x -> x)
.getMatch();
List<TypeNameWithArity> typeArityList = new ArrayList<>();
//typeArityList.add(TypeNameWithArity.of(t, 0));
typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_EXACT, t), 0));
typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_ANY, t), 1));
//typeArityList.add(TypeNameWithArity.of(TypeName.get(MatchesAny.class), 1));
IntStream.rangeClosed(0, maxArity).forEach(
extractArity -> {
TypeName[] typeVariables = createTypeVariables(u, extractVariableName, extractArity);
typeArityList.add(
TypeNameWithArity.of(
ParameterizedTypeName
.get(
ClassName.get(getDecomposableBuilderByArity(extractArity)),
typeVariables), extractArity));
});
return typeArityList;
} | [
"protected",
"List",
"<",
"TypeNameWithArity",
">",
"createTypeArityList",
"(",
"TypeName",
"t",
",",
"String",
"extractVariableName",
",",
"int",
"maxArity",
")",
"{",
"TypeName",
"u",
"=",
"match",
"(",
"t",
")",
".",
"when",
"(",
"typeOf",
"(",
"TypeVaria... | Returns a list of pairs of types and arities up to a given max arity. | [
"Returns",
"a",
"list",
"of",
"pairs",
"of",
"types",
"and",
"arities",
"up",
"to",
"a",
"given",
"max",
"arity",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L118-L143 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.createTypeVariables | protected TypeName[] createTypeVariables(
TypeName extractedType, String extractVariableName, int extractArity) {
List<TypeName> typeVariables = new ArrayList<>();
typeVariables.add(extractedType);
if (extractArity > 0) {
typeVariables.addAll(
IntStream.rangeClosed(1, extractArity)
.mapToObj(j -> TypeVariableName.get(extractVariableName + j))
.collect(Collectors.toList()));
}
return typeVariables.toArray(new TypeName[typeVariables.size()]);
} | java | protected TypeName[] createTypeVariables(
TypeName extractedType, String extractVariableName, int extractArity) {
List<TypeName> typeVariables = new ArrayList<>();
typeVariables.add(extractedType);
if (extractArity > 0) {
typeVariables.addAll(
IntStream.rangeClosed(1, extractArity)
.mapToObj(j -> TypeVariableName.get(extractVariableName + j))
.collect(Collectors.toList()));
}
return typeVariables.toArray(new TypeName[typeVariables.size()]);
} | [
"protected",
"TypeName",
"[",
"]",
"createTypeVariables",
"(",
"TypeName",
"extractedType",
",",
"String",
"extractVariableName",
",",
"int",
"extractArity",
")",
"{",
"List",
"<",
"TypeName",
">",
"typeVariables",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
... | Returns an array of type variables for a given type and arity. | [
"Returns",
"an",
"array",
"of",
"type",
"variables",
"for",
"a",
"given",
"type",
"and",
"arity",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L148-L160 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.getMatcherStatementArgs | protected static Object[] getMatcherStatementArgs(int matchedCount) {
TypeName matcher = ParameterizedTypeName.get(ClassName.get(Matcher.class), TypeName.OBJECT);
TypeName listOfMatchers = ParameterizedTypeName.get(ClassName.get(List.class), matcher);
TypeName lists = TypeName.get(Lists.class);
TypeName argumentMatchers = TypeName.get(ArgumentMatchers.class);
return Stream.concat(
ImmutableList.of(listOfMatchers, lists).stream(),
IntStream.range(0, matchedCount)
.mapToObj(i -> argumentMatchers)
).toArray(s -> new TypeName[s]);
} | java | protected static Object[] getMatcherStatementArgs(int matchedCount) {
TypeName matcher = ParameterizedTypeName.get(ClassName.get(Matcher.class), TypeName.OBJECT);
TypeName listOfMatchers = ParameterizedTypeName.get(ClassName.get(List.class), matcher);
TypeName lists = TypeName.get(Lists.class);
TypeName argumentMatchers = TypeName.get(ArgumentMatchers.class);
return Stream.concat(
ImmutableList.of(listOfMatchers, lists).stream(),
IntStream.range(0, matchedCount)
.mapToObj(i -> argumentMatchers)
).toArray(s -> new TypeName[s]);
} | [
"protected",
"static",
"Object",
"[",
"]",
"getMatcherStatementArgs",
"(",
"int",
"matchedCount",
")",
"{",
"TypeName",
"matcher",
"=",
"ParameterizedTypeName",
".",
"get",
"(",
"ClassName",
".",
"get",
"(",
"Matcher",
".",
"class",
")",
",",
"TypeName",
".",
... | Returns the statement arguments for the match method matcher statement. | [
"Returns",
"the",
"statement",
"arguments",
"for",
"the",
"match",
"method",
"matcher",
"statement",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L165-L176 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.getMatchType | protected MatchType getMatchType(TypeName m) {
return match(m)
.when(typeOf(ParameterizedTypeName.class)).get(
t -> {
if (isDecomposableBuilder(t.rawType)) {
return MatchType.DECOMPOSE;
} else if (t.rawType.equals(MATCH_ANY)) {
return MatchType.ANY;
} else if (t.rawType.equals(MATCH_EXACT)) {
return MatchType.EXACT;
} else {
return MatchType.EXACT;
}
})
.when(typeOf(TypeVariableName.class)).get(t -> MatchType.EXACT)
.orElse(MatchType.ANY)
.getMatch();
} | java | protected MatchType getMatchType(TypeName m) {
return match(m)
.when(typeOf(ParameterizedTypeName.class)).get(
t -> {
if (isDecomposableBuilder(t.rawType)) {
return MatchType.DECOMPOSE;
} else if (t.rawType.equals(MATCH_ANY)) {
return MatchType.ANY;
} else if (t.rawType.equals(MATCH_EXACT)) {
return MatchType.EXACT;
} else {
return MatchType.EXACT;
}
})
.when(typeOf(TypeVariableName.class)).get(t -> MatchType.EXACT)
.orElse(MatchType.ANY)
.getMatch();
} | [
"protected",
"MatchType",
"getMatchType",
"(",
"TypeName",
"m",
")",
"{",
"return",
"match",
"(",
"m",
")",
".",
"when",
"(",
"typeOf",
"(",
"ParameterizedTypeName",
".",
"class",
")",
")",
".",
"get",
"(",
"t",
"->",
"{",
"if",
"(",
"isDecomposableBuild... | Returns the type of match to use for a given type. | [
"Returns",
"the",
"type",
"of",
"match",
"to",
"use",
"for",
"a",
"given",
"type",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L181-L198 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.getExtractedTypes | protected List<TypeName> getExtractedTypes(TypeName permutationType, TypeName paramType) {
return match(permutationType)
.when(typeOf(ParameterizedTypeName.class)).get(
t -> {
if (isDecomposableBuilder(t.rawType)) {
return t.typeArguments.subList(1, t.typeArguments.size());
} else if (t.rawType.equals(MATCH_ANY)) {
return ImmutableList.of(paramType);
} else {
return Collections.<TypeName>emptyList();
}
})
.when(typeOf(TypeVariableName.class)).get(t -> ImmutableList.of())
.when(typeOf(ClassName.class)).get(t -> ImmutableList.of(paramType))
.orElse(t -> ImmutableList.of(t))
.getMatch();
} | java | protected List<TypeName> getExtractedTypes(TypeName permutationType, TypeName paramType) {
return match(permutationType)
.when(typeOf(ParameterizedTypeName.class)).get(
t -> {
if (isDecomposableBuilder(t.rawType)) {
return t.typeArguments.subList(1, t.typeArguments.size());
} else if (t.rawType.equals(MATCH_ANY)) {
return ImmutableList.of(paramType);
} else {
return Collections.<TypeName>emptyList();
}
})
.when(typeOf(TypeVariableName.class)).get(t -> ImmutableList.of())
.when(typeOf(ClassName.class)).get(t -> ImmutableList.of(paramType))
.orElse(t -> ImmutableList.of(t))
.getMatch();
} | [
"protected",
"List",
"<",
"TypeName",
">",
"getExtractedTypes",
"(",
"TypeName",
"permutationType",
",",
"TypeName",
"paramType",
")",
"{",
"return",
"match",
"(",
"permutationType",
")",
".",
"when",
"(",
"typeOf",
"(",
"ParameterizedTypeName",
".",
"class",
")... | Returns the extracted type parameters. | [
"Returns",
"the",
"extracted",
"type",
"parameters",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L216-L232 | train |
johnlcox/motif | generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java | BaseMatchMethodPermutationBuilder.getReturnStatementArgs | protected List<TypeName> getReturnStatementArgs(MatchType matchType, TypeName paramType) {
List<TypeName> extractA;
if (matchType == MatchType.DECOMPOSE) {
TypeName u = match(paramType)
.when(typeOf(TypeVariableName.class)).get(
x -> (TypeName) TypeVariableName.get("E" + x.name, x))
.orElse(x -> x)
.getMatch();
extractA = ImmutableList.of(u);
} else if (matchType == MatchType.ANY) {
extractA = ImmutableList.of(paramType);
} else {
extractA = ImmutableList.of();
}
return extractA;
} | java | protected List<TypeName> getReturnStatementArgs(MatchType matchType, TypeName paramType) {
List<TypeName> extractA;
if (matchType == MatchType.DECOMPOSE) {
TypeName u = match(paramType)
.when(typeOf(TypeVariableName.class)).get(
x -> (TypeName) TypeVariableName.get("E" + x.name, x))
.orElse(x -> x)
.getMatch();
extractA = ImmutableList.of(u);
} else if (matchType == MatchType.ANY) {
extractA = ImmutableList.of(paramType);
} else {
extractA = ImmutableList.of();
}
return extractA;
} | [
"protected",
"List",
"<",
"TypeName",
">",
"getReturnStatementArgs",
"(",
"MatchType",
"matchType",
",",
"TypeName",
"paramType",
")",
"{",
"List",
"<",
"TypeName",
">",
"extractA",
";",
"if",
"(",
"matchType",
"==",
"MatchType",
".",
"DECOMPOSE",
")",
"{",
... | Returns the statement arguments for the match method returns statement. | [
"Returns",
"the",
"statement",
"arguments",
"for",
"the",
"match",
"method",
"returns",
"statement",
"."
] | 33a72d79fcbac16c89f8c4b0567856f2442f59be | https://github.com/johnlcox/motif/blob/33a72d79fcbac16c89f8c4b0567856f2442f59be/generator/src/main/java/com/leacox/motif/generate/BaseMatchMethodPermutationBuilder.java#L237-L253 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java | ProbeSenderFactory.createMulticastProbeSender | public static ProbeSender createMulticastProbeSender() throws ProbeSenderException, TransportConfigException {
Transport mcastTransport = new MulticastTransport("");
ProbeSender gen = new ProbeSender(mcastTransport);
return gen;
} | java | public static ProbeSender createMulticastProbeSender() throws ProbeSenderException, TransportConfigException {
Transport mcastTransport = new MulticastTransport("");
ProbeSender gen = new ProbeSender(mcastTransport);
return gen;
} | [
"public",
"static",
"ProbeSender",
"createMulticastProbeSender",
"(",
")",
"throws",
"ProbeSenderException",
",",
"TransportConfigException",
"{",
"Transport",
"mcastTransport",
"=",
"new",
"MulticastTransport",
"(",
"\"\"",
")",
";",
"ProbeSender",
"gen",
"=",
"new",
... | Create a Multicast ProbeSender with all the default values. The default
values are the default multicast group address and port of the Argo
protocol. The Network Interface is the NI associated with the localhost
address.
@return configured ProbeSender instance
@throws ProbeSenderException if something went wrong
@throws TransportConfigException if something went wrong | [
"Create",
"a",
"Multicast",
"ProbeSender",
"with",
"all",
"the",
"default",
"values",
".",
"The",
"default",
"values",
"are",
"the",
"default",
"multicast",
"group",
"address",
"and",
"port",
"of",
"the",
"Argo",
"protocol",
".",
"The",
"Network",
"Interface",... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java#L48-L53 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java | ProbeSenderFactory.createMulticastProbeSender | public static ProbeSender createMulticastProbeSender(String niName) throws TransportConfigException {
Transport mcastTransport = new MulticastTransport(niName);
ProbeSender gen = new ProbeSender(mcastTransport);
return gen;
} | java | public static ProbeSender createMulticastProbeSender(String niName) throws TransportConfigException {
Transport mcastTransport = new MulticastTransport(niName);
ProbeSender gen = new ProbeSender(mcastTransport);
return gen;
} | [
"public",
"static",
"ProbeSender",
"createMulticastProbeSender",
"(",
"String",
"niName",
")",
"throws",
"TransportConfigException",
"{",
"Transport",
"mcastTransport",
"=",
"new",
"MulticastTransport",
"(",
"niName",
")",
";",
"ProbeSender",
"gen",
"=",
"new",
"Probe... | Create a Multicast ProbeSender specifying the Network Interface to send
on.
@param niName network interface name
@return configured ProbeSender instance
@throws TransportConfigException if something went wrong | [
"Create",
"a",
"Multicast",
"ProbeSender",
"specifying",
"the",
"Network",
"Interface",
"to",
"send",
"on",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java#L63-L67 | train |
di2e/Argo | ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java | ProbeSenderFactory.createSNSProbeSender | public static ProbeSender createSNSProbeSender(String ak, String sk) throws ProbeSenderException {
Transport snsTransport = new AmazonSNSTransport(ak, sk);
ProbeSender gen = new ProbeSender(snsTransport);
return gen;
} | java | public static ProbeSender createSNSProbeSender(String ak, String sk) throws ProbeSenderException {
Transport snsTransport = new AmazonSNSTransport(ak, sk);
ProbeSender gen = new ProbeSender(snsTransport);
return gen;
} | [
"public",
"static",
"ProbeSender",
"createSNSProbeSender",
"(",
"String",
"ak",
",",
"String",
"sk",
")",
"throws",
"ProbeSenderException",
"{",
"Transport",
"snsTransport",
"=",
"new",
"AmazonSNSTransport",
"(",
"ak",
",",
"sk",
")",
";",
"ProbeSender",
"gen",
... | Create a AmazonSNS transport ProbeSender using the default values.
@param ak the amazon access key
@param sk the amazon secret key
@return configured ProbeSender instance
@throws ProbeSenderException if something went wrong | [
"Create",
"a",
"AmazonSNS",
"transport",
"ProbeSender",
"using",
"the",
"default",
"values",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/ProbeSender/src/main/java/ws/argo/probe/ProbeSenderFactory.java#L108-L112 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.initializeHTTPClient | private void initializeHTTPClient() {
if (_config.isHTTPSConfigured()) {
try {
KeyStore trustKeystore = getClientTruststore();
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(trustKeystore, new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
// Allow both HTTP and HTTPS connections
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", sslsf)
.build();
HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r);
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
} catch (Exception e) {
LOGGER.error( "Issue creating HTTP client using supplied configuration. Proceeding with default non-SSL client.", e);
httpClient = HttpClients.createDefault();
}
} else {
httpClient = HttpClients.createDefault();
}
} | java | private void initializeHTTPClient() {
if (_config.isHTTPSConfigured()) {
try {
KeyStore trustKeystore = getClientTruststore();
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(trustKeystore, new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
// Allow both HTTP and HTTPS connections
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", sslsf)
.build();
HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r);
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
} catch (Exception e) {
LOGGER.error( "Issue creating HTTP client using supplied configuration. Proceeding with default non-SSL client.", e);
httpClient = HttpClients.createDefault();
}
} else {
httpClient = HttpClients.createDefault();
}
} | [
"private",
"void",
"initializeHTTPClient",
"(",
")",
"{",
"if",
"(",
"_config",
".",
"isHTTPSConfigured",
"(",
")",
")",
"{",
"try",
"{",
"KeyStore",
"trustKeystore",
"=",
"getClientTruststore",
"(",
")",
";",
"SSLContext",
"sslContext",
"=",
"SSLContexts",
".... | Create HTTP Client. | [
"Create",
"HTTP",
"Client",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L153-L184 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.getClientTruststore | private KeyStore getClientTruststore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore ks = null;
if (_config.getTruststoreType() != null && !_config.getTruststoreType().isEmpty()) {
try {
ks = KeyStore.getInstance(_config.getTruststoreType());
} catch (KeyStoreException e) {
LOGGER.warn( "The specified truststore type [" + _config.getTruststoreType() + "] didn't work.", e);
throw e;
}
} else {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
}
// get user password and file input stream
char[] password = _config.getTruststorePassword().toCharArray();
java.io.FileInputStream fis = null;
try {
fis = new java.io.FileInputStream(_config.geTruststoreFilename());
ks.load(fis, password);
} finally {
if (fis != null) {
fis.close();
}
}
return ks;
} | java | private KeyStore getClientTruststore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore ks = null;
if (_config.getTruststoreType() != null && !_config.getTruststoreType().isEmpty()) {
try {
ks = KeyStore.getInstance(_config.getTruststoreType());
} catch (KeyStoreException e) {
LOGGER.warn( "The specified truststore type [" + _config.getTruststoreType() + "] didn't work.", e);
throw e;
}
} else {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
}
// get user password and file input stream
char[] password = _config.getTruststorePassword().toCharArray();
java.io.FileInputStream fis = null;
try {
fis = new java.io.FileInputStream(_config.geTruststoreFilename());
ks.load(fis, password);
} finally {
if (fis != null) {
fis.close();
}
}
return ks;
} | [
"private",
"KeyStore",
"getClientTruststore",
"(",
")",
"throws",
"KeyStoreException",
",",
"NoSuchAlgorithmException",
",",
"CertificateException",
",",
"IOException",
"{",
"KeyStore",
"ks",
"=",
"null",
";",
"if",
"(",
"_config",
".",
"getTruststoreType",
"(",
")"... | Read the KeyStore information supplied from the responder configuration file.
@return the KeyStore object
@throws KeyStoreException if there is an issue reading the keystore
@throws NoSuchAlgorithmException if the truststore type is incorrect
@throws CertificateException if there is some issues reading in the certs
@throws IOException if there is an issue reading the keystore | [
"Read",
"the",
"KeyStore",
"information",
"supplied",
"from",
"the",
"responder",
"configuration",
"file",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L195-L224 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.stopResponder | public void stopResponder() {
LOGGER.info("Force shutdown of Responder [" + _runtimeId + "]");
_shutdownHook.start();
Runtime.getRuntime().removeShutdownHook(_shutdownHook);
} | java | public void stopResponder() {
LOGGER.info("Force shutdown of Responder [" + _runtimeId + "]");
_shutdownHook.start();
Runtime.getRuntime().removeShutdownHook(_shutdownHook);
} | [
"public",
"void",
"stopResponder",
"(",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Force shutdown of Responder [\"",
"+",
"_runtimeId",
"+",
"\"]\"",
")",
";",
"_shutdownHook",
".",
"start",
"(",
")",
";",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"removeSh... | Close the socket and tell the processing loop to terminate. This is a
forced shutdown rather then a natural shutdown. A natural shutdown happens
when the shutdown hook fires when the VM exists. This method forces all
that to happen. This is done to allow multiple Responders to be created and
destroyed during a single VM session. Necessary for various testing and
management procedures. | [
"Close",
"the",
"socket",
"and",
"tell",
"the",
"processing",
"loop",
"to",
"terminate",
".",
"This",
"is",
"a",
"forced",
"shutdown",
"rather",
"then",
"a",
"natural",
"shutdown",
".",
"A",
"natural",
"shutdown",
"happens",
"when",
"the",
"shutdown",
"hook"... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L333-L337 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.shutdown | public void shutdown() {
LOGGER.info("Responder shutting down: [" + _runtimeId + "]");
for (Transport t : _transports) {
try {
t.shutdown();
} catch (TransportException e) {
LOGGER.warn( "Error shutting down transport: [" + t.transportName() + "]", e);
}
}
} | java | public void shutdown() {
LOGGER.info("Responder shutting down: [" + _runtimeId + "]");
for (Transport t : _transports) {
try {
t.shutdown();
} catch (TransportException e) {
LOGGER.warn( "Error shutting down transport: [" + t.transportName() + "]", e);
}
}
} | [
"public",
"void",
"shutdown",
"(",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Responder shutting down: [\"",
"+",
"_runtimeId",
"+",
"\"]\"",
")",
";",
"for",
"(",
"Transport",
"t",
":",
"_transports",
")",
"{",
"try",
"{",
"t",
".",
"shutdown",
"(",
")",
... | This will shutdown the listening socket and remove the responder from the
multicast group. Part of the natural life cycle. It also will end the run
loop of the responder automatically - it will interrupt any read operation
going on and exit the run loop. | [
"This",
"will",
"shutdown",
"the",
"listening",
"socket",
"and",
"remove",
"the",
"responder",
"from",
"the",
"multicast",
"group",
".",
"Part",
"of",
"the",
"natural",
"life",
"cycle",
".",
"It",
"also",
"will",
"end",
"the",
"run",
"loop",
"of",
"the",
... | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L345-L354 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.run | public void run() {
// I hope that this hits you over the head with its simplicity.
// That's the idea. The instances of the transports are supposed to be self
// contained.
Thread transportThread;
for (Transport t : _transports) {
transportThread = new Thread(t);
transportThread.setName(t.transportName());
transportThread.start();
}
} | java | public void run() {
// I hope that this hits you over the head with its simplicity.
// That's the idea. The instances of the transports are supposed to be self
// contained.
Thread transportThread;
for (Transport t : _transports) {
transportThread = new Thread(t);
transportThread.setName(t.transportName());
transportThread.start();
}
} | [
"public",
"void",
"run",
"(",
")",
"{",
"// I hope that this hits you over the head with its simplicity.",
"// That's the idea. The instances of the transports are supposed to be self",
"// contained.",
"Thread",
"transportThread",
";",
"for",
"(",
"Transport",
"t",
":",
"_transpor... | This is the main run method for the Argo Responder. It starts up all the
configured transports in their own thread and starts their receive loops.
<p>
Transports run in their own thread. Thus, when all the transports are
running, this method will exit. You can shutdown the Responder by calling
the {@linkplain #shutdown()} method. This method will be called by the
{@linkplain ResponderShutdown} hook. | [
"This",
"is",
"the",
"main",
"run",
"method",
"for",
"the",
"Argo",
"Responder",
".",
"It",
"starts",
"up",
"all",
"the",
"configured",
"transports",
"in",
"their",
"own",
"thread",
"and",
"starts",
"their",
"receive",
"loops",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L372-L387 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.probesPerSecond | public synchronized float probesPerSecond() {
Instant now = new Instant();
Instant event = null;
int events = 0;
boolean done = false;
long timeWindow = 0;
long oldestTime = 0;
do {
event = messages.poll();
if (event != null) {
events++;
if (events == 1)
oldestTime = event.getMillis();
done = event.getMillis() >= now.getMillis();
} else {
done = true;
}
} while (!done);
timeWindow = now.getMillis() - oldestTime;
float mps = (float) events / timeWindow;
mps = (float) (mps * 1000.0);
return mps;
} | java | public synchronized float probesPerSecond() {
Instant now = new Instant();
Instant event = null;
int events = 0;
boolean done = false;
long timeWindow = 0;
long oldestTime = 0;
do {
event = messages.poll();
if (event != null) {
events++;
if (events == 1)
oldestTime = event.getMillis();
done = event.getMillis() >= now.getMillis();
} else {
done = true;
}
} while (!done);
timeWindow = now.getMillis() - oldestTime;
float mps = (float) events / timeWindow;
mps = (float) (mps * 1000.0);
return mps;
} | [
"public",
"synchronized",
"float",
"probesPerSecond",
"(",
")",
"{",
"Instant",
"now",
"=",
"new",
"Instant",
"(",
")",
";",
"Instant",
"event",
"=",
"null",
";",
"int",
"events",
"=",
"0",
";",
"boolean",
"done",
"=",
"false",
";",
"long",
"timeWindow",... | Calculates the number of probes per second over the last 1000 probes.
@return probes per second | [
"Calculates",
"the",
"number",
"of",
"probes",
"per",
"second",
"over",
"the",
"last",
"1000",
"probes",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L402-L431 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.main | public static void main(String[] args) throws ResponderConfigException {
Responder responder = initialize(args);
if (responder != null) {
responder.run();
}
} | java | public static void main(String[] args) throws ResponderConfigException {
Responder responder = initialize(args);
if (responder != null) {
responder.run();
}
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"ResponderConfigException",
"{",
"Responder",
"responder",
"=",
"initialize",
"(",
"args",
")",
";",
"if",
"(",
"responder",
"!=",
"null",
")",
"{",
"responder",
".",
"run"... | Main entry point for Argo Responder.
@param args command line arguments
@throws ResponderConfigException if bad things happen with the
configuration files | [
"Main",
"entry",
"point",
"for",
"Argo",
"Responder",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L491-L498 | train |
di2e/Argo | Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java | Responder.initialize | public static Responder initialize(String[] args) throws ResponderConfigException {
readVersionProperties();
LOGGER.info("Starting Argo Responder daemon process. Version " + ARGO_VERSION);
ResponderConfiguration config = parseCommandLine(args);
if (config == null) {
LOGGER.error( "Invalid Responder Configuration. Terminating Responder process.");
return null;
}
Responder responder = new Responder(config);
// load up the handler classes specified in the configuration parameters
try {
responder.loadHandlerPlugins(config.getProbeHandlerConfigs());
} catch (ProbeHandlerConfigException e) {
throw new ResponderConfigException("Error loading handler plugins: ", e);
}
// load up the transport classes specified in the configuration parameters
responder.loadTransportPlugins(config.getTransportConfigs());
LOGGER.info("Responder registering shutdown hook.");
ResponderShutdown hook = new ResponderShutdown(responder);
Runtime.getRuntime().addShutdownHook(hook);
// This needs to be sent to stdout as there is no way to force the logging
// of this via the LOGGER
System.out.println("Argo " + ARGO_VERSION + " :: " + "Responder started [" + responder._runtimeId + "] :: Responding as [" + (config.isHTTPSConfigured() ? "Secure HTTPS" : "Non-secure HTTP") + "]");
return responder;
} | java | public static Responder initialize(String[] args) throws ResponderConfigException {
readVersionProperties();
LOGGER.info("Starting Argo Responder daemon process. Version " + ARGO_VERSION);
ResponderConfiguration config = parseCommandLine(args);
if (config == null) {
LOGGER.error( "Invalid Responder Configuration. Terminating Responder process.");
return null;
}
Responder responder = new Responder(config);
// load up the handler classes specified in the configuration parameters
try {
responder.loadHandlerPlugins(config.getProbeHandlerConfigs());
} catch (ProbeHandlerConfigException e) {
throw new ResponderConfigException("Error loading handler plugins: ", e);
}
// load up the transport classes specified in the configuration parameters
responder.loadTransportPlugins(config.getTransportConfigs());
LOGGER.info("Responder registering shutdown hook.");
ResponderShutdown hook = new ResponderShutdown(responder);
Runtime.getRuntime().addShutdownHook(hook);
// This needs to be sent to stdout as there is no way to force the logging
// of this via the LOGGER
System.out.println("Argo " + ARGO_VERSION + " :: " + "Responder started [" + responder._runtimeId + "] :: Responding as [" + (config.isHTTPSConfigured() ? "Secure HTTPS" : "Non-secure HTTP") + "]");
return responder;
} | [
"public",
"static",
"Responder",
"initialize",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"ResponderConfigException",
"{",
"readVersionProperties",
"(",
")",
";",
"LOGGER",
".",
"info",
"(",
"\"Starting Argo Responder daemon process. Version \"",
"+",
"ARGO_VERSION... | Create a new Responder given the command line arguments.
@param args - command line arguments
@return the new Responder instance or null if something wonky happened
@throws ResponderConfigException if bad things happen with the
configuration files and the content of the files. For example if
the classnames for the probe handlers are bad (usually a type or
classpath issue) | [
"Create",
"a",
"new",
"Responder",
"given",
"the",
"command",
"line",
"arguments",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/Responder/ResponderDaemon/src/main/java/ws/argo/responder/Responder.java#L510-L543 | train |
di2e/Argo | clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java | CLIContext.loadProperties | private void loadProperties(String propFileName) {
if (propFileName != null) {
loadProperties(getClass().getResourceAsStream(propFileName), propFileName);
}
} | java | private void loadProperties(String propFileName) {
if (propFileName != null) {
loadProperties(getClass().getResourceAsStream(propFileName), propFileName);
}
} | [
"private",
"void",
"loadProperties",
"(",
"String",
"propFileName",
")",
"{",
"if",
"(",
"propFileName",
"!=",
"null",
")",
"{",
"loadProperties",
"(",
"getClass",
"(",
")",
".",
"getResourceAsStream",
"(",
"propFileName",
")",
",",
"propFileName",
")",
";",
... | Load properties from a resource stream.
@param propFileName The resource name. | [
"Load",
"properties",
"from",
"a",
"resource",
"stream",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java#L54-L58 | train |
di2e/Argo | clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java | CLIContext.loadProperties | private void loadProperties(InputStream stream, String path) {
if (stream == null) {
return;
}
try {
Properties props = new Properties();
props.load(stream);
Iterator<Object> keyIt = props.keySet().iterator();
while (keyIt.hasNext()) {
String key = keyIt.next().toString();
_properties.put(key, props.get(key));
}
}
catch (Exception e) {
Console.warn("Unable to load properties file ["+path+"].");
}
finally {
if (stream != null) {
try {
stream.close();
}
catch (Exception e) {
Console.warn("Unable to close properties file ["+path+"].");
}
}
}
} | java | private void loadProperties(InputStream stream, String path) {
if (stream == null) {
return;
}
try {
Properties props = new Properties();
props.load(stream);
Iterator<Object> keyIt = props.keySet().iterator();
while (keyIt.hasNext()) {
String key = keyIt.next().toString();
_properties.put(key, props.get(key));
}
}
catch (Exception e) {
Console.warn("Unable to load properties file ["+path+"].");
}
finally {
if (stream != null) {
try {
stream.close();
}
catch (Exception e) {
Console.warn("Unable to close properties file ["+path+"].");
}
}
}
} | [
"private",
"void",
"loadProperties",
"(",
"InputStream",
"stream",
",",
"String",
"path",
")",
"{",
"if",
"(",
"stream",
"==",
"null",
")",
"{",
"return",
";",
"}",
"try",
"{",
"Properties",
"props",
"=",
"new",
"Properties",
"(",
")",
";",
"props",
".... | Loads properties from the given stream.
This will close the stream.
@param stream The stream to load from.
@param path The path represented by the stream. | [
"Loads",
"properties",
"from",
"the",
"given",
"stream",
".",
"This",
"will",
"close",
"the",
"stream",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java#L82-L110 | train |
di2e/Argo | clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java | CLIContext.put | public Object put(String key, Object o) {
return _properties.put(key, o);
} | java | public Object put(String key, Object o) {
return _properties.put(key, o);
} | [
"public",
"Object",
"put",
"(",
"String",
"key",
",",
"Object",
"o",
")",
"{",
"return",
"_properties",
".",
"put",
"(",
"key",
",",
"o",
")",
";",
"}"
] | Add an object to the context.
@param key The key to add.
@param o The object to add.
@return The previous object associated with this key, or null if there was none. | [
"Add",
"an",
"object",
"to",
"the",
"context",
"."
] | f537a03d2d25fdfecda7999ec10e1da67dc3b8f3 | https://github.com/di2e/Argo/blob/f537a03d2d25fdfecda7999ec10e1da67dc3b8f3/clui/src/main/java/net/dharwin/common/tools/cli/api/CLIContext.java#L134-L136 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.