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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
scireum/parsii | src/main/java/parsii/eval/Scope.java | Scope.getNames | public Set<String> getNames() {
if (parent == null) {
return getLocalNames();
}
Set<String> result = new TreeSet<>();
result.addAll(parent.getNames());
result.addAll(getLocalNames());
return result;
} | java | public Set<String> getNames() {
if (parent == null) {
return getLocalNames();
}
Set<String> result = new TreeSet<>();
result.addAll(parent.getNames());
result.addAll(getLocalNames());
return result;
} | [
"public",
"Set",
"<",
"String",
">",
"getNames",
"(",
")",
"{",
"if",
"(",
"parent",
"==",
"null",
")",
"{",
"return",
"getLocalNames",
"(",
")",
";",
"}",
"Set",
"<",
"String",
">",
"result",
"=",
"new",
"TreeSet",
"<>",
"(",
")",
";",
"result",
... | Returns all names of variables known to this scope or one of its parent scopes.
@return a set of all known variable names | [
"Returns",
"all",
"names",
"of",
"variables",
"known",
"to",
"this",
"scope",
"or",
"one",
"of",
"its",
"parent",
"scopes",
"."
] | fbf686155b1147b9e07ae21dcd02820b15c79a8c | https://github.com/scireum/parsii/blob/fbf686155b1147b9e07ae21dcd02820b15c79a8c/src/main/java/parsii/eval/Scope.java#L193-L201 | train |
scireum/parsii | src/main/java/parsii/eval/Scope.java | Scope.getVariables | public Collection<Variable> getVariables() {
if (parent == null) {
return getLocalVariables();
}
List<Variable> result = new ArrayList<>();
result.addAll(parent.getVariables());
result.addAll(getLocalVariables());
return result;
} | java | public Collection<Variable> getVariables() {
if (parent == null) {
return getLocalVariables();
}
List<Variable> result = new ArrayList<>();
result.addAll(parent.getVariables());
result.addAll(getLocalVariables());
return result;
} | [
"public",
"Collection",
"<",
"Variable",
">",
"getVariables",
"(",
")",
"{",
"if",
"(",
"parent",
"==",
"null",
")",
"{",
"return",
"getLocalVariables",
"(",
")",
";",
"}",
"List",
"<",
"Variable",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
")"... | Returns all variables known to this scope or one of its parent scopes.
@return a collection of all known variables | [
"Returns",
"all",
"variables",
"known",
"to",
"this",
"scope",
"or",
"one",
"of",
"its",
"parent",
"scopes",
"."
] | fbf686155b1147b9e07ae21dcd02820b15c79a8c | https://github.com/scireum/parsii/blob/fbf686155b1147b9e07ae21dcd02820b15c79a8c/src/main/java/parsii/eval/Scope.java#L217-L225 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/PreConditions.java | PreConditions.ifNull | public static <T> T ifNull(final T reference, final T defaultValue) {
if (reference == null) {
return defaultValue;
}
return reference;
} | java | public static <T> T ifNull(final T reference, final T defaultValue) {
if (reference == null) {
return defaultValue;
}
return reference;
} | [
"public",
"static",
"<",
"T",
">",
"T",
"ifNull",
"(",
"final",
"T",
"reference",
",",
"final",
"T",
"defaultValue",
")",
"{",
"if",
"(",
"reference",
"==",
"null",
")",
"{",
"return",
"defaultValue",
";",
"}",
"return",
"reference",
";",
"}"
] | If our reference is null then return a default value instead.
@param reference the thing to check.
@param defaultValue the default value to return if the above reference is null.
@return the reference if not null, otherwise the default value. Note, if your default value
is null as well then you will get back null, sin... | [
"If",
"our",
"reference",
"is",
"null",
"then",
"return",
"a",
"default",
"value",
"instead",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/PreConditions.java#L132-L137 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/header/impl/ParametersSupport.java | ParametersSupport.consumeUntil | private Buffer consumeUntil(final Buffer name) {
try {
while (this.params.hasReadableBytes()) {
SipParser.consumeSEMI(this.params);
final Buffer[] keyValue = SipParser.consumeGenericParam(this.params);
ensureParamsMap();
final Buffer va... | java | private Buffer consumeUntil(final Buffer name) {
try {
while (this.params.hasReadableBytes()) {
SipParser.consumeSEMI(this.params);
final Buffer[] keyValue = SipParser.consumeGenericParam(this.params);
ensureParamsMap();
final Buffer va... | [
"private",
"Buffer",
"consumeUntil",
"(",
"final",
"Buffer",
"name",
")",
"{",
"try",
"{",
"while",
"(",
"this",
".",
"params",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"SipParser",
".",
"consumeSEMI",
"(",
"this",
".",
"params",
")",
";",
"final",
... | Internal helper method that will consume all raw parameters until we find the specified name
or if the name is null, then that will be the same as "consume all".
@param name
@return | [
"Internal",
"helper",
"method",
"that",
"will",
"consume",
"all",
"raw",
"parameters",
"until",
"we",
"find",
"the",
"specified",
"name",
"or",
"if",
"the",
"name",
"is",
"null",
"then",
"that",
"will",
"be",
"the",
"same",
"as",
"consume",
"all",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/header/impl/ParametersSupport.java#L124-L146 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/header/impl/ParametersSupport.java | ParametersSupport.ensureParams | private void ensureParams() {
if (this.isDirty) {
// note, it would only be dirty if we actually have inserted a value
// so therefore no need to check that the parammap is null
final Buffer restOfParams = this.params;
this.params = allcoateNewParamBuffer();
... | java | private void ensureParams() {
if (this.isDirty) {
// note, it would only be dirty if we actually have inserted a value
// so therefore no need to check that the parammap is null
final Buffer restOfParams = this.params;
this.params = allcoateNewParamBuffer();
... | [
"private",
"void",
"ensureParams",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isDirty",
")",
"{",
"// note, it would only be dirty if we actually have inserted a value",
"// so therefore no need to check that the parammap is null",
"final",
"Buffer",
"restOfParams",
"=",
"this",
... | Make sure that the internal params buffer is actually valid etc. | [
"Make",
"sure",
"that",
"the",
"internal",
"params",
"buffer",
"is",
"actually",
"valid",
"etc",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/header/impl/ParametersSupport.java#L192-L213 | train |
aboutsip/pkts | pkts-examples/src/main/java/io/pkts/examples/siplib/SipLibExample001.java | SipLibExample001.basicExample001 | public static void basicExample001() throws IOException {
final String rawMessage = new StringBuilder("BYE sip:bob@127.0.0.1:5060 SIP/2.0\r\n")
.append("Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-28976-1-7\r\n")
.append("From: alice <sip:alice@127.0.1.1:5061>;tag=28976SIPpTag... | java | public static void basicExample001() throws IOException {
final String rawMessage = new StringBuilder("BYE sip:bob@127.0.0.1:5060 SIP/2.0\r\n")
.append("Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-28976-1-7\r\n")
.append("From: alice <sip:alice@127.0.1.1:5061>;tag=28976SIPpTag... | [
"public",
"static",
"void",
"basicExample001",
"(",
")",
"throws",
"IOException",
"{",
"final",
"String",
"rawMessage",
"=",
"new",
"StringBuilder",
"(",
"\"BYE sip:bob@127.0.0.1:5060 SIP/2.0\\r\\n\"",
")",
".",
"append",
"(",
"\"Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4... | This is the most basic example showing how you can parse a SIP
message based off of a String. In this example, we are the ones
creating that raw message ourselves but typically you would read
this off of the network, or perhaps from a file if you are building
a tool of some sort. | [
"This",
"is",
"the",
"most",
"basic",
"example",
"showing",
"how",
"you",
"can",
"parse",
"a",
"SIP",
"message",
"based",
"off",
"of",
"a",
"String",
".",
"In",
"this",
"example",
"we",
"are",
"the",
"ones",
"creating",
"that",
"raw",
"message",
"ourselv... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-examples/src/main/java/io/pkts/examples/siplib/SipLibExample001.java#L26-L66 | train |
aboutsip/pkts | pkts-examples/src/main/java/io/pkts/examples/siplib/SipLibExample001.java | SipLibExample001.basicExample003 | public static void basicExample003() throws Exception {
// Generate a request again
final SipRequest invite = SipRequest.invite("sip:alice@aboutsip.com")
.withFromHeader("sip:bob@pkts.io")
.build();
// Create a 200 OK to that INVITE and also add a generic
... | java | public static void basicExample003() throws Exception {
// Generate a request again
final SipRequest invite = SipRequest.invite("sip:alice@aboutsip.com")
.withFromHeader("sip:bob@pkts.io")
.build();
// Create a 200 OK to that INVITE and also add a generic
... | [
"public",
"static",
"void",
"basicExample003",
"(",
")",
"throws",
"Exception",
"{",
"// Generate a request again",
"final",
"SipRequest",
"invite",
"=",
"SipRequest",
".",
"invite",
"(",
"\"sip:alice@aboutsip.com\"",
")",
".",
"withFromHeader",
"(",
"\"sip:bob@pkts.io\... | Creating responses is typically done based off a request and SIP Lib
allows you to do so but of course, the object returned will be a builder.
@throws Exception | [
"Creating",
"responses",
"is",
"typically",
"done",
"based",
"off",
"a",
"request",
"and",
"SIP",
"Lib",
"allows",
"you",
"to",
"do",
"so",
"but",
"of",
"course",
"the",
"object",
"returned",
"will",
"be",
"a",
"builder",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-examples/src/main/java/io/pkts/examples/siplib/SipLibExample001.java#L108-L122 | train |
aboutsip/pkts | pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java | SimpleCallStateMachine.init | private void init() {
this.currentState = CallState.START;
this.callTransitions = new ArrayList<CallState>();
this.messages = new TreeSet<SipPacket>(new PacketComparator());
} | java | private void init() {
this.currentState = CallState.START;
this.callTransitions = new ArrayList<CallState>();
this.messages = new TreeSet<SipPacket>(new PacketComparator());
} | [
"private",
"void",
"init",
"(",
")",
"{",
"this",
".",
"currentState",
"=",
"CallState",
".",
"START",
";",
"this",
".",
"callTransitions",
"=",
"new",
"ArrayList",
"<",
"CallState",
">",
"(",
")",
";",
"this",
".",
"messages",
"=",
"new",
"TreeSet",
"... | Start over from a clean slate... | [
"Start",
"over",
"from",
"a",
"clean",
"slate",
"..."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java#L98-L102 | train |
aboutsip/pkts | pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java | SimpleCallStateMachine.handleInCancellingState | private void handleInCancellingState(final SipPacket msg) throws SipPacketParseException {
// we don't move over to cancelled state even if
// we receive a 200 OK to the cancel request.
// therefore, not even checking it...
if (msg.isCancel()) {
transition(CallState.CANCELLI... | java | private void handleInCancellingState(final SipPacket msg) throws SipPacketParseException {
// we don't move over to cancelled state even if
// we receive a 200 OK to the cancel request.
// therefore, not even checking it...
if (msg.isCancel()) {
transition(CallState.CANCELLI... | [
"private",
"void",
"handleInCancellingState",
"(",
"final",
"SipPacket",
"msg",
")",
"throws",
"SipPacketParseException",
"{",
"// we don't move over to cancelled state even if",
"// we receive a 200 OK to the cancel request.",
"// therefore, not even checking it...",
"if",
"(",
"msg... | When in the cancelling state, we may actually end up going back to
IN_CALL in case we see a 2xx to the invite so pay attention for that.
@param msg
@throws SipPacketParseException | [
"When",
"in",
"the",
"cancelling",
"state",
"we",
"may",
"actually",
"end",
"up",
"going",
"back",
"to",
"IN_CALL",
"in",
"case",
"we",
"see",
"a",
"2xx",
"to",
"the",
"invite",
"so",
"pay",
"attention",
"for",
"that",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java#L219-L246 | train |
aboutsip/pkts | pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java | SimpleCallStateMachine.handleInCompletedState | private void handleInCompletedState(final SipPacket msg) throws SipPacketParseException {
if (msg.isRequest()) {
// TODO:
} else {
if (msg.isBye()) {
transition(CallState.COMPLETED, msg);
}
}
} | java | private void handleInCompletedState(final SipPacket msg) throws SipPacketParseException {
if (msg.isRequest()) {
// TODO:
} else {
if (msg.isBye()) {
transition(CallState.COMPLETED, msg);
}
}
} | [
"private",
"void",
"handleInCompletedState",
"(",
"final",
"SipPacket",
"msg",
")",
"throws",
"SipPacketParseException",
"{",
"if",
"(",
"msg",
".",
"isRequest",
"(",
")",
")",
"{",
"// TODO:",
"}",
"else",
"{",
"if",
"(",
"msg",
".",
"isBye",
"(",
")",
... | Handle state transitions for when we are already in the completed state.
@param msg
@throws SipPacketParseException | [
"Handle",
"state",
"transitions",
"for",
"when",
"we",
"are",
"already",
"in",
"the",
"completed",
"state",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java#L265-L273 | train |
aboutsip/pkts | pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java | SimpleCallStateMachine.handleInConfirmedState | private void handleInConfirmedState(final SipPacket msg) throws SipPacketParseException {
if (msg.isRequest()) {
if (msg.isBye()) {
if (this.byeRequest == null) {
this.byeRequest = msg.toRequest();
}
transition(CallState.COMPLETED, ... | java | private void handleInConfirmedState(final SipPacket msg) throws SipPacketParseException {
if (msg.isRequest()) {
if (msg.isBye()) {
if (this.byeRequest == null) {
this.byeRequest = msg.toRequest();
}
transition(CallState.COMPLETED, ... | [
"private",
"void",
"handleInConfirmedState",
"(",
"final",
"SipPacket",
"msg",
")",
"throws",
"SipPacketParseException",
"{",
"if",
"(",
"msg",
".",
"isRequest",
"(",
")",
")",
"{",
"if",
"(",
"msg",
".",
"isBye",
"(",
")",
")",
"{",
"if",
"(",
"this",
... | We will only get to the confirmed state on a 2xx response to the INVITE.
From here, we can stay in the confirmed state if we get an ACK or
transition over to completed if we get a BYE request.
@param msg
@throws SipPacketParseException | [
"We",
"will",
"only",
"get",
"to",
"the",
"confirmed",
"state",
"on",
"a",
"2xx",
"response",
"to",
"the",
"INVITE",
".",
"From",
"here",
"we",
"can",
"stay",
"in",
"the",
"confirmed",
"state",
"if",
"we",
"get",
"an",
"ACK",
"or",
"transition",
"over"... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java#L283-L304 | train |
aboutsip/pkts | pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java | SimpleCallStateMachine.transition | private void transition(final CallState nextState, final SipPacket msg) {
final CallState previousState = this.currentState;
this.currentState = nextState;
if (previousState != nextState) {
// don't add the same transition twice
this.callTransitions.add(nextState);
... | java | private void transition(final CallState nextState, final SipPacket msg) {
final CallState previousState = this.currentState;
this.currentState = nextState;
if (previousState != nextState) {
// don't add the same transition twice
this.callTransitions.add(nextState);
... | [
"private",
"void",
"transition",
"(",
"final",
"CallState",
"nextState",
",",
"final",
"SipPacket",
"msg",
")",
"{",
"final",
"CallState",
"previousState",
"=",
"this",
".",
"currentState",
";",
"this",
".",
"currentState",
"=",
"nextState",
";",
"if",
"(",
... | Helper method for doing transitions.
@param nextState
@param msg | [
"Helper",
"method",
"for",
"doing",
"transitions",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-streams/src/main/java/io/pkts/streams/impl/SimpleCallStateMachine.java#L433-L443 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/packet/impl/MACPacketImpl.java | MACPacketImpl.setMacAddress | private void setMacAddress(final String macAddress, final boolean setSourceMacAddress)
throws IllegalArgumentException {
if (macAddress == null || macAddress.isEmpty()) {
throw new IllegalArgumentException("Null or empty string cannot be a valid MAC Address.");
}
// very ... | java | private void setMacAddress(final String macAddress, final boolean setSourceMacAddress)
throws IllegalArgumentException {
if (macAddress == null || macAddress.isEmpty()) {
throw new IllegalArgumentException("Null or empty string cannot be a valid MAC Address.");
}
// very ... | [
"private",
"void",
"setMacAddress",
"(",
"final",
"String",
"macAddress",
",",
"final",
"boolean",
"setSourceMacAddress",
")",
"throws",
"IllegalArgumentException",
"{",
"if",
"(",
"macAddress",
"==",
"null",
"||",
"macAddress",
".",
"isEmpty",
"(",
")",
")",
"{... | Helper method for setting the mac address in the header buffer.
@param macAddress
the mac address to parse
@param setSourceMacAddress
whether this is to bet set as the source mac address or not.
False implies destination mac address of course.
@throws IllegalArgumentException | [
"Helper",
"method",
"for",
"setting",
"the",
"mac",
"address",
"in",
"the",
"header",
"buffer",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/packet/impl/MACPacketImpl.java#L169-L186 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java | IPv4PacketImpl.calculateChecksum | private int calculateChecksum() {
long sum = 0;
for (int i = 0; i < this.headers.capacity() - 1; i += 2) {
if (i != 10) {
sum += this.headers.getUnsignedShort(i);
}
}
while (sum >> 16 != 0) {
sum = (sum & 0xffff) + (sum >> 16);
... | java | private int calculateChecksum() {
long sum = 0;
for (int i = 0; i < this.headers.capacity() - 1; i += 2) {
if (i != 10) {
sum += this.headers.getUnsignedShort(i);
}
}
while (sum >> 16 != 0) {
sum = (sum & 0xffff) + (sum >> 16);
... | [
"private",
"int",
"calculateChecksum",
"(",
")",
"{",
"long",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"headers",
".",
"capacity",
"(",
")",
"-",
"1",
";",
"i",
"+=",
"2",
")",
"{",
"if",
"(",
"i",
... | Algorithm adopted from RFC 1071 - Computing the Internet Checksum
@return | [
"Algorithm",
"adopted",
"from",
"RFC",
"1071",
"-",
"Computing",
"the",
"Internet",
"Checksum"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java#L56-L69 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java | IPv4PacketImpl.setIP | private void setIP(final int startIndex, final String address) {
final String[] parts = address.split("\\.");
this.headers.setByte(startIndex + 0, (byte) Integer.parseInt(parts[0]));
this.headers.setByte(startIndex + 1, (byte) Integer.parseInt(parts[1]));
this.headers.setByte(startIndex ... | java | private void setIP(final int startIndex, final String address) {
final String[] parts = address.split("\\.");
this.headers.setByte(startIndex + 0, (byte) Integer.parseInt(parts[0]));
this.headers.setByte(startIndex + 1, (byte) Integer.parseInt(parts[1]));
this.headers.setByte(startIndex ... | [
"private",
"void",
"setIP",
"(",
"final",
"int",
"startIndex",
",",
"final",
"String",
"address",
")",
"{",
"final",
"String",
"[",
"]",
"parts",
"=",
"address",
".",
"split",
"(",
"\"\\\\.\"",
")",
";",
"this",
".",
"headers",
".",
"setByte",
"(",
"st... | Very naive initial implementation. Should be changed to do a better job
and its performance probably can go up a lot as well.
@param startIndex
@param address | [
"Very",
"naive",
"initial",
"implementation",
".",
"Should",
"be",
"changed",
"to",
"do",
"a",
"better",
"job",
"and",
"its",
"performance",
"probably",
"can",
"go",
"up",
"a",
"lot",
"as",
"well",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java#L220-L227 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java | IPv4PacketImpl.getHeaderLength | @Override
public int getHeaderLength() {
try {
final byte b = this.headers.getByte(0);
// length is encoded as the number of 32-bit words, so to get number of bytes we must multiply by 4
return (b & 0x0F) * 4;
} catch (final IOException e) {
throw new ... | java | @Override
public int getHeaderLength() {
try {
final byte b = this.headers.getByte(0);
// length is encoded as the number of 32-bit words, so to get number of bytes we must multiply by 4
return (b & 0x0F) * 4;
} catch (final IOException e) {
throw new ... | [
"@",
"Override",
"public",
"int",
"getHeaderLength",
"(",
")",
"{",
"try",
"{",
"final",
"byte",
"b",
"=",
"this",
".",
"headers",
".",
"getByte",
"(",
"0",
")",
";",
"// length is encoded as the number of 32-bit words, so to get number of bytes we must multiply by 4",
... | The length of the ipv4 headers
@return | [
"The",
"length",
"of",
"the",
"ipv4",
"headers"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/packet/impl/IPv4PacketImpl.java#L290-L299 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.getFramer | public static Function<SipHeader, ? extends SipHeader> getFramer(final Buffer b) {
// For headers that have the expected capitalization, do a quick case-sensitive
// search. If that fails do a slower case-insensitive search.
final Function<SipHeader, ? extends SipHeader> framer = framers.get(b);... | java | public static Function<SipHeader, ? extends SipHeader> getFramer(final Buffer b) {
// For headers that have the expected capitalization, do a quick case-sensitive
// search. If that fails do a slower case-insensitive search.
final Function<SipHeader, ? extends SipHeader> framer = framers.get(b);... | [
"public",
"static",
"Function",
"<",
"SipHeader",
",",
"?",
"extends",
"SipHeader",
">",
"getFramer",
"(",
"final",
"Buffer",
"b",
")",
"{",
"// For headers that have the expected capitalization, do a quick case-sensitive",
"// search. If that fails do a slower case-insensitive s... | For the given header name, return a function that will convert a generic header instance
into one with the correct subtype. | [
"For",
"the",
"given",
"header",
"name",
"return",
"a",
"function",
"that",
"will",
"convert",
"a",
"generic",
"header",
"instance",
"into",
"one",
"with",
"the",
"correct",
"subtype",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L235-L248 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isUDP | public static boolean isUDP(final Buffer t) {
try {
return t.capacity() == 3 && t.getByte(0) == 'U' && t.getByte(1) == 'D' && t.getByte(2) == 'P';
} catch (final IOException e) {
return false;
}
} | java | public static boolean isUDP(final Buffer t) {
try {
return t.capacity() == 3 && t.getByte(0) == 'U' && t.getByte(1) == 'D' && t.getByte(2) == 'P';
} catch (final IOException e) {
return false;
}
} | [
"public",
"static",
"boolean",
"isUDP",
"(",
"final",
"Buffer",
"t",
")",
"{",
"try",
"{",
"return",
"t",
".",
"capacity",
"(",
")",
"==",
"3",
"&&",
"t",
".",
"getByte",
"(",
"0",
")",
"==",
"'",
"'",
"&&",
"t",
".",
"getByte",
"(",
"1",
")",
... | Check whether the buffer is exactly three bytes long and has the bytes "UDP" in it.
@param t
@return | [
"Check",
"whether",
"the",
"buffer",
"is",
"exactly",
"three",
"bytes",
"long",
"and",
"has",
"the",
"bytes",
"UDP",
"in",
"it",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L288-L294 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isUDPLower | public static boolean isUDPLower(final Buffer t) {
try {
return t.capacity() == 3 && t.getByte(0) == 'u' && t.getByte(1) == 'd' && t.getByte(2) == 'p';
} catch (final IOException e) {
return false;
}
} | java | public static boolean isUDPLower(final Buffer t) {
try {
return t.capacity() == 3 && t.getByte(0) == 'u' && t.getByte(1) == 'd' && t.getByte(2) == 'p';
} catch (final IOException e) {
return false;
}
} | [
"public",
"static",
"boolean",
"isUDPLower",
"(",
"final",
"Buffer",
"t",
")",
"{",
"try",
"{",
"return",
"t",
".",
"capacity",
"(",
")",
"==",
"3",
"&&",
"t",
".",
"getByte",
"(",
"0",
")",
"==",
"'",
"'",
"&&",
"t",
".",
"getByte",
"(",
"1",
... | Check whether the buffer is exactly three bytes long and has the
bytes "udp" in it. Note, in SIP there is a different between transport
specified in a Via-header and a transport-param specified in a SIP URI.
One is upper case, one is lower case. Another really annoying thing
with SIP.
@param t
@return | [
"Check",
"whether",
"the",
"buffer",
"is",
"exactly",
"three",
"bytes",
"long",
"and",
"has",
"the",
"bytes",
"udp",
"in",
"it",
".",
"Note",
"in",
"SIP",
"there",
"is",
"a",
"different",
"between",
"transport",
"specified",
"in",
"a",
"Via",
"-",
"heade... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L347-L353 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isNext | public static boolean isNext(final Buffer buffer, final byte b) throws IOException {
if (buffer.hasReadableBytes()) {
final byte actual = buffer.peekByte();
return actual == b;
}
return false;
} | java | public static boolean isNext(final Buffer buffer, final byte b) throws IOException {
if (buffer.hasReadableBytes()) {
final byte actual = buffer.peekByte();
return actual == b;
}
return false;
} | [
"public",
"static",
"boolean",
"isNext",
"(",
"final",
"Buffer",
"buffer",
",",
"final",
"byte",
"b",
")",
"throws",
"IOException",
"{",
"if",
"(",
"buffer",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"final",
"byte",
"actual",
"=",
"buffer",
".",
"pee... | Will check whether the next readable byte in the buffer is a certain byte
@param buffer
the buffer to peek into
@param b
the byte we are checking is the next byte in the buffer to be
read
@return true if the next byte to read indeed is what we hope it is | [
"Will",
"check",
"whether",
"the",
"next",
"readable",
"byte",
"in",
"the",
"buffer",
"is",
"a",
"certain",
"byte"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L513-L520 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isNextDigit | public static boolean isNextDigit(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
if (buffer.hasReadableBytes()) {
final char next = (char) buffer.peekByte();
return next >= 48 && next <= 57;
}
return false;
} | java | public static boolean isNextDigit(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
if (buffer.hasReadableBytes()) {
final char next = (char) buffer.peekByte();
return next >= 48 && next <= 57;
}
return false;
} | [
"public",
"static",
"boolean",
"isNextDigit",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"IndexOutOfBoundsException",
",",
"IOException",
"{",
"if",
"(",
"buffer",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"final",
"char",
"next",
"=",
"(",
"char",
... | Check whether the next byte is a digit or not
@param buffer
@retur
@throws IOException
@throws IndexOutOfBoundsException | [
"Check",
"whether",
"the",
"next",
"byte",
"is",
"a",
"digit",
"or",
"not"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L530-L537 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.expectDigit | public static Buffer expectDigit(final Buffer buffer) throws SipParseException {
final int start = buffer.getReaderIndex();
try {
while (buffer.hasReadableBytes() && isNextDigit(buffer)) {
// consume it
buffer.readByte();
}
if (start ... | java | public static Buffer expectDigit(final Buffer buffer) throws SipParseException {
final int start = buffer.getReaderIndex();
try {
while (buffer.hasReadableBytes() && isNextDigit(buffer)) {
// consume it
buffer.readByte();
}
if (start ... | [
"public",
"static",
"Buffer",
"expectDigit",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"SipParseException",
"{",
"final",
"int",
"start",
"=",
"buffer",
".",
"getReaderIndex",
"(",
")",
";",
"try",
"{",
"while",
"(",
"buffer",
".",
"hasReadableBytes",
... | Will expect at least 1 digit and will continue consuming bytes until a
non-digit is encountered
@param buffer
the buffer to consume the digits from
@return the buffer containing digits only
@throws SipParseException
in case there is not one digit at the first position in the
buffer (where the current reader index is p... | [
"Will",
"expect",
"at",
"least",
"1",
"digit",
"and",
"will",
"continue",
"consuming",
"bytes",
"until",
"a",
"non",
"-",
"digit",
"is",
"encountered"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L552-L571 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.expectWS | public static int expectWS(final Buffer buffer) throws SipParseException {
int consumed = 0;
try {
if (buffer.hasReadableBytes()) {
final byte b = buffer.getByte(buffer.getReaderIndex());
if (b == SP || b == HTAB) {
// ok, it was a WS so co... | java | public static int expectWS(final Buffer buffer) throws SipParseException {
int consumed = 0;
try {
if (buffer.hasReadableBytes()) {
final byte b = buffer.getByte(buffer.getReaderIndex());
if (b == SP || b == HTAB) {
// ok, it was a WS so co... | [
"public",
"static",
"int",
"expectWS",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"SipParseException",
"{",
"int",
"consumed",
"=",
"0",
";",
"try",
"{",
"if",
"(",
"buffer",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"final",
"byte",
"b",
"=",
... | Expect the next byte to be a white space
@param buffer | [
"Expect",
"the",
"next",
"byte",
"to",
"be",
"a",
"white",
"space"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L694-L714 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.consumeAlphaNum | public static Buffer consumeAlphaNum(final Buffer buffer) throws IOException {
final int count = getAlphaNumCount(buffer);
if (count == 0) {
return null;
}
return buffer.readBytes(count);
} | java | public static Buffer consumeAlphaNum(final Buffer buffer) throws IOException {
final int count = getAlphaNumCount(buffer);
if (count == 0) {
return null;
}
return buffer.readBytes(count);
} | [
"public",
"static",
"Buffer",
"consumeAlphaNum",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"IOException",
"{",
"final",
"int",
"count",
"=",
"getAlphaNumCount",
"(",
"buffer",
")",
";",
"if",
"(",
"count",
"==",
"0",
")",
"{",
"return",
"null",
";",... | Consumes a alphanum.
@param buffer
@return
@throws IOException | [
"Consumes",
"a",
"alphanum",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1243-L1249 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.getAlphaNumCount | public static int getAlphaNumCount(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
boolean done = false;
int count = 0;
final int index = buffer.getReaderIndex();
while (buffer.hasReadableBytes() && !done) {
final byte b = buffer.readByte();
i... | java | public static int getAlphaNumCount(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
boolean done = false;
int count = 0;
final int index = buffer.getReaderIndex();
while (buffer.hasReadableBytes() && !done) {
final byte b = buffer.readByte();
i... | [
"public",
"static",
"int",
"getAlphaNumCount",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"IndexOutOfBoundsException",
",",
"IOException",
"{",
"boolean",
"done",
"=",
"false",
";",
"int",
"count",
"=",
"0",
";",
"final",
"int",
"index",
"=",
"buffer",
... | Helper method that counts the number of bytes that are considered part of
the next alphanum block.
@param buffer
@return a count of the number of bytes the next alphaum contains or zero
if none is found.
@throws IndexOutOfBoundsException
@throws IOException | [
"Helper",
"method",
"that",
"counts",
"the",
"number",
"of",
"bytes",
"that",
"are",
"considered",
"part",
"of",
"the",
"next",
"alphanum",
"block",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1576-L1590 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isNextAlphaNum | public static boolean isNextAlphaNum(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
if (buffer.hasReadableBytes()) {
final byte b = buffer.peekByte();
return isAlphaNum(b);
}
return false;
} | java | public static boolean isNextAlphaNum(final Buffer buffer) throws IndexOutOfBoundsException, IOException {
if (buffer.hasReadableBytes()) {
final byte b = buffer.peekByte();
return isAlphaNum(b);
}
return false;
} | [
"public",
"static",
"boolean",
"isNextAlphaNum",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"IndexOutOfBoundsException",
",",
"IOException",
"{",
"if",
"(",
"buffer",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"final",
"byte",
"b",
"=",
"buffer",
".",
... | Check whether next byte is a alpha numeric one.
@param buffer
@return true if the next byte is a alpha numeric character, otherwise
false
@throws IOException
@throws IndexOutOfBoundsException | [
"Check",
"whether",
"next",
"byte",
"is",
"a",
"alpha",
"numeric",
"one",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1601-L1608 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isHostPortCharacter | public static boolean isHostPortCharacter(final char ch) {
return isAlphaNum(ch) || ch == DASH || ch == PERIOD || ch == COLON;
} | java | public static boolean isHostPortCharacter(final char ch) {
return isAlphaNum(ch) || ch == DASH || ch == PERIOD || ch == COLON;
} | [
"public",
"static",
"boolean",
"isHostPortCharacter",
"(",
"final",
"char",
"ch",
")",
"{",
"return",
"isAlphaNum",
"(",
"ch",
")",
"||",
"ch",
"==",
"DASH",
"||",
"ch",
"==",
"PERIOD",
"||",
"ch",
"==",
"COLON",
";",
"}"
] | Checks whether the character could be part of the host portion of a SIP URI.
This does not perform an entirely robust validation as it does not operate
with the full context of the hostname.
@param ch
@return true if the character is valid in hostnames, false otherwise | [
"Checks",
"whether",
"the",
"character",
"could",
"be",
"part",
"of",
"the",
"host",
"portion",
"of",
"a",
"SIP",
"URI",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1619-L1621 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.consumeCRLF | public static int consumeCRLF(final Buffer buffer) throws SipParseException {
try {
buffer.markReaderIndex();
final byte cr = buffer.readByte();
final byte lf = buffer.readByte();
if (cr == CR && lf == LF) {
return 2;
}
} catch ... | java | public static int consumeCRLF(final Buffer buffer) throws SipParseException {
try {
buffer.markReaderIndex();
final byte cr = buffer.readByte();
final byte lf = buffer.readByte();
if (cr == CR && lf == LF) {
return 2;
}
} catch ... | [
"public",
"static",
"int",
"consumeCRLF",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"SipParseException",
"{",
"try",
"{",
"buffer",
".",
"markReaderIndex",
"(",
")",
";",
"final",
"byte",
"cr",
"=",
"buffer",
".",
"readByte",
"(",
")",
";",
"final",... | Consume CR + LF
@param buffer
@return the number of bytes we consumed, which should be two
if we indeed consumed CRLF or zero otherwise. | [
"Consume",
"CR",
"+",
"LF"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1690-L1705 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isHeaderAllowingMultipleValues | private static boolean isHeaderAllowingMultipleValues(final Buffer headerName) {
final int size = headerName.getReadableBytes();
if (size == 7) {
return !isSubjectHeader(headerName);
} else if (size == 5) {
return !isAllowHeader(headerName);
} else if (size == 4) ... | java | private static boolean isHeaderAllowingMultipleValues(final Buffer headerName) {
final int size = headerName.getReadableBytes();
if (size == 7) {
return !isSubjectHeader(headerName);
} else if (size == 5) {
return !isAllowHeader(headerName);
} else if (size == 4) ... | [
"private",
"static",
"boolean",
"isHeaderAllowingMultipleValues",
"(",
"final",
"Buffer",
"headerName",
")",
"{",
"final",
"int",
"size",
"=",
"headerName",
".",
"getReadableBytes",
"(",
")",
";",
"if",
"(",
"size",
"==",
"7",
")",
"{",
"return",
"!",
"isSub... | Not all headers allow for multiple values on a single line. This is a
basic check for validating whether or not that the header allows it or
not. Note, for headers such as Contact, it depends!
@param headerName
@return | [
"Not",
"all",
"headers",
"allow",
"for",
"multiple",
"values",
"on",
"a",
"single",
"line",
".",
"This",
"is",
"a",
"basic",
"check",
"for",
"validating",
"whether",
"or",
"not",
"that",
"the",
"header",
"allows",
"it",
"or",
"not",
".",
"Note",
"for",
... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1859-L1874 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.isDateHeader | private static boolean isDateHeader(final Buffer name) {
try {
return name.getByte(0) == 'D' && name.getByte(1) == 'a' &&
name.getByte(2) == 't' && name.getByte(3) == 'e';
} catch (final IOException e) {
return false;
}
} | java | private static boolean isDateHeader(final Buffer name) {
try {
return name.getByte(0) == 'D' && name.getByte(1) == 'a' &&
name.getByte(2) == 't' && name.getByte(3) == 'e';
} catch (final IOException e) {
return false;
}
} | [
"private",
"static",
"boolean",
"isDateHeader",
"(",
"final",
"Buffer",
"name",
")",
"{",
"try",
"{",
"return",
"name",
".",
"getByte",
"(",
"0",
")",
"==",
"'",
"'",
"&&",
"name",
".",
"getByte",
"(",
"1",
")",
"==",
"'",
"'",
"&&",
"name",
".",
... | The date header also allows for comma within the value of the header.
@param name
@return | [
"The",
"date",
"header",
"also",
"allows",
"for",
"comma",
"within",
"the",
"value",
"of",
"the",
"header",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L1882-L1889 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java | SipParser.nextHeader | public static SipHeader nextHeader(final Buffer buffer) throws SipParseException {
try {
final int startIndex = buffer.getReaderIndex();
int nameIndex = 0;
while (buffer.hasReadableBytes() && nameIndex == 0) {
if (isNext(buffer, SP) || isNext(buffer, HTAB) |... | java | public static SipHeader nextHeader(final Buffer buffer) throws SipParseException {
try {
final int startIndex = buffer.getReaderIndex();
int nameIndex = 0;
while (buffer.hasReadableBytes() && nameIndex == 0) {
if (isNext(buffer, SP) || isNext(buffer, HTAB) |... | [
"public",
"static",
"SipHeader",
"nextHeader",
"(",
"final",
"Buffer",
"buffer",
")",
"throws",
"SipParseException",
"{",
"try",
"{",
"final",
"int",
"startIndex",
"=",
"buffer",
".",
"getReaderIndex",
"(",
")",
";",
"int",
"nameIndex",
"=",
"0",
";",
"while... | Get the next header, which may actually be returning multiple if there
are multiple headers on the same line.
@param buffer
@return an array where the first element is the name of the buffer and
the second element is the value of the buffer
@throws SipParseException | [
"Get",
"the",
"next",
"header",
"which",
"may",
"actually",
"be",
"returning",
"multiple",
"if",
"there",
"are",
"multiple",
"headers",
"on",
"the",
"same",
"line",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipParser.java#L2043-L2106 | train |
aboutsip/pkts | pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java | Buffers.wrap | public static Buffer wrap(final byte[] buffer) {
if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("the buffer cannot be null or empty");
}
return new ByteBuffer(buffer);
} | java | public static Buffer wrap(final byte[] buffer) {
if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("the buffer cannot be null or empty");
}
return new ByteBuffer(buffer);
} | [
"public",
"static",
"Buffer",
"wrap",
"(",
"final",
"byte",
"[",
"]",
"buffer",
")",
"{",
"if",
"(",
"buffer",
"==",
"null",
"||",
"buffer",
".",
"length",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"the buffer cannot be null or ... | Wrap the supplied byte array
@param buffer
@return | [
"Wrap",
"the",
"supplied",
"byte",
"array"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java#L108-L114 | train |
aboutsip/pkts | pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java | Buffers.wrap | public static Buffer wrap(final Buffer one, final Buffer two) {
// TODO: create an actual composite buffer.
final int size1 = one != null ? one.getReadableBytes() : 0;
final int size2 = two != null ? two.getReadableBytes() : 0;
if (size1 == 0 && size2 > 0) {
return two.slice... | java | public static Buffer wrap(final Buffer one, final Buffer two) {
// TODO: create an actual composite buffer.
final int size1 = one != null ? one.getReadableBytes() : 0;
final int size2 = two != null ? two.getReadableBytes() : 0;
if (size1 == 0 && size2 > 0) {
return two.slice... | [
"public",
"static",
"Buffer",
"wrap",
"(",
"final",
"Buffer",
"one",
",",
"final",
"Buffer",
"two",
")",
"{",
"// TODO: create an actual composite buffer. ",
"final",
"int",
"size1",
"=",
"one",
"!=",
"null",
"?",
"one",
".",
"getReadableBytes",
"(",
")",
":",... | Combine two buffers into one. The resulting buffer will share the
underlying byte storage so changing the value in one will affect the
other. However, the original two buffers will still have their own reader
and writer index.
@param one
@param two
@return | [
"Combine",
"two",
"buffers",
"into",
"one",
".",
"The",
"resulting",
"buffer",
"will",
"share",
"the",
"underlying",
"byte",
"storage",
"so",
"changing",
"the",
"value",
"in",
"one",
"will",
"affect",
"the",
"other",
".",
"However",
"the",
"original",
"two",... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java#L142-L158 | train |
aboutsip/pkts | pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java | Buffers.wrap | public static Buffer wrap(final byte[] buffer, final int lowerBoundary, final int upperBoundary) {
if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("the buffer cannot be null or empty");
}
if (upperBoundary > buffer.length) {
throw new Illega... | java | public static Buffer wrap(final byte[] buffer, final int lowerBoundary, final int upperBoundary) {
if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("the buffer cannot be null or empty");
}
if (upperBoundary > buffer.length) {
throw new Illega... | [
"public",
"static",
"Buffer",
"wrap",
"(",
"final",
"byte",
"[",
"]",
"buffer",
",",
"final",
"int",
"lowerBoundary",
",",
"final",
"int",
"upperBoundary",
")",
"{",
"if",
"(",
"buffer",
"==",
"null",
"||",
"buffer",
".",
"length",
"==",
"0",
")",
"{",... | Wrap the supplied byte array specifying the allowed range of visible
bytes.
@param buffer
@param lowerBoundary
the index of the lowest byte that is accessible to this Buffer
(zero based index)
@param upperBoundary
the upper boundary (exclusive) of the range of visible bytes.
@return | [
"Wrap",
"the",
"supplied",
"byte",
"array",
"specifying",
"the",
"allowed",
"range",
"of",
"visible",
"bytes",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-buffers/src/main/java/io/pkts/buffer/Buffers.java#L172-L190 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/frame/PcapGlobalHeader.java | PcapGlobalHeader.write | public void write(final OutputStream out) throws IOException {
if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
out.write(MAGIC_BIG_ENDIAN);
} else {
out.write(MAGIC_LITTLE_ENDIAN);
}
out.write(this.body);
} | java | public void write(final OutputStream out) throws IOException {
if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
out.write(MAGIC_BIG_ENDIAN);
} else {
out.write(MAGIC_LITTLE_ENDIAN);
}
out.write(this.body);
} | [
"public",
"void",
"write",
"(",
"final",
"OutputStream",
"out",
")",
"throws",
"IOException",
"{",
"if",
"(",
"this",
".",
"byteOrder",
"==",
"ByteOrder",
".",
"BIG_ENDIAN",
")",
"{",
"out",
".",
"write",
"(",
"MAGIC_BIG_ENDIAN",
")",
";",
"}",
"else",
"... | Will write this header to the output stream.
@param out | [
"Will",
"write",
"this",
"header",
"to",
"the",
"output",
"stream",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/frame/PcapGlobalHeader.java#L238-L245 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/frame/PcapRecordHeader.java | PcapRecordHeader.createDefaultHeader | public static PcapRecordHeader createDefaultHeader(final long timestamp) {
final byte[] body = new byte[SIZE];
// time stamp seconds
// body[0] = (byte) 0x00;
// body[1] = (byte) 0x00;
// body[2] = (byte) 0x00;
// body[3] = (byte) 0x00;
// Time stamp microsecond... | java | public static PcapRecordHeader createDefaultHeader(final long timestamp) {
final byte[] body = new byte[SIZE];
// time stamp seconds
// body[0] = (byte) 0x00;
// body[1] = (byte) 0x00;
// body[2] = (byte) 0x00;
// body[3] = (byte) 0x00;
// Time stamp microsecond... | [
"public",
"static",
"PcapRecordHeader",
"createDefaultHeader",
"(",
"final",
"long",
"timestamp",
")",
"{",
"final",
"byte",
"[",
"]",
"body",
"=",
"new",
"byte",
"[",
"SIZE",
"]",
";",
"// time stamp seconds",
"// body[0] = (byte) 0x00;",
"// body[1] = (byte) 0x00;",... | Create a default record header, which you must alter later on to match
whatever it is you are writing into the pcap stream.
@param timestamp
the timestamp in milliseconds since epoch. This is the
timestamp of when the packet "arrived"
@return | [
"Create",
"a",
"default",
"record",
"header",
"which",
"you",
"must",
"alter",
"later",
"on",
"to",
"match",
"whatever",
"it",
"is",
"you",
"are",
"writing",
"into",
"the",
"pcap",
"stream",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/frame/PcapRecordHeader.java#L55-L87 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java | SipMessageStreamBuilder.process | public boolean process(final byte[] newData) {
if (newData != null) {
buffer.write(newData);
}
boolean done = false;
while (!done) {
final int index = buffer.getReaderIndex();
final State currentState = state;
state = actions[state.ordinal... | java | public boolean process(final byte[] newData) {
if (newData != null) {
buffer.write(newData);
}
boolean done = false;
while (!done) {
final int index = buffer.getReaderIndex();
final State currentState = state;
state = actions[state.ordinal... | [
"public",
"boolean",
"process",
"(",
"final",
"byte",
"[",
"]",
"newData",
")",
"{",
"if",
"(",
"newData",
"!=",
"null",
")",
"{",
"buffer",
".",
"write",
"(",
"newData",
")",
";",
"}",
"boolean",
"done",
"=",
"false",
";",
"while",
"(",
"!",
"done... | Process more incoming data.
@param newData
@return | [
"Process",
"more",
"incoming",
"data",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java#L205-L219 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java | SipMessageStreamBuilder.onInit | private final State onInit(final Buffer buffer) {
try {
while (buffer.hasReadableBytes()) {
final byte b = buffer.peekByte();
if (b == SipParser.SP || b == SipParser.HTAB || b == SipParser.CR || b == SipParser.LF) {
buffer.readByte();
... | java | private final State onInit(final Buffer buffer) {
try {
while (buffer.hasReadableBytes()) {
final byte b = buffer.peekByte();
if (b == SipParser.SP || b == SipParser.HTAB || b == SipParser.CR || b == SipParser.LF) {
buffer.readByte();
... | [
"private",
"final",
"State",
"onInit",
"(",
"final",
"Buffer",
"buffer",
")",
"{",
"try",
"{",
"while",
"(",
"buffer",
".",
"hasReadableBytes",
"(",
")",
")",
"{",
"final",
"byte",
"b",
"=",
"buffer",
".",
"peekByte",
"(",
")",
";",
"if",
"(",
"b",
... | While in the INIT state, we are just consuming any empty space
before heading off to start parsing the initial line
@param b
@return | [
"While",
"in",
"the",
"INIT",
"state",
"we",
"are",
"just",
"consuming",
"any",
"empty",
"space",
"before",
"heading",
"off",
"to",
"start",
"parsing",
"the",
"initial",
"line"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java#L241-L257 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java | SipMessageStreamBuilder.onInitialLine | private final State onInitialLine(final Buffer buffer) {
try {
buffer.markReaderIndex();
final Buffer part1 = buffer.readUntilSafe(config.getMaxAllowedInitialLineSize(), SipParser.SP);
final Buffer part2 = buffer.readUntilSafe(config.getMaxAllowedInitialLineSize(), SipParser.... | java | private final State onInitialLine(final Buffer buffer) {
try {
buffer.markReaderIndex();
final Buffer part1 = buffer.readUntilSafe(config.getMaxAllowedInitialLineSize(), SipParser.SP);
final Buffer part2 = buffer.readUntilSafe(config.getMaxAllowedInitialLineSize(), SipParser.... | [
"private",
"final",
"State",
"onInitialLine",
"(",
"final",
"Buffer",
"buffer",
")",
"{",
"try",
"{",
"buffer",
".",
"markReaderIndex",
"(",
")",
";",
"final",
"Buffer",
"part1",
"=",
"buffer",
".",
"readUntilSafe",
"(",
"config",
".",
"getMaxAllowedInitialLin... | Since it is quite uncommon to not have enough data on the line
to read the entire first line we are taking the simple approach
of just resetting the entire effort and we'll retry later. This
of course means that in the worst case scenario we will actually
iterate over data we have already seen before. However, seemed
l... | [
"Since",
"it",
"is",
"quite",
"uncommon",
"to",
"not",
"have",
"enough",
"data",
"on",
"the",
"line",
"to",
"read",
"the",
"entire",
"first",
"line",
"we",
"are",
"taking",
"the",
"simple",
"approach",
"of",
"just",
"resetting",
"the",
"entire",
"effort",
... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java#L271-L287 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java | SipMessageStreamBuilder.onCheckEndHeaderSection | private final State onCheckEndHeaderSection(final Buffer buffer) {
// can't tell. We need two bytes at least to check if there is
// more headers or not
if (buffer.getReadableBytes() < 2) {
return State.CHECK_FOR_END_OF_HEADER_SECTION;
}
// ok, so there was a CRLF so... | java | private final State onCheckEndHeaderSection(final Buffer buffer) {
// can't tell. We need two bytes at least to check if there is
// more headers or not
if (buffer.getReadableBytes() < 2) {
return State.CHECK_FOR_END_OF_HEADER_SECTION;
}
// ok, so there was a CRLF so... | [
"private",
"final",
"State",
"onCheckEndHeaderSection",
"(",
"final",
"Buffer",
"buffer",
")",
"{",
"// can't tell. We need two bytes at least to check if there is",
"// more headers or not",
"if",
"(",
"buffer",
".",
"getReadableBytes",
"(",
")",
"<",
"2",
")",
"{",
"r... | Every time we have parsed a header we need to check if there are more headers or
if we have reached the end of the section and as such there may be a body we need
to take care of. We know this by checking if there is a CRLF up next or not.
@param buffer
@return | [
"Every",
"time",
"we",
"have",
"parsed",
"a",
"header",
"we",
"need",
"to",
"check",
"if",
"there",
"are",
"more",
"headers",
"or",
"if",
"we",
"have",
"reached",
"the",
"end",
"of",
"the",
"section",
"and",
"as",
"such",
"there",
"may",
"be",
"a",
"... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java#L407-L422 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java | SipMessageStreamBuilder.onPayload | private final State onPayload(final Buffer buffer) {
if (contentLength == 0) {
return State.DONE;
}
if (buffer.getReadableBytes() >= contentLength) {
try {
payload = buffer.readBytes(contentLength);
} catch (final IOException e) {
... | java | private final State onPayload(final Buffer buffer) {
if (contentLength == 0) {
return State.DONE;
}
if (buffer.getReadableBytes() >= contentLength) {
try {
payload = buffer.readBytes(contentLength);
} catch (final IOException e) {
... | [
"private",
"final",
"State",
"onPayload",
"(",
"final",
"Buffer",
"buffer",
")",
"{",
"if",
"(",
"contentLength",
"==",
"0",
")",
"{",
"return",
"State",
".",
"DONE",
";",
"}",
"if",
"(",
"buffer",
".",
"getReadableBytes",
"(",
")",
">=",
"contentLength"... | We may or may not have a payload, which depends on whether there is a Content-length
header available or not. If yes, then we will just slice out that entire thing once
we have enough readable bytes in the buffer.
@param buffer
@return | [
"We",
"may",
"or",
"may",
"not",
"have",
"a",
"payload",
"which",
"depends",
"on",
"whether",
"there",
"is",
"a",
"Content",
"-",
"length",
"header",
"available",
"or",
"not",
".",
"If",
"yes",
"then",
"we",
"will",
"just",
"slice",
"out",
"that",
"ent... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageStreamBuilder.java#L432-L447 | train |
aboutsip/pkts | pkts-buffers/src/main/java/io/pkts/buffer/InputStreamBuffer.java | InputStreamBuffer.getWritingRow | private java.nio.ByteBuffer getWritingRow() {
final int row = this.writerIndex / this.localCapacity;
if (row >= this.storage.size()) {
final java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(this.localCapacity);
this.storage.add(buf);
return buf;
}
... | java | private java.nio.ByteBuffer getWritingRow() {
final int row = this.writerIndex / this.localCapacity;
if (row >= this.storage.size()) {
final java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(this.localCapacity);
this.storage.add(buf);
return buf;
}
... | [
"private",
"java",
".",
"nio",
".",
"ByteBuffer",
"getWritingRow",
"(",
")",
"{",
"final",
"int",
"row",
"=",
"this",
".",
"writerIndex",
"/",
"this",
".",
"localCapacity",
";",
"if",
"(",
"row",
">=",
"this",
".",
"storage",
".",
"size",
"(",
")",
"... | Get which "row" we currently are working with for writing
@return | [
"Get",
"which",
"row",
"we",
"currently",
"are",
"working",
"with",
"for",
"writing"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-buffers/src/main/java/io/pkts/buffer/InputStreamBuffer.java#L206-L215 | train |
aboutsip/pkts | pkts-buffers/src/main/java/io/pkts/buffer/InputStreamBuffer.java | InputStreamBuffer.getReadingRow | private java.nio.ByteBuffer getReadingRow() {
final int row = this.readerIndex / this.localCapacity;
return this.storage.get(row);
} | java | private java.nio.ByteBuffer getReadingRow() {
final int row = this.readerIndex / this.localCapacity;
return this.storage.get(row);
} | [
"private",
"java",
".",
"nio",
".",
"ByteBuffer",
"getReadingRow",
"(",
")",
"{",
"final",
"int",
"row",
"=",
"this",
".",
"readerIndex",
"/",
"this",
".",
"localCapacity",
";",
"return",
"this",
".",
"storage",
".",
"get",
"(",
"row",
")",
";",
"}"
] | Get which "row" we currently are working with for reading
@return | [
"Get",
"which",
"row",
"we",
"currently",
"are",
"working",
"with",
"for",
"reading"
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-buffers/src/main/java/io/pkts/buffer/InputStreamBuffer.java#L222-L225 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/framer/RTPFramer.java | RTPFramer.accept | @Override
public boolean accept(final Buffer data) throws IOException {
// a RTP packet has at least 12 bytes. Check that
if (data.getReadableBytes() < 12) {
// not enough bytes but see if we actually could
// get another 12 bytes by forcing the underlying
// impl... | java | @Override
public boolean accept(final Buffer data) throws IOException {
// a RTP packet has at least 12 bytes. Check that
if (data.getReadableBytes() < 12) {
// not enough bytes but see if we actually could
// get another 12 bytes by forcing the underlying
// impl... | [
"@",
"Override",
"public",
"boolean",
"accept",
"(",
"final",
"Buffer",
"data",
")",
"throws",
"IOException",
"{",
"// a RTP packet has at least 12 bytes. Check that",
"if",
"(",
"data",
".",
"getReadableBytes",
"(",
")",
"<",
"12",
")",
"{",
"// not enough bytes bu... | There is no real good test to make sure that the data indeed is an RTP packet. Appendix 2 in
RFC3550 describes one way of doing it but you really need a sequence of packets in order to
be able to determine if this indeed is a RTP packet or not. The best is to analyze the
session negotiation but here we are just looking... | [
"There",
"is",
"no",
"real",
"good",
"test",
"to",
"make",
"sure",
"that",
"the",
"data",
"indeed",
"is",
"an",
"RTP",
"packet",
".",
"Appendix",
"2",
"in",
"RFC3550",
"describes",
"one",
"way",
"of",
"doing",
"it",
"but",
"you",
"really",
"need",
"a",... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/framer/RTPFramer.java#L44-L83 | train |
aboutsip/pkts | pkts-core/src/main/java/io/pkts/packet/impl/AbstractPacket.java | AbstractPacket.write | @Override
public final void write(final OutputStream out) throws IOException {
if (this.nextPacket != null) {
this.nextPacket.write(out);
} else {
this.write(out, this.payload);
}
} | java | @Override
public final void write(final OutputStream out) throws IOException {
if (this.nextPacket != null) {
this.nextPacket.write(out);
} else {
this.write(out, this.payload);
}
} | [
"@",
"Override",
"public",
"final",
"void",
"write",
"(",
"final",
"OutputStream",
"out",
")",
"throws",
"IOException",
"{",
"if",
"(",
"this",
".",
"nextPacket",
"!=",
"null",
")",
"{",
"this",
".",
"nextPacket",
".",
"write",
"(",
"out",
")",
";",
"}... | The write strategy is fairly simple. If we have a "nextPacket" it means
that we have been asked to frame our payload which also means that that
payload may have changed and therefore ask the nextPacket to write itself
back out to the stream. If there is no nextPacket we can just take the
raw payload and write it out as... | [
"The",
"write",
"strategy",
"is",
"fairly",
"simple",
".",
"If",
"we",
"have",
"a",
"nextPacket",
"it",
"means",
"that",
"we",
"have",
"been",
"asked",
"to",
"frame",
"our",
"payload",
"which",
"also",
"means",
"that",
"that",
"payload",
"may",
"have",
"... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-core/src/main/java/io/pkts/packet/impl/AbstractPacket.java#L86-L93 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageBuilder.java | SipMessageBuilder.addTrackedHeader | private short addTrackedHeader(final short index, final SipHeader header) {
if (index != -1) {
headers.set(index, header.ensure());
return index;
}
return addHeader(header.ensure());
} | java | private short addTrackedHeader(final short index, final SipHeader header) {
if (index != -1) {
headers.set(index, header.ensure());
return index;
}
return addHeader(header.ensure());
} | [
"private",
"short",
"addTrackedHeader",
"(",
"final",
"short",
"index",
",",
"final",
"SipHeader",
"header",
")",
"{",
"if",
"(",
"index",
"!=",
"-",
"1",
")",
"{",
"headers",
".",
"set",
"(",
"index",
",",
"header",
".",
"ensure",
"(",
")",
")",
";"... | There are several headers that we want to know their position
and in that case we use this method to add them since we want
to either add them to a particular position or we want to
remember which index we added them to. | [
"There",
"are",
"several",
"headers",
"that",
"we",
"want",
"to",
"know",
"their",
"position",
"and",
"in",
"that",
"case",
"we",
"use",
"this",
"method",
"to",
"add",
"them",
"since",
"we",
"want",
"to",
"either",
"add",
"them",
"to",
"a",
"particular",... | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageBuilder.java#L167-L173 | train |
aboutsip/pkts | pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageBuilder.java | SipMessageBuilder.chainConsumers | private <T> Consumer<T> chainConsumers(final Consumer<T> currentConsumer, final Consumer<T> consumer) {
if (currentConsumer != null) {
return currentConsumer.andThen(consumer);
}
return consumer;
} | java | private <T> Consumer<T> chainConsumers(final Consumer<T> currentConsumer, final Consumer<T> consumer) {
if (currentConsumer != null) {
return currentConsumer.andThen(consumer);
}
return consumer;
} | [
"private",
"<",
"T",
">",
"Consumer",
"<",
"T",
">",
"chainConsumers",
"(",
"final",
"Consumer",
"<",
"T",
">",
"currentConsumer",
",",
"final",
"Consumer",
"<",
"T",
">",
"consumer",
")",
"{",
"if",
"(",
"currentConsumer",
"!=",
"null",
")",
"{",
"ret... | Helper function to chain consumers together or return the new one if the current consumer
isn't set.
@param currentConsumer the current consumer, which may be null
@param consumer the new consumer to chain with the current one.
@param <T>
@return the chained consumer (or the new consumer if there previously wasn't one... | [
"Helper",
"function",
"to",
"chain",
"consumers",
"together",
"or",
"return",
"the",
"new",
"one",
"if",
"the",
"current",
"consumer",
"isn",
"t",
"set",
"."
] | 0f06bb0dac76c812187829f580a8d476ca99a1a1 | https://github.com/aboutsip/pkts/blob/0f06bb0dac76c812187829f580a8d476ca99a1a1/pkts-sip/src/main/java/io/pkts/packet/sip/impl/SipMessageBuilder.java#L899-L905 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/ProbabilitiesPanel.java | ProbabilitiesPanel.createEvolutionPipeline | public EvolutionaryOperator<List<ColouredPolygon>> createEvolutionPipeline(PolygonImageFactory factory,
Dimension canvasSize,
Random rng)
{
List<Evolu... | java | public EvolutionaryOperator<List<ColouredPolygon>> createEvolutionPipeline(PolygonImageFactory factory,
Dimension canvasSize,
Random rng)
{
List<Evolu... | [
"public",
"EvolutionaryOperator",
"<",
"List",
"<",
"ColouredPolygon",
">",
">",
"createEvolutionPipeline",
"(",
"PolygonImageFactory",
"factory",
",",
"Dimension",
"canvasSize",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"EvolutionaryOperator",
"<",
"List",
"<",
... | Construct the combination of evolutionary operators that will be used to evolve the
polygon-based images.
@param factory A source of polygons.
@param canvasSize The size of the target image.
@param rng A source of randomness.
@return A complex evolutionary operator constructed from simpler operators. | [
"Construct",
"the",
"combination",
"of",
"evolutionary",
"operators",
"that",
"will",
"be",
"used",
"to",
"evolve",
"the",
"polygon",
"-",
"based",
"images",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/ProbabilitiesPanel.java#L150-L171 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java | TravellingSalesmanApplet.createTask | private SwingBackgroundTask<List<String>> createTask(final Collection<String> cities)
{
final TravellingSalesmanStrategy strategy = strategyPanel.getStrategy();
return new SwingBackgroundTask<List<String>>()
{
private long elapsedTime = 0;
@Override
prote... | java | private SwingBackgroundTask<List<String>> createTask(final Collection<String> cities)
{
final TravellingSalesmanStrategy strategy = strategyPanel.getStrategy();
return new SwingBackgroundTask<List<String>>()
{
private long elapsedTime = 0;
@Override
prote... | [
"private",
"SwingBackgroundTask",
"<",
"List",
"<",
"String",
">",
">",
"createTask",
"(",
"final",
"Collection",
"<",
"String",
">",
"cities",
")",
"{",
"final",
"TravellingSalesmanStrategy",
"strategy",
"=",
"strategyPanel",
".",
"getStrategy",
"(",
")",
";",
... | Helper method to create a background task for running the travelling
salesman algorithm.
@param cities The set of cities to generate a route for.
@return A Swing task that will execute on a background thread and update
the GUI when it is done. | [
"Helper",
"method",
"to",
"create",
"a",
"background",
"task",
"for",
"running",
"the",
"travelling",
"salesman",
"algorithm",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java#L103-L129 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java | TravellingSalesmanApplet.createResultString | private String createResultString(String strategyDescription,
List<String> shortestRoute,
double distance,
long elapsedTime)
{
StringBuilder buffer = new StringBuilder();
buffer.append('... | java | private String createResultString(String strategyDescription,
List<String> shortestRoute,
double distance,
long elapsedTime)
{
StringBuilder buffer = new StringBuilder();
buffer.append('... | [
"private",
"String",
"createResultString",
"(",
"String",
"strategyDescription",
",",
"List",
"<",
"String",
">",
"shortestRoute",
",",
"double",
"distance",
",",
"long",
"elapsedTime",
")",
"{",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
")",
... | Helper method for formatting a result as a string for display. | [
"Helper",
"method",
"for",
"formatting",
"a",
"result",
"as",
"a",
"string",
"for",
"display",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java#L135-L160 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java | TravellingSalesmanApplet.setEnabled | @Override
public void setEnabled(boolean b)
{
itineraryPanel.setEnabled(b);
strategyPanel.setEnabled(b);
executionPanel.setEnabled(b);
super.setEnabled(b);
} | java | @Override
public void setEnabled(boolean b)
{
itineraryPanel.setEnabled(b);
strategyPanel.setEnabled(b);
executionPanel.setEnabled(b);
super.setEnabled(b);
} | [
"@",
"Override",
"public",
"void",
"setEnabled",
"(",
"boolean",
"b",
")",
"{",
"itineraryPanel",
".",
"setEnabled",
"(",
"b",
")",
";",
"strategyPanel",
".",
"setEnabled",
"(",
"b",
")",
";",
"executionPanel",
".",
"setEnabled",
"(",
"b",
")",
";",
"sup... | Toggles whether the controls are enabled for input or not.
@param b Enables the controls if this flag is true, disables them otherwise. | [
"Toggles",
"whether",
"the",
"controls",
"are",
"enabled",
"for",
"input",
"or",
"not",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/TravellingSalesmanApplet.java#L167-L174 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java | StringEvaluator.getFitness | public double getFitness(String candidate,
List<? extends String> population)
{
int errors = 0;
for (int i = 0; i < candidate.length(); i++)
{
if (candidate.charAt(i) != targetString.charAt(i))
{
++errors;
}
... | java | public double getFitness(String candidate,
List<? extends String> population)
{
int errors = 0;
for (int i = 0; i < candidate.length(); i++)
{
if (candidate.charAt(i) != targetString.charAt(i))
{
++errors;
}
... | [
"public",
"double",
"getFitness",
"(",
"String",
"candidate",
",",
"List",
"<",
"?",
"extends",
"String",
">",
"population",
")",
"{",
"int",
"errors",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"candidate",
".",
"length",
"(",
... | Assigns one "penalty point" for every character in the candidate
string that differs from the corresponding position in the target
string.
@param candidate The evolved string to evaluate.
@param population {@inheritDoc}
@return The fitness score (how many characters are wrong) of the
specified string. | [
"Assigns",
"one",
"penalty",
"point",
"for",
"every",
"character",
"in",
"the",
"candidate",
"string",
"that",
"differs",
"from",
"the",
"corresponding",
"position",
"in",
"the",
"target",
"string",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java#L51-L63 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Simplification.java | Simplification.apply | public List<Node> apply(List<Node> selectedCandidates, Random rng)
{
List<Node> evolved = new ArrayList<Node>(selectedCandidates.size());
for (Node node : selectedCandidates)
{
evolved.add(probability.nextEvent(rng) ? node.simplify() : node);
}
return evolved;
... | java | public List<Node> apply(List<Node> selectedCandidates, Random rng)
{
List<Node> evolved = new ArrayList<Node>(selectedCandidates.size());
for (Node node : selectedCandidates)
{
evolved.add(probability.nextEvent(rng) ? node.simplify() : node);
}
return evolved;
... | [
"public",
"List",
"<",
"Node",
">",
"apply",
"(",
"List",
"<",
"Node",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"Node",
">",
"evolved",
"=",
"new",
"ArrayList",
"<",
"Node",
">",
"(",
"selectedCandidates",
".",
"size",
"(... | Simplify the expressions represented by the candidates. Each expression
is simplified according to the configured probability.
@param selectedCandidates The individuals to evolve.
@param rng A source of randomness.
@return The (possibly) simplified candidates. | [
"Simplify",
"the",
"expressions",
"represented",
"by",
"the",
"candidates",
".",
"Each",
"expression",
"is",
"simplified",
"according",
"to",
"the",
"configured",
"probability",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Simplification.java#L62-L70 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/selection/TruncationSelection.java | TruncationSelection.select | public <S> List<S> select(List<EvaluatedCandidate<S>> population,
boolean naturalFitnessScores,
int selectionSize,
Random rng)
{
List<S> selection = new ArrayList<S>(selectionSize);
double ratio = selectionRat... | java | public <S> List<S> select(List<EvaluatedCandidate<S>> population,
boolean naturalFitnessScores,
int selectionSize,
Random rng)
{
List<S> selection = new ArrayList<S>(selectionSize);
double ratio = selectionRat... | [
"public",
"<",
"S",
">",
"List",
"<",
"S",
">",
"select",
"(",
"List",
"<",
"EvaluatedCandidate",
"<",
"S",
">",
">",
"population",
",",
"boolean",
"naturalFitnessScores",
",",
"int",
"selectionSize",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"S",
"... | Selects the fittest candidates. If the selectionRatio results in
fewer selected candidates than required, then these candidates are
selected multiple times to make up the shortfall.
@param population The population of evolved and evaluated candidates
from which to select.
@param naturalFitnessScores Whether higher fit... | [
"Selects",
"the",
"fittest",
"candidates",
".",
"If",
"the",
"selectionRatio",
"results",
"in",
"fewer",
"selected",
"candidates",
"than",
"required",
"then",
"these",
"candidates",
"are",
"selected",
"multiple",
"times",
"to",
"make",
"up",
"the",
"shortfall",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/selection/TruncationSelection.java#L84-L106 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/SteadyStateEvolutionEngine.java | SteadyStateEvolutionEngine.doReplacement | protected void doReplacement(List<EvaluatedCandidate<T>> existingPopulation,
List<EvaluatedCandidate<T>> newCandidates,
int eliteCount,
Random rng)
{
assert newCandidates.size() < existingPopulation.size() - e... | java | protected void doReplacement(List<EvaluatedCandidate<T>> existingPopulation,
List<EvaluatedCandidate<T>> newCandidates,
int eliteCount,
Random rng)
{
assert newCandidates.size() < existingPopulation.size() - e... | [
"protected",
"void",
"doReplacement",
"(",
"List",
"<",
"EvaluatedCandidate",
"<",
"T",
">",
">",
"existingPopulation",
",",
"List",
"<",
"EvaluatedCandidate",
"<",
"T",
">",
">",
"newCandidates",
",",
"int",
"eliteCount",
",",
"Random",
"rng",
")",
"{",
"as... | Add the offspring to the population, removing the same number of existing individuals to make
space for them.
This method randomly chooses which individuals should be replaced, but it can be over-ridden
in sub-classes if alternative behaviour is required.
@param existingPopulation The full popultation, sorted in descen... | [
"Add",
"the",
"offspring",
"to",
"the",
"population",
"removing",
"the",
"same",
"number",
"of",
"existing",
"individuals",
"to",
"make",
"space",
"for",
"them",
".",
"This",
"method",
"randomly",
"chooses",
"which",
"individuals",
"should",
"be",
"replaced",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/SteadyStateEvolutionEngine.java#L122-L146 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphFactory.java | BiomorphFactory.generateRandomCandidate | public Biomorph generateRandomCandidate(Random rng)
{
int[] genes = new int[Biomorph.GENE_COUNT];
for (int i = 0; i < Biomorph.GENE_COUNT - 1; i++)
{
// First 8 genes have values between -5 and 5.
genes[i] = rng.nextInt(11) - 5;
}
// Last genes ha a va... | java | public Biomorph generateRandomCandidate(Random rng)
{
int[] genes = new int[Biomorph.GENE_COUNT];
for (int i = 0; i < Biomorph.GENE_COUNT - 1; i++)
{
// First 8 genes have values between -5 and 5.
genes[i] = rng.nextInt(11) - 5;
}
// Last genes ha a va... | [
"public",
"Biomorph",
"generateRandomCandidate",
"(",
"Random",
"rng",
")",
"{",
"int",
"[",
"]",
"genes",
"=",
"new",
"int",
"[",
"Biomorph",
".",
"GENE_COUNT",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Biomorph",
".",
"GENE_COUNT",
... | Generates a random biomorph by providing a random value for each gene.
@param rng The source of randomness used to generate the biomoprh.
@return A randomly-generated biomorph. | [
"Generates",
"a",
"random",
"biomorph",
"by",
"providing",
"a",
"random",
"value",
"for",
"each",
"gene",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphFactory.java#L32-L43 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java | StringsExample.main | public static void main(String[] args)
{
String target = args.length == 0 ? "HELLO WORLD" : convertArgs(args);
String result = evolveString(target);
System.out.println("Evolution result: " + result);
} | java | public static void main(String[] args)
{
String target = args.length == 0 ? "HELLO WORLD" : convertArgs(args);
String result = evolveString(target);
System.out.println("Evolution result: " + result);
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"String",
"target",
"=",
"args",
".",
"length",
"==",
"0",
"?",
"\"HELLO WORLD\"",
":",
"convertArgs",
"(",
"args",
")",
";",
"String",
"result",
"=",
"evolveString",
"(",
"... | Entry point for the sample application. Any data specified on the
command line is considered to be the target String. If no target is
specified, a default of "HELLOW WORLD" is used instead.
@param args The target String (as an array of words). | [
"Entry",
"point",
"for",
"the",
"sample",
"application",
".",
"Any",
"data",
"specified",
"on",
"the",
"command",
"line",
"is",
"considered",
"to",
"be",
"the",
"target",
"String",
".",
"If",
"no",
"target",
"is",
"specified",
"a",
"default",
"of",
"HELLOW... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java#L58-L63 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java | StringsExample.convertArgs | private static String convertArgs(String[] args)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < args.length; i++)
{
result.append(args[i]);
if (i < args.length - 1)
{
result.append(' ');
}
}
re... | java | private static String convertArgs(String[] args)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < args.length; i++)
{
result.append(args[i]);
if (i < args.length - 1)
{
result.append(' ');
}
}
re... | [
"private",
"static",
"String",
"convertArgs",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"StringBuilder",
"result",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
... | Converts an arguments array into a single String of words
separated by spaces.
@param args The command-line arguments.
@return A single String made from the command line data. | [
"Converts",
"an",
"arguments",
"array",
"into",
"a",
"single",
"String",
"of",
"words",
"separated",
"by",
"spaces",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java#L91-L103 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java | RandomBiomorphMutation.apply | public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
{
List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
for (Biomorph biomorph : selectedCandidates)
{
mutatedPopulation.add(mutateBiomorph(biomorph, rng));
}
... | java | public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
{
List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
for (Biomorph biomorph : selectedCandidates)
{
mutatedPopulation.add(mutateBiomorph(biomorph, rng));
}
... | [
"public",
"List",
"<",
"Biomorph",
">",
"apply",
"(",
"List",
"<",
"Biomorph",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"Biomorph",
">",
"mutatedPopulation",
"=",
"new",
"ArrayList",
"<",
"Biomorph",
">",
"(",
"selectedCandidat... | Randomly mutate each selected candidate.
@param selectedCandidates {@inheritDoc}
@param rng {@inheritDoc}
@return {@inheritDoc} | [
"Randomly",
"mutate",
"each",
"selected",
"candidate",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java#L49-L57 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java | RandomBiomorphMutation.mutateBiomorph | private Biomorph mutateBiomorph(Biomorph biomorph, Random rng)
{
int[] genes = biomorph.getGenotype();
assert genes.length == Biomorph.GENE_COUNT : "Biomorphs must have " + Biomorph.GENE_COUNT + " genes.";
for (int i = 0; i < Biomorph.GENE_COUNT - 1; i++)
{
if (mutationPr... | java | private Biomorph mutateBiomorph(Biomorph biomorph, Random rng)
{
int[] genes = biomorph.getGenotype();
assert genes.length == Biomorph.GENE_COUNT : "Biomorphs must have " + Biomorph.GENE_COUNT + " genes.";
for (int i = 0; i < Biomorph.GENE_COUNT - 1; i++)
{
if (mutationPr... | [
"private",
"Biomorph",
"mutateBiomorph",
"(",
"Biomorph",
"biomorph",
",",
"Random",
"rng",
")",
"{",
"int",
"[",
"]",
"genes",
"=",
"biomorph",
".",
"getGenotype",
"(",
")",
";",
"assert",
"genes",
".",
"length",
"==",
"Biomorph",
".",
"GENE_COUNT",
":",
... | Mutates a single biomorph.
@param biomorph The biomorph to mutate.
@param rng The source of randomness to use for mutation.
@return A mutated version of the biomorph. | [
"Mutates",
"a",
"single",
"biomorph",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java#L66-L97 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java | TreeFactory.makeNode | private Node makeNode(Random rng, int maxDepth)
{
if (functionProbability.nextEvent(rng) && maxDepth > 1)
{
// Max depth for sub-trees is one less than max depth for this node.
int depth = maxDepth - 1;
switch (rng.nextInt(5))
{
case 0:... | java | private Node makeNode(Random rng, int maxDepth)
{
if (functionProbability.nextEvent(rng) && maxDepth > 1)
{
// Max depth for sub-trees is one less than max depth for this node.
int depth = maxDepth - 1;
switch (rng.nextInt(5))
{
case 0:... | [
"private",
"Node",
"makeNode",
"(",
"Random",
"rng",
",",
"int",
"maxDepth",
")",
"{",
"if",
"(",
"functionProbability",
".",
"nextEvent",
"(",
"rng",
")",
"&&",
"maxDepth",
">",
"1",
")",
"{",
"// Max depth for sub-trees is one less than max depth for this node.",
... | Recursively constructs a tree of Nodes, up to the specified maximum depth.
@param rng The RNG used to random create nodes.
@param maxDepth The maximum depth of the generated tree.
@return A tree of nodes. | [
"Recursively",
"constructs",
"a",
"tree",
"of",
"Nodes",
"up",
"to",
"the",
"specified",
"maximum",
"depth",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java#L91-L114 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOperator.java | ListOperator.apply | public List<List<T>> apply(List<List<T>> selectedCandidates, Random rng)
{
List<List<T>> output = new ArrayList<List<T>>(selectedCandidates.size());
for (List<T> item : selectedCandidates)
{
output.add(delegate.apply(item, rng));
}
return output;
} | java | public List<List<T>> apply(List<List<T>> selectedCandidates, Random rng)
{
List<List<T>> output = new ArrayList<List<T>>(selectedCandidates.size());
for (List<T> item : selectedCandidates)
{
output.add(delegate.apply(item, rng));
}
return output;
} | [
"public",
"List",
"<",
"List",
"<",
"T",
">",
">",
"apply",
"(",
"List",
"<",
"List",
"<",
"T",
">",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"List",
"<",
"T",
">>",
"output",
"=",
"new",
"ArrayList",
"<",
"List",
"... | Applies the configured operator to each list candidate, operating on the elements
that make up a candidate rather than on the list of candidates.
candidates and returns the results.
@param selectedCandidates A list of list candidates.
@param rng A source of randomness.
@return The result of applying the configured oper... | [
"Applies",
"the",
"configured",
"operator",
"to",
"each",
"list",
"candidate",
"operating",
"on",
"the",
"elements",
"that",
"make",
"up",
"a",
"candidate",
"rather",
"than",
"on",
"the",
"list",
"of",
"candidates",
".",
"candidates",
"and",
"returns",
"the",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOperator.java#L59-L67 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java | DawkinsBiomorphMutation.apply | public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
{
List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
int mutatedGene = 0;
int mutation = 1;
for (Biomorph b : selectedCandidates)
{
int[] genes = b.getGe... | java | public List<Biomorph> apply(List<Biomorph> selectedCandidates, Random rng)
{
List<Biomorph> mutatedPopulation = new ArrayList<Biomorph>(selectedCandidates.size());
int mutatedGene = 0;
int mutation = 1;
for (Biomorph b : selectedCandidates)
{
int[] genes = b.getGe... | [
"public",
"List",
"<",
"Biomorph",
">",
"apply",
"(",
"List",
"<",
"Biomorph",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"Biomorph",
">",
"mutatedPopulation",
"=",
"new",
"ArrayList",
"<",
"Biomorph",
">",
"(",
"selectedCandidat... | Mutate a population of biomorphs non-randomly, ensuring that each selected
candidate is mutated differently.
@param selectedCandidates {@inheritDoc}
@param rng A source of randomness (not used since this mutation is non-random).
@return {@inheritDoc} | [
"Mutate",
"a",
"population",
"of",
"biomorphs",
"non",
"-",
"randomly",
"ensuring",
"that",
"each",
"selected",
"candidate",
"is",
"mutated",
"differently",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java#L37-L66 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonColourMutation.java | PolygonColourMutation.mutateColour | private Color mutateColour(Color colour, Random rng)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
return new Color(mutateColourComponent(colour.getRed()),
mutateColourComponent(colour.getGreen()),
mutateColourComponent(... | java | private Color mutateColour(Color colour, Random rng)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
return new Color(mutateColourComponent(colour.getRed()),
mutateColourComponent(colour.getGreen()),
mutateColourComponent(... | [
"private",
"Color",
"mutateColour",
"(",
"Color",
"colour",
",",
"Random",
"rng",
")",
"{",
"if",
"(",
"mutationProbability",
".",
"nextValue",
"(",
")",
".",
"nextEvent",
"(",
"rng",
")",
")",
"{",
"return",
"new",
"Color",
"(",
"mutateColourComponent",
"... | Mutate the specified colour.
@param colour The colour to mutate.
@param rng A source of randomness.
@return The (possibly) mutated colour. | [
"Mutate",
"the",
"specified",
"colour",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonColourMutation.java#L86-L99 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/util/concurrent/ConfigurableThreadFactory.java | ConfigurableThreadFactory.newThread | public Thread newThread(Runnable runnable)
{
Thread thread = new Thread(runnable, nameGenerator.nextID());
thread.setPriority(priority);
thread.setDaemon(daemon);
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
return thread;
} | java | public Thread newThread(Runnable runnable)
{
Thread thread = new Thread(runnable, nameGenerator.nextID());
thread.setPriority(priority);
thread.setDaemon(daemon);
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
return thread;
} | [
"public",
"Thread",
"newThread",
"(",
"Runnable",
"runnable",
")",
"{",
"Thread",
"thread",
"=",
"new",
"Thread",
"(",
"runnable",
",",
"nameGenerator",
".",
"nextID",
"(",
")",
")",
";",
"thread",
".",
"setPriority",
"(",
"priority",
")",
";",
"thread",
... | Creates a new thread configured according to this factory's parameters.
@param runnable The runnable to be executed by the new thread.
@return The created thread. | [
"Creates",
"a",
"new",
"thread",
"configured",
"according",
"to",
"this",
"factory",
"s",
"parameters",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/util/concurrent/ConfigurableThreadFactory.java#L89-L96 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/Replacement.java | Replacement.apply | public List<T> apply(List<T> selectedCandidates, Random rng)
{
List<T> output = new ArrayList<T>(selectedCandidates.size());
for (T candidate : selectedCandidates)
{
output.add(replacementProbability.nextValue().nextEvent(rng)
? factory.generateRandomCandid... | java | public List<T> apply(List<T> selectedCandidates, Random rng)
{
List<T> output = new ArrayList<T>(selectedCandidates.size());
for (T candidate : selectedCandidates)
{
output.add(replacementProbability.nextValue().nextEvent(rng)
? factory.generateRandomCandid... | [
"public",
"List",
"<",
"T",
">",
"apply",
"(",
"List",
"<",
"T",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"T",
">",
"output",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
"selectedCandidates",
".",
"size",
"(",
")",
"... | Randomly replace zero or more of the selected candidates with new,
independent individuals that are randomly created.
@param selectedCandidates The selected candidates, some of these may be
discarded and replaced with new individuals.
@param rng A source of randomness.
@return The remaining candidates after some (or no... | [
"Randomly",
"replace",
"zero",
"or",
"more",
"of",
"the",
"selected",
"candidates",
"with",
"new",
"independent",
"individuals",
"that",
"are",
"randomly",
"created",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/Replacement.java#L85-L95 | train |
dwdyer/watchmaker | swing/src/java/main/org/uncommons/swing/ConfigurableLineBorder.java | ConfigurableLineBorder.paintBorder | public void paintBorder(Component component,
Graphics graphics,
int x,
int y,
int width,
int height)
{
if (top)
{
graphics.fillRect(x, y, width, thi... | java | public void paintBorder(Component component,
Graphics graphics,
int x,
int y,
int width,
int height)
{
if (top)
{
graphics.fillRect(x, y, width, thi... | [
"public",
"void",
"paintBorder",
"(",
"Component",
"component",
",",
"Graphics",
"graphics",
",",
"int",
"x",
",",
"int",
"y",
",",
"int",
"width",
",",
"int",
"height",
")",
"{",
"if",
"(",
"top",
")",
"{",
"graphics",
".",
"fillRect",
"(",
"x",
","... | Renders borders for the specified component based on the configuration
of this border object.
@param component The component for which the border is painted.
@param graphics A {@link Graphics} object to use for painting.
@param x The X-coordinate of the top left point of the border rectangle.
@param y The Y-coordinate ... | [
"Renders",
"borders",
"for",
"the",
"specified",
"component",
"based",
"on",
"the",
"configuration",
"of",
"this",
"border",
"object",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/swing/src/java/main/org/uncommons/swing/ConfigurableLineBorder.java#L73-L96 | train |
dwdyer/watchmaker | swing/src/java/main/org/uncommons/watchmaker/swing/evolutionmonitor/PopulationFitnessView.java | PopulationFitnessView.updateDomainAxisRange | private void updateDomainAxisRange()
{
int count = dataSet.getSeries(0).getItemCount();
if (count < SHOW_FIXED_GENERATIONS)
{
domainAxis.setRangeWithMargins(0, SHOW_FIXED_GENERATIONS);
}
else if (allDataButton.isSelected())
{
domainAxis.setRang... | java | private void updateDomainAxisRange()
{
int count = dataSet.getSeries(0).getItemCount();
if (count < SHOW_FIXED_GENERATIONS)
{
domainAxis.setRangeWithMargins(0, SHOW_FIXED_GENERATIONS);
}
else if (allDataButton.isSelected())
{
domainAxis.setRang... | [
"private",
"void",
"updateDomainAxisRange",
"(",
")",
"{",
"int",
"count",
"=",
"dataSet",
".",
"getSeries",
"(",
"0",
")",
".",
"getItemCount",
"(",
")",
";",
"if",
"(",
"count",
"<",
"SHOW_FIXED_GENERATIONS",
")",
"{",
"domainAxis",
".",
"setRangeWithMargi... | If "all data" is selected, set the range of the domain axis to include all
values. Otherwise set it to show the most recent 200 generations. | [
"If",
"all",
"data",
"is",
"selected",
"set",
"the",
"range",
"of",
"the",
"domain",
"axis",
"to",
"include",
"all",
"values",
".",
"Otherwise",
"set",
"it",
"to",
"show",
"the",
"most",
"recent",
"200",
"generations",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/swing/src/java/main/org/uncommons/watchmaker/swing/evolutionmonitor/PopulationFitnessView.java#L159-L174 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageEvaluator.java | PolygonImageEvaluator.convertImage | private BufferedImage convertImage(BufferedImage image)
{
if (image.getType() == BufferedImage.TYPE_INT_RGB)
{
return image;
}
else
{
BufferedImage newImage = new BufferedImage(image.getWidth(),
im... | java | private BufferedImage convertImage(BufferedImage image)
{
if (image.getType() == BufferedImage.TYPE_INT_RGB)
{
return image;
}
else
{
BufferedImage newImage = new BufferedImage(image.getWidth(),
im... | [
"private",
"BufferedImage",
"convertImage",
"(",
"BufferedImage",
"image",
")",
"{",
"if",
"(",
"image",
".",
"getType",
"(",
")",
"==",
"BufferedImage",
".",
"TYPE_INT_RGB",
")",
"{",
"return",
"image",
";",
"}",
"else",
"{",
"BufferedImage",
"newImage",
"=... | Make sure that the image is in the most efficient format for reading from.
This avoids having to convert pixels every time we access them.
@param image The image to convert.
@return The image converted to INT_RGB format. | [
"Make",
"sure",
"that",
"the",
"image",
"is",
"in",
"the",
"most",
"efficient",
"format",
"for",
"reading",
"from",
".",
"This",
"avoids",
"having",
"to",
"convert",
"pixels",
"every",
"time",
"we",
"access",
"them",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageEvaluator.java#L87-L101 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageEvaluator.java | PolygonImageEvaluator.getFitness | public double getFitness(List<ColouredPolygon> candidate,
List<? extends List<ColouredPolygon>> population)
{
// Use one renderer per thread because they are not thread safe.
Renderer<List<ColouredPolygon>, BufferedImage> renderer = threadLocalRenderer.get();
if ... | java | public double getFitness(List<ColouredPolygon> candidate,
List<? extends List<ColouredPolygon>> population)
{
// Use one renderer per thread because they are not thread safe.
Renderer<List<ColouredPolygon>, BufferedImage> renderer = threadLocalRenderer.get();
if ... | [
"public",
"double",
"getFitness",
"(",
"List",
"<",
"ColouredPolygon",
">",
"candidate",
",",
"List",
"<",
"?",
"extends",
"List",
"<",
"ColouredPolygon",
">",
">",
"population",
")",
"{",
"// Use one renderer per thread because they are not thread safe.",
"Renderer",
... | Render the polygons as an image and then do a pixel-by-pixel comparison
against the target image. The fitness score is the total error. A lower
score means a closer match.
@param candidate The image to evaluate.
@param population Not used.
@return A number indicating how close the candidate image is to the target ima... | [
"Render",
"the",
"polygons",
"as",
"an",
"image",
"and",
"then",
"do",
"a",
"pixel",
"-",
"by",
"-",
"pixel",
"comparison",
"against",
"the",
"target",
"image",
".",
"The",
"fitness",
"score",
"is",
"the",
"total",
"error",
".",
"A",
"lower",
"score",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageEvaluator.java#L113-L142 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/SplitEvolution.java | SplitEvolution.apply | public List<T> apply(List<T> selectedCandidates, Random rng)
{
double ratio = weightVariable.nextValue();
int size = (int) Math.round(ratio * selectedCandidates.size());
// Shuffle the collection before applying each operation so that the
// split is not influenced by any ordering a... | java | public List<T> apply(List<T> selectedCandidates, Random rng)
{
double ratio = weightVariable.nextValue();
int size = (int) Math.round(ratio * selectedCandidates.size());
// Shuffle the collection before applying each operation so that the
// split is not influenced by any ordering a... | [
"public",
"List",
"<",
"T",
">",
"apply",
"(",
"List",
"<",
"T",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"double",
"ratio",
"=",
"weightVariable",
".",
"nextValue",
"(",
")",
";",
"int",
"size",
"=",
"(",
"int",
")",
"Math",
".",
... | Applies one evolutionary operator to part of the population and another
to the remainder. Returns a list combining the output of both. Which
candidates are submitted to which stream is determined randomly.
@param selectedCandidates A list of the candidates that survived to be
eligible for evolution.
@param rng A sour... | [
"Applies",
"one",
"evolutionary",
"operator",
"to",
"part",
"of",
"the",
"population",
"and",
"another",
"to",
"the",
"remainder",
".",
"Returns",
"a",
"list",
"combining",
"the",
"output",
"of",
"both",
".",
"Which",
"candidates",
"are",
"submitted",
"to",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/SplitEvolution.java#L101-L118 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/MonaLisaApplet.java | MonaLisaApplet.main | public static void main(String[] args) throws IOException
{
MonaLisaApplet gui = new MonaLisaApplet();
// If a URL is specified as an argument, use that image. Otherwise use the default Mona Lisa picture.
URL imageURL = args.length > 0
? new URL(args[0])
... | java | public static void main(String[] args) throws IOException
{
MonaLisaApplet gui = new MonaLisaApplet();
// If a URL is specified as an argument, use that image. Otherwise use the default Mona Lisa picture.
URL imageURL = args.length > 0
? new URL(args[0])
... | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"IOException",
"{",
"MonaLisaApplet",
"gui",
"=",
"new",
"MonaLisaApplet",
"(",
")",
";",
"// If a URL is specified as an argument, use that image. Otherwise use the default Mona Lisa pictu... | Entry point for running this example as an application rather than an applet.
@param args Program arguments (ignored).
@throws IOException If there is a problem loading the target image. | [
"Entry",
"point",
"for",
"running",
"this",
"example",
"as",
"an",
"application",
"rather",
"than",
"an",
"applet",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/MonaLisaApplet.java#L176-L185 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/IdentityOperator.java | IdentityOperator.apply | public List<T> apply(List<T> selectedCandidates, Random rng)
{
return new ArrayList<T>(selectedCandidates);
} | java | public List<T> apply(List<T> selectedCandidates, Random rng)
{
return new ArrayList<T>(selectedCandidates);
} | [
"public",
"List",
"<",
"T",
">",
"apply",
"(",
"List",
"<",
"T",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"return",
"new",
"ArrayList",
"<",
"T",
">",
"(",
"selectedCandidates",
")",
";",
"}"
] | Returns the selected candidates unaltered.
@param selectedCandidates The candidates to "evolve" (or do
nothing to in this case).
@param rng A source of randomness (not used).
@return The unaltered candidates. | [
"Returns",
"the",
"selected",
"candidates",
"unaltered",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/IdentityOperator.java#L40-L43 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeCrossover.java | TreeCrossover.mate | @Override
protected List<Node> mate(Node parent1,
Node parent2,
int numberOfCrossoverPoints,
Random rng)
{
List<Node> offspring = new ArrayList<Node>(2);
Node offspring1 = parent1;
Node offspring2 =... | java | @Override
protected List<Node> mate(Node parent1,
Node parent2,
int numberOfCrossoverPoints,
Random rng)
{
List<Node> offspring = new ArrayList<Node>(2);
Node offspring1 = parent1;
Node offspring2 =... | [
"@",
"Override",
"protected",
"List",
"<",
"Node",
">",
"mate",
"(",
"Node",
"parent1",
",",
"Node",
"parent2",
",",
"int",
"numberOfCrossoverPoints",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"Node",
">",
"offspring",
"=",
"new",
"ArrayList",
"<",
"N... | Swaps randomly selected sub-trees between the two parents.
@param parent1 The first parent.
@param parent2 The second parent.
@param numberOfCrossoverPoints The number of cross-overs to perform.
@param rng A source of randomness.
@return A list of two offspring, generated by swapping sub-trees
between the two parents. | [
"Swaps",
"randomly",
"selected",
"sub",
"-",
"trees",
"between",
"the",
"two",
"parents",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeCrossover.java#L48-L71 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/factories/StringFactory.java | StringFactory.generateRandomCandidate | public String generateRandomCandidate(Random rng)
{
char[] chars = new char[stringLength];
for (int i = 0; i < stringLength; i++)
{
chars[i] = alphabet[rng.nextInt(alphabet.length)];
}
return new String(chars);
} | java | public String generateRandomCandidate(Random rng)
{
char[] chars = new char[stringLength];
for (int i = 0; i < stringLength; i++)
{
chars[i] = alphabet[rng.nextInt(alphabet.length)];
}
return new String(chars);
} | [
"public",
"String",
"generateRandomCandidate",
"(",
"Random",
"rng",
")",
"{",
"char",
"[",
"]",
"chars",
"=",
"new",
"char",
"[",
"stringLength",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"stringLength",
";",
"i",
"++",
")",
"{",
... | Generates a random string of a pre-configured length. Each character
is randomly selected from the pre-configured alphabet. The same
character may appear multiple times and some characters may not appear
at all.
@param rng A source of randomness used to select characters to make up
the string.
@return A randomly gene... | [
"Generates",
"a",
"random",
"string",
"of",
"a",
"pre",
"-",
"configured",
"length",
".",
"Each",
"character",
"is",
"randomly",
"selected",
"from",
"the",
"pre",
"-",
"configured",
"alphabet",
".",
"The",
"same",
"character",
"may",
"appear",
"multiple",
"t... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/factories/StringFactory.java#L53-L61 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/util/reflection/ReflectionUtils.java | ReflectionUtils.findKnownMethod | public static Method findKnownMethod(Class<?> aClass,
String name,
Class<?>... paramTypes)
{
try
{
return aClass.getMethod(name, paramTypes);
}
catch (NoSuchMethodException ex)
{
... | java | public static Method findKnownMethod(Class<?> aClass,
String name,
Class<?>... paramTypes)
{
try
{
return aClass.getMethod(name, paramTypes);
}
catch (NoSuchMethodException ex)
{
... | [
"public",
"static",
"Method",
"findKnownMethod",
"(",
"Class",
"<",
"?",
">",
"aClass",
",",
"String",
"name",
",",
"Class",
"<",
"?",
">",
"...",
"paramTypes",
")",
"{",
"try",
"{",
"return",
"aClass",
".",
"getMethod",
"(",
"name",
",",
"paramTypes",
... | Looks up a method that is explicitly identified. This method should only
be used for methods that definitely exist. It does not throw the checked
NoSuchMethodException. If the method does not exist, it will instead fail
with an unchecked IllegalArgumentException.
@param aClass The class in which the method exists.
@... | [
"Looks",
"up",
"a",
"method",
"that",
"is",
"explicitly",
"identified",
".",
"This",
"method",
"should",
"only",
"be",
"used",
"for",
"methods",
"that",
"definitely",
"exist",
".",
"It",
"does",
"not",
"throw",
"the",
"checked",
"NoSuchMethodException",
".",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/util/reflection/ReflectionUtils.java#L140-L153 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/util/reflection/ReflectionUtils.java | ReflectionUtils.findKnownConstructor | public static <T> Constructor<T> findKnownConstructor(Class<T> aClass,
Class<?>... paramTypes)
{
try
{
return aClass.getConstructor(paramTypes);
}
catch (NoSuchMethodException ex)
{
// This cann... | java | public static <T> Constructor<T> findKnownConstructor(Class<T> aClass,
Class<?>... paramTypes)
{
try
{
return aClass.getConstructor(paramTypes);
}
catch (NoSuchMethodException ex)
{
// This cann... | [
"public",
"static",
"<",
"T",
">",
"Constructor",
"<",
"T",
">",
"findKnownConstructor",
"(",
"Class",
"<",
"T",
">",
"aClass",
",",
"Class",
"<",
"?",
">",
"...",
"paramTypes",
")",
"{",
"try",
"{",
"return",
"aClass",
".",
"getConstructor",
"(",
"par... | Looks up a constructor that is explicitly identified. This method should only
be used for constructors that definitely exist. It does not throw the checked
NoSuchMethodException. If the constructor does not exist, it will instead fail
with an unchecked IllegalArgumentException.
@param <T> The type of object that the... | [
"Looks",
"up",
"a",
"constructor",
"that",
"is",
"explicitly",
"identified",
".",
"This",
"method",
"should",
"only",
"be",
"used",
"for",
"constructors",
"that",
"definitely",
"exist",
".",
"It",
"does",
"not",
"throw",
"the",
"checked",
"NoSuchMethodException"... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/util/reflection/ReflectionUtils.java#L166-L178 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/islands/IslandEvolution.java | IslandEvolution.createEpochTasks | private List<Callable<List<EvaluatedCandidate<T>>>> createEpochTasks(int populationSize,
int eliteCount,
int epochLength,
... | java | private List<Callable<List<EvaluatedCandidate<T>>>> createEpochTasks(int populationSize,
int eliteCount,
int epochLength,
... | [
"private",
"List",
"<",
"Callable",
"<",
"List",
"<",
"EvaluatedCandidate",
"<",
"T",
">",
">",
">",
">",
"createEpochTasks",
"(",
"int",
"populationSize",
",",
"int",
"eliteCount",
",",
"int",
"epochLength",
",",
"List",
"<",
"List",
"<",
"T",
">",
">",... | Create the concurrently-executed tasks that perform evolution on each island. | [
"Create",
"the",
"concurrently",
"-",
"executed",
"tasks",
"that",
"perform",
"evolution",
"on",
"each",
"island",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/islands/IslandEvolution.java#L262-L278 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/AbstractCrossover.java | AbstractCrossover.apply | public List<T> apply(List<T> selectedCandidates, Random rng)
{
// Shuffle the collection before applying each operation so that the
// evolution is not influenced by any ordering artifacts from previous
// operations.
List<T> selectionClone = new ArrayList<T>(selectedCandidates);
... | java | public List<T> apply(List<T> selectedCandidates, Random rng)
{
// Shuffle the collection before applying each operation so that the
// evolution is not influenced by any ordering artifacts from previous
// operations.
List<T> selectionClone = new ArrayList<T>(selectedCandidates);
... | [
"public",
"List",
"<",
"T",
">",
"apply",
"(",
"List",
"<",
"T",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"// Shuffle the collection before applying each operation so that the",
"// evolution is not influenced by any ordering artifacts from previous",
"// oper... | Applies the cross-over operation to the selected candidates. Pairs of
candidates are chosen randomly and subjected to cross-over to produce
a pair of offspring candidates.
@param selectedCandidates The evolved individuals that have survived to
be eligible to reproduce.
@param rng A source of randomness used to determi... | [
"Applies",
"the",
"cross",
"-",
"over",
"operation",
"to",
"the",
"selected",
"candidates",
".",
"Pairs",
"of",
"candidates",
"are",
"chosen",
"randomly",
"and",
"subjected",
"to",
"cross",
"-",
"over",
"to",
"produce",
"a",
"pair",
"of",
"offspring",
"candi... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/AbstractCrossover.java#L124-L165 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuCellRenderer.java | SudokuCellRenderer.getBorder | private Border getBorder(int row, int column)
{
if (row % 3 == 2)
{
switch (column % 3)
{
case 2: return BOTTOM_RIGHT_BORDER;
case 0: return BOTTOM_LEFT_BORDER;
default: return BOTTOM_BORDER;
}
}
else... | java | private Border getBorder(int row, int column)
{
if (row % 3 == 2)
{
switch (column % 3)
{
case 2: return BOTTOM_RIGHT_BORDER;
case 0: return BOTTOM_LEFT_BORDER;
default: return BOTTOM_BORDER;
}
}
else... | [
"private",
"Border",
"getBorder",
"(",
"int",
"row",
",",
"int",
"column",
")",
"{",
"if",
"(",
"row",
"%",
"3",
"==",
"2",
")",
"{",
"switch",
"(",
"column",
"%",
"3",
")",
"{",
"case",
"2",
":",
"return",
"BOTTOM_RIGHT_BORDER",
";",
"case",
"0",
... | Get appropriate border for cell based on its position in the grid. | [
"Get",
"appropriate",
"border",
"for",
"cell",
"based",
"on",
"its",
"position",
"in",
"the",
"grid",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuCellRenderer.java#L134-L161 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java | EvolutionUtils.shouldContinue | public static <T> List<TerminationCondition> shouldContinue(PopulationData<T> data,
TerminationCondition... conditions)
{
// If the thread has been interrupted, we should abort and return whatever
// result we currently have.
if... | java | public static <T> List<TerminationCondition> shouldContinue(PopulationData<T> data,
TerminationCondition... conditions)
{
// If the thread has been interrupted, we should abort and return whatever
// result we currently have.
if... | [
"public",
"static",
"<",
"T",
">",
"List",
"<",
"TerminationCondition",
">",
"shouldContinue",
"(",
"PopulationData",
"<",
"T",
">",
"data",
",",
"TerminationCondition",
"...",
"conditions",
")",
"{",
"// If the thread has been interrupted, we should abort and return what... | Given data about the current population and a set of termination conditions, determines
whether or not the evolution should continue.
@param data The current state of the population.
@param conditions One or more termination conditions. The evolution should not continue if
any of these is satisfied.
@param <T> The typ... | [
"Given",
"data",
"about",
"the",
"current",
"population",
"and",
"a",
"set",
"of",
"termination",
"conditions",
"determines",
"whether",
"or",
"not",
"the",
"evolution",
"should",
"continue",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java#L47-L66 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java | EvolutionUtils.getPopulationData | public static <T> PopulationData<T> getPopulationData(List<EvaluatedCandidate<T>> evaluatedPopulation,
boolean naturalFitness,
int eliteCount,
int... | java | public static <T> PopulationData<T> getPopulationData(List<EvaluatedCandidate<T>> evaluatedPopulation,
boolean naturalFitness,
int eliteCount,
int... | [
"public",
"static",
"<",
"T",
">",
"PopulationData",
"<",
"T",
">",
"getPopulationData",
"(",
"List",
"<",
"EvaluatedCandidate",
"<",
"T",
">",
">",
"evaluatedPopulation",
",",
"boolean",
"naturalFitness",
",",
"int",
"eliteCount",
",",
"int",
"iterationNumber",... | Gets data about the current population, including the fittest candidate
and statistics about the population as a whole.
@param evaluatedPopulation Population of candidate solutions with their
associated fitness scores.
@param naturalFitness True if higher fitness scores mean fitter individuals, false otherwise.
@param... | [
"Gets",
"data",
"about",
"the",
"current",
"population",
"including",
"the",
"fittest",
"candidate",
"and",
"statistics",
"about",
"the",
"population",
"as",
"a",
"whole",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java#L108-L128 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageRenderer.java | PolygonImageRenderer.render | public BufferedImage render(List<ColouredPolygon> entity)
{
// Need to set the background before applying the transform.
graphics.setTransform(IDENTITY_TRANSFORM);
graphics.setColor(Color.GRAY);
graphics.fillRect(0, 0, targetSize.width, targetSize.height);
if (transform != nu... | java | public BufferedImage render(List<ColouredPolygon> entity)
{
// Need to set the background before applying the transform.
graphics.setTransform(IDENTITY_TRANSFORM);
graphics.setColor(Color.GRAY);
graphics.fillRect(0, 0, targetSize.width, targetSize.height);
if (transform != nu... | [
"public",
"BufferedImage",
"render",
"(",
"List",
"<",
"ColouredPolygon",
">",
"entity",
")",
"{",
"// Need to set the background before applying the transform.",
"graphics",
".",
"setTransform",
"(",
"IDENTITY_TRANSFORM",
")",
";",
"graphics",
".",
"setColor",
"(",
"Co... | Renders the specified polygons as an image.
@param entity A collection of coloured polygons.
@return An image object displaying the polygons. | [
"Renders",
"the",
"specified",
"polygons",
"as",
"an",
"image",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/PolygonImageRenderer.java#L74-L90 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/islands/RingMigration.java | RingMigration.migrate | public <S extends Object> void migrate(List<List<EvaluatedCandidate<S>>> islandPopulations, int migrantCount, Random rng)
{
// The first batch of immigrants is from the last island to the first.
List<EvaluatedCandidate<S>> lastIsland = islandPopulations.get(islandPopulations.size() - 1);
Col... | java | public <S extends Object> void migrate(List<List<EvaluatedCandidate<S>>> islandPopulations, int migrantCount, Random rng)
{
// The first batch of immigrants is from the last island to the first.
List<EvaluatedCandidate<S>> lastIsland = islandPopulations.get(islandPopulations.size() - 1);
Col... | [
"public",
"<",
"S",
"extends",
"Object",
">",
"void",
"migrate",
"(",
"List",
"<",
"List",
"<",
"EvaluatedCandidate",
"<",
"S",
">",
">",
">",
"islandPopulations",
",",
"int",
"migrantCount",
",",
"Random",
"rng",
")",
"{",
"// The first batch of immigrants is... | Migrates a fixed number of individuals from each island to the adjacent island.
Operates as if the islands are arranged in a ring with migration occurring in a
clockwise direction. The individuals to be migrated are chosen completely at random.
@param islandPopulations A list of the populations of each island.
@param ... | [
"Migrates",
"a",
"fixed",
"number",
"of",
"individuals",
"from",
"each",
"island",
"to",
"the",
"adjacent",
"island",
".",
"Operates",
"as",
"if",
"the",
"islands",
"are",
"arranged",
"in",
"a",
"ring",
"with",
"migration",
"occurring",
"in",
"a",
"clockwise... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/islands/RingMigration.java#L42-L67 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/ItineraryPanel.java | ItineraryPanel.getSelectedCities | public Collection<String> getSelectedCities()
{
Set<String> cities = new TreeSet<String>();
for (JCheckBox checkBox : checkBoxes)
{
if (checkBox.isSelected())
{
cities.add(checkBox.getText());
}
}
return cities;
} | java | public Collection<String> getSelectedCities()
{
Set<String> cities = new TreeSet<String>();
for (JCheckBox checkBox : checkBoxes)
{
if (checkBox.isSelected())
{
cities.add(checkBox.getText());
}
}
return cities;
} | [
"public",
"Collection",
"<",
"String",
">",
"getSelectedCities",
"(",
")",
"{",
"Set",
"<",
"String",
">",
"cities",
"=",
"new",
"TreeSet",
"<",
"String",
">",
"(",
")",
";",
"for",
"(",
"JCheckBox",
"checkBox",
":",
"checkBoxes",
")",
"{",
"if",
"(",
... | Returns the cities that have been selected as part of the itinerary.
@return A list of cities. | [
"Returns",
"the",
"cities",
"that",
"have",
"been",
"selected",
"as",
"part",
"of",
"the",
"itinerary",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/ItineraryPanel.java#L89-L100 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/AddVertexMutation.java | AddVertexMutation.mutateVertices | @Override
protected List<Point> mutateVertices(List<Point> vertices, Random rng)
{
// A single point is added with the configured probability, unless
// we already have the maximum permitted number of points.
if (vertices.size() < MAX_VERTEX_COUNT && getMutationProbability().nextValue().... | java | @Override
protected List<Point> mutateVertices(List<Point> vertices, Random rng)
{
// A single point is added with the configured probability, unless
// we already have the maximum permitted number of points.
if (vertices.size() < MAX_VERTEX_COUNT && getMutationProbability().nextValue().... | [
"@",
"Override",
"protected",
"List",
"<",
"Point",
">",
"mutateVertices",
"(",
"List",
"<",
"Point",
">",
"vertices",
",",
"Random",
"rng",
")",
"{",
"// A single point is added with the configured probability, unless",
"// we already have the maximum permitted number of poi... | Mutates the list of vertices for a given polygon by adding a new random point.
Whether or not a point is actually added is determined by the configured mutation probability.
@param vertices A list of the points that make up the polygon.
@param rng A source of randomness.
@return A mutated list of points. | [
"Mutates",
"the",
"list",
"of",
"vertices",
"for",
"a",
"given",
"polygon",
"by",
"adding",
"a",
"new",
"random",
"point",
".",
"Whether",
"or",
"not",
"a",
"point",
"is",
"actually",
"added",
"is",
"determined",
"by",
"the",
"configured",
"mutation",
"pro... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/monalisa/AddVertexMutation.java#L66-L83 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/Biomorph.java | Biomorph.getPatternPhenotype | public int[][] getPatternPhenotype()
{
if (phenotype == null)
{
// Decode the genes as per Dawkins' rules.
int[] dx = new int[GENE_COUNT - 1];
dx[3] = genes[0];
dx[4] = genes[1];
dx[5] = genes[2];
dx[1] = -dx[3];
dx... | java | public int[][] getPatternPhenotype()
{
if (phenotype == null)
{
// Decode the genes as per Dawkins' rules.
int[] dx = new int[GENE_COUNT - 1];
dx[3] = genes[0];
dx[4] = genes[1];
dx[5] = genes[2];
dx[1] = -dx[3];
dx... | [
"public",
"int",
"[",
"]",
"[",
"]",
"getPatternPhenotype",
"(",
")",
"{",
"if",
"(",
"phenotype",
"==",
"null",
")",
"{",
"// Decode the genes as per Dawkins' rules.",
"int",
"[",
"]",
"dx",
"=",
"new",
"int",
"[",
"GENE_COUNT",
"-",
"1",
"]",
";",
"dx"... | Returns an array of integers that represent the graphical pattern
determined by the biomorph's genes.
@return A 2-dimensional array containing the 8-element dx and dy
arrays required to draw the biomorph. | [
"Returns",
"an",
"array",
"of",
"integers",
"that",
"represent",
"the",
"graphical",
"pattern",
"determined",
"by",
"the",
"biomorph",
"s",
"genes",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/Biomorph.java#L72-L103 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuRowMutation.java | SudokuRowMutation.isIntroducingFixedConflict | private boolean isIntroducingFixedConflict(Sudoku sudoku,
int row,
int fromIndex,
int toIndex)
{
return columnFixedValues[fromIndex][sudoku.getValue(row, toIndex) - 1]... | java | private boolean isIntroducingFixedConflict(Sudoku sudoku,
int row,
int fromIndex,
int toIndex)
{
return columnFixedValues[fromIndex][sudoku.getValue(row, toIndex) - 1]... | [
"private",
"boolean",
"isIntroducingFixedConflict",
"(",
"Sudoku",
"sudoku",
",",
"int",
"row",
",",
"int",
"fromIndex",
",",
"int",
"toIndex",
")",
"{",
"return",
"columnFixedValues",
"[",
"fromIndex",
"]",
"[",
"sudoku",
".",
"getValue",
"(",
"row",
",",
"... | Checks whether the proposed mutation would introduce a duplicate of a fixed value
into a column or sub-grid. | [
"Checks",
"whether",
"the",
"proposed",
"mutation",
"would",
"introduce",
"a",
"duplicate",
"of",
"a",
"fixed",
"value",
"into",
"a",
"column",
"or",
"sub",
"-",
"grid",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuRowMutation.java#L167-L176 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/EvolutionPipeline.java | EvolutionPipeline.apply | public List<T> apply(List<T> selectedCandidates, Random rng)
{
List<T> population = selectedCandidates;
for (EvolutionaryOperator<T> operator : pipeline)
{
population = operator.apply(population, rng);
}
return population;
} | java | public List<T> apply(List<T> selectedCandidates, Random rng)
{
List<T> population = selectedCandidates;
for (EvolutionaryOperator<T> operator : pipeline)
{
population = operator.apply(population, rng);
}
return population;
} | [
"public",
"List",
"<",
"T",
">",
"apply",
"(",
"List",
"<",
"T",
">",
"selectedCandidates",
",",
"Random",
"rng",
")",
"{",
"List",
"<",
"T",
">",
"population",
"=",
"selectedCandidates",
";",
"for",
"(",
"EvolutionaryOperator",
"<",
"T",
">",
"operator"... | Applies each operation in the pipeline in turn to the selection.
@param selectedCandidates The candidates to subjected to evolution.
@param rng A source of randomness used by all stochastic processes in
the pipeline.
@return A list of evolved candidates. | [
"Applies",
"each",
"operation",
"in",
"the",
"pipeline",
"in",
"turn",
"to",
"the",
"selection",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/EvolutionPipeline.java#L61-L69 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/RouteEvaluator.java | RouteEvaluator.getFitness | public double getFitness(List<String> candidate,
List<? extends List<String>> population)
{
int totalDistance = 0;
int cityCount = candidate.size();
for (int i = 0; i < cityCount; i++)
{
int nextIndex = i < cityCount - 1 ? i + 1 : 0;
... | java | public double getFitness(List<String> candidate,
List<? extends List<String>> population)
{
int totalDistance = 0;
int cityCount = candidate.size();
for (int i = 0; i < cityCount; i++)
{
int nextIndex = i < cityCount - 1 ? i + 1 : 0;
... | [
"public",
"double",
"getFitness",
"(",
"List",
"<",
"String",
">",
"candidate",
",",
"List",
"<",
"?",
"extends",
"List",
"<",
"String",
">",
">",
"population",
")",
"{",
"int",
"totalDistance",
"=",
"0",
";",
"int",
"cityCount",
"=",
"candidate",
".",
... | Calculates the length of an evolved route.
@param candidate The route to evaluate.
@param population {@inheritDoc}
@return The total distance (in kilometres) of a journey that visits
each city in order and returns to the starting point. | [
"Calculates",
"the",
"length",
"of",
"an",
"evolved",
"route",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/travellingsalesman/RouteEvaluator.java#L50-L62 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/Launcher.java | Launcher.main | public static void main(String[] args)
{
Class<?> exampleClass = args.length > 0 ? EXAMPLES.get(args[0]) : null;
if (exampleClass == null)
{
System.err.println("First argument must be the name of an example, i.e. one of "
+ Arrays.toString(EXAMPLES.... | java | public static void main(String[] args)
{
Class<?> exampleClass = args.length > 0 ? EXAMPLES.get(args[0]) : null;
if (exampleClass == null)
{
System.err.println("First argument must be the name of an example, i.e. one of "
+ Arrays.toString(EXAMPLES.... | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"Class",
"<",
"?",
">",
"exampleClass",
"=",
"args",
".",
"length",
">",
"0",
"?",
"EXAMPLES",
".",
"get",
"(",
"args",
"[",
"0",
"]",
")",
":",
"null",
";",
"if",
"... | Launch the specified example application from the command-line.
@param args First item is the name of the example to run. Any subsequent arguments are passed
on to the specific example. | [
"Launch",
"the",
"specified",
"example",
"application",
"from",
"the",
"command",
"-",
"line",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/Launcher.java#L61-L78 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/StringMutation.java | StringMutation.mutateString | private String mutateString(String s, Random rng)
{
StringBuilder buffer = new StringBuilder(s);
for (int i = 0; i < buffer.length(); i++)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
buffer.setCharAt(i, alphabet[rng.nextInt(alphabet.length)... | java | private String mutateString(String s, Random rng)
{
StringBuilder buffer = new StringBuilder(s);
for (int i = 0; i < buffer.length(); i++)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
buffer.setCharAt(i, alphabet[rng.nextInt(alphabet.length)... | [
"private",
"String",
"mutateString",
"(",
"String",
"s",
",",
"Random",
"rng",
")",
"{",
"StringBuilder",
"buffer",
"=",
"new",
"StringBuilder",
"(",
"s",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"buffer",
".",
"length",
"(",
")",
... | Mutate a single string. Zero or more characters may be modified. The
probability of any given character being modified is governed by the
probability generator configured for this mutation operator.
@param s The string to mutate.
@param rng A source of randomness.
@return The mutated string. | [
"Mutate",
"a",
"single",
"string",
".",
"Zero",
"or",
"more",
"characters",
"may",
"be",
"modified",
".",
"The",
"probability",
"of",
"any",
"given",
"character",
"being",
"modified",
"is",
"governed",
"by",
"the",
"probability",
"generator",
"configured",
"fo... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/StringMutation.java#L83-L94 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/GeneticProgrammingExample.java | GeneticProgrammingExample.evolveProgram | public static Node evolveProgram(Map<double[], Double> data)
{
TreeFactory factory = new TreeFactory(2, // Number of parameters passed into each program.
4, // Maximum depth of generated trees.
Probability.EVENS, // ... | java | public static Node evolveProgram(Map<double[], Double> data)
{
TreeFactory factory = new TreeFactory(2, // Number of parameters passed into each program.
4, // Maximum depth of generated trees.
Probability.EVENS, // ... | [
"public",
"static",
"Node",
"evolveProgram",
"(",
"Map",
"<",
"double",
"[",
"]",
",",
"Double",
">",
"data",
")",
"{",
"TreeFactory",
"factory",
"=",
"new",
"TreeFactory",
"(",
"2",
",",
"// Number of parameters passed into each program.",
"4",
",",
"// Maximum... | Evolve a function to fit the specified data.
@param data A map from input values to expected output values.
@return A program that generates the correct outputs for all specified
sets of input. | [
"Evolve",
"a",
"function",
"to",
"fit",
"the",
"specified",
"data",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/GeneticProgrammingExample.java#L66-L84 | train |
dwdyer/watchmaker | swing/src/java/main/org/uncommons/watchmaker/swing/evolutionmonitor/EvolutionMonitor.java | EvolutionMonitor.showWindow | private void showWindow(Window newWindow)
{
if (window != null)
{
window.remove(getGUIComponent());
window.setVisible(false);
window.dispose();
window = null;
}
newWindow.add(getGUIComponent(), BorderLayout.CENTER);
newWindow.pa... | java | private void showWindow(Window newWindow)
{
if (window != null)
{
window.remove(getGUIComponent());
window.setVisible(false);
window.dispose();
window = null;
}
newWindow.add(getGUIComponent(), BorderLayout.CENTER);
newWindow.pa... | [
"private",
"void",
"showWindow",
"(",
"Window",
"newWindow",
")",
"{",
"if",
"(",
"window",
"!=",
"null",
")",
"{",
"window",
".",
"remove",
"(",
"getGUIComponent",
"(",
")",
")",
";",
"window",
".",
"setVisible",
"(",
"false",
")",
";",
"window",
".",... | Helper method for showing the evolution monitor in a frame or dialog.
@param newWindow The frame or dialog used to show the evolution monitor. | [
"Helper",
"method",
"for",
"showing",
"the",
"evolution",
"monitor",
"in",
"a",
"frame",
"or",
"dialog",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/swing/src/java/main/org/uncommons/watchmaker/swing/evolutionmonitor/EvolutionMonitor.java#L236-L249 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOrderCrossover.java | ListOrderCrossover.checkUnmappedElements | private void checkUnmappedElements(List<T> offspring,
Map<T, T> mapping,
int mappingStart,
int mappingEnd)
{
for (int i = 0; i < offspring.size(); i++)
{
if (!isInsideMapp... | java | private void checkUnmappedElements(List<T> offspring,
Map<T, T> mapping,
int mappingStart,
int mappingEnd)
{
for (int i = 0; i < offspring.size(); i++)
{
if (!isInsideMapp... | [
"private",
"void",
"checkUnmappedElements",
"(",
"List",
"<",
"T",
">",
"offspring",
",",
"Map",
"<",
"T",
",",
"T",
">",
"mapping",
",",
"int",
"mappingStart",
",",
"int",
"mappingEnd",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"o... | Checks elements that are outside of the partially mapped section to
see if there are any duplicate items in the list. If there are, they
are mapped appropriately. | [
"Checks",
"elements",
"that",
"are",
"outside",
"of",
"the",
"partially",
"mapped",
"section",
"to",
"see",
"if",
"there",
"are",
"any",
"duplicate",
"items",
"in",
"the",
"list",
".",
"If",
"there",
"are",
"they",
"are",
"mapped",
"appropriately",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOrderCrossover.java#L127-L144 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOrderCrossover.java | ListOrderCrossover.isInsideMappedRegion | private boolean isInsideMappedRegion(int position,
int startPoint,
int endPoint)
{
boolean enclosed = (position < endPoint && position >= startPoint);
boolean wrapAround = (startPoint > endPoint && (position >= startPo... | java | private boolean isInsideMappedRegion(int position,
int startPoint,
int endPoint)
{
boolean enclosed = (position < endPoint && position >= startPoint);
boolean wrapAround = (startPoint > endPoint && (position >= startPo... | [
"private",
"boolean",
"isInsideMappedRegion",
"(",
"int",
"position",
",",
"int",
"startPoint",
",",
"int",
"endPoint",
")",
"{",
"boolean",
"enclosed",
"=",
"(",
"position",
"<",
"endPoint",
"&&",
"position",
">=",
"startPoint",
")",
";",
"boolean",
"wrapArou... | Checks whether a given list position is within the partially mapped
region used for cross-over.
@param position The list position to check.
@param startPoint The starting index (inclusive) of the mapped region.
@param endPoint The end index (exclusive) of the mapped region.
@return True if the specified position is in ... | [
"Checks",
"whether",
"a",
"given",
"list",
"position",
"is",
"within",
"the",
"partially",
"mapped",
"region",
"used",
"for",
"cross",
"-",
"over",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/ListOrderCrossover.java#L156-L163 | train |
dwdyer/watchmaker | examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java | AbstractExampleApplet.configure | private void configure(final Container container)
{
try
{
// Use invokeAndWait so that we can be sure that initialisation is complete
// before continuing.
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
... | java | private void configure(final Container container)
{
try
{
// Use invokeAndWait so that we can be sure that initialisation is complete
// before continuing.
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
... | [
"private",
"void",
"configure",
"(",
"final",
"Container",
"container",
")",
"{",
"try",
"{",
"// Use invokeAndWait so that we can be sure that initialisation is complete",
"// before continuing.",
"SwingUtilities",
".",
"invokeAndWait",
"(",
"new",
"Runnable",
"(",
")",
"{... | Configure the program to display its GUI in the specified container.
@param container The container to place the GUI components in. | [
"Configure",
"the",
"program",
"to",
"display",
"its",
"GUI",
"in",
"the",
"specified",
"container",
"."
] | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java#L46-L79 | train |
dwdyer/watchmaker | framework/src/java/main/org/uncommons/watchmaker/framework/operators/BitStringMutation.java | BitStringMutation.mutateBitString | private BitString mutateBitString(BitString bitString, Random rng)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
BitString mutatedBitString = bitString.clone();
int mutations = mutationCount.nextValue();
for (int i = 0; i < mutations; i++)
{
... | java | private BitString mutateBitString(BitString bitString, Random rng)
{
if (mutationProbability.nextValue().nextEvent(rng))
{
BitString mutatedBitString = bitString.clone();
int mutations = mutationCount.nextValue();
for (int i = 0; i < mutations; i++)
{
... | [
"private",
"BitString",
"mutateBitString",
"(",
"BitString",
"bitString",
",",
"Random",
"rng",
")",
"{",
"if",
"(",
"mutationProbability",
".",
"nextValue",
"(",
")",
".",
"nextEvent",
"(",
"rng",
")",
")",
"{",
"BitString",
"mutatedBitString",
"=",
"bitStrin... | Mutate a single bit string. Zero or more bits may be flipped. The
probability of any given bit being flipped is governed by the probability
generator configured for this mutation operator.
@param bitString The bit string to mutate.
@param rng A source of randomness.
@return The mutated bit string. | [
"Mutate",
"a",
"single",
"bit",
"string",
".",
"Zero",
"or",
"more",
"bits",
"may",
"be",
"flipped",
".",
"The",
"probability",
"of",
"any",
"given",
"bit",
"being",
"flipped",
"is",
"governed",
"by",
"the",
"probability",
"generator",
"configured",
"for",
... | 33d942350e6bf7d9a17b9262a4f898158530247e | https://github.com/dwdyer/watchmaker/blob/33d942350e6bf7d9a17b9262a4f898158530247e/framework/src/java/main/org/uncommons/watchmaker/framework/operators/BitStringMutation.java#L86-L99 | train |
urbanairship/datacube | src/main/java/com/urbanairship/datacube/dbharnesses/WithHTable.java | WithHTable.run | public static <T> T run(HTablePool pool, byte[] tableName, HTableRunnable<T> runnable)
throws IOException {
HTableInterface hTable = null;
try {
hTable = pool.getTable(tableName);
return runnable.runWith(hTable);
} catch (Exception e) {
if (e insta... | java | public static <T> T run(HTablePool pool, byte[] tableName, HTableRunnable<T> runnable)
throws IOException {
HTableInterface hTable = null;
try {
hTable = pool.getTable(tableName);
return runnable.runWith(hTable);
} catch (Exception e) {
if (e insta... | [
"public",
"static",
"<",
"T",
">",
"T",
"run",
"(",
"HTablePool",
"pool",
",",
"byte",
"[",
"]",
"tableName",
",",
"HTableRunnable",
"<",
"T",
">",
"runnable",
")",
"throws",
"IOException",
"{",
"HTableInterface",
"hTable",
"=",
"null",
";",
"try",
"{",
... | Take an htable from the pool, use it with the given HTableRunnable, and return it to
the pool. This is the "loan pattern" where the htable resource is used temporarily by
the runnable. | [
"Take",
"an",
"htable",
"from",
"the",
"pool",
"use",
"it",
"with",
"the",
"given",
"HTableRunnable",
"and",
"return",
"it",
"to",
"the",
"pool",
".",
"This",
"is",
"the",
"loan",
"pattern",
"where",
"the",
"htable",
"resource",
"is",
"used",
"temporarily"... | 89c6b68744cc384c8b49f921cdb0a0f9f414ada6 | https://github.com/urbanairship/datacube/blob/89c6b68744cc384c8b49f921cdb0a0f9f414ada6/src/main/java/com/urbanairship/datacube/dbharnesses/WithHTable.java#L28-L45 | train |
urbanairship/datacube | src/main/java/com/urbanairship/datacube/dbharnesses/WithHTable.java | WithHTable.put | public static void put(HTablePool pool, byte[] tableName, final Put put) throws IOException {
run(pool, tableName, new HTableRunnable<Object>() {
@Override
public Object runWith(HTableInterface hTable) throws IOException {
hTable.put(put);
return null;
... | java | public static void put(HTablePool pool, byte[] tableName, final Put put) throws IOException {
run(pool, tableName, new HTableRunnable<Object>() {
@Override
public Object runWith(HTableInterface hTable) throws IOException {
hTable.put(put);
return null;
... | [
"public",
"static",
"void",
"put",
"(",
"HTablePool",
"pool",
",",
"byte",
"[",
"]",
"tableName",
",",
"final",
"Put",
"put",
")",
"throws",
"IOException",
"{",
"run",
"(",
"pool",
",",
"tableName",
",",
"new",
"HTableRunnable",
"<",
"Object",
">",
"(",
... | Do an HBase put and return null.
@throws IOException if the underlying HBase operation throws an IOException | [
"Do",
"an",
"HBase",
"put",
"and",
"return",
"null",
"."
] | 89c6b68744cc384c8b49f921cdb0a0f9f414ada6 | https://github.com/urbanairship/datacube/blob/89c6b68744cc384c8b49f921cdb0a0f9f414ada6/src/main/java/com/urbanairship/datacube/dbharnesses/WithHTable.java#L56-L64 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.