id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
163,800 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java | JettyManager.requestBlock | public synchronized String requestBlock(String name) {
if (blocks.isEmpty()) {
return "exit";
}
remainingBlocks.decrementAndGet();
return blocks.poll().createResponse();
} | java | public synchronized String requestBlock(String name) {
if (blocks.isEmpty()) {
return "exit";
}
remainingBlocks.decrementAndGet();
return blocks.poll().createResponse();
} | [
"public",
"synchronized",
"String",
"requestBlock",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"blocks",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"\"exit\"",
";",
"}",
"remainingBlocks",
".",
"decrementAndGet",
"(",
")",
";",
"return",
"blocks",
".",
"poll",
"(",
")",
".",
"createResponse",
"(",
")",
";",
"}"
] | Returns a description a block of work, or "exit" if no more blocks exist
@param name the assigned name of the consumer requesting a block of work
@return a description a block of work, or "exit" if no more blocks exist | [
"Returns",
"a",
"description",
"a",
"block",
"of",
"work",
"or",
"exit",
"if",
"no",
"more",
"blocks",
"exist"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java#L76-L83 |
163,801 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java | JettyManager.makeReport | public String makeReport(String name, String report) {
long increment = Long.valueOf(report);
long currentLineCount = globalLineCounter.addAndGet(increment);
if (currentLineCount >= maxScenarios) {
return "exit";
} else {
return "ok";
}
} | java | public String makeReport(String name, String report) {
long increment = Long.valueOf(report);
long currentLineCount = globalLineCounter.addAndGet(increment);
if (currentLineCount >= maxScenarios) {
return "exit";
} else {
return "ok";
}
} | [
"public",
"String",
"makeReport",
"(",
"String",
"name",
",",
"String",
"report",
")",
"{",
"long",
"increment",
"=",
"Long",
".",
"valueOf",
"(",
"report",
")",
";",
"long",
"currentLineCount",
"=",
"globalLineCounter",
".",
"addAndGet",
"(",
"increment",
")",
";",
"if",
"(",
"currentLineCount",
">=",
"maxScenarios",
")",
"{",
"return",
"\"exit\"",
";",
"}",
"else",
"{",
"return",
"\"ok\"",
";",
"}",
"}"
] | Handles reports by consumers
@param name the name of the reporting consumer
@param report the number of lines the consumer has written since last report
@return "exit" if maxScenarios has been reached, "ok" otherwise | [
"Handles",
"reports",
"by",
"consumers"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java#L101-L110 |
163,802 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java | JettyManager.prepareStatus | public void prepareStatus() {
globalLineCounter = new AtomicLong(0);
time = new AtomicLong(System.currentTimeMillis());
startTime = System.currentTimeMillis();
lastCount = 0;
// Status thread regularly reports on what is happening
Thread statusThread = new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Status thread interrupted");
}
long thisTime = System.currentTimeMillis();
long currentCount = globalLineCounter.get();
if (thisTime - time.get() > 1000) {
long oldTime = time.get();
time.set(thisTime);
double avgRate = 1000.0 * currentCount / (thisTime - startTime);
double instRate = 1000.0 * (currentCount - lastCount) / (thisTime - oldTime);
lastCount = currentCount;
System.out.println(currentCount + " AvgRage:" + ((int) avgRate) + " lines/sec instRate:"
+ ((int) instRate) + " lines/sec Unassigned Work: "
+ remainingBlocks.get() + " blocks");
}
}
}
};
statusThread.start();
} | java | public void prepareStatus() {
globalLineCounter = new AtomicLong(0);
time = new AtomicLong(System.currentTimeMillis());
startTime = System.currentTimeMillis();
lastCount = 0;
// Status thread regularly reports on what is happening
Thread statusThread = new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Status thread interrupted");
}
long thisTime = System.currentTimeMillis();
long currentCount = globalLineCounter.get();
if (thisTime - time.get() > 1000) {
long oldTime = time.get();
time.set(thisTime);
double avgRate = 1000.0 * currentCount / (thisTime - startTime);
double instRate = 1000.0 * (currentCount - lastCount) / (thisTime - oldTime);
lastCount = currentCount;
System.out.println(currentCount + " AvgRage:" + ((int) avgRate) + " lines/sec instRate:"
+ ((int) instRate) + " lines/sec Unassigned Work: "
+ remainingBlocks.get() + " blocks");
}
}
}
};
statusThread.start();
} | [
"public",
"void",
"prepareStatus",
"(",
")",
"{",
"globalLineCounter",
"=",
"new",
"AtomicLong",
"(",
"0",
")",
";",
"time",
"=",
"new",
"AtomicLong",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"startTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"lastCount",
"=",
"0",
";",
"// Status thread regularly reports on what is happening",
"Thread",
"statusThread",
"=",
"new",
"Thread",
"(",
")",
"{",
"public",
"void",
"run",
"(",
")",
"{",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"1000",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Status thread interrupted\"",
")",
";",
"}",
"long",
"thisTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"long",
"currentCount",
"=",
"globalLineCounter",
".",
"get",
"(",
")",
";",
"if",
"(",
"thisTime",
"-",
"time",
".",
"get",
"(",
")",
">",
"1000",
")",
"{",
"long",
"oldTime",
"=",
"time",
".",
"get",
"(",
")",
";",
"time",
".",
"set",
"(",
"thisTime",
")",
";",
"double",
"avgRate",
"=",
"1000.0",
"*",
"currentCount",
"/",
"(",
"thisTime",
"-",
"startTime",
")",
";",
"double",
"instRate",
"=",
"1000.0",
"*",
"(",
"currentCount",
"-",
"lastCount",
")",
"/",
"(",
"thisTime",
"-",
"oldTime",
")",
";",
"lastCount",
"=",
"currentCount",
";",
"System",
".",
"out",
".",
"println",
"(",
"currentCount",
"+",
"\" AvgRage:\"",
"+",
"(",
"(",
"int",
")",
"avgRate",
")",
"+",
"\" lines/sec instRate:\"",
"+",
"(",
"(",
"int",
")",
"instRate",
")",
"+",
"\" lines/sec Unassigned Work: \"",
"+",
"remainingBlocks",
".",
"get",
"(",
")",
"+",
"\" blocks\"",
")",
";",
"}",
"}",
"}",
"}",
";",
"statusThread",
".",
"start",
"(",
")",
";",
"}"
] | Establishes a thread that on one second intervals reports the number of remaining WorkBlocks enqueued and the
total number of lines written and reported by consumers | [
"Establishes",
"a",
"thread",
"that",
"on",
"one",
"second",
"intervals",
"reports",
"the",
"number",
"of",
"remaining",
"WorkBlocks",
"enqueued",
"and",
"the",
"total",
"number",
"of",
"lines",
"written",
"and",
"reported",
"by",
"consumers"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java#L126-L159 |
163,803 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java | JettyManager.prepareServer | public void prepareServer() {
try {
server = new Server(0);
jettyHandler = new AbstractHandler() {
public void handle(String target, Request req, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/plain");
String[] operands = request.getRequestURI().split("/");
String name = "";
String command = "";
String value = "";
//operands[0] = "", request starts with a "/"
if (operands.length >= 2) {
name = operands[1];
}
if (operands.length >= 3) {
command = operands[2];
}
if (operands.length >= 4) {
value = operands[3];
}
if (command.equals("report")) { //report a number of lines written
response.getWriter().write(makeReport(name, value));
} else if (command.equals("request") && value.equals("block")) { //request a new block of work
response.getWriter().write(requestBlock(name));
} else if (command.equals("request") && value.equals("name")) { //request a new name to report with
response.getWriter().write(requestName());
} else { //non recognized response
response.getWriter().write("exit");
}
((Request) request).setHandled(true);
}
};
server.setHandler(jettyHandler);
// Select any available port
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector nc = (NetworkConnector) connectors[0];
listeningPort = nc.getLocalPort();
hostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
e.printStackTrace();
}
} | java | public void prepareServer() {
try {
server = new Server(0);
jettyHandler = new AbstractHandler() {
public void handle(String target, Request req, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/plain");
String[] operands = request.getRequestURI().split("/");
String name = "";
String command = "";
String value = "";
//operands[0] = "", request starts with a "/"
if (operands.length >= 2) {
name = operands[1];
}
if (operands.length >= 3) {
command = operands[2];
}
if (operands.length >= 4) {
value = operands[3];
}
if (command.equals("report")) { //report a number of lines written
response.getWriter().write(makeReport(name, value));
} else if (command.equals("request") && value.equals("block")) { //request a new block of work
response.getWriter().write(requestBlock(name));
} else if (command.equals("request") && value.equals("name")) { //request a new name to report with
response.getWriter().write(requestName());
} else { //non recognized response
response.getWriter().write("exit");
}
((Request) request).setHandled(true);
}
};
server.setHandler(jettyHandler);
// Select any available port
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector nc = (NetworkConnector) connectors[0];
listeningPort = nc.getLocalPort();
hostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
e.printStackTrace();
}
} | [
"public",
"void",
"prepareServer",
"(",
")",
"{",
"try",
"{",
"server",
"=",
"new",
"Server",
"(",
"0",
")",
";",
"jettyHandler",
"=",
"new",
"AbstractHandler",
"(",
")",
"{",
"public",
"void",
"handle",
"(",
"String",
"target",
",",
"Request",
"req",
",",
"HttpServletRequest",
"request",
",",
"HttpServletResponse",
"response",
")",
"throws",
"IOException",
",",
"ServletException",
"{",
"response",
".",
"setContentType",
"(",
"\"text/plain\"",
")",
";",
"String",
"[",
"]",
"operands",
"=",
"request",
".",
"getRequestURI",
"(",
")",
".",
"split",
"(",
"\"/\"",
")",
";",
"String",
"name",
"=",
"\"\"",
";",
"String",
"command",
"=",
"\"\"",
";",
"String",
"value",
"=",
"\"\"",
";",
"//operands[0] = \"\", request starts with a \"/\"",
"if",
"(",
"operands",
".",
"length",
">=",
"2",
")",
"{",
"name",
"=",
"operands",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"operands",
".",
"length",
">=",
"3",
")",
"{",
"command",
"=",
"operands",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"operands",
".",
"length",
">=",
"4",
")",
"{",
"value",
"=",
"operands",
"[",
"3",
"]",
";",
"}",
"if",
"(",
"command",
".",
"equals",
"(",
"\"report\"",
")",
")",
"{",
"//report a number of lines written",
"response",
".",
"getWriter",
"(",
")",
".",
"write",
"(",
"makeReport",
"(",
"name",
",",
"value",
")",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"equals",
"(",
"\"request\"",
")",
"&&",
"value",
".",
"equals",
"(",
"\"block\"",
")",
")",
"{",
"//request a new block of work",
"response",
".",
"getWriter",
"(",
")",
".",
"write",
"(",
"requestBlock",
"(",
"name",
")",
")",
";",
"}",
"else",
"if",
"(",
"command",
".",
"equals",
"(",
"\"request\"",
")",
"&&",
"value",
".",
"equals",
"(",
"\"name\"",
")",
")",
"{",
"//request a new name to report with",
"response",
".",
"getWriter",
"(",
")",
".",
"write",
"(",
"requestName",
"(",
")",
")",
";",
"}",
"else",
"{",
"//non recognized response",
"response",
".",
"getWriter",
"(",
")",
".",
"write",
"(",
"\"exit\"",
")",
";",
"}",
"(",
"(",
"Request",
")",
"request",
")",
".",
"setHandled",
"(",
"true",
")",
";",
"}",
"}",
";",
"server",
".",
"setHandler",
"(",
"jettyHandler",
")",
";",
"// Select any available port",
"server",
".",
"start",
"(",
")",
";",
"Connector",
"[",
"]",
"connectors",
"=",
"server",
".",
"getConnectors",
"(",
")",
";",
"NetworkConnector",
"nc",
"=",
"(",
"NetworkConnector",
")",
"connectors",
"[",
"0",
"]",
";",
"listeningPort",
"=",
"nc",
".",
"getLocalPort",
"(",
")",
";",
"hostName",
"=",
"InetAddress",
".",
"getLocalHost",
"(",
")",
".",
"getHostName",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Prepares a Jetty server for communicating with consumers. | [
"Prepares",
"a",
"Jetty",
"server",
"for",
"communicating",
"with",
"consumers",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/manager/JettyManager.java#L164-L217 |
163,804 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java | XmlWriter.getXmlFormatted | public String getXmlFormatted(Map<String, String> dataMap) {
StringBuilder sb = new StringBuilder();
for (String var : outTemplate) {
sb.append(appendXmlStartTag(var));
sb.append(dataMap.get(var));
sb.append(appendXmlEndingTag(var));
}
return sb.toString();
} | java | public String getXmlFormatted(Map<String, String> dataMap) {
StringBuilder sb = new StringBuilder();
for (String var : outTemplate) {
sb.append(appendXmlStartTag(var));
sb.append(dataMap.get(var));
sb.append(appendXmlEndingTag(var));
}
return sb.toString();
} | [
"public",
"String",
"getXmlFormatted",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"dataMap",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"String",
"var",
":",
"outTemplate",
")",
"{",
"sb",
".",
"append",
"(",
"appendXmlStartTag",
"(",
"var",
")",
")",
";",
"sb",
".",
"append",
"(",
"dataMap",
".",
"get",
"(",
"var",
")",
")",
";",
"sb",
".",
"append",
"(",
"appendXmlEndingTag",
"(",
"var",
")",
")",
";",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] | Given an array of variable names, returns an Xml String
of values.
@param dataMap an map containing variable names and their corresponding values
names.
@param dataMap
@return values in Xml format | [
"Given",
"an",
"array",
"of",
"variable",
"names",
"returns",
"an",
"Xml",
"String",
"of",
"values",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java#L91-L99 |
163,805 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java | XmlWriter.appendXmlStartTag | private String appendXmlStartTag(String value) {
StringBuilder sb = new StringBuilder();
sb.append("<").append(value).append(">");
return sb.toString();
} | java | private String appendXmlStartTag(String value) {
StringBuilder sb = new StringBuilder();
sb.append("<").append(value).append(">");
return sb.toString();
} | [
"private",
"String",
"appendXmlStartTag",
"(",
"String",
"value",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"sb",
".",
"append",
"(",
"\"<\"",
")",
".",
"append",
"(",
"value",
")",
".",
"append",
"(",
"\">\"",
")",
";",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] | Helper xml start tag writer
@param value the output stream to use in writing | [
"Helper",
"xml",
"start",
"tag",
"writer"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java#L106-L111 |
163,806 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java | XmlWriter.appendXmlEndingTag | private String appendXmlEndingTag(String value) {
StringBuilder sb = new StringBuilder();
sb.append("</").append(value).append(">");
return sb.toString();
} | java | private String appendXmlEndingTag(String value) {
StringBuilder sb = new StringBuilder();
sb.append("</").append(value).append(">");
return sb.toString();
} | [
"private",
"String",
"appendXmlEndingTag",
"(",
"String",
"value",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"sb",
".",
"append",
"(",
"\"</\"",
")",
".",
"append",
"(",
"value",
")",
".",
"append",
"(",
"\">\"",
")",
";",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] | Helper xml end tag writer
@param value the output stream to use in writing | [
"Helper",
"xml",
"end",
"tag",
"writer"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/writer/XmlWriter.java#L118-L123 |
163,807 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java | SCXMLEngine.fillInitialVariables | private Map<String, String> fillInitialVariables() {
Map<String, TransitionTarget> targets = model.getChildren();
Set<String> variables = new HashSet<>();
for (TransitionTarget target : targets.values()) {
OnEntry entry = target.getOnEntry();
List<Action> actions = entry.getActions();
for (Action action : actions) {
if (action instanceof Assign) {
String variable = ((Assign) action).getName();
variables.add(variable);
} else if (action instanceof SetAssignExtension.SetAssignTag) {
String variable = ((SetAssignExtension.SetAssignTag) action).getName();
variables.add(variable);
}
}
}
Map<String, String> result = new HashMap<>();
for (String variable : variables) {
result.put(variable, "");
}
return result;
} | java | private Map<String, String> fillInitialVariables() {
Map<String, TransitionTarget> targets = model.getChildren();
Set<String> variables = new HashSet<>();
for (TransitionTarget target : targets.values()) {
OnEntry entry = target.getOnEntry();
List<Action> actions = entry.getActions();
for (Action action : actions) {
if (action instanceof Assign) {
String variable = ((Assign) action).getName();
variables.add(variable);
} else if (action instanceof SetAssignExtension.SetAssignTag) {
String variable = ((SetAssignExtension.SetAssignTag) action).getName();
variables.add(variable);
}
}
}
Map<String, String> result = new HashMap<>();
for (String variable : variables) {
result.put(variable, "");
}
return result;
} | [
"private",
"Map",
"<",
"String",
",",
"String",
">",
"fillInitialVariables",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"TransitionTarget",
">",
"targets",
"=",
"model",
".",
"getChildren",
"(",
")",
";",
"Set",
"<",
"String",
">",
"variables",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"TransitionTarget",
"target",
":",
"targets",
".",
"values",
"(",
")",
")",
"{",
"OnEntry",
"entry",
"=",
"target",
".",
"getOnEntry",
"(",
")",
";",
"List",
"<",
"Action",
">",
"actions",
"=",
"entry",
".",
"getActions",
"(",
")",
";",
"for",
"(",
"Action",
"action",
":",
"actions",
")",
"{",
"if",
"(",
"action",
"instanceof",
"Assign",
")",
"{",
"String",
"variable",
"=",
"(",
"(",
"Assign",
")",
"action",
")",
".",
"getName",
"(",
")",
";",
"variables",
".",
"add",
"(",
"variable",
")",
";",
"}",
"else",
"if",
"(",
"action",
"instanceof",
"SetAssignExtension",
".",
"SetAssignTag",
")",
"{",
"String",
"variable",
"=",
"(",
"(",
"SetAssignExtension",
".",
"SetAssignTag",
")",
"action",
")",
".",
"getName",
"(",
")",
";",
"variables",
".",
"add",
"(",
"variable",
")",
";",
"}",
"}",
"}",
"Map",
"<",
"String",
",",
"String",
">",
"result",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"variable",
":",
"variables",
")",
"{",
"result",
".",
"put",
"(",
"variable",
",",
"\"\"",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Searches the model for all variable assignments and makes a default map of those variables, setting them to ""
@return the default variable assignment map | [
"Searches",
"the",
"model",
"for",
"all",
"variable",
"assignments",
"and",
"makes",
"a",
"default",
"map",
"of",
"those",
"variables",
"setting",
"them",
"to"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java#L102-L126 |
163,808 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java | SCXMLEngine.bfs | public List<PossibleState> bfs(int min) throws ModelException {
List<PossibleState> bootStrap = new LinkedList<>();
TransitionTarget initial = model.getInitialTarget();
PossibleState initialState = new PossibleState(initial, fillInitialVariables());
bootStrap.add(initialState);
while (bootStrap.size() < min) {
PossibleState state = bootStrap.remove(0);
TransitionTarget nextState = state.nextState;
if (nextState.getId().equalsIgnoreCase("end")) {
throw new ModelException("Could not achieve required bootstrap without reaching end state");
}
//run every action in series
List<Map<String, String>> product = new LinkedList<>();
product.add(new HashMap<>(state.variables));
OnEntry entry = nextState.getOnEntry();
List<Action> actions = entry.getActions();
for (Action action : actions) {
for (CustomTagExtension tagExtension : tagExtensionList) {
if (tagExtension.getTagActionClass().isInstance(action)) {
product = tagExtension.pipelinePossibleStates(action, product);
}
}
}
//go through every transition and see which of the products are valid, adding them to the list
List<Transition> transitions = nextState.getTransitionsList();
for (Transition transition : transitions) {
String condition = transition.getCond();
TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0);
for (Map<String, String> p : product) {
Boolean pass;
if (condition == null) {
pass = true;
} else {
//scrub the context clean so we may use it to evaluate transition conditional
Context context = this.getRootContext();
context.reset();
//set up new context
for (Map.Entry<String, String> e : p.entrySet()) {
context.set(e.getKey(), e.getValue());
}
//evaluate condition
try {
pass = (Boolean) this.getEvaluator().eval(context, condition);
} catch (SCXMLExpressionException ex) {
pass = false;
}
}
//transition condition satisfied, add to bootstrap list
if (pass) {
PossibleState result = new PossibleState(target, p);
bootStrap.add(result);
}
}
}
}
return bootStrap;
} | java | public List<PossibleState> bfs(int min) throws ModelException {
List<PossibleState> bootStrap = new LinkedList<>();
TransitionTarget initial = model.getInitialTarget();
PossibleState initialState = new PossibleState(initial, fillInitialVariables());
bootStrap.add(initialState);
while (bootStrap.size() < min) {
PossibleState state = bootStrap.remove(0);
TransitionTarget nextState = state.nextState;
if (nextState.getId().equalsIgnoreCase("end")) {
throw new ModelException("Could not achieve required bootstrap without reaching end state");
}
//run every action in series
List<Map<String, String>> product = new LinkedList<>();
product.add(new HashMap<>(state.variables));
OnEntry entry = nextState.getOnEntry();
List<Action> actions = entry.getActions();
for (Action action : actions) {
for (CustomTagExtension tagExtension : tagExtensionList) {
if (tagExtension.getTagActionClass().isInstance(action)) {
product = tagExtension.pipelinePossibleStates(action, product);
}
}
}
//go through every transition and see which of the products are valid, adding them to the list
List<Transition> transitions = nextState.getTransitionsList();
for (Transition transition : transitions) {
String condition = transition.getCond();
TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0);
for (Map<String, String> p : product) {
Boolean pass;
if (condition == null) {
pass = true;
} else {
//scrub the context clean so we may use it to evaluate transition conditional
Context context = this.getRootContext();
context.reset();
//set up new context
for (Map.Entry<String, String> e : p.entrySet()) {
context.set(e.getKey(), e.getValue());
}
//evaluate condition
try {
pass = (Boolean) this.getEvaluator().eval(context, condition);
} catch (SCXMLExpressionException ex) {
pass = false;
}
}
//transition condition satisfied, add to bootstrap list
if (pass) {
PossibleState result = new PossibleState(target, p);
bootStrap.add(result);
}
}
}
}
return bootStrap;
} | [
"public",
"List",
"<",
"PossibleState",
">",
"bfs",
"(",
"int",
"min",
")",
"throws",
"ModelException",
"{",
"List",
"<",
"PossibleState",
">",
"bootStrap",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"TransitionTarget",
"initial",
"=",
"model",
".",
"getInitialTarget",
"(",
")",
";",
"PossibleState",
"initialState",
"=",
"new",
"PossibleState",
"(",
"initial",
",",
"fillInitialVariables",
"(",
")",
")",
";",
"bootStrap",
".",
"add",
"(",
"initialState",
")",
";",
"while",
"(",
"bootStrap",
".",
"size",
"(",
")",
"<",
"min",
")",
"{",
"PossibleState",
"state",
"=",
"bootStrap",
".",
"remove",
"(",
"0",
")",
";",
"TransitionTarget",
"nextState",
"=",
"state",
".",
"nextState",
";",
"if",
"(",
"nextState",
".",
"getId",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"\"end\"",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"\"Could not achieve required bootstrap without reaching end state\"",
")",
";",
"}",
"//run every action in series\r",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"product",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"product",
".",
"add",
"(",
"new",
"HashMap",
"<>",
"(",
"state",
".",
"variables",
")",
")",
";",
"OnEntry",
"entry",
"=",
"nextState",
".",
"getOnEntry",
"(",
")",
";",
"List",
"<",
"Action",
">",
"actions",
"=",
"entry",
".",
"getActions",
"(",
")",
";",
"for",
"(",
"Action",
"action",
":",
"actions",
")",
"{",
"for",
"(",
"CustomTagExtension",
"tagExtension",
":",
"tagExtensionList",
")",
"{",
"if",
"(",
"tagExtension",
".",
"getTagActionClass",
"(",
")",
".",
"isInstance",
"(",
"action",
")",
")",
"{",
"product",
"=",
"tagExtension",
".",
"pipelinePossibleStates",
"(",
"action",
",",
"product",
")",
";",
"}",
"}",
"}",
"//go through every transition and see which of the products are valid, adding them to the list\r",
"List",
"<",
"Transition",
">",
"transitions",
"=",
"nextState",
".",
"getTransitionsList",
"(",
")",
";",
"for",
"(",
"Transition",
"transition",
":",
"transitions",
")",
"{",
"String",
"condition",
"=",
"transition",
".",
"getCond",
"(",
")",
";",
"TransitionTarget",
"target",
"=",
"(",
"(",
"List",
"<",
"TransitionTarget",
">",
")",
"transition",
".",
"getTargets",
"(",
")",
")",
".",
"get",
"(",
"0",
")",
";",
"for",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"p",
":",
"product",
")",
"{",
"Boolean",
"pass",
";",
"if",
"(",
"condition",
"==",
"null",
")",
"{",
"pass",
"=",
"true",
";",
"}",
"else",
"{",
"//scrub the context clean so we may use it to evaluate transition conditional\r",
"Context",
"context",
"=",
"this",
".",
"getRootContext",
"(",
")",
";",
"context",
".",
"reset",
"(",
")",
";",
"//set up new context\r",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"e",
":",
"p",
".",
"entrySet",
"(",
")",
")",
"{",
"context",
".",
"set",
"(",
"e",
".",
"getKey",
"(",
")",
",",
"e",
".",
"getValue",
"(",
")",
")",
";",
"}",
"//evaluate condition\r",
"try",
"{",
"pass",
"=",
"(",
"Boolean",
")",
"this",
".",
"getEvaluator",
"(",
")",
".",
"eval",
"(",
"context",
",",
"condition",
")",
";",
"}",
"catch",
"(",
"SCXMLExpressionException",
"ex",
")",
"{",
"pass",
"=",
"false",
";",
"}",
"}",
"//transition condition satisfied, add to bootstrap list\r",
"if",
"(",
"pass",
")",
"{",
"PossibleState",
"result",
"=",
"new",
"PossibleState",
"(",
"target",
",",
"p",
")",
";",
"bootStrap",
".",
"add",
"(",
"result",
")",
";",
"}",
"}",
"}",
"}",
"return",
"bootStrap",
";",
"}"
] | Performs a partial BFS on model until the search frontier reaches the desired bootstrap size
@param min the desired bootstrap size
@return a list of found PossibleState
@throws ModelException if the desired bootstrap can not be reached | [
"Performs",
"a",
"partial",
"BFS",
"on",
"model",
"until",
"the",
"search",
"frontier",
"reaches",
"the",
"desired",
"bootstrap",
"size"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java#L135-L205 |
163,809 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java | SCXMLEngine.process | public void process(SearchDistributor distributor) {
List<PossibleState> bootStrap;
try {
bootStrap = bfs(bootStrapMin);
} catch (ModelException e) {
bootStrap = new LinkedList<>();
}
List<Frontier> frontiers = new LinkedList<>();
for (PossibleState p : bootStrap) {
SCXMLFrontier dge = new SCXMLFrontier(p, model, tagExtensionList);
frontiers.add(dge);
}
distributor.distribute(frontiers);
} | java | public void process(SearchDistributor distributor) {
List<PossibleState> bootStrap;
try {
bootStrap = bfs(bootStrapMin);
} catch (ModelException e) {
bootStrap = new LinkedList<>();
}
List<Frontier> frontiers = new LinkedList<>();
for (PossibleState p : bootStrap) {
SCXMLFrontier dge = new SCXMLFrontier(p, model, tagExtensionList);
frontiers.add(dge);
}
distributor.distribute(frontiers);
} | [
"public",
"void",
"process",
"(",
"SearchDistributor",
"distributor",
")",
"{",
"List",
"<",
"PossibleState",
">",
"bootStrap",
";",
"try",
"{",
"bootStrap",
"=",
"bfs",
"(",
"bootStrapMin",
")",
";",
"}",
"catch",
"(",
"ModelException",
"e",
")",
"{",
"bootStrap",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"}",
"List",
"<",
"Frontier",
">",
"frontiers",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"for",
"(",
"PossibleState",
"p",
":",
"bootStrap",
")",
"{",
"SCXMLFrontier",
"dge",
"=",
"new",
"SCXMLFrontier",
"(",
"p",
",",
"model",
",",
"tagExtensionList",
")",
";",
"frontiers",
".",
"add",
"(",
"dge",
")",
";",
"}",
"distributor",
".",
"distribute",
"(",
"frontiers",
")",
";",
"}"
] | Performs the BFS and gives the results to a distributor to distribute
@param distributor the distributor | [
"Performs",
"the",
"BFS",
"and",
"gives",
"the",
"results",
"to",
"a",
"distributor",
"to",
"distribute"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java#L212-L227 |
163,810 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java | SCXMLEngine.setModelByInputFileStream | public void setModelByInputFileStream(InputStream inputFileStream) {
try {
this.model = SCXMLParser.parse(new InputSource(inputFileStream), null, customActionsFromTagExtensions());
this.setStateMachine(this.model);
} catch (IOException | SAXException | ModelException e) {
e.printStackTrace();
}
} | java | public void setModelByInputFileStream(InputStream inputFileStream) {
try {
this.model = SCXMLParser.parse(new InputSource(inputFileStream), null, customActionsFromTagExtensions());
this.setStateMachine(this.model);
} catch (IOException | SAXException | ModelException e) {
e.printStackTrace();
}
} | [
"public",
"void",
"setModelByInputFileStream",
"(",
"InputStream",
"inputFileStream",
")",
"{",
"try",
"{",
"this",
".",
"model",
"=",
"SCXMLParser",
".",
"parse",
"(",
"new",
"InputSource",
"(",
"inputFileStream",
")",
",",
"null",
",",
"customActionsFromTagExtensions",
"(",
")",
")",
";",
"this",
".",
"setStateMachine",
"(",
"this",
".",
"model",
")",
";",
"}",
"catch",
"(",
"IOException",
"|",
"SAXException",
"|",
"ModelException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Sets the SCXML model with an InputStream
@param inputFileStream the model input stream | [
"Sets",
"the",
"SCXML",
"model",
"with",
"an",
"InputStream"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java#L248-L255 |
163,811 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java | SCXMLEngine.setModelByText | public void setModelByText(String model) {
try {
InputStream is = new ByteArrayInputStream(model.getBytes());
this.model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions());
this.setStateMachine(this.model);
} catch (IOException | SAXException | ModelException e) {
e.printStackTrace();
}
} | java | public void setModelByText(String model) {
try {
InputStream is = new ByteArrayInputStream(model.getBytes());
this.model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions());
this.setStateMachine(this.model);
} catch (IOException | SAXException | ModelException e) {
e.printStackTrace();
}
} | [
"public",
"void",
"setModelByText",
"(",
"String",
"model",
")",
"{",
"try",
"{",
"InputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"model",
".",
"getBytes",
"(",
")",
")",
";",
"this",
".",
"model",
"=",
"SCXMLParser",
".",
"parse",
"(",
"new",
"InputSource",
"(",
"is",
")",
",",
"null",
",",
"customActionsFromTagExtensions",
"(",
")",
")",
";",
"this",
".",
"setStateMachine",
"(",
"this",
".",
"model",
")",
";",
"}",
"catch",
"(",
"IOException",
"|",
"SAXException",
"|",
"ModelException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Sets the SCXML model with a string
@param model the model text | [
"Sets",
"the",
"SCXML",
"model",
"with",
"a",
"string"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLEngine.java#L262-L270 |
163,812 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java | NWiseExtension.makeNWiseTuples | public List<Set<String>> makeNWiseTuples(String[] variables, int nWise) {
List<Set<String>> completeTuples = new ArrayList<>();
makeNWiseTuplesHelper(completeTuples, variables, 0, new HashSet<String>(), nWise);
return completeTuples;
} | java | public List<Set<String>> makeNWiseTuples(String[] variables, int nWise) {
List<Set<String>> completeTuples = new ArrayList<>();
makeNWiseTuplesHelper(completeTuples, variables, 0, new HashSet<String>(), nWise);
return completeTuples;
} | [
"public",
"List",
"<",
"Set",
"<",
"String",
">",
">",
"makeNWiseTuples",
"(",
"String",
"[",
"]",
"variables",
",",
"int",
"nWise",
")",
"{",
"List",
"<",
"Set",
"<",
"String",
">>",
"completeTuples",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"makeNWiseTuplesHelper",
"(",
"completeTuples",
",",
"variables",
",",
"0",
",",
"new",
"HashSet",
"<",
"String",
">",
"(",
")",
",",
"nWise",
")",
";",
"return",
"completeTuples",
";",
"}"
] | Produces all tuples of size n chosen from a list of variable names
@param variables the list of variable names to make tuples of
@param nWise the size of the desired tuples
@return all tuples of size nWise | [
"Produces",
"all",
"tuples",
"of",
"size",
"n",
"chosen",
"from",
"a",
"list",
"of",
"variable",
"names"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java#L73-L78 |
163,813 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java | NWiseExtension.produceNWise | public List<Map<String, String>> produceNWise(int nWise, String[] coVariables, Map<String, String[]> variableDomains) {
List<Set<String>> tuples = makeNWiseTuples(coVariables, nWise);
List<Map<String, String>> testCases = new ArrayList<>();
for (Set<String> tuple : tuples) {
testCases.addAll(expandTupleIntoTestCases(tuple, variableDomains));
}
return testCases;
} | java | public List<Map<String, String>> produceNWise(int nWise, String[] coVariables, Map<String, String[]> variableDomains) {
List<Set<String>> tuples = makeNWiseTuples(coVariables, nWise);
List<Map<String, String>> testCases = new ArrayList<>();
for (Set<String> tuple : tuples) {
testCases.addAll(expandTupleIntoTestCases(tuple, variableDomains));
}
return testCases;
} | [
"public",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"produceNWise",
"(",
"int",
"nWise",
",",
"String",
"[",
"]",
"coVariables",
",",
"Map",
"<",
"String",
",",
"String",
"[",
"]",
">",
"variableDomains",
")",
"{",
"List",
"<",
"Set",
"<",
"String",
">>",
"tuples",
"=",
"makeNWiseTuples",
"(",
"coVariables",
",",
"nWise",
")",
";",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"testCases",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Set",
"<",
"String",
">",
"tuple",
":",
"tuples",
")",
"{",
"testCases",
".",
"addAll",
"(",
"expandTupleIntoTestCases",
"(",
"tuple",
",",
"variableDomains",
")",
")",
";",
"}",
"return",
"testCases",
";",
"}"
] | Finds all nWise combinations of a set of variables, each with a given domain of values
@param nWise the number of variables in each combination
@param coVariables the varisbles
@param variableDomains the domains
@return all nWise combinations of the set of variables | [
"Finds",
"all",
"nWise",
"combinations",
"of",
"a",
"set",
"of",
"variables",
"each",
"with",
"a",
"given",
"domain",
"of",
"values"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java#L119-L128 |
163,814 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java | NWiseExtension.pipelinePossibleStates | public List<Map<String, String>> pipelinePossibleStates(NWiseAction action, List<Map<String, String>> possibleStateList) {
String[] coVariables = action.getCoVariables().split(",");
int n = Integer.valueOf(action.getN());
List<Map<String, String>> newPossibleStateList = new ArrayList<>();
for (Map<String, String> possibleState : possibleStateList) {
Map<String, String[]> variableDomains = new HashMap<>();
Map<String, String> defaultVariableValues = new HashMap<>();
for (String variable : coVariables) {
String variableMetaInfo = possibleState.get(variable);
String[] variableDomain = variableMetaInfo.split(",");
variableDomains.put(variable, variableDomain);
defaultVariableValues.put(variable, variableDomain[0]);
}
List<Map<String, String>> nWiseCombinations = produceNWise(n, coVariables, variableDomains);
for (Map<String, String> nWiseCombination : nWiseCombinations) {
Map<String, String> newPossibleState = new HashMap<>(possibleState);
newPossibleState.putAll(defaultVariableValues);
newPossibleState.putAll(nWiseCombination);
newPossibleStateList.add(newPossibleState);
}
}
return newPossibleStateList;
} | java | public List<Map<String, String>> pipelinePossibleStates(NWiseAction action, List<Map<String, String>> possibleStateList) {
String[] coVariables = action.getCoVariables().split(",");
int n = Integer.valueOf(action.getN());
List<Map<String, String>> newPossibleStateList = new ArrayList<>();
for (Map<String, String> possibleState : possibleStateList) {
Map<String, String[]> variableDomains = new HashMap<>();
Map<String, String> defaultVariableValues = new HashMap<>();
for (String variable : coVariables) {
String variableMetaInfo = possibleState.get(variable);
String[] variableDomain = variableMetaInfo.split(",");
variableDomains.put(variable, variableDomain);
defaultVariableValues.put(variable, variableDomain[0]);
}
List<Map<String, String>> nWiseCombinations = produceNWise(n, coVariables, variableDomains);
for (Map<String, String> nWiseCombination : nWiseCombinations) {
Map<String, String> newPossibleState = new HashMap<>(possibleState);
newPossibleState.putAll(defaultVariableValues);
newPossibleState.putAll(nWiseCombination);
newPossibleStateList.add(newPossibleState);
}
}
return newPossibleStateList;
} | [
"public",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"pipelinePossibleStates",
"(",
"NWiseAction",
"action",
",",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"possibleStateList",
")",
"{",
"String",
"[",
"]",
"coVariables",
"=",
"action",
".",
"getCoVariables",
"(",
")",
".",
"split",
"(",
"\",\"",
")",
";",
"int",
"n",
"=",
"Integer",
".",
"valueOf",
"(",
"action",
".",
"getN",
"(",
")",
")",
";",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"newPossibleStateList",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"possibleState",
":",
"possibleStateList",
")",
"{",
"Map",
"<",
"String",
",",
"String",
"[",
"]",
">",
"variableDomains",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"Map",
"<",
"String",
",",
"String",
">",
"defaultVariableValues",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"variable",
":",
"coVariables",
")",
"{",
"String",
"variableMetaInfo",
"=",
"possibleState",
".",
"get",
"(",
"variable",
")",
";",
"String",
"[",
"]",
"variableDomain",
"=",
"variableMetaInfo",
".",
"split",
"(",
"\",\"",
")",
";",
"variableDomains",
".",
"put",
"(",
"variable",
",",
"variableDomain",
")",
";",
"defaultVariableValues",
".",
"put",
"(",
"variable",
",",
"variableDomain",
"[",
"0",
"]",
")",
";",
"}",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"nWiseCombinations",
"=",
"produceNWise",
"(",
"n",
",",
"coVariables",
",",
"variableDomains",
")",
";",
"for",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"nWiseCombination",
":",
"nWiseCombinations",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"newPossibleState",
"=",
"new",
"HashMap",
"<>",
"(",
"possibleState",
")",
";",
"newPossibleState",
".",
"putAll",
"(",
"defaultVariableValues",
")",
";",
"newPossibleState",
".",
"putAll",
"(",
"nWiseCombination",
")",
";",
"newPossibleStateList",
".",
"add",
"(",
"newPossibleState",
")",
";",
"}",
"}",
"return",
"newPossibleStateList",
";",
"}"
] | Uses current variable assignments and info in an NWiseActionTag to expand on an n wise combinatorial set
@param action an NWiseAction Action
@param possibleStateList a current list of possible states produced so far from expanding a model state
@return every input possible state expanded on an n wise combinatorial set defined by that input possible state | [
"Uses",
"current",
"variable",
"assignments",
"and",
"info",
"in",
"an",
"NWiseActionTag",
"to",
"expand",
"on",
"an",
"n",
"wise",
"combinatorial",
"set"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/NWiseExtension.java#L137-L163 |
163,815 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/transformer/SampleMachineTransformer.java | SampleMachineTransformer.transform | public void transform(DataPipe cr) {
Map<String, String> map = cr.getDataMap();
for (String key : map.keySet()) {
String value = map.get(key);
if (value.equals("#{customplaceholder}")) {
// Generate a random number
int ran = rand.nextInt();
map.put(key, String.valueOf(ran));
} else if (value.equals("#{divideBy2}")) {
String i = map.get("var_out_V3");
String result = String.valueOf(Integer.valueOf(i) / 2);
map.put(key, result);
}
}
} | java | public void transform(DataPipe cr) {
Map<String, String> map = cr.getDataMap();
for (String key : map.keySet()) {
String value = map.get(key);
if (value.equals("#{customplaceholder}")) {
// Generate a random number
int ran = rand.nextInt();
map.put(key, String.valueOf(ran));
} else if (value.equals("#{divideBy2}")) {
String i = map.get("var_out_V3");
String result = String.valueOf(Integer.valueOf(i) / 2);
map.put(key, result);
}
}
} | [
"public",
"void",
"transform",
"(",
"DataPipe",
"cr",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"map",
"=",
"cr",
".",
"getDataMap",
"(",
")",
";",
"for",
"(",
"String",
"key",
":",
"map",
".",
"keySet",
"(",
")",
")",
"{",
"String",
"value",
"=",
"map",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"value",
".",
"equals",
"(",
"\"#{customplaceholder}\"",
")",
")",
"{",
"// Generate a random number",
"int",
"ran",
"=",
"rand",
".",
"nextInt",
"(",
")",
";",
"map",
".",
"put",
"(",
"key",
",",
"String",
".",
"valueOf",
"(",
"ran",
")",
")",
";",
"}",
"else",
"if",
"(",
"value",
".",
"equals",
"(",
"\"#{divideBy2}\"",
")",
")",
"{",
"String",
"i",
"=",
"map",
".",
"get",
"(",
"\"var_out_V3\"",
")",
";",
"String",
"result",
"=",
"String",
".",
"valueOf",
"(",
"Integer",
".",
"valueOf",
"(",
"i",
")",
"/",
"2",
")",
";",
"map",
".",
"put",
"(",
"key",
",",
"result",
")",
";",
"}",
"}",
"}"
] | Replace known tags in the current data values with actual values as appropriate
@param cr a reference to DataPipe from which to read the current map | [
"Replace",
"known",
"tags",
"in",
"the",
"current",
"data",
"values",
"with",
"actual",
"values",
"as",
"appropriate"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/transformer/SampleMachineTransformer.java#L38-L54 |
163,816 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/distributor/multithreaded/QueueResultsProcessing.java | QueueResultsProcessing.processOutput | @Override
public void processOutput(Map<String, String> resultsMap) {
queue.add(resultsMap);
if (queue.size() > 10000) {
log.info("Queue size " + queue.size() + ", waiting");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
log.info("Interrupted ", ex);
}
}
} | java | @Override
public void processOutput(Map<String, String> resultsMap) {
queue.add(resultsMap);
if (queue.size() > 10000) {
log.info("Queue size " + queue.size() + ", waiting");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
log.info("Interrupted ", ex);
}
}
} | [
"@",
"Override",
"public",
"void",
"processOutput",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"resultsMap",
")",
"{",
"queue",
".",
"add",
"(",
"resultsMap",
")",
";",
"if",
"(",
"queue",
".",
"size",
"(",
")",
">",
"10000",
")",
"{",
"log",
".",
"info",
"(",
"\"Queue size \"",
"+",
"queue",
".",
"size",
"(",
")",
"+",
"\", waiting\"",
")",
";",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"500",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"ex",
")",
"{",
"log",
".",
"info",
"(",
"\"Interrupted \"",
",",
"ex",
")",
";",
"}",
"}",
"}"
] | Stores the output from a Frontier into the queue, pausing and waiting if the given queue is too large
@param resultsMap map of String and String representing the output of a Frontier's DFS | [
"Stores",
"the",
"output",
"from",
"a",
"Frontier",
"into",
"the",
"queue",
"pausing",
"and",
"waiting",
"if",
"the",
"given",
"queue",
"is",
"too",
"large"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/distributor/multithreaded/QueueResultsProcessing.java#L49-L61 |
163,817 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/consumer/ContextWriter.java | ContextWriter.writeOutput | public void writeOutput(DataPipe cr) {
try {
context.write(NullWritable.get(), new Text(cr.getPipeDelimited(outTemplate)));
} catch (Exception e) {
throw new RuntimeException("Exception occurred while writing to Context", e);
}
} | java | public void writeOutput(DataPipe cr) {
try {
context.write(NullWritable.get(), new Text(cr.getPipeDelimited(outTemplate)));
} catch (Exception e) {
throw new RuntimeException("Exception occurred while writing to Context", e);
}
} | [
"public",
"void",
"writeOutput",
"(",
"DataPipe",
"cr",
")",
"{",
"try",
"{",
"context",
".",
"write",
"(",
"NullWritable",
".",
"get",
"(",
")",
",",
"new",
"Text",
"(",
"cr",
".",
"getPipeDelimited",
"(",
"outTemplate",
")",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Exception occurred while writing to Context\"",
",",
"e",
")",
";",
"}",
"}"
] | Write to a context. Uses NullWritable for key so that only value of output string is ultimately written
@param cr the DataPipe to write to | [
"Write",
"to",
"a",
"context",
".",
"Uses",
"NullWritable",
"for",
"key",
"so",
"that",
"only",
"value",
"of",
"output",
"string",
"is",
"ultimately",
"written"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/consumer/ContextWriter.java#L49-L55 |
163,818 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLGapper.java | SCXMLGapper.decompose | public Map<String, String> decompose(Frontier frontier, String modelText) {
if (!(frontier instanceof SCXMLFrontier)) {
return null;
}
TransitionTarget target = ((SCXMLFrontier) frontier).getRoot().nextState;
Map<String, String> variables = ((SCXMLFrontier) frontier).getRoot().variables;
Map<String, String> decomposition = new HashMap<String, String>();
decomposition.put("target", target.getId());
StringBuilder packedVariables = new StringBuilder();
for (Map.Entry<String, String> variable : variables.entrySet()) {
packedVariables.append(variable.getKey());
packedVariables.append("::");
packedVariables.append(variable.getValue());
packedVariables.append(";");
}
decomposition.put("variables", packedVariables.toString());
decomposition.put("model", modelText);
return decomposition;
} | java | public Map<String, String> decompose(Frontier frontier, String modelText) {
if (!(frontier instanceof SCXMLFrontier)) {
return null;
}
TransitionTarget target = ((SCXMLFrontier) frontier).getRoot().nextState;
Map<String, String> variables = ((SCXMLFrontier) frontier).getRoot().variables;
Map<String, String> decomposition = new HashMap<String, String>();
decomposition.put("target", target.getId());
StringBuilder packedVariables = new StringBuilder();
for (Map.Entry<String, String> variable : variables.entrySet()) {
packedVariables.append(variable.getKey());
packedVariables.append("::");
packedVariables.append(variable.getValue());
packedVariables.append(";");
}
decomposition.put("variables", packedVariables.toString());
decomposition.put("model", modelText);
return decomposition;
} | [
"public",
"Map",
"<",
"String",
",",
"String",
">",
"decompose",
"(",
"Frontier",
"frontier",
",",
"String",
"modelText",
")",
"{",
"if",
"(",
"!",
"(",
"frontier",
"instanceof",
"SCXMLFrontier",
")",
")",
"{",
"return",
"null",
";",
"}",
"TransitionTarget",
"target",
"=",
"(",
"(",
"SCXMLFrontier",
")",
"frontier",
")",
".",
"getRoot",
"(",
")",
".",
"nextState",
";",
"Map",
"<",
"String",
",",
"String",
">",
"variables",
"=",
"(",
"(",
"SCXMLFrontier",
")",
"frontier",
")",
".",
"getRoot",
"(",
")",
".",
"variables",
";",
"Map",
"<",
"String",
",",
"String",
">",
"decomposition",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"decomposition",
".",
"put",
"(",
"\"target\"",
",",
"target",
".",
"getId",
"(",
")",
")",
";",
"StringBuilder",
"packedVariables",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"variable",
":",
"variables",
".",
"entrySet",
"(",
")",
")",
"{",
"packedVariables",
".",
"append",
"(",
"variable",
".",
"getKey",
"(",
")",
")",
";",
"packedVariables",
".",
"append",
"(",
"\"::\"",
")",
";",
"packedVariables",
".",
"append",
"(",
"variable",
".",
"getValue",
"(",
")",
")",
";",
"packedVariables",
".",
"append",
"(",
"\";\"",
")",
";",
"}",
"decomposition",
".",
"put",
"(",
"\"variables\"",
",",
"packedVariables",
".",
"toString",
"(",
")",
")",
";",
"decomposition",
".",
"put",
"(",
"\"model\"",
",",
"modelText",
")",
";",
"return",
"decomposition",
";",
"}"
] | Takes a model and an SCXMLFrontier and decomposes the Frontier into a Map of Strings to Strings
These strings can be sent over a network to get a Frontier past a 'gap'
@param frontier the Frontier
@param modelText the model
@return the map of strings representing a decomposition | [
"Takes",
"a",
"model",
"and",
"an",
"SCXMLFrontier",
"and",
"decomposes",
"the",
"Frontier",
"into",
"a",
"Map",
"of",
"Strings",
"to",
"Strings",
"These",
"strings",
"can",
"be",
"sent",
"over",
"a",
"network",
"to",
"get",
"a",
"Frontier",
"past",
"a",
"gap"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/SCXMLGapper.java#L75-L98 |
163,819 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/CmdLine.java | CmdLine.printHelp | public static void printHelp(final Options options) {
Collection<Option> c = options.getOptions();
System.out.println("Command line options are:");
int longestLongOption = 0;
for (Option op : c) {
if (op.getLongOpt().length() > longestLongOption) {
longestLongOption = op.getLongOpt().length();
}
}
longestLongOption += 2;
String spaces = StringUtils.repeat(" ", longestLongOption);
for (Option op : c) {
System.out.print("\t-" + op.getOpt() + " --" + op.getLongOpt());
if (op.getLongOpt().length() < spaces.length()) {
System.out.print(spaces.substring(op.getLongOpt().length()));
} else {
System.out.print(" ");
}
System.out.println(op.getDescription());
}
} | java | public static void printHelp(final Options options) {
Collection<Option> c = options.getOptions();
System.out.println("Command line options are:");
int longestLongOption = 0;
for (Option op : c) {
if (op.getLongOpt().length() > longestLongOption) {
longestLongOption = op.getLongOpt().length();
}
}
longestLongOption += 2;
String spaces = StringUtils.repeat(" ", longestLongOption);
for (Option op : c) {
System.out.print("\t-" + op.getOpt() + " --" + op.getLongOpt());
if (op.getLongOpt().length() < spaces.length()) {
System.out.print(spaces.substring(op.getLongOpt().length()));
} else {
System.out.print(" ");
}
System.out.println(op.getDescription());
}
} | [
"public",
"static",
"void",
"printHelp",
"(",
"final",
"Options",
"options",
")",
"{",
"Collection",
"<",
"Option",
">",
"c",
"=",
"options",
".",
"getOptions",
"(",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"Command line options are:\"",
")",
";",
"int",
"longestLongOption",
"=",
"0",
";",
"for",
"(",
"Option",
"op",
":",
"c",
")",
"{",
"if",
"(",
"op",
".",
"getLongOpt",
"(",
")",
".",
"length",
"(",
")",
">",
"longestLongOption",
")",
"{",
"longestLongOption",
"=",
"op",
".",
"getLongOpt",
"(",
")",
".",
"length",
"(",
")",
";",
"}",
"}",
"longestLongOption",
"+=",
"2",
";",
"String",
"spaces",
"=",
"StringUtils",
".",
"repeat",
"(",
"\" \"",
",",
"longestLongOption",
")",
";",
"for",
"(",
"Option",
"op",
":",
"c",
")",
"{",
"System",
".",
"out",
".",
"print",
"(",
"\"\\t-\"",
"+",
"op",
".",
"getOpt",
"(",
")",
"+",
"\" --\"",
"+",
"op",
".",
"getLongOpt",
"(",
")",
")",
";",
"if",
"(",
"op",
".",
"getLongOpt",
"(",
")",
".",
"length",
"(",
")",
"<",
"spaces",
".",
"length",
"(",
")",
")",
"{",
"System",
".",
"out",
".",
"print",
"(",
"spaces",
".",
"substring",
"(",
"op",
".",
"getLongOpt",
"(",
")",
".",
"length",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"System",
".",
"out",
".",
"print",
"(",
"\" \"",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"op",
".",
"getDescription",
"(",
")",
")",
";",
"}",
"}"
] | Prints the help on the command line
@param options Options object from commons-cli | [
"Prints",
"the",
"help",
"on",
"the",
"command",
"line"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/CmdLine.java#L62-L84 |
163,820 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/CmdLine.java | CmdLine.main | public static void main(String[] args) {
CmdLine cmd = new CmdLine();
Configuration conf = new Configuration();
int res = 0;
try {
res = ToolRunner.run(conf, cmd, args);
} catch (Exception e) {
System.err.println("Error while running MR job");
e.printStackTrace();
}
System.exit(res);
} | java | public static void main(String[] args) {
CmdLine cmd = new CmdLine();
Configuration conf = new Configuration();
int res = 0;
try {
res = ToolRunner.run(conf, cmd, args);
} catch (Exception e) {
System.err.println("Error while running MR job");
e.printStackTrace();
}
System.exit(res);
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"CmdLine",
"cmd",
"=",
"new",
"CmdLine",
"(",
")",
";",
"Configuration",
"conf",
"=",
"new",
"Configuration",
"(",
")",
";",
"int",
"res",
"=",
"0",
";",
"try",
"{",
"res",
"=",
"ToolRunner",
".",
"run",
"(",
"conf",
",",
"cmd",
",",
"args",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"Error while running MR job\"",
")",
";",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"System",
".",
"exit",
"(",
"res",
")",
";",
"}"
] | Entry point for this example
Uses HDFS ToolRunner to wrap processing of
@param args Command-line arguments for HDFS example | [
"Entry",
"point",
"for",
"this",
"example",
"Uses",
"HDFS",
"ToolRunner",
"to",
"wrap",
"processing",
"of"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/CmdLine.java#L184-L195 |
163,821 | FINRAOS/DataGenerator | dg-common/src/main/java/org/finra/datagenerator/common/Helpers/ScalaInJavaHelper.java | ScalaInJavaHelper.linkedListToScalaIterable | public static scala.collection.Iterable linkedListToScalaIterable(LinkedList<?> linkedList) {
return JavaConverters.asScalaIterableConverter(linkedList).asScala();
} | java | public static scala.collection.Iterable linkedListToScalaIterable(LinkedList<?> linkedList) {
return JavaConverters.asScalaIterableConverter(linkedList).asScala();
} | [
"public",
"static",
"scala",
".",
"collection",
".",
"Iterable",
"linkedListToScalaIterable",
"(",
"LinkedList",
"<",
"?",
">",
"linkedList",
")",
"{",
"return",
"JavaConverters",
".",
"asScalaIterableConverter",
"(",
"linkedList",
")",
".",
"asScala",
"(",
")",
";",
"}"
] | Convert a Java LinkedList to a Scala Iterable.
@param linkedList Java LinkedList to convert
@return Scala Iterable | [
"Convert",
"a",
"Java",
"LinkedList",
"to",
"a",
"Scala",
"Iterable",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-common/src/main/java/org/finra/datagenerator/common/Helpers/ScalaInJavaHelper.java#L36-L38 |
163,822 | FINRAOS/DataGenerator | dg-common/src/main/java/org/finra/datagenerator/common/Helpers/ScalaInJavaHelper.java | ScalaInJavaHelper.flattenOption | public static <T> T flattenOption(scala.Option<T> option) {
if (option.isEmpty()) {
return null;
} else {
return option.get();
}
} | java | public static <T> T flattenOption(scala.Option<T> option) {
if (option.isEmpty()) {
return null;
} else {
return option.get();
}
} | [
"public",
"static",
"<",
"T",
">",
"T",
"flattenOption",
"(",
"scala",
".",
"Option",
"<",
"T",
">",
"option",
")",
"{",
"if",
"(",
"option",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"option",
".",
"get",
"(",
")",
";",
"}",
"}"
] | Flattens an option into its value or else null, which is not great but is usually more convenient in Java.
@param option Optional value -- either Some(T) or None
@param <T> Any type
@return The value inside the option, or else null | [
"Flattens",
"an",
"option",
"into",
"its",
"value",
"or",
"else",
"null",
"which",
"is",
"not",
"great",
"but",
"is",
"usually",
"more",
"convenient",
"in",
"Java",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-common/src/main/java/org/finra/datagenerator/common/Helpers/ScalaInJavaHelper.java#L46-L52 |
163,823 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/SingleValueAssignExtension.java | SingleValueAssignExtension.pipelinePossibleStates | public List<Map<String, String>> pipelinePossibleStates(Assign action, List<Map<String, String>> possibleStateList) {
for (Map<String, String> possibleState : possibleStateList) {
possibleState.put(action.getName(), action.getExpr());
}
return possibleStateList;
} | java | public List<Map<String, String>> pipelinePossibleStates(Assign action, List<Map<String, String>> possibleStateList) {
for (Map<String, String> possibleState : possibleStateList) {
possibleState.put(action.getName(), action.getExpr());
}
return possibleStateList;
} | [
"public",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"pipelinePossibleStates",
"(",
"Assign",
"action",
",",
"List",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"possibleStateList",
")",
"{",
"for",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"possibleState",
":",
"possibleStateList",
")",
"{",
"possibleState",
".",
"put",
"(",
"action",
".",
"getName",
"(",
")",
",",
"action",
".",
"getExpr",
"(",
")",
")",
";",
"}",
"return",
"possibleStateList",
";",
"}"
] | Assigns one variable to one value
@param action an Assign Action
@param possibleStateList a current list of possible states produced so far from expanding a model state
@return the same list, with every possible state augmented with an assigned variable, defined by action | [
"Assigns",
"one",
"variable",
"to",
"one",
"value"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/engine/scxml/tags/SingleValueAssignExtension.java#L49-L55 |
163,824 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/writer/JsonWriter.java | JsonWriter.getJsonFormatted | public JSONObject getJsonFormatted(Map<String, String> dataMap) {
JSONObject oneRowJson = new JSONObject();
for (int i = 0; i < outTemplate.length; i++) {
oneRowJson.put(outTemplate[i], dataMap.get(outTemplate[i]));
}
return oneRowJson;
} | java | public JSONObject getJsonFormatted(Map<String, String> dataMap) {
JSONObject oneRowJson = new JSONObject();
for (int i = 0; i < outTemplate.length; i++) {
oneRowJson.put(outTemplate[i], dataMap.get(outTemplate[i]));
}
return oneRowJson;
} | [
"public",
"JSONObject",
"getJsonFormatted",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"dataMap",
")",
"{",
"JSONObject",
"oneRowJson",
"=",
"new",
"JSONObject",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"outTemplate",
".",
"length",
";",
"i",
"++",
")",
"{",
"oneRowJson",
".",
"put",
"(",
"outTemplate",
"[",
"i",
"]",
",",
"dataMap",
".",
"get",
"(",
"outTemplate",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"oneRowJson",
";",
"}"
] | Given an array of variable names, returns a JsonObject
of values.
@param dataMap an map containing variable names and their corresponding values
names.
@return a json object of values | [
"Given",
"an",
"array",
"of",
"variable",
"names",
"returns",
"a",
"JsonObject",
"of",
"values",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/writer/JsonWriter.java#L80-L89 |
163,825 | FINRAOS/DataGenerator | dg-common/src/main/java/org/finra/datagenerator/common/SocialNetwork_Example_Java/SocialNetworkStructureBuilder.java | SocialNetworkStructureBuilder.generateAllNodeDataTypeGraphCombinationsOfMaxLength | public Vector<Graph<UserStub>> generateAllNodeDataTypeGraphCombinationsOfMaxLength(int length) {
Vector<Graph<UserStub>> graphs = super.generateAllNodeDataTypeGraphCombinationsOfMaxLength(length);
if (WRITE_STRUCTURES_IN_PARALLEL) {
// Left as an exercise to the student.
throw new NotImplementedError();
} else {
int i = 0;
for (Iterator<Graph<UserStub>> iter = graphs.toIterator(); iter.hasNext();) {
Graph<UserStub> graph = iter.next();
graph.setGraphId("S_" + ++i + "_" + graph.allNodes().size());
graph.writeDotFile(outDir + graph.graphId() + ".gv", false, ALSO_WRITE_AS_PNG);
}
System.out.println("Wrote " + i + " graph files in DOT format to " + outDir + "");
}
return graphs;
} | java | public Vector<Graph<UserStub>> generateAllNodeDataTypeGraphCombinationsOfMaxLength(int length) {
Vector<Graph<UserStub>> graphs = super.generateAllNodeDataTypeGraphCombinationsOfMaxLength(length);
if (WRITE_STRUCTURES_IN_PARALLEL) {
// Left as an exercise to the student.
throw new NotImplementedError();
} else {
int i = 0;
for (Iterator<Graph<UserStub>> iter = graphs.toIterator(); iter.hasNext();) {
Graph<UserStub> graph = iter.next();
graph.setGraphId("S_" + ++i + "_" + graph.allNodes().size());
graph.writeDotFile(outDir + graph.graphId() + ".gv", false, ALSO_WRITE_AS_PNG);
}
System.out.println("Wrote " + i + " graph files in DOT format to " + outDir + "");
}
return graphs;
} | [
"public",
"Vector",
"<",
"Graph",
"<",
"UserStub",
">",
">",
"generateAllNodeDataTypeGraphCombinationsOfMaxLength",
"(",
"int",
"length",
")",
"{",
"Vector",
"<",
"Graph",
"<",
"UserStub",
">>",
"graphs",
"=",
"super",
".",
"generateAllNodeDataTypeGraphCombinationsOfMaxLength",
"(",
"length",
")",
";",
"if",
"(",
"WRITE_STRUCTURES_IN_PARALLEL",
")",
"{",
"// Left as an exercise to the student.\r",
"throw",
"new",
"NotImplementedError",
"(",
")",
";",
"}",
"else",
"{",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"Iterator",
"<",
"Graph",
"<",
"UserStub",
">",
">",
"iter",
"=",
"graphs",
".",
"toIterator",
"(",
")",
";",
"iter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"Graph",
"<",
"UserStub",
">",
"graph",
"=",
"iter",
".",
"next",
"(",
")",
";",
"graph",
".",
"setGraphId",
"(",
"\"S_\"",
"+",
"++",
"i",
"+",
"\"_\"",
"+",
"graph",
".",
"allNodes",
"(",
")",
".",
"size",
"(",
")",
")",
";",
"graph",
".",
"writeDotFile",
"(",
"outDir",
"+",
"graph",
".",
"graphId",
"(",
")",
"+",
"\".gv\"",
",",
"false",
",",
"ALSO_WRITE_AS_PNG",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"\"Wrote \"",
"+",
"i",
"+",
"\" graph files in DOT format to \"",
"+",
"outDir",
"+",
"\"\"",
")",
";",
"}",
"return",
"graphs",
";",
"}"
] | Build all combinations of graph structures for generic event stubs of a maximum length
@param length Maximum number of nodes in each to generate
@return All graph combinations of specified length or less | [
"Build",
"all",
"combinations",
"of",
"graph",
"structures",
"for",
"generic",
"event",
"stubs",
"of",
"a",
"maximum",
"length"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-common/src/main/java/org/finra/datagenerator/common/SocialNetwork_Example_Java/SocialNetworkStructureBuilder.java#L66-L83 |
163,826 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/consumer/DataConsumer.java | DataConsumer.consume | public int consume(Map<String, String> initialVars) {
this.dataPipe = new DataPipe(this);
// Set initial variables
for (Map.Entry<String, String> ent : initialVars.entrySet()) {
dataPipe.getDataMap().put(ent.getKey(), ent.getValue());
}
// Call transformers
for (DataTransformer dc : dataTransformers) {
dc.transform(dataPipe);
}
// Call writers
for (DataWriter oneOw : dataWriters) {
try {
oneOw.writeOutput(dataPipe);
} catch (Exception e) { //NOPMD
log.error("Exception in DataWriter", e);
}
}
return 1;
} | java | public int consume(Map<String, String> initialVars) {
this.dataPipe = new DataPipe(this);
// Set initial variables
for (Map.Entry<String, String> ent : initialVars.entrySet()) {
dataPipe.getDataMap().put(ent.getKey(), ent.getValue());
}
// Call transformers
for (DataTransformer dc : dataTransformers) {
dc.transform(dataPipe);
}
// Call writers
for (DataWriter oneOw : dataWriters) {
try {
oneOw.writeOutput(dataPipe);
} catch (Exception e) { //NOPMD
log.error("Exception in DataWriter", e);
}
}
return 1;
} | [
"public",
"int",
"consume",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"initialVars",
")",
"{",
"this",
".",
"dataPipe",
"=",
"new",
"DataPipe",
"(",
"this",
")",
";",
"// Set initial variables\r",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"ent",
":",
"initialVars",
".",
"entrySet",
"(",
")",
")",
"{",
"dataPipe",
".",
"getDataMap",
"(",
")",
".",
"put",
"(",
"ent",
".",
"getKey",
"(",
")",
",",
"ent",
".",
"getValue",
"(",
")",
")",
";",
"}",
"// Call transformers\r",
"for",
"(",
"DataTransformer",
"dc",
":",
"dataTransformers",
")",
"{",
"dc",
".",
"transform",
"(",
"dataPipe",
")",
";",
"}",
"// Call writers\r",
"for",
"(",
"DataWriter",
"oneOw",
":",
"dataWriters",
")",
"{",
"try",
"{",
"oneOw",
".",
"writeOutput",
"(",
"dataPipe",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"//NOPMD\r",
"log",
".",
"error",
"(",
"\"Exception in DataWriter\"",
",",
"e",
")",
";",
"}",
"}",
"return",
"1",
";",
"}"
] | Consumes a produced result. Calls every transformer in sequence, then
calls every dataWriter in sequence.
@param initialVars a map containing the initial variables assignments
@return the number of lines written | [
"Consumes",
"a",
"produced",
"result",
".",
"Calls",
"every",
"transformer",
"in",
"sequence",
"then",
"calls",
"every",
"dataWriter",
"in",
"sequence",
"."
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/consumer/DataConsumer.java#L138-L161 |
163,827 | FINRAOS/DataGenerator | dg-core/src/main/java/org/finra/datagenerator/consumer/DataConsumer.java | DataConsumer.sendRequest | public Future<String> sendRequest(final String path, final ReportingHandler reportingHandler) {
return threadPool.submit(new Callable<String>() {
@Override
public String call() {
String response = getResponse(path);
if (reportingHandler != null) {
reportingHandler.handleResponse(response);
}
return response;
}
});
} | java | public Future<String> sendRequest(final String path, final ReportingHandler reportingHandler) {
return threadPool.submit(new Callable<String>() {
@Override
public String call() {
String response = getResponse(path);
if (reportingHandler != null) {
reportingHandler.handleResponse(response);
}
return response;
}
});
} | [
"public",
"Future",
"<",
"String",
">",
"sendRequest",
"(",
"final",
"String",
"path",
",",
"final",
"ReportingHandler",
"reportingHandler",
")",
"{",
"return",
"threadPool",
".",
"submit",
"(",
"new",
"Callable",
"<",
"String",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"String",
"call",
"(",
")",
"{",
"String",
"response",
"=",
"getResponse",
"(",
"path",
")",
";",
"if",
"(",
"reportingHandler",
"!=",
"null",
")",
"{",
"reportingHandler",
".",
"handleResponse",
"(",
"response",
")",
";",
"}",
"return",
"response",
";",
"}",
"}",
")",
";",
"}"
] | Creates a future that will send a request to the reporting host and call
the handler with the response
@param path the path at the reporting host which the request will be made
@param reportingHandler the handler to receive the response once executed
and recieved
@return a {@link java.util.concurrent.Future} for handing the request | [
"Creates",
"a",
"future",
"that",
"will",
"send",
"a",
"request",
"to",
"the",
"reporting",
"host",
"and",
"call",
"the",
"handler",
"with",
"the",
"response"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-core/src/main/java/org/finra/datagenerator/consumer/DataConsumer.java#L211-L224 |
163,828 | FINRAOS/DataGenerator | dg-example-default/src/main/java/org/finra/datagenerator/samples/transformer/SampleMachineTransformer.java | SampleMachineTransformer.transform | public void transform(DataPipe cr) {
for (Map.Entry<String, String> entry : cr.getDataMap().entrySet()) {
String value = entry.getValue();
if (value.equals("#{customplaceholder}")) {
// Generate a random number
int ran = rand.nextInt();
entry.setValue(String.valueOf(ran));
}
}
} | java | public void transform(DataPipe cr) {
for (Map.Entry<String, String> entry : cr.getDataMap().entrySet()) {
String value = entry.getValue();
if (value.equals("#{customplaceholder}")) {
// Generate a random number
int ran = rand.nextInt();
entry.setValue(String.valueOf(ran));
}
}
} | [
"public",
"void",
"transform",
"(",
"DataPipe",
"cr",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"cr",
".",
"getDataMap",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"value",
".",
"equals",
"(",
"\"#{customplaceholder}\"",
")",
")",
"{",
"// Generate a random number",
"int",
"ran",
"=",
"rand",
".",
"nextInt",
"(",
")",
";",
"entry",
".",
"setValue",
"(",
"String",
".",
"valueOf",
"(",
"ran",
")",
")",
";",
"}",
"}",
"}"
] | The transform method for this DataTransformer
@param cr a reference to DataPipe from which to read the current map | [
"The",
"transform",
"method",
"for",
"this",
"DataTransformer"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-default/src/main/java/org/finra/datagenerator/samples/transformer/SampleMachineTransformer.java#L38-L48 |
163,829 | FINRAOS/DataGenerator | dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/consumer/SampleMachineConsumer.java | SampleMachineConsumer.isExit | public boolean isExit() {
if (currentRow > finalRow) { //request new block of work
String newBlock = this.sendRequestSync("this/request/block");
LineCountManager.LineCountBlock block = new LineCountManager.LineCountBlock(0, 0);
if (newBlock.contains("exit")) {
getExitFlag().set(true);
makeReport(true);
return true;
} else {
block.buildFromResponse(newBlock);
}
currentRow = block.getStart();
finalRow = block.getStop();
} else { //report the number of lines written
makeReport(false);
if (exit.get()) {
getExitFlag().set(true);
return true;
}
}
return false;
} | java | public boolean isExit() {
if (currentRow > finalRow) { //request new block of work
String newBlock = this.sendRequestSync("this/request/block");
LineCountManager.LineCountBlock block = new LineCountManager.LineCountBlock(0, 0);
if (newBlock.contains("exit")) {
getExitFlag().set(true);
makeReport(true);
return true;
} else {
block.buildFromResponse(newBlock);
}
currentRow = block.getStart();
finalRow = block.getStop();
} else { //report the number of lines written
makeReport(false);
if (exit.get()) {
getExitFlag().set(true);
return true;
}
}
return false;
} | [
"public",
"boolean",
"isExit",
"(",
")",
"{",
"if",
"(",
"currentRow",
">",
"finalRow",
")",
"{",
"//request new block of work",
"String",
"newBlock",
"=",
"this",
".",
"sendRequestSync",
"(",
"\"this/request/block\"",
")",
";",
"LineCountManager",
".",
"LineCountBlock",
"block",
"=",
"new",
"LineCountManager",
".",
"LineCountBlock",
"(",
"0",
",",
"0",
")",
";",
"if",
"(",
"newBlock",
".",
"contains",
"(",
"\"exit\"",
")",
")",
"{",
"getExitFlag",
"(",
")",
".",
"set",
"(",
"true",
")",
";",
"makeReport",
"(",
"true",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"block",
".",
"buildFromResponse",
"(",
"newBlock",
")",
";",
"}",
"currentRow",
"=",
"block",
".",
"getStart",
"(",
")",
";",
"finalRow",
"=",
"block",
".",
"getStop",
"(",
")",
";",
"}",
"else",
"{",
"//report the number of lines written",
"makeReport",
"(",
"false",
")",
";",
"if",
"(",
"exit",
".",
"get",
"(",
")",
")",
"{",
"getExitFlag",
"(",
")",
".",
"set",
"(",
"true",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Exit reporting up to distributor, using information gained from status reports to the LineCountManager
@return a boolean of whether this consumer should immediately exit | [
"Exit",
"reporting",
"up",
"to",
"distributor",
"using",
"information",
"gained",
"from",
"status",
"reports",
"to",
"the",
"LineCountManager"
] | 1f69f949401cbed4db4f553c3eb8350832c4d45a | https://github.com/FINRAOS/DataGenerator/blob/1f69f949401cbed4db4f553c3eb8350832c4d45a/dg-example-hadoop/src/main/java/org/finra/datagenerator/samples/consumer/SampleMachineConsumer.java#L101-L126 |
163,830 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java | CountrySpinnerAdapter.getDropDownView | @Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.item_country, parent, false);
viewHolder = new ViewHolder();
viewHolder.mImageView = (ImageView) convertView.findViewById(R.id.intl_phone_edit__country__item_image);
viewHolder.mNameView = (TextView) convertView.findViewById(R.id.intl_phone_edit__country__item_name);
viewHolder.mDialCode = (TextView) convertView.findViewById(R.id.intl_phone_edit__country__item_dialcode);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Country country = getItem(position);
viewHolder.mImageView.setImageResource(getFlagResource(country));
viewHolder.mNameView.setText(country.getName());
viewHolder.mDialCode.setText(String.format("+%s", country.getDialCode()));
return convertView;
} | java | @Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.item_country, parent, false);
viewHolder = new ViewHolder();
viewHolder.mImageView = (ImageView) convertView.findViewById(R.id.intl_phone_edit__country__item_image);
viewHolder.mNameView = (TextView) convertView.findViewById(R.id.intl_phone_edit__country__item_name);
viewHolder.mDialCode = (TextView) convertView.findViewById(R.id.intl_phone_edit__country__item_dialcode);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Country country = getItem(position);
viewHolder.mImageView.setImageResource(getFlagResource(country));
viewHolder.mNameView.setText(country.getName());
viewHolder.mDialCode.setText(String.format("+%s", country.getDialCode()));
return convertView;
} | [
"@",
"Override",
"public",
"View",
"getDropDownView",
"(",
"int",
"position",
",",
"View",
"convertView",
",",
"ViewGroup",
"parent",
")",
"{",
"final",
"ViewHolder",
"viewHolder",
";",
"if",
"(",
"convertView",
"==",
"null",
")",
"{",
"convertView",
"=",
"mLayoutInflater",
".",
"inflate",
"(",
"R",
".",
"layout",
".",
"item_country",
",",
"parent",
",",
"false",
")",
";",
"viewHolder",
"=",
"new",
"ViewHolder",
"(",
")",
";",
"viewHolder",
".",
"mImageView",
"=",
"(",
"ImageView",
")",
"convertView",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"intl_phone_edit__country__item_image",
")",
";",
"viewHolder",
".",
"mNameView",
"=",
"(",
"TextView",
")",
"convertView",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"intl_phone_edit__country__item_name",
")",
";",
"viewHolder",
".",
"mDialCode",
"=",
"(",
"TextView",
")",
"convertView",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"intl_phone_edit__country__item_dialcode",
")",
";",
"convertView",
".",
"setTag",
"(",
"viewHolder",
")",
";",
"}",
"else",
"{",
"viewHolder",
"=",
"(",
"ViewHolder",
")",
"convertView",
".",
"getTag",
"(",
")",
";",
"}",
"Country",
"country",
"=",
"getItem",
"(",
"position",
")",
";",
"viewHolder",
".",
"mImageView",
".",
"setImageResource",
"(",
"getFlagResource",
"(",
"country",
")",
")",
";",
"viewHolder",
".",
"mNameView",
".",
"setText",
"(",
"country",
".",
"getName",
"(",
")",
")",
";",
"viewHolder",
".",
"mDialCode",
".",
"setText",
"(",
"String",
".",
"format",
"(",
"\"+%s\"",
",",
"country",
".",
"getDialCode",
"(",
")",
")",
")",
";",
"return",
"convertView",
";",
"}"
] | Drop down item view
@param position position of item
@param convertView View of item
@param parent parent view of item's view
@return covertView | [
"Drop",
"down",
"item",
"view"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java#L32-L51 |
163,831 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java | CountrySpinnerAdapter.getView | @Override
public View getView(int position, View convertView, ViewGroup parent) {
Country country = getItem(position);
if (convertView == null) {
convertView = new ImageView(getContext());
}
((ImageView) convertView).setImageResource(getFlagResource(country));
return convertView;
} | java | @Override
public View getView(int position, View convertView, ViewGroup parent) {
Country country = getItem(position);
if (convertView == null) {
convertView = new ImageView(getContext());
}
((ImageView) convertView).setImageResource(getFlagResource(country));
return convertView;
} | [
"@",
"Override",
"public",
"View",
"getView",
"(",
"int",
"position",
",",
"View",
"convertView",
",",
"ViewGroup",
"parent",
")",
"{",
"Country",
"country",
"=",
"getItem",
"(",
"position",
")",
";",
"if",
"(",
"convertView",
"==",
"null",
")",
"{",
"convertView",
"=",
"new",
"ImageView",
"(",
"getContext",
"(",
")",
")",
";",
"}",
"(",
"(",
"ImageView",
")",
"convertView",
")",
".",
"setImageResource",
"(",
"getFlagResource",
"(",
"country",
")",
")",
";",
"return",
"convertView",
";",
"}"
] | Drop down selected view
@param position position of selected item
@param convertView View of selected item
@param parent parent of selected view
@return convertView | [
"Drop",
"down",
"selected",
"view"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java#L61-L72 |
163,832 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java | CountrySpinnerAdapter.getFlagResource | private int getFlagResource(Country country) {
return getContext().getResources().getIdentifier("country_" + country.getIso().toLowerCase(), "drawable", getContext().getPackageName());
} | java | private int getFlagResource(Country country) {
return getContext().getResources().getIdentifier("country_" + country.getIso().toLowerCase(), "drawable", getContext().getPackageName());
} | [
"private",
"int",
"getFlagResource",
"(",
"Country",
"country",
")",
"{",
"return",
"getContext",
"(",
")",
".",
"getResources",
"(",
")",
".",
"getIdentifier",
"(",
"\"country_\"",
"+",
"country",
".",
"getIso",
"(",
")",
".",
"toLowerCase",
"(",
")",
",",
"\"drawable\"",
",",
"getContext",
"(",
")",
".",
"getPackageName",
"(",
")",
")",
";",
"}"
] | Fetch flag resource by Country
@param country Country
@return int of resource | 0 value if not exists | [
"Fetch",
"flag",
"resource",
"by",
"Country"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountrySpinnerAdapter.java#L80-L82 |
163,833 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountriesFetcher.java | CountriesFetcher.getJsonFromRaw | private static String getJsonFromRaw(Context context, int resource) {
String json;
try {
InputStream inputStream = context.getResources().openRawResource(resource);
int size = inputStream.available();
byte[] buffer = new byte[size];
inputStream.read(buffer);
inputStream.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
} | java | private static String getJsonFromRaw(Context context, int resource) {
String json;
try {
InputStream inputStream = context.getResources().openRawResource(resource);
int size = inputStream.available();
byte[] buffer = new byte[size];
inputStream.read(buffer);
inputStream.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
} | [
"private",
"static",
"String",
"getJsonFromRaw",
"(",
"Context",
"context",
",",
"int",
"resource",
")",
"{",
"String",
"json",
";",
"try",
"{",
"InputStream",
"inputStream",
"=",
"context",
".",
"getResources",
"(",
")",
".",
"openRawResource",
"(",
"resource",
")",
";",
"int",
"size",
"=",
"inputStream",
".",
"available",
"(",
")",
";",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"size",
"]",
";",
"inputStream",
".",
"read",
"(",
"buffer",
")",
";",
"inputStream",
".",
"close",
"(",
")",
";",
"json",
"=",
"new",
"String",
"(",
"buffer",
",",
"\"UTF-8\"",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"ex",
".",
"printStackTrace",
"(",
")",
";",
"return",
"null",
";",
"}",
"return",
"json",
";",
"}"
] | Fetch JSON from RAW resource
@param context Context
@param resource Resource int of the RAW file
@return JSON | [
"Fetch",
"JSON",
"from",
"RAW",
"resource"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountriesFetcher.java#L24-L38 |
163,834 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountriesFetcher.java | CountriesFetcher.getCountries | public static CountryList getCountries(Context context) {
if (mCountries != null) {
return mCountries;
}
mCountries = new CountryList();
try {
JSONArray countries = new JSONArray(getJsonFromRaw(context, R.raw.countries));
for (int i = 0; i < countries.length(); i++) {
try {
JSONObject country = (JSONObject) countries.get(i);
mCountries.add(new Country(country.getString("name"), country.getString("iso2"), country.getInt("dialCode")));
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return mCountries;
} | java | public static CountryList getCountries(Context context) {
if (mCountries != null) {
return mCountries;
}
mCountries = new CountryList();
try {
JSONArray countries = new JSONArray(getJsonFromRaw(context, R.raw.countries));
for (int i = 0; i < countries.length(); i++) {
try {
JSONObject country = (JSONObject) countries.get(i);
mCountries.add(new Country(country.getString("name"), country.getString("iso2"), country.getInt("dialCode")));
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return mCountries;
} | [
"public",
"static",
"CountryList",
"getCountries",
"(",
"Context",
"context",
")",
"{",
"if",
"(",
"mCountries",
"!=",
"null",
")",
"{",
"return",
"mCountries",
";",
"}",
"mCountries",
"=",
"new",
"CountryList",
"(",
")",
";",
"try",
"{",
"JSONArray",
"countries",
"=",
"new",
"JSONArray",
"(",
"getJsonFromRaw",
"(",
"context",
",",
"R",
".",
"raw",
".",
"countries",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"countries",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"try",
"{",
"JSONObject",
"country",
"=",
"(",
"JSONObject",
")",
"countries",
".",
"get",
"(",
"i",
")",
";",
"mCountries",
".",
"add",
"(",
"new",
"Country",
"(",
"country",
".",
"getString",
"(",
"\"name\"",
")",
",",
"country",
".",
"getString",
"(",
"\"iso2\"",
")",
",",
"country",
".",
"getInt",
"(",
"\"dialCode\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"JSONException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"return",
"mCountries",
";",
"}"
] | Import CountryList from RAW resource
@param context Context
@return CountryList | [
"Import",
"CountryList",
"from",
"RAW",
"resource"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/CountriesFetcher.java#L46-L65 |
163,835 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.init | private void init(AttributeSet attrs) {
inflate(getContext(), R.layout.intl_phone_input, this);
/**+
* Country spinner
*/
mCountrySpinner = (Spinner) findViewById(R.id.intl_phone_edit__country);
mCountrySpinnerAdapter = new CountrySpinnerAdapter(getContext());
mCountrySpinner.setAdapter(mCountrySpinnerAdapter);
mCountries = CountriesFetcher.getCountries(getContext());
mCountrySpinnerAdapter.addAll(mCountries);
mCountrySpinner.setOnItemSelectedListener(mCountrySpinnerListener);
setFlagDefaults(attrs);
/**
* Phone text field
*/
mPhoneEdit = (EditText) findViewById(R.id.intl_phone_edit__phone);
mPhoneEdit.addTextChangedListener(mPhoneNumberWatcher);
setDefault();
setEditTextDefaults(attrs);
} | java | private void init(AttributeSet attrs) {
inflate(getContext(), R.layout.intl_phone_input, this);
/**+
* Country spinner
*/
mCountrySpinner = (Spinner) findViewById(R.id.intl_phone_edit__country);
mCountrySpinnerAdapter = new CountrySpinnerAdapter(getContext());
mCountrySpinner.setAdapter(mCountrySpinnerAdapter);
mCountries = CountriesFetcher.getCountries(getContext());
mCountrySpinnerAdapter.addAll(mCountries);
mCountrySpinner.setOnItemSelectedListener(mCountrySpinnerListener);
setFlagDefaults(attrs);
/**
* Phone text field
*/
mPhoneEdit = (EditText) findViewById(R.id.intl_phone_edit__phone);
mPhoneEdit.addTextChangedListener(mPhoneNumberWatcher);
setDefault();
setEditTextDefaults(attrs);
} | [
"private",
"void",
"init",
"(",
"AttributeSet",
"attrs",
")",
"{",
"inflate",
"(",
"getContext",
"(",
")",
",",
"R",
".",
"layout",
".",
"intl_phone_input",
",",
"this",
")",
";",
"/**+\n * Country spinner\n */",
"mCountrySpinner",
"=",
"(",
"Spinner",
")",
"findViewById",
"(",
"R",
".",
"id",
".",
"intl_phone_edit__country",
")",
";",
"mCountrySpinnerAdapter",
"=",
"new",
"CountrySpinnerAdapter",
"(",
"getContext",
"(",
")",
")",
";",
"mCountrySpinner",
".",
"setAdapter",
"(",
"mCountrySpinnerAdapter",
")",
";",
"mCountries",
"=",
"CountriesFetcher",
".",
"getCountries",
"(",
"getContext",
"(",
")",
")",
";",
"mCountrySpinnerAdapter",
".",
"addAll",
"(",
"mCountries",
")",
";",
"mCountrySpinner",
".",
"setOnItemSelectedListener",
"(",
"mCountrySpinnerListener",
")",
";",
"setFlagDefaults",
"(",
"attrs",
")",
";",
"/**\n * Phone text field\n */",
"mPhoneEdit",
"=",
"(",
"EditText",
")",
"findViewById",
"(",
"R",
".",
"id",
".",
"intl_phone_edit__phone",
")",
";",
"mPhoneEdit",
".",
"addTextChangedListener",
"(",
"mPhoneNumberWatcher",
")",
";",
"setDefault",
"(",
")",
";",
"setEditTextDefaults",
"(",
"attrs",
")",
";",
"}"
] | Init after constructor | [
"Init",
"after",
"constructor"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L71-L95 |
163,836 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.hideKeyboard | public void hideKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mPhoneEdit.getWindowToken(), 0);
} | java | public void hideKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mPhoneEdit.getWindowToken(), 0);
} | [
"public",
"void",
"hideKeyboard",
"(",
")",
"{",
"InputMethodManager",
"inputMethodManager",
"=",
"(",
"InputMethodManager",
")",
"getContext",
"(",
")",
".",
"getApplicationContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"INPUT_METHOD_SERVICE",
")",
";",
"inputMethodManager",
".",
"hideSoftInputFromWindow",
"(",
"mPhoneEdit",
".",
"getWindowToken",
"(",
")",
",",
"0",
")",
";",
"}"
] | Hide keyboard from phoneEdit field | [
"Hide",
"keyboard",
"from",
"phoneEdit",
"field"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L131-L134 |
163,837 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.setDefault | public void setDefault() {
try {
TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
String phone = telephonyManager.getLine1Number();
if (phone != null && !phone.isEmpty()) {
this.setNumber(phone);
} else {
String iso = telephonyManager.getNetworkCountryIso();
setEmptyDefault(iso);
}
} catch (SecurityException e) {
setEmptyDefault();
}
} | java | public void setDefault() {
try {
TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
String phone = telephonyManager.getLine1Number();
if (phone != null && !phone.isEmpty()) {
this.setNumber(phone);
} else {
String iso = telephonyManager.getNetworkCountryIso();
setEmptyDefault(iso);
}
} catch (SecurityException e) {
setEmptyDefault();
}
} | [
"public",
"void",
"setDefault",
"(",
")",
"{",
"try",
"{",
"TelephonyManager",
"telephonyManager",
"=",
"(",
"TelephonyManager",
")",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"TELEPHONY_SERVICE",
")",
";",
"String",
"phone",
"=",
"telephonyManager",
".",
"getLine1Number",
"(",
")",
";",
"if",
"(",
"phone",
"!=",
"null",
"&&",
"!",
"phone",
".",
"isEmpty",
"(",
")",
")",
"{",
"this",
".",
"setNumber",
"(",
"phone",
")",
";",
"}",
"else",
"{",
"String",
"iso",
"=",
"telephonyManager",
".",
"getNetworkCountryIso",
"(",
")",
";",
"setEmptyDefault",
"(",
"iso",
")",
";",
"}",
"}",
"catch",
"(",
"SecurityException",
"e",
")",
"{",
"setEmptyDefault",
"(",
")",
";",
"}",
"}"
] | Set default value
Will try to retrieve phone number from device | [
"Set",
"default",
"value",
"Will",
"try",
"to",
"retrieve",
"phone",
"number",
"from",
"device"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L140-L153 |
163,838 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.setEmptyDefault | public void setEmptyDefault(String iso) {
if (iso == null || iso.isEmpty()) {
iso = DEFAULT_COUNTRY;
}
int defaultIdx = mCountries.indexOfIso(iso);
mSelectedCountry = mCountries.get(defaultIdx);
mCountrySpinner.setSelection(defaultIdx);
} | java | public void setEmptyDefault(String iso) {
if (iso == null || iso.isEmpty()) {
iso = DEFAULT_COUNTRY;
}
int defaultIdx = mCountries.indexOfIso(iso);
mSelectedCountry = mCountries.get(defaultIdx);
mCountrySpinner.setSelection(defaultIdx);
} | [
"public",
"void",
"setEmptyDefault",
"(",
"String",
"iso",
")",
"{",
"if",
"(",
"iso",
"==",
"null",
"||",
"iso",
".",
"isEmpty",
"(",
")",
")",
"{",
"iso",
"=",
"DEFAULT_COUNTRY",
";",
"}",
"int",
"defaultIdx",
"=",
"mCountries",
".",
"indexOfIso",
"(",
"iso",
")",
";",
"mSelectedCountry",
"=",
"mCountries",
".",
"get",
"(",
"defaultIdx",
")",
";",
"mCountrySpinner",
".",
"setSelection",
"(",
"defaultIdx",
")",
";",
"}"
] | Set default value with
@param iso ISO2 of country | [
"Set",
"default",
"value",
"with"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L160-L167 |
163,839 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.setHint | private void setHint() {
if (mPhoneEdit != null && mSelectedCountry != null && mSelectedCountry.getIso() != null) {
Phonenumber.PhoneNumber phoneNumber = mPhoneUtil.getExampleNumberForType(mSelectedCountry.getIso(), PhoneNumberUtil.PhoneNumberType.MOBILE);
if (phoneNumber != null) {
mPhoneEdit.setHint(mPhoneUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
}
}
} | java | private void setHint() {
if (mPhoneEdit != null && mSelectedCountry != null && mSelectedCountry.getIso() != null) {
Phonenumber.PhoneNumber phoneNumber = mPhoneUtil.getExampleNumberForType(mSelectedCountry.getIso(), PhoneNumberUtil.PhoneNumberType.MOBILE);
if (phoneNumber != null) {
mPhoneEdit.setHint(mPhoneUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
}
}
} | [
"private",
"void",
"setHint",
"(",
")",
"{",
"if",
"(",
"mPhoneEdit",
"!=",
"null",
"&&",
"mSelectedCountry",
"!=",
"null",
"&&",
"mSelectedCountry",
".",
"getIso",
"(",
")",
"!=",
"null",
")",
"{",
"Phonenumber",
".",
"PhoneNumber",
"phoneNumber",
"=",
"mPhoneUtil",
".",
"getExampleNumberForType",
"(",
"mSelectedCountry",
".",
"getIso",
"(",
")",
",",
"PhoneNumberUtil",
".",
"PhoneNumberType",
".",
"MOBILE",
")",
";",
"if",
"(",
"phoneNumber",
"!=",
"null",
")",
"{",
"mPhoneEdit",
".",
"setHint",
"(",
"mPhoneUtil",
".",
"format",
"(",
"phoneNumber",
",",
"PhoneNumberUtil",
".",
"PhoneNumberFormat",
".",
"NATIONAL",
")",
")",
";",
"}",
"}",
"}"
] | Set hint number for country | [
"Set",
"hint",
"number",
"for",
"country"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L179-L186 |
163,840 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.getPhoneNumber | @SuppressWarnings("unused")
public Phonenumber.PhoneNumber getPhoneNumber() {
try {
String iso = null;
if (mSelectedCountry != null) {
iso = mSelectedCountry.getIso();
}
return mPhoneUtil.parse(mPhoneEdit.getText().toString(), iso);
} catch (NumberParseException ignored) {
return null;
}
} | java | @SuppressWarnings("unused")
public Phonenumber.PhoneNumber getPhoneNumber() {
try {
String iso = null;
if (mSelectedCountry != null) {
iso = mSelectedCountry.getIso();
}
return mPhoneUtil.parse(mPhoneEdit.getText().toString(), iso);
} catch (NumberParseException ignored) {
return null;
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"Phonenumber",
".",
"PhoneNumber",
"getPhoneNumber",
"(",
")",
"{",
"try",
"{",
"String",
"iso",
"=",
"null",
";",
"if",
"(",
"mSelectedCountry",
"!=",
"null",
")",
"{",
"iso",
"=",
"mSelectedCountry",
".",
"getIso",
"(",
")",
";",
"}",
"return",
"mPhoneUtil",
".",
"parse",
"(",
"mPhoneEdit",
".",
"getText",
"(",
")",
".",
"toString",
"(",
")",
",",
"iso",
")",
";",
"}",
"catch",
"(",
"NumberParseException",
"ignored",
")",
"{",
"return",
"null",
";",
"}",
"}"
] | Get PhoneNumber object
@return PhonenUmber | null on error | [
"Get",
"PhoneNumber",
"object"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L302-L313 |
163,841 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.isValid | @SuppressWarnings("unused")
public boolean isValid() {
Phonenumber.PhoneNumber phoneNumber = getPhoneNumber();
return phoneNumber != null && mPhoneUtil.isValidNumber(phoneNumber);
} | java | @SuppressWarnings("unused")
public boolean isValid() {
Phonenumber.PhoneNumber phoneNumber = getPhoneNumber();
return phoneNumber != null && mPhoneUtil.isValidNumber(phoneNumber);
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"boolean",
"isValid",
"(",
")",
"{",
"Phonenumber",
".",
"PhoneNumber",
"phoneNumber",
"=",
"getPhoneNumber",
"(",
")",
";",
"return",
"phoneNumber",
"!=",
"null",
"&&",
"mPhoneUtil",
".",
"isValidNumber",
"(",
"phoneNumber",
")",
";",
"}"
] | Check if number is valid
@return boolean | [
"Check",
"if",
"number",
"is",
"valid"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L330-L334 |
163,842 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.setError | @SuppressWarnings("unused")
public void setError(CharSequence error, Drawable icon) {
mPhoneEdit.setError(error, icon);
} | java | @SuppressWarnings("unused")
public void setError(CharSequence error, Drawable icon) {
mPhoneEdit.setError(error, icon);
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"void",
"setError",
"(",
"CharSequence",
"error",
",",
"Drawable",
"icon",
")",
"{",
"mPhoneEdit",
".",
"setError",
"(",
"error",
",",
"icon",
")",
";",
"}"
] | Sets an error message that will be displayed in a popup when the EditText has focus along
with an icon displayed at the right-hand side.
@param error error message to show | [
"Sets",
"an",
"error",
"message",
"that",
"will",
"be",
"displayed",
"in",
"a",
"popup",
"when",
"the",
"EditText",
"has",
"focus",
"along",
"with",
"an",
"icon",
"displayed",
"at",
"the",
"right",
"-",
"hand",
"side",
"."
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L373-L376 |
163,843 | AlmogBaku/IntlPhoneInput | intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java | IntlPhoneInput.setOnKeyboardDone | public void setOnKeyboardDone(final IntlPhoneInputListener listener) {
mPhoneEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
listener.done(IntlPhoneInput.this, isValid());
}
return false;
}
});
} | java | public void setOnKeyboardDone(final IntlPhoneInputListener listener) {
mPhoneEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
listener.done(IntlPhoneInput.this, isValid());
}
return false;
}
});
} | [
"public",
"void",
"setOnKeyboardDone",
"(",
"final",
"IntlPhoneInputListener",
"listener",
")",
"{",
"mPhoneEdit",
".",
"setOnEditorActionListener",
"(",
"new",
"TextView",
".",
"OnEditorActionListener",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"onEditorAction",
"(",
"TextView",
"v",
",",
"int",
"actionId",
",",
"KeyEvent",
"event",
")",
"{",
"if",
"(",
"actionId",
"==",
"EditorInfo",
".",
"IME_ACTION_DONE",
")",
"{",
"listener",
".",
"done",
"(",
"IntlPhoneInput",
".",
"this",
",",
"isValid",
"(",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"}",
")",
";",
"}"
] | Set keyboard done listener to detect when the user click "DONE" on his keyboard
@param listener IntlPhoneInputListener | [
"Set",
"keyboard",
"done",
"listener",
"to",
"detect",
"when",
"the",
"user",
"click",
"DONE",
"on",
"his",
"keyboard"
] | ac7313a2d1683feb4d535d5dbee6676b53879059 | https://github.com/AlmogBaku/IntlPhoneInput/blob/ac7313a2d1683feb4d535d5dbee6676b53879059/intlphoneinput/src/main/java/net/rimoto/intlphoneinput/IntlPhoneInput.java#L397-L407 |
163,844 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.allocateClient | private synchronized Client allocateClient(int targetPlayer, String description) throws IOException {
Client result = openClients.get(targetPlayer);
if (result == null) {
// We need to open a new connection.
final DeviceAnnouncement deviceAnnouncement = DeviceFinder.getInstance().getLatestAnnouncementFrom(targetPlayer);
if (deviceAnnouncement == null) {
throw new IllegalStateException("Player " + targetPlayer + " could not be found " + description);
}
final int dbServerPort = getPlayerDBServerPort(targetPlayer);
if (dbServerPort < 0) {
throw new IllegalStateException("Player " + targetPlayer + " does not have a db server " + description);
}
final byte posingAsPlayerNumber = (byte) chooseAskingPlayerNumber(targetPlayer);
Socket socket = null;
try {
InetSocketAddress address = new InetSocketAddress(deviceAnnouncement.getAddress(), dbServerPort);
socket = new Socket();
socket.connect(address, socketTimeout.get());
socket.setSoTimeout(socketTimeout.get());
result = new Client(socket, targetPlayer, posingAsPlayerNumber);
} catch (IOException e) {
try {
socket.close();
} catch (IOException e2) {
logger.error("Problem closing socket for failed client creation attempt " + description);
}
throw e;
}
openClients.put(targetPlayer, result);
useCounts.put(result, 0);
}
useCounts.put(result, useCounts.get(result) + 1);
return result;
} | java | private synchronized Client allocateClient(int targetPlayer, String description) throws IOException {
Client result = openClients.get(targetPlayer);
if (result == null) {
// We need to open a new connection.
final DeviceAnnouncement deviceAnnouncement = DeviceFinder.getInstance().getLatestAnnouncementFrom(targetPlayer);
if (deviceAnnouncement == null) {
throw new IllegalStateException("Player " + targetPlayer + " could not be found " + description);
}
final int dbServerPort = getPlayerDBServerPort(targetPlayer);
if (dbServerPort < 0) {
throw new IllegalStateException("Player " + targetPlayer + " does not have a db server " + description);
}
final byte posingAsPlayerNumber = (byte) chooseAskingPlayerNumber(targetPlayer);
Socket socket = null;
try {
InetSocketAddress address = new InetSocketAddress(deviceAnnouncement.getAddress(), dbServerPort);
socket = new Socket();
socket.connect(address, socketTimeout.get());
socket.setSoTimeout(socketTimeout.get());
result = new Client(socket, targetPlayer, posingAsPlayerNumber);
} catch (IOException e) {
try {
socket.close();
} catch (IOException e2) {
logger.error("Problem closing socket for failed client creation attempt " + description);
}
throw e;
}
openClients.put(targetPlayer, result);
useCounts.put(result, 0);
}
useCounts.put(result, useCounts.get(result) + 1);
return result;
} | [
"private",
"synchronized",
"Client",
"allocateClient",
"(",
"int",
"targetPlayer",
",",
"String",
"description",
")",
"throws",
"IOException",
"{",
"Client",
"result",
"=",
"openClients",
".",
"get",
"(",
"targetPlayer",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"// We need to open a new connection.",
"final",
"DeviceAnnouncement",
"deviceAnnouncement",
"=",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestAnnouncementFrom",
"(",
"targetPlayer",
")",
";",
"if",
"(",
"deviceAnnouncement",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Player \"",
"+",
"targetPlayer",
"+",
"\" could not be found \"",
"+",
"description",
")",
";",
"}",
"final",
"int",
"dbServerPort",
"=",
"getPlayerDBServerPort",
"(",
"targetPlayer",
")",
";",
"if",
"(",
"dbServerPort",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Player \"",
"+",
"targetPlayer",
"+",
"\" does not have a db server \"",
"+",
"description",
")",
";",
"}",
"final",
"byte",
"posingAsPlayerNumber",
"=",
"(",
"byte",
")",
"chooseAskingPlayerNumber",
"(",
"targetPlayer",
")",
";",
"Socket",
"socket",
"=",
"null",
";",
"try",
"{",
"InetSocketAddress",
"address",
"=",
"new",
"InetSocketAddress",
"(",
"deviceAnnouncement",
".",
"getAddress",
"(",
")",
",",
"dbServerPort",
")",
";",
"socket",
"=",
"new",
"Socket",
"(",
")",
";",
"socket",
".",
"connect",
"(",
"address",
",",
"socketTimeout",
".",
"get",
"(",
")",
")",
";",
"socket",
".",
"setSoTimeout",
"(",
"socketTimeout",
".",
"get",
"(",
")",
")",
";",
"result",
"=",
"new",
"Client",
"(",
"socket",
",",
"targetPlayer",
",",
"posingAsPlayerNumber",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"try",
"{",
"socket",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e2",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem closing socket for failed client creation attempt \"",
"+",
"description",
")",
";",
"}",
"throw",
"e",
";",
"}",
"openClients",
".",
"put",
"(",
"targetPlayer",
",",
"result",
")",
";",
"useCounts",
".",
"put",
"(",
"result",
",",
"0",
")",
";",
"}",
"useCounts",
".",
"put",
"(",
"result",
",",
"useCounts",
".",
"get",
"(",
"result",
")",
"+",
"1",
")",
";",
"return",
"result",
";",
"}"
] | Finds or opens a client to talk to the dbserver on the specified player, incrementing its use count.
@param targetPlayer the player number whose database needs to be interacted with
@param description a short description of the task being performed for error reporting if it fails,
should be a verb phrase like "requesting track metadata"
@return the communication client for talking to that player, or {@code null} if the player could not be found
@throws IllegalStateException if we can't find the target player or there is no suitable player number for us
to pretend to be
@throws IOException if there is a problem communicating | [
"Finds",
"or",
"opens",
"a",
"client",
"to",
"talk",
"to",
"the",
"dbserver",
"on",
"the",
"specified",
"player",
"incrementing",
"its",
"use",
"count",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L103-L138 |
163,845 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.closeClient | private void closeClient(Client client) {
logger.debug("Closing client {}", client);
client.close();
openClients.remove(client.targetPlayer);
useCounts.remove(client);
timestamps.remove(client);
} | java | private void closeClient(Client client) {
logger.debug("Closing client {}", client);
client.close();
openClients.remove(client.targetPlayer);
useCounts.remove(client);
timestamps.remove(client);
} | [
"private",
"void",
"closeClient",
"(",
"Client",
"client",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Closing client {}\"",
",",
"client",
")",
";",
"client",
".",
"close",
"(",
")",
";",
"openClients",
".",
"remove",
"(",
"client",
".",
"targetPlayer",
")",
";",
"useCounts",
".",
"remove",
"(",
"client",
")",
";",
"timestamps",
".",
"remove",
"(",
"client",
")",
";",
"}"
] | When it is time to actually close a client, do so, and clean up the related data structures.
@param client the client which has been idle for long enough to be closed | [
"When",
"it",
"is",
"time",
"to",
"actually",
"close",
"a",
"client",
"do",
"so",
"and",
"clean",
"up",
"the",
"related",
"data",
"structures",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L145-L151 |
163,846 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.freeClient | private synchronized void freeClient(Client client) {
int current = useCounts.get(client);
if (current > 0) {
timestamps.put(client, System.currentTimeMillis()); // Mark that it was used until now.
useCounts.put(client, current - 1);
if ((current == 1) && (idleLimit.get() == 0)) {
closeClient(client); // This was the last use, and we are supposed to immediately close idle clients.
}
} else {
logger.error("Ignoring attempt to free a client that is not allocated: {}", client);
}
} | java | private synchronized void freeClient(Client client) {
int current = useCounts.get(client);
if (current > 0) {
timestamps.put(client, System.currentTimeMillis()); // Mark that it was used until now.
useCounts.put(client, current - 1);
if ((current == 1) && (idleLimit.get() == 0)) {
closeClient(client); // This was the last use, and we are supposed to immediately close idle clients.
}
} else {
logger.error("Ignoring attempt to free a client that is not allocated: {}", client);
}
} | [
"private",
"synchronized",
"void",
"freeClient",
"(",
"Client",
"client",
")",
"{",
"int",
"current",
"=",
"useCounts",
".",
"get",
"(",
"client",
")",
";",
"if",
"(",
"current",
">",
"0",
")",
"{",
"timestamps",
".",
"put",
"(",
"client",
",",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"// Mark that it was used until now.",
"useCounts",
".",
"put",
"(",
"client",
",",
"current",
"-",
"1",
")",
";",
"if",
"(",
"(",
"current",
"==",
"1",
")",
"&&",
"(",
"idleLimit",
".",
"get",
"(",
")",
"==",
"0",
")",
")",
"{",
"closeClient",
"(",
"client",
")",
";",
"// This was the last use, and we are supposed to immediately close idle clients.",
"}",
"}",
"else",
"{",
"logger",
".",
"error",
"(",
"\"Ignoring attempt to free a client that is not allocated: {}\"",
",",
"client",
")",
";",
"}",
"}"
] | Decrements the client's use count, and makes it eligible for closing if it is no longer in use.
@param client the dbserver connection client which is no longer being used for a task | [
"Decrements",
"the",
"client",
"s",
"use",
"count",
"and",
"makes",
"it",
"eligible",
"for",
"closing",
"if",
"it",
"is",
"no",
"longer",
"in",
"use",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L158-L169 |
163,847 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.invokeWithClientSession | public <T> T invokeWithClientSession(int targetPlayer, ClientTask<T> task, String description)
throws Exception {
if (!isRunning()) {
throw new IllegalStateException("ConnectionManager is not running, aborting " + description);
}
final Client client = allocateClient(targetPlayer, description);
try {
return task.useClient(client);
} finally {
freeClient(client);
}
} | java | public <T> T invokeWithClientSession(int targetPlayer, ClientTask<T> task, String description)
throws Exception {
if (!isRunning()) {
throw new IllegalStateException("ConnectionManager is not running, aborting " + description);
}
final Client client = allocateClient(targetPlayer, description);
try {
return task.useClient(client);
} finally {
freeClient(client);
}
} | [
"public",
"<",
"T",
">",
"T",
"invokeWithClientSession",
"(",
"int",
"targetPlayer",
",",
"ClientTask",
"<",
"T",
">",
"task",
",",
"String",
"description",
")",
"throws",
"Exception",
"{",
"if",
"(",
"!",
"isRunning",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"ConnectionManager is not running, aborting \"",
"+",
"description",
")",
";",
"}",
"final",
"Client",
"client",
"=",
"allocateClient",
"(",
"targetPlayer",
",",
"description",
")",
";",
"try",
"{",
"return",
"task",
".",
"useClient",
"(",
"client",
")",
";",
"}",
"finally",
"{",
"freeClient",
"(",
"client",
")",
";",
"}",
"}"
] | Obtain a dbserver client session that can be used to perform some task, call that task with the client,
then release the client.
@param targetPlayer the player number whose dbserver we wish to communicate with
@param task the activity that will be performed with exclusive access to a dbserver connection
@param description a short description of the task being performed for error reporting if it fails,
should be a verb phrase like "requesting track metadata"
@param <T> the type that will be returned by the task to be performed
@return the value returned by the completed task
@throws IOException if there is a problem communicating
@throws Exception from the underlying {@code task}, if any | [
"Obtain",
"a",
"dbserver",
"client",
"session",
"that",
"can",
"be",
"used",
"to",
"perform",
"some",
"task",
"call",
"that",
"task",
"with",
"the",
"client",
"then",
"release",
"the",
"client",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L186-L198 |
163,848 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.getPlayerDBServerPort | @SuppressWarnings("WeakerAccess")
public int getPlayerDBServerPort(int player) {
ensureRunning();
Integer result = dbServerPorts.get(player);
if (result == null) {
return -1;
}
return result;
} | java | @SuppressWarnings("WeakerAccess")
public int getPlayerDBServerPort(int player) {
ensureRunning();
Integer result = dbServerPorts.get(player);
if (result == null) {
return -1;
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"int",
"getPlayerDBServerPort",
"(",
"int",
"player",
")",
"{",
"ensureRunning",
"(",
")",
";",
"Integer",
"result",
"=",
"dbServerPorts",
".",
"get",
"(",
"player",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"result",
";",
"}"
] | Look up the database server port reported by a given player. You should not use this port directly; instead
ask this class for a session to use while you communicate with the database.
@param player the player number of interest
@return the port number on which its database server is running, or -1 if unknown
@throws IllegalStateException if not running | [
"Look",
"up",
"the",
"database",
"server",
"port",
"reported",
"by",
"a",
"given",
"player",
".",
"You",
"should",
"not",
"use",
"this",
"port",
"directly",
";",
"instead",
"ask",
"this",
"class",
"for",
"a",
"session",
"to",
"use",
"while",
"you",
"communicate",
"with",
"the",
"database",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L215-L223 |
163,849 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.requestPlayerDBServerPort | private void requestPlayerDBServerPort(DeviceAnnouncement announcement) {
Socket socket = null;
try {
InetSocketAddress address = new InetSocketAddress(announcement.getAddress(), DB_SERVER_QUERY_PORT);
socket = new Socket();
socket.connect(address, socketTimeout.get());
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
socket.setSoTimeout(socketTimeout.get());
os.write(DB_SERVER_QUERY_PACKET);
byte[] response = readResponseWithExpectedSize(is, 2, "database server port query packet");
if (response.length == 2) {
setPlayerDBServerPort(announcement.getNumber(), (int)Util.bytesToNumber(response, 0, 2));
}
} catch (java.net.ConnectException ce) {
logger.info("Player " + announcement.getNumber() +
" doesn't answer rekordbox port queries, connection refused. Won't attempt to request metadata.");
} catch (Exception e) {
logger.warn("Problem requesting database server port number", e);
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing database server port request socket", e);
}
}
}
} | java | private void requestPlayerDBServerPort(DeviceAnnouncement announcement) {
Socket socket = null;
try {
InetSocketAddress address = new InetSocketAddress(announcement.getAddress(), DB_SERVER_QUERY_PORT);
socket = new Socket();
socket.connect(address, socketTimeout.get());
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
socket.setSoTimeout(socketTimeout.get());
os.write(DB_SERVER_QUERY_PACKET);
byte[] response = readResponseWithExpectedSize(is, 2, "database server port query packet");
if (response.length == 2) {
setPlayerDBServerPort(announcement.getNumber(), (int)Util.bytesToNumber(response, 0, 2));
}
} catch (java.net.ConnectException ce) {
logger.info("Player " + announcement.getNumber() +
" doesn't answer rekordbox port queries, connection refused. Won't attempt to request metadata.");
} catch (Exception e) {
logger.warn("Problem requesting database server port number", e);
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
logger.warn("Problem closing database server port request socket", e);
}
}
}
} | [
"private",
"void",
"requestPlayerDBServerPort",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"Socket",
"socket",
"=",
"null",
";",
"try",
"{",
"InetSocketAddress",
"address",
"=",
"new",
"InetSocketAddress",
"(",
"announcement",
".",
"getAddress",
"(",
")",
",",
"DB_SERVER_QUERY_PORT",
")",
";",
"socket",
"=",
"new",
"Socket",
"(",
")",
";",
"socket",
".",
"connect",
"(",
"address",
",",
"socketTimeout",
".",
"get",
"(",
")",
")",
";",
"InputStream",
"is",
"=",
"socket",
".",
"getInputStream",
"(",
")",
";",
"OutputStream",
"os",
"=",
"socket",
".",
"getOutputStream",
"(",
")",
";",
"socket",
".",
"setSoTimeout",
"(",
"socketTimeout",
".",
"get",
"(",
")",
")",
";",
"os",
".",
"write",
"(",
"DB_SERVER_QUERY_PACKET",
")",
";",
"byte",
"[",
"]",
"response",
"=",
"readResponseWithExpectedSize",
"(",
"is",
",",
"2",
",",
"\"database server port query packet\"",
")",
";",
"if",
"(",
"response",
".",
"length",
"==",
"2",
")",
"{",
"setPlayerDBServerPort",
"(",
"announcement",
".",
"getNumber",
"(",
")",
",",
"(",
"int",
")",
"Util",
".",
"bytesToNumber",
"(",
"response",
",",
"0",
",",
"2",
")",
")",
";",
"}",
"}",
"catch",
"(",
"java",
".",
"net",
".",
"ConnectException",
"ce",
")",
"{",
"logger",
".",
"info",
"(",
"\"Player \"",
"+",
"announcement",
".",
"getNumber",
"(",
")",
"+",
"\" doesn't answer rekordbox port queries, connection refused. Won't attempt to request metadata.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem requesting database server port number\"",
",",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"socket",
"!=",
"null",
")",
"{",
"try",
"{",
"socket",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing database server port request socket\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"}"
] | Query a player to determine the port on which its database server is running.
@param announcement the device announcement with which we detected a new player on the network. | [
"Query",
"a",
"player",
"to",
"determine",
"the",
"port",
"on",
"which",
"its",
"database",
"server",
"is",
"running",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L274-L302 |
163,850 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.receiveBytes | private byte[] receiveBytes(InputStream is) throws IOException {
byte[] buffer = new byte[8192];
int len = (is.read(buffer));
if (len < 1) {
throw new IOException("receiveBytes read " + len + " bytes.");
}
return Arrays.copyOf(buffer, len);
} | java | private byte[] receiveBytes(InputStream is) throws IOException {
byte[] buffer = new byte[8192];
int len = (is.read(buffer));
if (len < 1) {
throw new IOException("receiveBytes read " + len + " bytes.");
}
return Arrays.copyOf(buffer, len);
} | [
"private",
"byte",
"[",
"]",
"receiveBytes",
"(",
"InputStream",
"is",
")",
"throws",
"IOException",
"{",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"8192",
"]",
";",
"int",
"len",
"=",
"(",
"is",
".",
"read",
"(",
"buffer",
")",
")",
";",
"if",
"(",
"len",
"<",
"1",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"receiveBytes read \"",
"+",
"len",
"+",
"\" bytes.\"",
")",
";",
"}",
"return",
"Arrays",
".",
"copyOf",
"(",
"buffer",
",",
"len",
")",
";",
"}"
] | Receive some bytes from the player we are requesting metadata from.
@param is the input stream associated with the player metadata socket.
@return the bytes read.
@throws IOException if there is a problem reading the response | [
"Receive",
"some",
"bytes",
"from",
"the",
"player",
"we",
"are",
"requesting",
"metadata",
"from",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L343-L350 |
163,851 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.readResponseWithExpectedSize | @SuppressWarnings("SameParameterValue")
private byte[] readResponseWithExpectedSize(InputStream is, int size, String description) throws IOException {
byte[] result = receiveBytes(is);
if (result.length != size) {
logger.warn("Expected " + size + " bytes while reading " + description + " response, received " + result.length);
}
return result;
} | java | @SuppressWarnings("SameParameterValue")
private byte[] readResponseWithExpectedSize(InputStream is, int size, String description) throws IOException {
byte[] result = receiveBytes(is);
if (result.length != size) {
logger.warn("Expected " + size + " bytes while reading " + description + " response, received " + result.length);
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"private",
"byte",
"[",
"]",
"readResponseWithExpectedSize",
"(",
"InputStream",
"is",
",",
"int",
"size",
",",
"String",
"description",
")",
"throws",
"IOException",
"{",
"byte",
"[",
"]",
"result",
"=",
"receiveBytes",
"(",
"is",
")",
";",
"if",
"(",
"result",
".",
"length",
"!=",
"size",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Expected \"",
"+",
"size",
"+",
"\" bytes while reading \"",
"+",
"description",
"+",
"\" response, received \"",
"+",
"result",
".",
"length",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Receive an expected number of bytes from the player, logging a warning if we get a different number of them.
@param is the input stream associated with the player metadata socket.
@param size the number of bytes we expect to receive.
@param description the type of response being processed, for use in the warning message.
@return the bytes read.
@throws IOException if there is a problem reading the response. | [
"Receive",
"an",
"expected",
"number",
"of",
"bytes",
"from",
"the",
"player",
"logging",
"a",
"warning",
"if",
"we",
"get",
"a",
"different",
"number",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L362-L369 |
163,852 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.closeIdleClients | private synchronized void closeIdleClients() {
List<Client> candidates = new LinkedList<Client>(openClients.values());
logger.debug("Scanning for idle clients; " + candidates.size() + " candidates.");
for (Client client : candidates) {
if ((useCounts.get(client) < 1) &&
((timestamps.get(client) + idleLimit.get() * 1000) <= System.currentTimeMillis())) {
logger.debug("Idle time reached for unused client {}", client);
closeClient(client);
}
}
} | java | private synchronized void closeIdleClients() {
List<Client> candidates = new LinkedList<Client>(openClients.values());
logger.debug("Scanning for idle clients; " + candidates.size() + " candidates.");
for (Client client : candidates) {
if ((useCounts.get(client) < 1) &&
((timestamps.get(client) + idleLimit.get() * 1000) <= System.currentTimeMillis())) {
logger.debug("Idle time reached for unused client {}", client);
closeClient(client);
}
}
} | [
"private",
"synchronized",
"void",
"closeIdleClients",
"(",
")",
"{",
"List",
"<",
"Client",
">",
"candidates",
"=",
"new",
"LinkedList",
"<",
"Client",
">",
"(",
"openClients",
".",
"values",
"(",
")",
")",
";",
"logger",
".",
"debug",
"(",
"\"Scanning for idle clients; \"",
"+",
"candidates",
".",
"size",
"(",
")",
"+",
"\" candidates.\"",
")",
";",
"for",
"(",
"Client",
"client",
":",
"candidates",
")",
"{",
"if",
"(",
"(",
"useCounts",
".",
"get",
"(",
"client",
")",
"<",
"1",
")",
"&&",
"(",
"(",
"timestamps",
".",
"get",
"(",
"client",
")",
"+",
"idleLimit",
".",
"get",
"(",
")",
"*",
"1000",
")",
"<=",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Idle time reached for unused client {}\"",
",",
"client",
")",
";",
"closeClient",
"(",
"client",
")",
";",
"}",
"}",
"}"
] | Finds any clients which are not currently in use, and which have been idle for longer than the
idle timeout, and closes them. | [
"Finds",
"any",
"clients",
"which",
"are",
"not",
"currently",
"in",
"use",
"and",
"which",
"have",
"been",
"idle",
"for",
"longer",
"than",
"the",
"idle",
"timeout",
"and",
"closes",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L440-L450 |
163,853 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.start | public synchronized void start() throws SocketException {
if (!isRunning()) {
DeviceFinder.getInstance().addLifecycleListener(lifecycleListener);
DeviceFinder.getInstance().addDeviceAnnouncementListener(announcementListener);
DeviceFinder.getInstance().start();
for (DeviceAnnouncement device: DeviceFinder.getInstance().getCurrentDevices()) {
requestPlayerDBServerPort(device);
}
new Thread(null, new Runnable() {
@Override
public void run() {
while (isRunning()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.warn("Interrupted sleeping to close idle dbserver clients");
}
closeIdleClients();
}
logger.info("Idle dbserver client closer shutting down.");
}
}, "Idle dbserver client closer").start();
running.set(true);
deliverLifecycleAnnouncement(logger, true);
}
} | java | public synchronized void start() throws SocketException {
if (!isRunning()) {
DeviceFinder.getInstance().addLifecycleListener(lifecycleListener);
DeviceFinder.getInstance().addDeviceAnnouncementListener(announcementListener);
DeviceFinder.getInstance().start();
for (DeviceAnnouncement device: DeviceFinder.getInstance().getCurrentDevices()) {
requestPlayerDBServerPort(device);
}
new Thread(null, new Runnable() {
@Override
public void run() {
while (isRunning()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.warn("Interrupted sleeping to close idle dbserver clients");
}
closeIdleClients();
}
logger.info("Idle dbserver client closer shutting down.");
}
}, "Idle dbserver client closer").start();
running.set(true);
deliverLifecycleAnnouncement(logger, true);
}
} | [
"public",
"synchronized",
"void",
"start",
"(",
")",
"throws",
"SocketException",
"{",
"if",
"(",
"!",
"isRunning",
"(",
")",
")",
"{",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"addLifecycleListener",
"(",
"lifecycleListener",
")",
";",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"addDeviceAnnouncementListener",
"(",
"announcementListener",
")",
";",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"start",
"(",
")",
";",
"for",
"(",
"DeviceAnnouncement",
"device",
":",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"getCurrentDevices",
"(",
")",
")",
"{",
"requestPlayerDBServerPort",
"(",
"device",
")",
";",
"}",
"new",
"Thread",
"(",
"null",
",",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"while",
"(",
"isRunning",
"(",
")",
")",
"{",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"500",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Interrupted sleeping to close idle dbserver clients\"",
")",
";",
"}",
"closeIdleClients",
"(",
")",
";",
"}",
"logger",
".",
"info",
"(",
"\"Idle dbserver client closer shutting down.\"",
")",
";",
"}",
"}",
",",
"\"Idle dbserver client closer\"",
")",
".",
"start",
"(",
")",
";",
"running",
".",
"set",
"(",
"true",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"true",
")",
";",
"}",
"}"
] | Start offering shared dbserver sessions.
@throws SocketException if there is a problem opening connections | [
"Start",
"offering",
"shared",
"dbserver",
"sessions",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L457-L484 |
163,854 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java | ConnectionManager.stop | public synchronized void stop() {
if (isRunning()) {
running.set(false);
DeviceFinder.getInstance().removeDeviceAnnouncementListener(announcementListener);
dbServerPorts.clear();
for (Client client : openClients.values()) {
try {
client.close();
} catch (Exception e) {
logger.warn("Problem closing " + client + " when stopping", e);
}
}
openClients.clear();
useCounts.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | java | public synchronized void stop() {
if (isRunning()) {
running.set(false);
DeviceFinder.getInstance().removeDeviceAnnouncementListener(announcementListener);
dbServerPorts.clear();
for (Client client : openClients.values()) {
try {
client.close();
} catch (Exception e) {
logger.warn("Problem closing " + client + " when stopping", e);
}
}
openClients.clear();
useCounts.clear();
deliverLifecycleAnnouncement(logger, false);
}
} | [
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"isRunning",
"(",
")",
")",
"{",
"running",
".",
"set",
"(",
"false",
")",
";",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"removeDeviceAnnouncementListener",
"(",
"announcementListener",
")",
";",
"dbServerPorts",
".",
"clear",
"(",
")",
";",
"for",
"(",
"Client",
"client",
":",
"openClients",
".",
"values",
"(",
")",
")",
"{",
"try",
"{",
"client",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem closing \"",
"+",
"client",
"+",
"\" when stopping\"",
",",
"e",
")",
";",
"}",
"}",
"openClients",
".",
"clear",
"(",
")",
";",
"useCounts",
".",
"clear",
"(",
")",
";",
"deliverLifecycleAnnouncement",
"(",
"logger",
",",
"false",
")",
";",
"}",
"}"
] | Stop offering shared dbserver sessions. | [
"Stop",
"offering",
"shared",
"dbserver",
"sessions",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/ConnectionManager.java#L489-L505 |
163,855 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildSearchableItem | private SearchableItem buildSearchableItem(Message menuItem) {
return new SearchableItem((int) ((NumberField) menuItem.arguments.get(1)).getValue(),
((StringField) menuItem.arguments.get(3)).getValue());
} | java | private SearchableItem buildSearchableItem(Message menuItem) {
return new SearchableItem((int) ((NumberField) menuItem.arguments.get(1)).getValue(),
((StringField) menuItem.arguments.get(3)).getValue());
} | [
"private",
"SearchableItem",
"buildSearchableItem",
"(",
"Message",
"menuItem",
")",
"{",
"return",
"new",
"SearchableItem",
"(",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
",",
"(",
"(",
"StringField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
")",
";",
"}"
] | Creates a searchable item that represents a metadata field found for a track.
@param menuItem the rendered menu item containing the searchable metadata field
@return the searchable metadata field | [
"Creates",
"a",
"searchable",
"item",
"that",
"represents",
"a",
"metadata",
"field",
"found",
"for",
"a",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L156-L159 |
163,856 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildColorItem | private ColorItem buildColorItem(Message menuItem) {
final int colorId = (int) ((NumberField) menuItem.arguments.get(1)).getValue();
final String label = ((StringField) menuItem.arguments.get(3)).getValue();
return buildColorItem(colorId, label);
} | java | private ColorItem buildColorItem(Message menuItem) {
final int colorId = (int) ((NumberField) menuItem.arguments.get(1)).getValue();
final String label = ((StringField) menuItem.arguments.get(3)).getValue();
return buildColorItem(colorId, label);
} | [
"private",
"ColorItem",
"buildColorItem",
"(",
"Message",
"menuItem",
")",
"{",
"final",
"int",
"colorId",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"final",
"String",
"label",
"=",
"(",
"(",
"StringField",
")",
"menuItem",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
";",
"return",
"buildColorItem",
"(",
"colorId",
",",
"label",
")",
";",
"}"
] | Creates a color item that represents a color field found for a track based on a dbserver message.
@param menuItem the rendered menu item containing the color metadata field
@return the color metadata field | [
"Creates",
"a",
"color",
"item",
"that",
"represents",
"a",
"color",
"field",
"found",
"for",
"a",
"track",
"based",
"on",
"a",
"dbserver",
"message",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L168-L172 |
163,857 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.buildColorItem | private ColorItem buildColorItem(int colorId, String label) {
Color color;
String colorName;
switch (colorId) {
case 0:
color = new Color(0, 0, 0, 0);
colorName = "No Color";
break;
case 1:
color = Color.PINK;
colorName = "Pink";
break;
case 2:
color = Color.RED;
colorName = "Red";
break;
case 3:
color = Color.ORANGE;
colorName = "Orange";
break;
case 4:
color = Color.YELLOW;
colorName = "Yellow";
break;
case 5:
color = Color.GREEN;
colorName = "Green";
break;
case 6:
color = Color.CYAN;
colorName = "Aqua";
break;
case 7:
color = Color.BLUE;
colorName = "Blue";
break;
case 8:
color = new Color(128, 0, 128);
colorName = "Purple";
break;
default:
color = new Color(0, 0, 0, 0);
colorName = "Unknown Color";
}
return new ColorItem(colorId, label, color, colorName);
} | java | private ColorItem buildColorItem(int colorId, String label) {
Color color;
String colorName;
switch (colorId) {
case 0:
color = new Color(0, 0, 0, 0);
colorName = "No Color";
break;
case 1:
color = Color.PINK;
colorName = "Pink";
break;
case 2:
color = Color.RED;
colorName = "Red";
break;
case 3:
color = Color.ORANGE;
colorName = "Orange";
break;
case 4:
color = Color.YELLOW;
colorName = "Yellow";
break;
case 5:
color = Color.GREEN;
colorName = "Green";
break;
case 6:
color = Color.CYAN;
colorName = "Aqua";
break;
case 7:
color = Color.BLUE;
colorName = "Blue";
break;
case 8:
color = new Color(128, 0, 128);
colorName = "Purple";
break;
default:
color = new Color(0, 0, 0, 0);
colorName = "Unknown Color";
}
return new ColorItem(colorId, label, color, colorName);
} | [
"private",
"ColorItem",
"buildColorItem",
"(",
"int",
"colorId",
",",
"String",
"label",
")",
"{",
"Color",
"color",
";",
"String",
"colorName",
";",
"switch",
"(",
"colorId",
")",
"{",
"case",
"0",
":",
"color",
"=",
"new",
"Color",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"colorName",
"=",
"\"No Color\"",
";",
"break",
";",
"case",
"1",
":",
"color",
"=",
"Color",
".",
"PINK",
";",
"colorName",
"=",
"\"Pink\"",
";",
"break",
";",
"case",
"2",
":",
"color",
"=",
"Color",
".",
"RED",
";",
"colorName",
"=",
"\"Red\"",
";",
"break",
";",
"case",
"3",
":",
"color",
"=",
"Color",
".",
"ORANGE",
";",
"colorName",
"=",
"\"Orange\"",
";",
"break",
";",
"case",
"4",
":",
"color",
"=",
"Color",
".",
"YELLOW",
";",
"colorName",
"=",
"\"Yellow\"",
";",
"break",
";",
"case",
"5",
":",
"color",
"=",
"Color",
".",
"GREEN",
";",
"colorName",
"=",
"\"Green\"",
";",
"break",
";",
"case",
"6",
":",
"color",
"=",
"Color",
".",
"CYAN",
";",
"colorName",
"=",
"\"Aqua\"",
";",
"break",
";",
"case",
"7",
":",
"color",
"=",
"Color",
".",
"BLUE",
";",
"colorName",
"=",
"\"Blue\"",
";",
"break",
";",
"case",
"8",
":",
"color",
"=",
"new",
"Color",
"(",
"128",
",",
"0",
",",
"128",
")",
";",
"colorName",
"=",
"\"Purple\"",
";",
"break",
";",
"default",
":",
"color",
"=",
"new",
"Color",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"colorName",
"=",
"\"Unknown Color\"",
";",
"}",
"return",
"new",
"ColorItem",
"(",
"colorId",
",",
"label",
",",
"color",
",",
"colorName",
")",
";",
"}"
] | Creates a color item that represents a color field fond for a track.
@param colorId the key of the color as found in the database
@param label the corresponding color label as found in the database (or sent in the dbserver message)
@return the color metadata field | [
"Creates",
"a",
"color",
"item",
"that",
"represents",
"a",
"color",
"field",
"fond",
"for",
"a",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L182-L227 |
163,858 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java | TrackMetadata.parseMetadataItem | private void parseMetadataItem(Message item) {
switch (item.getMenuItemType()) {
case TRACK_TITLE:
title = ((StringField) item.arguments.get(3)).getValue();
artworkId = (int) ((NumberField) item.arguments.get(8)).getValue();
break;
case ARTIST:
artist = buildSearchableItem(item);
break;
case ORIGINAL_ARTIST:
originalArtist = buildSearchableItem(item);
break;
case REMIXER:
remixer = buildSearchableItem(item);
case ALBUM_TITLE:
album = buildSearchableItem(item);
break;
case LABEL:
label = buildSearchableItem(item);
break;
case DURATION:
duration = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case TEMPO:
tempo = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case COMMENT:
comment = ((StringField) item.arguments.get(3)).getValue();
break;
case KEY:
key = buildSearchableItem(item);
break;
case RATING:
rating = (int) ((NumberField)item.arguments.get(1)).getValue();
break;
case COLOR_NONE:
case COLOR_AQUA:
case COLOR_BLUE:
case COLOR_GREEN:
case COLOR_ORANGE:
case COLOR_PINK:
case COLOR_PURPLE:
case COLOR_RED:
case COLOR_YELLOW:
color = buildColorItem(item);
break;
case GENRE:
genre = buildSearchableItem(item);
break;
case DATE_ADDED:
dateAdded = ((StringField) item.arguments.get(3)).getValue();
break;
case YEAR:
year = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case BIT_RATE:
bitRate = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
default:
logger.warn("Ignoring track metadata item with unknown type: {}", item);
}
} | java | private void parseMetadataItem(Message item) {
switch (item.getMenuItemType()) {
case TRACK_TITLE:
title = ((StringField) item.arguments.get(3)).getValue();
artworkId = (int) ((NumberField) item.arguments.get(8)).getValue();
break;
case ARTIST:
artist = buildSearchableItem(item);
break;
case ORIGINAL_ARTIST:
originalArtist = buildSearchableItem(item);
break;
case REMIXER:
remixer = buildSearchableItem(item);
case ALBUM_TITLE:
album = buildSearchableItem(item);
break;
case LABEL:
label = buildSearchableItem(item);
break;
case DURATION:
duration = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case TEMPO:
tempo = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case COMMENT:
comment = ((StringField) item.arguments.get(3)).getValue();
break;
case KEY:
key = buildSearchableItem(item);
break;
case RATING:
rating = (int) ((NumberField)item.arguments.get(1)).getValue();
break;
case COLOR_NONE:
case COLOR_AQUA:
case COLOR_BLUE:
case COLOR_GREEN:
case COLOR_ORANGE:
case COLOR_PINK:
case COLOR_PURPLE:
case COLOR_RED:
case COLOR_YELLOW:
color = buildColorItem(item);
break;
case GENRE:
genre = buildSearchableItem(item);
break;
case DATE_ADDED:
dateAdded = ((StringField) item.arguments.get(3)).getValue();
break;
case YEAR:
year = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
case BIT_RATE:
bitRate = (int) ((NumberField) item.arguments.get(1)).getValue();
break;
default:
logger.warn("Ignoring track metadata item with unknown type: {}", item);
}
} | [
"private",
"void",
"parseMetadataItem",
"(",
"Message",
"item",
")",
"{",
"switch",
"(",
"item",
".",
"getMenuItemType",
"(",
")",
")",
"{",
"case",
"TRACK_TITLE",
":",
"title",
"=",
"(",
"(",
"StringField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
";",
"artworkId",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"8",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"ARTIST",
":",
"artist",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"ORIGINAL_ARTIST",
":",
"originalArtist",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"REMIXER",
":",
"remixer",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"case",
"ALBUM_TITLE",
":",
"album",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"LABEL",
":",
"label",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"DURATION",
":",
"duration",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"TEMPO",
":",
"tempo",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"COMMENT",
":",
"comment",
"=",
"(",
"(",
"StringField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"KEY",
":",
"key",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"RATING",
":",
"rating",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"COLOR_NONE",
":",
"case",
"COLOR_AQUA",
":",
"case",
"COLOR_BLUE",
":",
"case",
"COLOR_GREEN",
":",
"case",
"COLOR_ORANGE",
":",
"case",
"COLOR_PINK",
":",
"case",
"COLOR_PURPLE",
":",
"case",
"COLOR_RED",
":",
"case",
"COLOR_YELLOW",
":",
"color",
"=",
"buildColorItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"GENRE",
":",
"genre",
"=",
"buildSearchableItem",
"(",
"item",
")",
";",
"break",
";",
"case",
"DATE_ADDED",
":",
"dateAdded",
"=",
"(",
"(",
"StringField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"3",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"YEAR",
":",
"year",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"case",
"BIT_RATE",
":",
"bitRate",
"=",
"(",
"int",
")",
"(",
"(",
"NumberField",
")",
"item",
".",
"arguments",
".",
"get",
"(",
"1",
")",
")",
".",
"getValue",
"(",
")",
";",
"break",
";",
"default",
":",
"logger",
".",
"warn",
"(",
"\"Ignoring track metadata item with unknown type: {}\"",
",",
"item",
")",
";",
"}",
"}"
] | Processes one of the menu responses that jointly constitute the track metadata, updating our
fields accordingly.
@param item the menu response to be considered | [
"Processes",
"one",
"of",
"the",
"menu",
"responses",
"that",
"jointly",
"constitute",
"the",
"track",
"metadata",
"updating",
"our",
"fields",
"accordingly",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/TrackMetadata.java#L350-L427 |
163,859 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.getRawData | @SuppressWarnings("WeakerAccess")
public ByteBuffer getRawData() {
if (rawData != null) {
rawData.rewind();
return rawData.slice();
}
return null;
} | java | @SuppressWarnings("WeakerAccess")
public ByteBuffer getRawData() {
if (rawData != null) {
rawData.rewind();
return rawData.slice();
}
return null;
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"ByteBuffer",
"getRawData",
"(",
")",
"{",
"if",
"(",
"rawData",
"!=",
"null",
")",
"{",
"rawData",
".",
"rewind",
"(",
")",
";",
"return",
"rawData",
".",
"slice",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the raw bytes of the beat grid as it was read over the network. This can be used to analyze fields
that have not yet been reliably understood, and is also used for storing the beat grid in a cache file.
This is not available when the beat grid was loaded by Crate Digger.
@return the bytes that make up the beat grid | [
"Get",
"the",
"raw",
"bytes",
"of",
"the",
"beat",
"grid",
"as",
"it",
"was",
"read",
"over",
"the",
"network",
".",
"This",
"can",
"be",
"used",
"to",
"analyze",
"fields",
"that",
"have",
"not",
"yet",
"been",
"reliably",
"understood",
"and",
"is",
"also",
"used",
"for",
"storing",
"the",
"beat",
"grid",
"in",
"a",
"cache",
"file",
".",
"This",
"is",
"not",
"available",
"when",
"the",
"beat",
"grid",
"was",
"loaded",
"by",
"Crate",
"Digger",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L37-L44 |
163,860 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.findTag | private RekordboxAnlz.BeatGridTag findTag(RekordboxAnlz anlzFile) {
for (RekordboxAnlz.TaggedSection section : anlzFile.sections()) {
if (section.body() instanceof RekordboxAnlz.BeatGridTag) {
return (RekordboxAnlz.BeatGridTag) section.body();
}
}
throw new IllegalArgumentException("No beat grid found inside analysis file " + anlzFile);
} | java | private RekordboxAnlz.BeatGridTag findTag(RekordboxAnlz anlzFile) {
for (RekordboxAnlz.TaggedSection section : anlzFile.sections()) {
if (section.body() instanceof RekordboxAnlz.BeatGridTag) {
return (RekordboxAnlz.BeatGridTag) section.body();
}
}
throw new IllegalArgumentException("No beat grid found inside analysis file " + anlzFile);
} | [
"private",
"RekordboxAnlz",
".",
"BeatGridTag",
"findTag",
"(",
"RekordboxAnlz",
"anlzFile",
")",
"{",
"for",
"(",
"RekordboxAnlz",
".",
"TaggedSection",
"section",
":",
"anlzFile",
".",
"sections",
"(",
")",
")",
"{",
"if",
"(",
"section",
".",
"body",
"(",
")",
"instanceof",
"RekordboxAnlz",
".",
"BeatGridTag",
")",
"{",
"return",
"(",
"RekordboxAnlz",
".",
"BeatGridTag",
")",
"section",
".",
"body",
"(",
")",
";",
"}",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No beat grid found inside analysis file \"",
"+",
"anlzFile",
")",
";",
"}"
] | Helper function to find the beat grid section in a rekordbox track analysis file.
@param anlzFile the file that was downloaded from the player
@return the section containing the beat grid | [
"Helper",
"function",
"to",
"find",
"the",
"beat",
"grid",
"section",
"in",
"a",
"rekordbox",
"track",
"analysis",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L101-L108 |
163,861 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.beatOffset | private int beatOffset(int beatNumber) {
if (beatCount == 0) {
throw new IllegalStateException("There are no beats in this beat grid.");
}
if (beatNumber < 1 || beatNumber > beatCount) {
throw new IndexOutOfBoundsException("beatNumber (" + beatNumber + ") must be between 1 and " + beatCount);
}
return beatNumber - 1;
} | java | private int beatOffset(int beatNumber) {
if (beatCount == 0) {
throw new IllegalStateException("There are no beats in this beat grid.");
}
if (beatNumber < 1 || beatNumber > beatCount) {
throw new IndexOutOfBoundsException("beatNumber (" + beatNumber + ") must be between 1 and " + beatCount);
}
return beatNumber - 1;
} | [
"private",
"int",
"beatOffset",
"(",
"int",
"beatNumber",
")",
"{",
"if",
"(",
"beatCount",
"==",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"There are no beats in this beat grid.\"",
")",
";",
"}",
"if",
"(",
"beatNumber",
"<",
"1",
"||",
"beatNumber",
">",
"beatCount",
")",
"{",
"throw",
"new",
"IndexOutOfBoundsException",
"(",
"\"beatNumber (\"",
"+",
"beatNumber",
"+",
"\") must be between 1 and \"",
"+",
"beatCount",
")",
";",
"}",
"return",
"beatNumber",
"-",
"1",
";",
"}"
] | Calculate where within the beat grid array the information for the specified beat can be found.
Yes, this is a super simple calculation; the main point of the method is to provide a nice exception
when the beat is out of bounds.
@param beatNumber the beat desired
@return the offset of the start of our cache arrays for information about that beat | [
"Calculate",
"where",
"within",
"the",
"beat",
"grid",
"array",
"the",
"information",
"for",
"the",
"specified",
"beat",
"can",
"be",
"found",
".",
"Yes",
"this",
"is",
"a",
"super",
"simple",
"calculation",
";",
"the",
"main",
"point",
"of",
"the",
"method",
"is",
"to",
"provide",
"a",
"nice",
"exception",
"when",
"the",
"beat",
"is",
"out",
"of",
"bounds",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L159-L167 |
163,862 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java | BeatGrid.findBeatAtTime | @SuppressWarnings("WeakerAccess")
public int findBeatAtTime(long milliseconds) {
int found = Arrays.binarySearch(timeWithinTrackValues, milliseconds);
if (found >= 0) { // An exact match, just change 0-based array index to 1-based beat number
return found + 1;
} else if (found == -1) { // We are before the first beat
return found;
} else { // We are after some beat, report its beat number
return -(found + 1);
}
} | java | @SuppressWarnings("WeakerAccess")
public int findBeatAtTime(long milliseconds) {
int found = Arrays.binarySearch(timeWithinTrackValues, milliseconds);
if (found >= 0) { // An exact match, just change 0-based array index to 1-based beat number
return found + 1;
} else if (found == -1) { // We are before the first beat
return found;
} else { // We are after some beat, report its beat number
return -(found + 1);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"int",
"findBeatAtTime",
"(",
"long",
"milliseconds",
")",
"{",
"int",
"found",
"=",
"Arrays",
".",
"binarySearch",
"(",
"timeWithinTrackValues",
",",
"milliseconds",
")",
";",
"if",
"(",
"found",
">=",
"0",
")",
"{",
"// An exact match, just change 0-based array index to 1-based beat number",
"return",
"found",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"found",
"==",
"-",
"1",
")",
"{",
"// We are before the first beat",
"return",
"found",
";",
"}",
"else",
"{",
"// We are after some beat, report its beat number",
"return",
"-",
"(",
"found",
"+",
"1",
")",
";",
"}",
"}"
] | Finds the beat in which the specified track position falls.
@param milliseconds how long the track has been playing
@return the beat number represented by that time, or -1 if the time is before the first beat | [
"Finds",
"the",
"beat",
"in",
"which",
"the",
"specified",
"track",
"position",
"falls",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/BeatGrid.java#L208-L218 |
163,863 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestTrackMenuFrom | public List<Message> requestTrackMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
return MetadataFinder.getInstance().getFullTrackList(slotReference.slot, client, sortOrder);
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting track menu");
} | java | public List<Message> requestTrackMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
return MetadataFinder.getInstance().getFullTrackList(slotReference.slot, client, sortOrder);
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting track menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestTrackMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">>",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"List",
"<",
"Message",
">",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"return",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getFullTrackList",
"(",
"slotReference",
".",
"slot",
",",
"client",
",",
"sortOrder",
")",
";",
"}",
"}",
";",
"return",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"slotReference",
".",
"player",
",",
"task",
",",
"\"requesting track menu\"",
")",
";",
"}"
] | Ask the specified player for a Track menu.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@return the entries in the track menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"a",
"Track",
"menu",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L179-L190 |
163,864 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestArtistMenuFrom | public List<Message> requestArtistMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Artist menu.");
Message response = client.menuRequest(Message.KnownType.ARTIST_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
new NumberField(sortOrder));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.REKORDBOX, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting artist menu");
} | java | public List<Message> requestArtistMenuFrom(final SlotReference slotReference, final int sortOrder)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Artist menu.");
Message response = client.menuRequest(Message.KnownType.ARTIST_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
new NumberField(sortOrder));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.REKORDBOX, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting artist menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestArtistMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">>",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"List",
"<",
"Message",
">",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"if",
"(",
"client",
".",
"tryLockingForMenuOperations",
"(",
"MetadataFinder",
".",
"MENU_TIMEOUT",
",",
"TimeUnit",
".",
"SECONDS",
")",
")",
"{",
"try",
"{",
"logger",
".",
"debug",
"(",
"\"Requesting Artist menu.\"",
")",
";",
"Message",
"response",
"=",
"client",
".",
"menuRequest",
"(",
"Message",
".",
"KnownType",
".",
"ARTIST_MENU_REQ",
",",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slotReference",
".",
"slot",
",",
"new",
"NumberField",
"(",
"sortOrder",
")",
")",
";",
"return",
"client",
".",
"renderMenuItems",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slotReference",
".",
"slot",
",",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
",",
"response",
")",
";",
"}",
"finally",
"{",
"client",
".",
"unlockForMenuOperations",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TimeoutException",
"(",
"\"Unable to lock player for menu operations.\"",
")",
";",
"}",
"}",
"}",
";",
"return",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"slotReference",
".",
"player",
",",
"task",
",",
"\"requesting artist menu\"",
")",
";",
"}"
] | Ask the specified player for an Artist menu.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@return the entries in the artist menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"an",
"Artist",
"menu",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L204-L226 |
163,865 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java | MenuLoader.requestFolderMenuFrom | public List<Message> requestFolderMenuFrom(final SlotReference slotReference, final int sortOrder, final int folderId)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Key menu.");
Message response = client.menuRequestTyped(Message.KnownType.FOLDER_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
CdjStatus.TrackType.UNANALYZED, new NumberField(sortOrder), new NumberField(folderId), new NumberField(0xffffff));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.UNANALYZED, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting folder menu");
} | java | public List<Message> requestFolderMenuFrom(final SlotReference slotReference, final int sortOrder, final int folderId)
throws Exception {
ConnectionManager.ClientTask<List<Message>> task = new ConnectionManager.ClientTask<List<Message>>() {
@Override
public List<Message> useClient(Client client) throws Exception {
if (client.tryLockingForMenuOperations(MetadataFinder.MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
logger.debug("Requesting Key menu.");
Message response = client.menuRequestTyped(Message.KnownType.FOLDER_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slotReference.slot,
CdjStatus.TrackType.UNANALYZED, new NumberField(sortOrder), new NumberField(folderId), new NumberField(0xffffff));
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slotReference.slot, CdjStatus.TrackType.UNANALYZED, response);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock player for menu operations.");
}
}
};
return ConnectionManager.getInstance().invokeWithClientSession(slotReference.player, task, "requesting folder menu");
} | [
"public",
"List",
"<",
"Message",
">",
"requestFolderMenuFrom",
"(",
"final",
"SlotReference",
"slotReference",
",",
"final",
"int",
"sortOrder",
",",
"final",
"int",
"folderId",
")",
"throws",
"Exception",
"{",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">>",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"List",
"<",
"Message",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"List",
"<",
"Message",
">",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"if",
"(",
"client",
".",
"tryLockingForMenuOperations",
"(",
"MetadataFinder",
".",
"MENU_TIMEOUT",
",",
"TimeUnit",
".",
"SECONDS",
")",
")",
"{",
"try",
"{",
"logger",
".",
"debug",
"(",
"\"Requesting Key menu.\"",
")",
";",
"Message",
"response",
"=",
"client",
".",
"menuRequestTyped",
"(",
"Message",
".",
"KnownType",
".",
"FOLDER_MENU_REQ",
",",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slotReference",
".",
"slot",
",",
"CdjStatus",
".",
"TrackType",
".",
"UNANALYZED",
",",
"new",
"NumberField",
"(",
"sortOrder",
")",
",",
"new",
"NumberField",
"(",
"folderId",
")",
",",
"new",
"NumberField",
"(",
"0xffffff",
")",
")",
";",
"return",
"client",
".",
"renderMenuItems",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slotReference",
".",
"slot",
",",
"CdjStatus",
".",
"TrackType",
".",
"UNANALYZED",
",",
"response",
")",
";",
"}",
"finally",
"{",
"client",
".",
"unlockForMenuOperations",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TimeoutException",
"(",
"\"Unable to lock player for menu operations.\"",
")",
";",
"}",
"}",
"}",
";",
"return",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"slotReference",
".",
"player",
",",
"task",
",",
"\"requesting folder menu\"",
")",
";",
"}"
] | Ask the specified player for a Folder menu for exploring its raw filesystem.
This is a request for unanalyzed items, so we do a typed menu request.
@param slotReference the player and slot for which the menu is desired
@param sortOrder the order in which responses should be sorted, 0 for default, see Section 6.11.1 of the
<a href="https://github.com/Deep-Symmetry/dysentery/blob/master/doc/Analysis.pdf">Packet Analysis
document</a> for details
@param folderId identifies the folder whose contents should be listed, use -1 to get the root folder
@return the entries in the folder menu
@throws Exception if there is a problem obtaining the menu | [
"Ask",
"the",
"specified",
"player",
"for",
"a",
"Folder",
"menu",
"for",
"exploring",
"its",
"raw",
"filesystem",
".",
"This",
"is",
"a",
"request",
"for",
"unanalyzed",
"items",
"so",
"we",
"do",
"a",
"typed",
"menu",
"request",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MenuLoader.java#L1575-L1597 |
163,866 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java | Field.read | public static Field read(DataInputStream is) throws IOException {
final byte tag = is.readByte();
final Field result;
switch (tag) {
case 0x0f:
case 0x10:
case 0x11:
result = new NumberField(tag, is);
break;
case 0x14:
result = new BinaryField(is);
break;
case 0x26:
result = new StringField(is);
break;
default:
throw new IOException("Unable to read a field with type tag " + tag);
}
logger.debug("..received> {}", result);
return result;
} | java | public static Field read(DataInputStream is) throws IOException {
final byte tag = is.readByte();
final Field result;
switch (tag) {
case 0x0f:
case 0x10:
case 0x11:
result = new NumberField(tag, is);
break;
case 0x14:
result = new BinaryField(is);
break;
case 0x26:
result = new StringField(is);
break;
default:
throw new IOException("Unable to read a field with type tag " + tag);
}
logger.debug("..received> {}", result);
return result;
} | [
"public",
"static",
"Field",
"read",
"(",
"DataInputStream",
"is",
")",
"throws",
"IOException",
"{",
"final",
"byte",
"tag",
"=",
"is",
".",
"readByte",
"(",
")",
";",
"final",
"Field",
"result",
";",
"switch",
"(",
"tag",
")",
"{",
"case",
"0x0f",
":",
"case",
"0x10",
":",
"case",
"0x11",
":",
"result",
"=",
"new",
"NumberField",
"(",
"tag",
",",
"is",
")",
";",
"break",
";",
"case",
"0x14",
":",
"result",
"=",
"new",
"BinaryField",
"(",
"is",
")",
";",
"break",
";",
"case",
"0x26",
":",
"result",
"=",
"new",
"StringField",
"(",
"is",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IOException",
"(",
"\"Unable to read a field with type tag \"",
"+",
"tag",
")",
";",
"}",
"logger",
".",
"debug",
"(",
"\"..received> {}\"",
",",
"result",
")",
";",
"return",
"result",
";",
"}"
] | Read a field from the supplied stream, starting with the tag that identifies the type, and reading enough
to collect the corresponding value.
@param is the stream on which a type tag is expected to be the next byte, followed by the field value.
@return the field that was found on the stream.
@throws IOException if there is a problem reading the field. | [
"Read",
"a",
"field",
"from",
"the",
"supplied",
"stream",
"starting",
"with",
"the",
"tag",
"that",
"identifies",
"the",
"type",
"and",
"reading",
"enough",
"to",
"collect",
"the",
"corresponding",
"value",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java#L63-L87 |
163,867 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java | Field.write | public void write(WritableByteChannel channel) throws IOException {
logger.debug("..writing> {}", this);
Util.writeFully(getBytes(), channel);
} | java | public void write(WritableByteChannel channel) throws IOException {
logger.debug("..writing> {}", this);
Util.writeFully(getBytes(), channel);
} | [
"public",
"void",
"write",
"(",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"..writing> {}\"",
",",
"this",
")",
";",
"Util",
".",
"writeFully",
"(",
"getBytes",
"(",
")",
",",
"channel",
")",
";",
"}"
] | Write the field to the specified channel.
@param channel the channel to which it should be written
@throws IOException if there is a problem writing to the channel | [
"Write",
"the",
"field",
"to",
"the",
"specified",
"channel",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/dbserver/Field.java#L113-L116 |
163,868 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataFrom | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final CdjStatus status) {
if (status.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK || status.getRekordboxId() == 0) {
return null;
}
final DataReference track = new DataReference(status.getTrackSourcePlayer(), status.getTrackSourceSlot(),
status.getRekordboxId());
return requestMetadataFrom(track, status.getTrackType());
} | java | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final CdjStatus status) {
if (status.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK || status.getRekordboxId() == 0) {
return null;
}
final DataReference track = new DataReference(status.getTrackSourcePlayer(), status.getTrackSourceSlot(),
status.getRekordboxId());
return requestMetadataFrom(track, status.getTrackType());
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"TrackMetadata",
"requestMetadataFrom",
"(",
"final",
"CdjStatus",
"status",
")",
"{",
"if",
"(",
"status",
".",
"getTrackSourceSlot",
"(",
")",
"==",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"NO_TRACK",
"||",
"status",
".",
"getRekordboxId",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"final",
"DataReference",
"track",
"=",
"new",
"DataReference",
"(",
"status",
".",
"getTrackSourcePlayer",
"(",
")",
",",
"status",
".",
"getTrackSourceSlot",
"(",
")",
",",
"status",
".",
"getRekordboxId",
"(",
")",
")",
";",
"return",
"requestMetadataFrom",
"(",
"track",
",",
"status",
".",
"getTrackType",
"(",
")",
")",
";",
"}"
] | Given a status update from a CDJ, find the metadata for the track that it has loaded, if any. If there is
an appropriate metadata cache, will use that, otherwise makes a query to the players dbserver.
@param status the CDJ status update that will be used to determine the loaded track and ask the appropriate
player for metadata about it
@return the metadata that was obtained, if any | [
"Given",
"a",
"status",
"update",
"from",
"a",
"CDJ",
"find",
"the",
"metadata",
"for",
"the",
"track",
"that",
"it",
"has",
"loaded",
"if",
"any",
".",
"If",
"there",
"is",
"an",
"appropriate",
"metadata",
"cache",
"will",
"use",
"that",
"otherwise",
"makes",
"a",
"query",
"to",
"the",
"players",
"dbserver",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L52-L60 |
163,869 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataFrom | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final DataReference track, final CdjStatus.TrackType trackType) {
return requestMetadataInternal(track, trackType, false);
} | java | @SuppressWarnings("WeakerAccess")
public TrackMetadata requestMetadataFrom(final DataReference track, final CdjStatus.TrackType trackType) {
return requestMetadataInternal(track, trackType, false);
} | [
"@",
"SuppressWarnings",
"(",
"\"WeakerAccess\"",
")",
"public",
"TrackMetadata",
"requestMetadataFrom",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
")",
"{",
"return",
"requestMetadataInternal",
"(",
"track",
",",
"trackType",
",",
"false",
")",
";",
"}"
] | Ask the specified player for metadata about the track in the specified slot with the specified rekordbox ID,
unless we have a metadata cache available for the specified media slot, in which case that will be used instead.
@param track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@return the metadata, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"metadata",
"about",
"the",
"track",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"unless",
"we",
"have",
"a",
"metadata",
"cache",
"available",
"for",
"the",
"specified",
"media",
"slot",
"in",
"which",
"case",
"that",
"will",
"be",
"used",
"instead",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L73-L76 |
163,870 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.requestMetadataInternal | private TrackMetadata requestMetadataInternal(final DataReference track, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this request.
MetadataCache cache = getMetadataCache(SlotReference.getSlotReference(track));
if (cache != null && trackType == CdjStatus.TrackType.REKORDBOX) {
return cache.getTrackMetadata(null, track);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = getMediaDetailsFor(track.getSlotReference());
if (sourceDetails != null) {
final TrackMetadata provided = allMetadataProviders.getTrackMetadata(sourceDetails, track);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (passive.get() && failIfPassive && track.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// Use the dbserver protocol implementation to request the metadata.
ConnectionManager.ClientTask<TrackMetadata> task = new ConnectionManager.ClientTask<TrackMetadata>() {
@Override
public TrackMetadata useClient(Client client) throws Exception {
return queryMetadata(track, trackType, client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(track.player, task, "requesting metadata");
} catch (Exception e) {
logger.error("Problem requesting metadata, returning null", e);
}
return null;
} | java | private TrackMetadata requestMetadataInternal(final DataReference track, final CdjStatus.TrackType trackType,
final boolean failIfPassive) {
// First check if we are using cached data for this request.
MetadataCache cache = getMetadataCache(SlotReference.getSlotReference(track));
if (cache != null && trackType == CdjStatus.TrackType.REKORDBOX) {
return cache.getTrackMetadata(null, track);
}
// Then see if any registered metadata providers can offer it for us.
final MediaDetails sourceDetails = getMediaDetailsFor(track.getSlotReference());
if (sourceDetails != null) {
final TrackMetadata provided = allMetadataProviders.getTrackMetadata(sourceDetails, track);
if (provided != null) {
return provided;
}
}
// At this point, unless we are allowed to actively request the data, we are done. We can always actively
// request tracks from rekordbox.
if (passive.get() && failIfPassive && track.slot != CdjStatus.TrackSourceSlot.COLLECTION) {
return null;
}
// Use the dbserver protocol implementation to request the metadata.
ConnectionManager.ClientTask<TrackMetadata> task = new ConnectionManager.ClientTask<TrackMetadata>() {
@Override
public TrackMetadata useClient(Client client) throws Exception {
return queryMetadata(track, trackType, client);
}
};
try {
return ConnectionManager.getInstance().invokeWithClientSession(track.player, task, "requesting metadata");
} catch (Exception e) {
logger.error("Problem requesting metadata, returning null", e);
}
return null;
} | [
"private",
"TrackMetadata",
"requestMetadataInternal",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"final",
"boolean",
"failIfPassive",
")",
"{",
"// First check if we are using cached data for this request.",
"MetadataCache",
"cache",
"=",
"getMetadataCache",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"track",
")",
")",
";",
"if",
"(",
"cache",
"!=",
"null",
"&&",
"trackType",
"==",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
")",
"{",
"return",
"cache",
".",
"getTrackMetadata",
"(",
"null",
",",
"track",
")",
";",
"}",
"// Then see if any registered metadata providers can offer it for us.",
"final",
"MediaDetails",
"sourceDetails",
"=",
"getMediaDetailsFor",
"(",
"track",
".",
"getSlotReference",
"(",
")",
")",
";",
"if",
"(",
"sourceDetails",
"!=",
"null",
")",
"{",
"final",
"TrackMetadata",
"provided",
"=",
"allMetadataProviders",
".",
"getTrackMetadata",
"(",
"sourceDetails",
",",
"track",
")",
";",
"if",
"(",
"provided",
"!=",
"null",
")",
"{",
"return",
"provided",
";",
"}",
"}",
"// At this point, unless we are allowed to actively request the data, we are done. We can always actively",
"// request tracks from rekordbox.",
"if",
"(",
"passive",
".",
"get",
"(",
")",
"&&",
"failIfPassive",
"&&",
"track",
".",
"slot",
"!=",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"COLLECTION",
")",
"{",
"return",
"null",
";",
"}",
"// Use the dbserver protocol implementation to request the metadata.",
"ConnectionManager",
".",
"ClientTask",
"<",
"TrackMetadata",
">",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"TrackMetadata",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"TrackMetadata",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"return",
"queryMetadata",
"(",
"track",
",",
"trackType",
",",
"client",
")",
";",
"}",
"}",
";",
"try",
"{",
"return",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"track",
".",
"player",
",",
"task",
",",
"\"requesting metadata\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem requesting metadata, returning null\"",
",",
"e",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Ask the specified player for metadata about the track in the specified slot with the specified rekordbox ID,
using cached media instead if it is available, and possibly giving up if we are in passive mode.
@param track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@param failIfPassive will prevent the request from taking place if we are in passive mode, so that automatic
metadata updates will use available caches only
@return the metadata found, if any | [
"Ask",
"the",
"specified",
"player",
"for",
"metadata",
"about",
"the",
"track",
"in",
"the",
"specified",
"slot",
"with",
"the",
"specified",
"rekordbox",
"ID",
"using",
"cached",
"media",
"instead",
"if",
"it",
"is",
"available",
"and",
"possibly",
"giving",
"up",
"if",
"we",
"are",
"in",
"passive",
"mode",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L90-L127 |
163,871 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.queryMetadata | TrackMetadata queryMetadata(final DataReference track, final CdjStatus.TrackType trackType, final Client client)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(20, TimeUnit.SECONDS)) {
try {
final Message.KnownType requestType = (trackType == CdjStatus.TrackType.REKORDBOX) ?
Message.KnownType.REKORDBOX_METADATA_REQ : Message.KnownType.UNANALYZED_METADATA_REQ;
final Message response = client.menuRequestTyped(requestType, Message.MenuIdentifier.MAIN_MENU,
track.slot, trackType, new NumberField(track.rekordboxId));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE) {
return null;
}
// Gather the cue list and all the metadata menu items
final List<Message> items = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, track.slot, trackType, response);
final CueList cueList = getCueList(track.rekordboxId, track.slot, client);
return new TrackMetadata(track, trackType, items, cueList);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | java | TrackMetadata queryMetadata(final DataReference track, final CdjStatus.TrackType trackType, final Client client)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(20, TimeUnit.SECONDS)) {
try {
final Message.KnownType requestType = (trackType == CdjStatus.TrackType.REKORDBOX) ?
Message.KnownType.REKORDBOX_METADATA_REQ : Message.KnownType.UNANALYZED_METADATA_REQ;
final Message response = client.menuRequestTyped(requestType, Message.MenuIdentifier.MAIN_MENU,
track.slot, trackType, new NumberField(track.rekordboxId));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE) {
return null;
}
// Gather the cue list and all the metadata menu items
final List<Message> items = client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, track.slot, trackType, response);
final CueList cueList = getCueList(track.rekordboxId, track.slot, client);
return new TrackMetadata(track, trackType, items, cueList);
} finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | [
"TrackMetadata",
"queryMetadata",
"(",
"final",
"DataReference",
"track",
",",
"final",
"CdjStatus",
".",
"TrackType",
"trackType",
",",
"final",
"Client",
"client",
")",
"throws",
"IOException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"// Send the metadata menu request",
"if",
"(",
"client",
".",
"tryLockingForMenuOperations",
"(",
"20",
",",
"TimeUnit",
".",
"SECONDS",
")",
")",
"{",
"try",
"{",
"final",
"Message",
".",
"KnownType",
"requestType",
"=",
"(",
"trackType",
"==",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
")",
"?",
"Message",
".",
"KnownType",
".",
"REKORDBOX_METADATA_REQ",
":",
"Message",
".",
"KnownType",
".",
"UNANALYZED_METADATA_REQ",
";",
"final",
"Message",
"response",
"=",
"client",
".",
"menuRequestTyped",
"(",
"requestType",
",",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"track",
".",
"slot",
",",
"trackType",
",",
"new",
"NumberField",
"(",
"track",
".",
"rekordboxId",
")",
")",
";",
"final",
"long",
"count",
"=",
"response",
".",
"getMenuResultsCount",
"(",
")",
";",
"if",
"(",
"count",
"==",
"Message",
".",
"NO_MENU_RESULTS_AVAILABLE",
")",
"{",
"return",
"null",
";",
"}",
"// Gather the cue list and all the metadata menu items",
"final",
"List",
"<",
"Message",
">",
"items",
"=",
"client",
".",
"renderMenuItems",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"track",
".",
"slot",
",",
"trackType",
",",
"response",
")",
";",
"final",
"CueList",
"cueList",
"=",
"getCueList",
"(",
"track",
".",
"rekordboxId",
",",
"track",
".",
"slot",
",",
"client",
")",
";",
"return",
"new",
"TrackMetadata",
"(",
"track",
",",
"trackType",
",",
"items",
",",
"cueList",
")",
";",
"}",
"finally",
"{",
"client",
".",
"unlockForMenuOperations",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TimeoutException",
"(",
"\"Unable to lock the player for menu operations\"",
")",
";",
"}",
"}"
] | Request metadata for a specific track ID, given a dbserver connection to a player that has already been set up.
Separated into its own method so it could be used multiple times with the same connection when gathering
all track metadata.
@param track uniquely identifies the track whose metadata is desired
@param trackType identifies the type of track being requested, which affects the type of metadata request
message that must be used
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved metadata, or {@code null} if there is no such track
@throws IOException if there is a communication problem
@throws InterruptedException if the thread is interrupted while trying to lock the client for menu operations
@throws TimeoutException if we are unable to lock the client for menu operations | [
"Request",
"metadata",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"dbserver",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
".",
"Separated",
"into",
"its",
"own",
"method",
"so",
"it",
"could",
"be",
"used",
"multiple",
"times",
"with",
"the",
"same",
"connection",
"when",
"gathering",
"all",
"track",
"metadata",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L150-L175 |
163,872 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getCueList | CueList getCueList(int rekordboxId, CdjStatus.TrackSourceSlot slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.CUE_LIST_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.CUE_LIST) {
return new CueList(response);
}
logger.error("Unexpected response type when requesting cue list: {}", response);
return null;
} | java | CueList getCueList(int rekordboxId, CdjStatus.TrackSourceSlot slot, Client client)
throws IOException {
Message response = client.simpleRequest(Message.KnownType.CUE_LIST_REQ, null,
client.buildRMST(Message.MenuIdentifier.DATA, slot), new NumberField(rekordboxId));
if (response.knownType == Message.KnownType.CUE_LIST) {
return new CueList(response);
}
logger.error("Unexpected response type when requesting cue list: {}", response);
return null;
} | [
"CueList",
"getCueList",
"(",
"int",
"rekordboxId",
",",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"Client",
"client",
")",
"throws",
"IOException",
"{",
"Message",
"response",
"=",
"client",
".",
"simpleRequest",
"(",
"Message",
".",
"KnownType",
".",
"CUE_LIST_REQ",
",",
"null",
",",
"client",
".",
"buildRMST",
"(",
"Message",
".",
"MenuIdentifier",
".",
"DATA",
",",
"slot",
")",
",",
"new",
"NumberField",
"(",
"rekordboxId",
")",
")",
";",
"if",
"(",
"response",
".",
"knownType",
"==",
"Message",
".",
"KnownType",
".",
"CUE_LIST",
")",
"{",
"return",
"new",
"CueList",
"(",
"response",
")",
";",
"}",
"logger",
".",
"error",
"(",
"\"Unexpected response type when requesting cue list: {}\"",
",",
"response",
")",
";",
"return",
"null",
";",
"}"
] | Requests the cue list for a specific track ID, given a dbserver connection to a player that has already
been set up.
@param rekordboxId the track of interest
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved cue list, or {@code null} if none was available
@throws IOException if there is a communication problem | [
"Requests",
"the",
"cue",
"list",
"for",
"a",
"specific",
"track",
"ID",
"given",
"a",
"dbserver",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L188-L197 |
163,873 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getFullTrackList | List<Message> getFullTrackList(final CdjStatus.TrackSourceSlot slot, final Client client, final int sortOrder)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
Message response = client.menuRequest(Message.KnownType.TRACK_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slot,
new NumberField(sortOrder));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE || count == 0) {
return Collections.emptyList();
}
// Gather all the metadata menu items
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot, CdjStatus.TrackType.REKORDBOX, response);
}
finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | java | List<Message> getFullTrackList(final CdjStatus.TrackSourceSlot slot, final Client client, final int sortOrder)
throws IOException, InterruptedException, TimeoutException {
// Send the metadata menu request
if (client.tryLockingForMenuOperations(MENU_TIMEOUT, TimeUnit.SECONDS)) {
try {
Message response = client.menuRequest(Message.KnownType.TRACK_MENU_REQ, Message.MenuIdentifier.MAIN_MENU, slot,
new NumberField(sortOrder));
final long count = response.getMenuResultsCount();
if (count == Message.NO_MENU_RESULTS_AVAILABLE || count == 0) {
return Collections.emptyList();
}
// Gather all the metadata menu items
return client.renderMenuItems(Message.MenuIdentifier.MAIN_MENU, slot, CdjStatus.TrackType.REKORDBOX, response);
}
finally {
client.unlockForMenuOperations();
}
} else {
throw new TimeoutException("Unable to lock the player for menu operations");
}
} | [
"List",
"<",
"Message",
">",
"getFullTrackList",
"(",
"final",
"CdjStatus",
".",
"TrackSourceSlot",
"slot",
",",
"final",
"Client",
"client",
",",
"final",
"int",
"sortOrder",
")",
"throws",
"IOException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"// Send the metadata menu request",
"if",
"(",
"client",
".",
"tryLockingForMenuOperations",
"(",
"MENU_TIMEOUT",
",",
"TimeUnit",
".",
"SECONDS",
")",
")",
"{",
"try",
"{",
"Message",
"response",
"=",
"client",
".",
"menuRequest",
"(",
"Message",
".",
"KnownType",
".",
"TRACK_MENU_REQ",
",",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
",",
"new",
"NumberField",
"(",
"sortOrder",
")",
")",
";",
"final",
"long",
"count",
"=",
"response",
".",
"getMenuResultsCount",
"(",
")",
";",
"if",
"(",
"count",
"==",
"Message",
".",
"NO_MENU_RESULTS_AVAILABLE",
"||",
"count",
"==",
"0",
")",
"{",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}",
"// Gather all the metadata menu items",
"return",
"client",
".",
"renderMenuItems",
"(",
"Message",
".",
"MenuIdentifier",
".",
"MAIN_MENU",
",",
"slot",
",",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
",",
"response",
")",
";",
"}",
"finally",
"{",
"client",
".",
"unlockForMenuOperations",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TimeoutException",
"(",
"\"Unable to lock the player for menu operations\"",
")",
";",
"}",
"}"
] | Request the list of all tracks in the specified slot, given a dbserver connection to a player that has already
been set up.
@param slot identifies the media slot we are querying
@param client the dbserver client that is communicating with the appropriate player
@return the retrieved track list entry items
@throws IOException if there is a communication problem
@throws InterruptedException if the thread is interrupted while trying to lock the client for menu operations
@throws TimeoutException if we are unable to lock the client for menu operations | [
"Request",
"the",
"list",
"of",
"all",
"tracks",
"in",
"the",
"specified",
"slot",
"given",
"a",
"dbserver",
"connection",
"to",
"a",
"player",
"that",
"has",
"already",
"been",
"set",
"up",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L212-L233 |
163,874 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.clearDeck | private void clearDeck(CdjStatus update) {
if (hotCache.remove(DeckReference.getDeckReference(update.getDeviceNumber(), 0)) != null) {
deliverTrackMetadataUpdate(update.getDeviceNumber(), null);
}
} | java | private void clearDeck(CdjStatus update) {
if (hotCache.remove(DeckReference.getDeckReference(update.getDeviceNumber(), 0)) != null) {
deliverTrackMetadataUpdate(update.getDeviceNumber(), null);
}
} | [
"private",
"void",
"clearDeck",
"(",
"CdjStatus",
"update",
")",
"{",
"if",
"(",
"hotCache",
".",
"remove",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"0",
")",
")",
"!=",
"null",
")",
"{",
"deliverTrackMetadataUpdate",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"null",
")",
";",
"}",
"}"
] | We have received an update that invalidates any previous metadata for that player, so clear it out, and alert
any listeners if this represents a change. This does not affect the hot cues; they will stick around until the
player loads a new track that overwrites one or more of them.
@param update the update which means we can have no metadata for the associated player | [
"We",
"have",
"received",
"an",
"update",
"that",
"invalidates",
"any",
"previous",
"metadata",
"for",
"that",
"player",
"so",
"clear",
"it",
"out",
"and",
"alert",
"any",
"listeners",
"if",
"this",
"represents",
"a",
"change",
".",
"This",
"does",
"not",
"affect",
"the",
"hot",
"cues",
";",
"they",
"will",
"stick",
"around",
"until",
"the",
"player",
"loads",
"a",
"new",
"track",
"that",
"overwrites",
"one",
"or",
"more",
"of",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L432-L436 |
163,875 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.clearMetadata | private void clearMetadata(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverTrackMetadataUpdate(player, null); // Inform listeners the metadata is gone.
}
}
}
} | java | private void clearMetadata(DeviceAnnouncement announcement) {
final int player = announcement.getNumber();
// Iterate over a copy to avoid concurrent modification issues
for (DeckReference deck : new HashSet<DeckReference>(hotCache.keySet())) {
if (deck.player == player) {
hotCache.remove(deck);
if (deck.hotCue == 0) {
deliverTrackMetadataUpdate(player, null); // Inform listeners the metadata is gone.
}
}
}
} | [
"private",
"void",
"clearMetadata",
"(",
"DeviceAnnouncement",
"announcement",
")",
"{",
"final",
"int",
"player",
"=",
"announcement",
".",
"getNumber",
"(",
")",
";",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"DeckReference",
"deck",
":",
"new",
"HashSet",
"<",
"DeckReference",
">",
"(",
"hotCache",
".",
"keySet",
"(",
")",
")",
")",
"{",
"if",
"(",
"deck",
".",
"player",
"==",
"player",
")",
"{",
"hotCache",
".",
"remove",
"(",
"deck",
")",
";",
"if",
"(",
"deck",
".",
"hotCue",
"==",
"0",
")",
"{",
"deliverTrackMetadataUpdate",
"(",
"player",
",",
"null",
")",
";",
"// Inform listeners the metadata is gone.",
"}",
"}",
"}",
"}"
] | We have received notification that a device is no longer on the network, so clear out its metadata.
@param announcement the packet which reported the device’s disappearance | [
"We",
"have",
"received",
"notification",
"that",
"a",
"device",
"is",
"no",
"longer",
"on",
"the",
"network",
"so",
"clear",
"out",
"its",
"metadata",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L443-L454 |
163,876 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.updateMetadata | private void updateMetadata(CdjStatus update, TrackMetadata data) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), 0), data); // Main deck
if (data.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : data.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), entry.hotCueNumber), data);
}
}
}
deliverTrackMetadataUpdate(update.getDeviceNumber(), data);
} | java | private void updateMetadata(CdjStatus update, TrackMetadata data) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), 0), data); // Main deck
if (data.getCueList() != null) { // Update the cache with any hot cues in this track as well
for (CueList.Entry entry : data.getCueList().entries) {
if (entry.hotCueNumber != 0) {
hotCache.put(DeckReference.getDeckReference(update.getDeviceNumber(), entry.hotCueNumber), data);
}
}
}
deliverTrackMetadataUpdate(update.getDeviceNumber(), data);
} | [
"private",
"void",
"updateMetadata",
"(",
"CdjStatus",
"update",
",",
"TrackMetadata",
"data",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"0",
")",
",",
"data",
")",
";",
"// Main deck",
"if",
"(",
"data",
".",
"getCueList",
"(",
")",
"!=",
"null",
")",
"{",
"// Update the cache with any hot cues in this track as well",
"for",
"(",
"CueList",
".",
"Entry",
"entry",
":",
"data",
".",
"getCueList",
"(",
")",
".",
"entries",
")",
"{",
"if",
"(",
"entry",
".",
"hotCueNumber",
"!=",
"0",
")",
"{",
"hotCache",
".",
"put",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"entry",
".",
"hotCueNumber",
")",
",",
"data",
")",
";",
"}",
"}",
"}",
"deliverTrackMetadataUpdate",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"data",
")",
";",
"}"
] | We have obtained metadata for a device, so store it and alert any listeners.
@param update the update which caused us to retrieve this metadata
@param data the metadata which we received | [
"We",
"have",
"obtained",
"metadata",
"for",
"a",
"device",
"so",
"store",
"it",
"and",
"alert",
"any",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L462-L472 |
163,877 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getLoadedTracks | public Map<DeckReference, TrackMetadata> getLoadedTracks() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, TrackMetadata>(hotCache));
} | java | public Map<DeckReference, TrackMetadata> getLoadedTracks() {
ensureRunning();
// Make a copy so callers get an immutable snapshot of the current state.
return Collections.unmodifiableMap(new HashMap<DeckReference, TrackMetadata>(hotCache));
} | [
"public",
"Map",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"getLoadedTracks",
"(",
")",
"{",
"ensureRunning",
"(",
")",
";",
"// Make a copy so callers get an immutable snapshot of the current state.",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"new",
"HashMap",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"(",
"hotCache",
")",
")",
";",
"}"
] | Get the metadata of all tracks currently loaded in any player, either on the play deck, or in a hot cue.
@return the track information reported by all current players, including any tracks loaded in their hot cue slots
@throws IllegalStateException if the MetadataFinder is not running | [
"Get",
"the",
"metadata",
"of",
"all",
"tracks",
"currently",
"loaded",
"in",
"any",
"player",
"either",
"on",
"the",
"play",
"deck",
"or",
"in",
"a",
"hot",
"cue",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L481-L485 |
163,878 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.attachMetadataCache | public void attachMetadataCache(SlotReference slot, File file)
throws IOException {
ensureRunning();
if (slot.player < 1 || slot.player > 4 || DeviceFinder.getInstance().getLatestAnnouncementFrom(slot.player) == null) {
throw new IllegalArgumentException("unable to attach metadata cache for player " + slot.player);
}
if ((slot.slot != CdjStatus.TrackSourceSlot.USB_SLOT) && (slot.slot != CdjStatus.TrackSourceSlot.SD_SLOT)) {
throw new IllegalArgumentException("unable to attach metadata cache for slot " + slot.slot);
}
MetadataCache cache = new MetadataCache(file);
final MediaDetails slotDetails = getMediaDetailsFor(slot);
if (cache.sourceMedia != null && slotDetails != null) {
if (!slotDetails.hashKey().equals(cache.sourceMedia.hashKey())) {
throw new IllegalArgumentException("Cache was created for different media (" + cache.sourceMedia.hashKey() +
") than is in the slot (" + slotDetails.hashKey() + ").");
}
if (slotDetails.hasChanged(cache.sourceMedia)) {
logger.warn("Media has changed (" + slotDetails + ") since cache was created (" + cache.sourceMedia +
"). Attaching anyway as instructed.");
}
}
attachMetadataCacheInternal(slot, cache);
} | java | public void attachMetadataCache(SlotReference slot, File file)
throws IOException {
ensureRunning();
if (slot.player < 1 || slot.player > 4 || DeviceFinder.getInstance().getLatestAnnouncementFrom(slot.player) == null) {
throw new IllegalArgumentException("unable to attach metadata cache for player " + slot.player);
}
if ((slot.slot != CdjStatus.TrackSourceSlot.USB_SLOT) && (slot.slot != CdjStatus.TrackSourceSlot.SD_SLOT)) {
throw new IllegalArgumentException("unable to attach metadata cache for slot " + slot.slot);
}
MetadataCache cache = new MetadataCache(file);
final MediaDetails slotDetails = getMediaDetailsFor(slot);
if (cache.sourceMedia != null && slotDetails != null) {
if (!slotDetails.hashKey().equals(cache.sourceMedia.hashKey())) {
throw new IllegalArgumentException("Cache was created for different media (" + cache.sourceMedia.hashKey() +
") than is in the slot (" + slotDetails.hashKey() + ").");
}
if (slotDetails.hasChanged(cache.sourceMedia)) {
logger.warn("Media has changed (" + slotDetails + ") since cache was created (" + cache.sourceMedia +
"). Attaching anyway as instructed.");
}
}
attachMetadataCacheInternal(slot, cache);
} | [
"public",
"void",
"attachMetadataCache",
"(",
"SlotReference",
"slot",
",",
"File",
"file",
")",
"throws",
"IOException",
"{",
"ensureRunning",
"(",
")",
";",
"if",
"(",
"slot",
".",
"player",
"<",
"1",
"||",
"slot",
".",
"player",
">",
"4",
"||",
"DeviceFinder",
".",
"getInstance",
"(",
")",
".",
"getLatestAnnouncementFrom",
"(",
"slot",
".",
"player",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"unable to attach metadata cache for player \"",
"+",
"slot",
".",
"player",
")",
";",
"}",
"if",
"(",
"(",
"slot",
".",
"slot",
"!=",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"USB_SLOT",
")",
"&&",
"(",
"slot",
".",
"slot",
"!=",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"SD_SLOT",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"unable to attach metadata cache for slot \"",
"+",
"slot",
".",
"slot",
")",
";",
"}",
"MetadataCache",
"cache",
"=",
"new",
"MetadataCache",
"(",
"file",
")",
";",
"final",
"MediaDetails",
"slotDetails",
"=",
"getMediaDetailsFor",
"(",
"slot",
")",
";",
"if",
"(",
"cache",
".",
"sourceMedia",
"!=",
"null",
"&&",
"slotDetails",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"slotDetails",
".",
"hashKey",
"(",
")",
".",
"equals",
"(",
"cache",
".",
"sourceMedia",
".",
"hashKey",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cache was created for different media (\"",
"+",
"cache",
".",
"sourceMedia",
".",
"hashKey",
"(",
")",
"+",
"\") than is in the slot (\"",
"+",
"slotDetails",
".",
"hashKey",
"(",
")",
"+",
"\").\"",
")",
";",
"}",
"if",
"(",
"slotDetails",
".",
"hasChanged",
"(",
"cache",
".",
"sourceMedia",
")",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Media has changed (\"",
"+",
"slotDetails",
"+",
"\") since cache was created (\"",
"+",
"cache",
".",
"sourceMedia",
"+",
"\"). Attaching anyway as instructed.\"",
")",
";",
"}",
"}",
"attachMetadataCacheInternal",
"(",
"slot",
",",
"cache",
")",
";",
"}"
] | Attach a metadata cache file to a particular player media slot, so the cache will be used instead of querying
the player for metadata. This supports operation with metadata during shows where DJs are using all four player
numbers and heavily cross-linking between them.
If the media is ejected from that player slot, the cache will be detached.
@param slot the media slot to which a meta data cache is to be attached
@param file the metadata cache to be attached
@throws IOException if there is a problem reading the cache file
@throws IllegalArgumentException if an invalid player number or slot is supplied
@throws IllegalStateException if the metadata finder is not running | [
"Attach",
"a",
"metadata",
"cache",
"file",
"to",
"a",
"particular",
"player",
"media",
"slot",
"so",
"the",
"cache",
"will",
"be",
"used",
"instead",
"of",
"querying",
"the",
"player",
"for",
"metadata",
".",
"This",
"supports",
"operation",
"with",
"metadata",
"during",
"shows",
"where",
"DJs",
"are",
"using",
"all",
"four",
"player",
"numbers",
"and",
"heavily",
"cross",
"-",
"linking",
"between",
"them",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L540-L563 |
163,879 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.attachMetadataCacheInternal | void attachMetadataCacheInternal(SlotReference slot, MetadataCache cache) {
MetadataCache oldCache = metadataCacheFiles.put(slot, cache);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing previous metadata cache", e);
}
}
deliverCacheUpdate(slot, cache);
} | java | void attachMetadataCacheInternal(SlotReference slot, MetadataCache cache) {
MetadataCache oldCache = metadataCacheFiles.put(slot, cache);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing previous metadata cache", e);
}
}
deliverCacheUpdate(slot, cache);
} | [
"void",
"attachMetadataCacheInternal",
"(",
"SlotReference",
"slot",
",",
"MetadataCache",
"cache",
")",
"{",
"MetadataCache",
"oldCache",
"=",
"metadataCacheFiles",
".",
"put",
"(",
"slot",
",",
"cache",
")",
";",
"if",
"(",
"oldCache",
"!=",
"null",
")",
"{",
"try",
"{",
"oldCache",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem closing previous metadata cache\"",
",",
"e",
")",
";",
"}",
"}",
"deliverCacheUpdate",
"(",
"slot",
",",
"cache",
")",
";",
"}"
] | Finishes the process of attaching a metadata cache file once it has been opened and validated.
@param slot the slot to which the cache should be attached
@param cache the opened, validated metadata cache file | [
"Finishes",
"the",
"process",
"of",
"attaching",
"a",
"metadata",
"cache",
"file",
"once",
"it",
"has",
"been",
"opened",
"and",
"validated",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L571-L582 |
163,880 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.detachMetadataCache | public void detachMetadataCache(SlotReference slot) {
MetadataCache oldCache = metadataCacheFiles.remove(slot);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing metadata cache", e);
}
deliverCacheUpdate(slot, null);
}
} | java | public void detachMetadataCache(SlotReference slot) {
MetadataCache oldCache = metadataCacheFiles.remove(slot);
if (oldCache != null) {
try {
oldCache.close();
} catch (IOException e) {
logger.error("Problem closing metadata cache", e);
}
deliverCacheUpdate(slot, null);
}
} | [
"public",
"void",
"detachMetadataCache",
"(",
"SlotReference",
"slot",
")",
"{",
"MetadataCache",
"oldCache",
"=",
"metadataCacheFiles",
".",
"remove",
"(",
"slot",
")",
";",
"if",
"(",
"oldCache",
"!=",
"null",
")",
"{",
"try",
"{",
"oldCache",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem closing metadata cache\"",
",",
"e",
")",
";",
"}",
"deliverCacheUpdate",
"(",
"slot",
",",
"null",
")",
";",
"}",
"}"
] | Removes any metadata cache file that might have been assigned to a particular player media slot, so metadata
will be looked up from the player itself.
@param slot the media slot to which a meta data cache is to be attached | [
"Removes",
"any",
"metadata",
"cache",
"file",
"that",
"might",
"have",
"been",
"assigned",
"to",
"a",
"particular",
"player",
"media",
"slot",
"so",
"metadata",
"will",
"be",
"looked",
"up",
"from",
"the",
"player",
"itself",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L590-L600 |
163,881 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getAutoAttachCacheFiles | public List<File> getAutoAttachCacheFiles() {
ArrayList<File> currentFiles = new ArrayList<File>(autoAttachCacheFiles);
Collections.sort(currentFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
return Collections.unmodifiableList(currentFiles);
} | java | public List<File> getAutoAttachCacheFiles() {
ArrayList<File> currentFiles = new ArrayList<File>(autoAttachCacheFiles);
Collections.sort(currentFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
return Collections.unmodifiableList(currentFiles);
} | [
"public",
"List",
"<",
"File",
">",
"getAutoAttachCacheFiles",
"(",
")",
"{",
"ArrayList",
"<",
"File",
">",
"currentFiles",
"=",
"new",
"ArrayList",
"<",
"File",
">",
"(",
"autoAttachCacheFiles",
")",
";",
"Collections",
".",
"sort",
"(",
"currentFiles",
",",
"new",
"Comparator",
"<",
"File",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"int",
"compare",
"(",
"File",
"o1",
",",
"File",
"o2",
")",
"{",
"return",
"o1",
".",
"getName",
"(",
")",
".",
"compareTo",
"(",
"o2",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"currentFiles",
")",
";",
"}"
] | Get the metadata cache files that are currently configured to be automatically attached when matching media is
mounted in a player on the network.
@return the current auto-attache cache files, sorted by name | [
"Get",
"the",
"metadata",
"cache",
"files",
"that",
"are",
"currently",
"configured",
"to",
"be",
"automatically",
"attached",
"when",
"matching",
"media",
"is",
"mounted",
"in",
"a",
"player",
"on",
"the",
"network",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L665-L674 |
163,882 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.flushHotCacheSlot | private void flushHotCacheSlot(SlotReference slot) {
// Iterate over a copy to avoid concurrent modification issues
for (Map.Entry<DeckReference, TrackMetadata> entry : new HashMap<DeckReference,TrackMetadata>(hotCache).entrySet()) {
if (slot == SlotReference.getSlotReference(entry.getValue().trackReference)) {
logger.debug("Evicting cached metadata in response to unmount report {}", entry.getValue());
hotCache.remove(entry.getKey());
}
}
} | java | private void flushHotCacheSlot(SlotReference slot) {
// Iterate over a copy to avoid concurrent modification issues
for (Map.Entry<DeckReference, TrackMetadata> entry : new HashMap<DeckReference,TrackMetadata>(hotCache).entrySet()) {
if (slot == SlotReference.getSlotReference(entry.getValue().trackReference)) {
logger.debug("Evicting cached metadata in response to unmount report {}", entry.getValue());
hotCache.remove(entry.getKey());
}
}
} | [
"private",
"void",
"flushHotCacheSlot",
"(",
"SlotReference",
"slot",
")",
"{",
"// Iterate over a copy to avoid concurrent modification issues",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"entry",
":",
"new",
"HashMap",
"<",
"DeckReference",
",",
"TrackMetadata",
">",
"(",
"hotCache",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"slot",
"==",
"SlotReference",
".",
"getSlotReference",
"(",
"entry",
".",
"getValue",
"(",
")",
".",
"trackReference",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Evicting cached metadata in response to unmount report {}\"",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"hotCache",
".",
"remove",
"(",
"entry",
".",
"getKey",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Discards any tracks from the hot cache that were loaded from a now-unmounted media slot, because they are no
longer valid. | [
"Discards",
"any",
"tracks",
"from",
"the",
"hot",
"cache",
"that",
"were",
"loaded",
"from",
"a",
"now",
"-",
"unmounted",
"media",
"slot",
"because",
"they",
"are",
"no",
"longer",
"valid",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L715-L723 |
163,883 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.recordMount | private void recordMount(SlotReference slot) {
if (mediaMounts.add(slot)) {
deliverMountUpdate(slot, true);
}
if (!mediaDetails.containsKey(slot)) {
try {
VirtualCdj.getInstance().sendMediaQuery(slot);
} catch (Exception e) {
logger.warn("Problem trying to request media details for " + slot, e);
}
}
} | java | private void recordMount(SlotReference slot) {
if (mediaMounts.add(slot)) {
deliverMountUpdate(slot, true);
}
if (!mediaDetails.containsKey(slot)) {
try {
VirtualCdj.getInstance().sendMediaQuery(slot);
} catch (Exception e) {
logger.warn("Problem trying to request media details for " + slot, e);
}
}
} | [
"private",
"void",
"recordMount",
"(",
"SlotReference",
"slot",
")",
"{",
"if",
"(",
"mediaMounts",
".",
"add",
"(",
"slot",
")",
")",
"{",
"deliverMountUpdate",
"(",
"slot",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"mediaDetails",
".",
"containsKey",
"(",
"slot",
")",
")",
"{",
"try",
"{",
"VirtualCdj",
".",
"getInstance",
"(",
")",
".",
"sendMediaQuery",
"(",
"slot",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem trying to request media details for \"",
"+",
"slot",
",",
"e",
")",
";",
"}",
"}",
"}"
] | Records that there is media mounted in a particular media player slot, updating listeners if this is a change.
Also send a query to the player requesting details about the media mounted in that slot, if we don't already
have that information.
@param slot the slot in which media is mounted | [
"Records",
"that",
"there",
"is",
"media",
"mounted",
"in",
"a",
"particular",
"media",
"player",
"slot",
"updating",
"listeners",
"if",
"this",
"is",
"a",
"change",
".",
"Also",
"send",
"a",
"query",
"to",
"the",
"player",
"requesting",
"details",
"about",
"the",
"media",
"mounted",
"in",
"that",
"slot",
"if",
"we",
"don",
"t",
"already",
"have",
"that",
"information",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L748-L759 |
163,884 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.removeMount | private void removeMount(SlotReference slot) {
mediaDetails.remove(slot);
if (mediaMounts.remove(slot)) {
deliverMountUpdate(slot, false);
}
} | java | private void removeMount(SlotReference slot) {
mediaDetails.remove(slot);
if (mediaMounts.remove(slot)) {
deliverMountUpdate(slot, false);
}
} | [
"private",
"void",
"removeMount",
"(",
"SlotReference",
"slot",
")",
"{",
"mediaDetails",
".",
"remove",
"(",
"slot",
")",
";",
"if",
"(",
"mediaMounts",
".",
"remove",
"(",
"slot",
")",
")",
"{",
"deliverMountUpdate",
"(",
"slot",
",",
"false",
")",
";",
"}",
"}"
] | Records that there is no media mounted in a particular media player slot, updating listeners if this is a change,
and clearing any affected items from our in-memory caches.
@param slot the slot in which no media is mounted | [
"Records",
"that",
"there",
"is",
"no",
"media",
"mounted",
"in",
"a",
"particular",
"media",
"player",
"slot",
"updating",
"listeners",
"if",
"this",
"is",
"a",
"change",
"and",
"clearing",
"any",
"affected",
"items",
"from",
"our",
"in",
"-",
"memory",
"caches",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L767-L772 |
163,885 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverMountUpdate | private void deliverMountUpdate(SlotReference slot, boolean mounted) {
if (mounted) {
logger.info("Reporting media mounted in " + slot);
} else {
logger.info("Reporting media removed from " + slot);
}
for (final MountListener listener : getMountListeners()) {
try {
if (mounted) {
listener.mediaMounted(slot);
} else {
listener.mediaUnmounted(slot);
}
} catch (Throwable t) {
logger.warn("Problem delivering mount update to listener", t);
}
}
if (mounted) {
MetadataCache.tryAutoAttaching(slot);
}
} | java | private void deliverMountUpdate(SlotReference slot, boolean mounted) {
if (mounted) {
logger.info("Reporting media mounted in " + slot);
} else {
logger.info("Reporting media removed from " + slot);
}
for (final MountListener listener : getMountListeners()) {
try {
if (mounted) {
listener.mediaMounted(slot);
} else {
listener.mediaUnmounted(slot);
}
} catch (Throwable t) {
logger.warn("Problem delivering mount update to listener", t);
}
}
if (mounted) {
MetadataCache.tryAutoAttaching(slot);
}
} | [
"private",
"void",
"deliverMountUpdate",
"(",
"SlotReference",
"slot",
",",
"boolean",
"mounted",
")",
"{",
"if",
"(",
"mounted",
")",
"{",
"logger",
".",
"info",
"(",
"\"Reporting media mounted in \"",
"+",
"slot",
")",
";",
"}",
"else",
"{",
"logger",
".",
"info",
"(",
"\"Reporting media removed from \"",
"+",
"slot",
")",
";",
"}",
"for",
"(",
"final",
"MountListener",
"listener",
":",
"getMountListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"mounted",
")",
"{",
"listener",
".",
"mediaMounted",
"(",
"slot",
")",
";",
"}",
"else",
"{",
"listener",
".",
"mediaUnmounted",
"(",
"slot",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering mount update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"if",
"(",
"mounted",
")",
"{",
"MetadataCache",
".",
"tryAutoAttaching",
"(",
"slot",
")",
";",
"}",
"}"
] | Send a mount update announcement to all registered listeners, and see if we can auto-attach a media cache file.
@param slot the slot in which media has been mounted or unmounted
@param mounted will be {@code true} if there is now media mounted in the specified slot | [
"Send",
"a",
"mount",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"and",
"see",
"if",
"we",
"can",
"auto",
"-",
"attach",
"a",
"media",
"cache",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L870-L892 |
163,886 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverCacheUpdate | private void deliverCacheUpdate(SlotReference slot, MetadataCache cache) {
for (final MetadataCacheListener listener : getCacheListeners()) {
try {
if (cache == null) {
listener.cacheDetached(slot);
} else {
listener.cacheAttached(slot, cache);
}
} catch (Throwable t) {
logger.warn("Problem delivering metadata cache update to listener", t);
}
}
} | java | private void deliverCacheUpdate(SlotReference slot, MetadataCache cache) {
for (final MetadataCacheListener listener : getCacheListeners()) {
try {
if (cache == null) {
listener.cacheDetached(slot);
} else {
listener.cacheAttached(slot, cache);
}
} catch (Throwable t) {
logger.warn("Problem delivering metadata cache update to listener", t);
}
}
} | [
"private",
"void",
"deliverCacheUpdate",
"(",
"SlotReference",
"slot",
",",
"MetadataCache",
"cache",
")",
"{",
"for",
"(",
"final",
"MetadataCacheListener",
"listener",
":",
"getCacheListeners",
"(",
")",
")",
"{",
"try",
"{",
"if",
"(",
"cache",
"==",
"null",
")",
"{",
"listener",
".",
"cacheDetached",
"(",
"slot",
")",
";",
"}",
"else",
"{",
"listener",
".",
"cacheAttached",
"(",
"slot",
",",
"cache",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering metadata cache update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] | Send a metadata cache update announcement to all registered listeners.
@param slot the media slot whose cache status has changed
@param cache the cache which has been attached, or, if {@code null}, the previous cache has been detached | [
"Send",
"a",
"metadata",
"cache",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L952-L964 |
163,887 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.deliverTrackMetadataUpdate | private void deliverTrackMetadataUpdate(int player, TrackMetadata metadata) {
if (!getTrackMetadataListeners().isEmpty()) {
final TrackMetadataUpdate update = new TrackMetadataUpdate(player, metadata);
for (final TrackMetadataListener listener : getTrackMetadataListeners()) {
try {
listener.metadataChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering track metadata update to listener", t);
}
}
}
} | java | private void deliverTrackMetadataUpdate(int player, TrackMetadata metadata) {
if (!getTrackMetadataListeners().isEmpty()) {
final TrackMetadataUpdate update = new TrackMetadataUpdate(player, metadata);
for (final TrackMetadataListener listener : getTrackMetadataListeners()) {
try {
listener.metadataChanged(update);
} catch (Throwable t) {
logger.warn("Problem delivering track metadata update to listener", t);
}
}
}
} | [
"private",
"void",
"deliverTrackMetadataUpdate",
"(",
"int",
"player",
",",
"TrackMetadata",
"metadata",
")",
"{",
"if",
"(",
"!",
"getTrackMetadataListeners",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"TrackMetadataUpdate",
"update",
"=",
"new",
"TrackMetadataUpdate",
"(",
"player",
",",
"metadata",
")",
";",
"for",
"(",
"final",
"TrackMetadataListener",
"listener",
":",
"getTrackMetadataListeners",
"(",
")",
")",
"{",
"try",
"{",
"listener",
".",
"metadataChanged",
"(",
"update",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem delivering track metadata update to listener\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}"
] | Send a track metadata update announcement to all registered listeners. | [
"Send",
"a",
"track",
"metadata",
"update",
"announcement",
"to",
"all",
"registered",
"listeners",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1023-L1035 |
163,888 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.addMetadataProviderForMedia | private void addMetadataProviderForMedia(String key, MetadataProvider provider) {
if (!metadataProviders.containsKey(key)) {
metadataProviders.put(key, Collections.newSetFromMap(new ConcurrentHashMap<MetadataProvider, Boolean>()));
}
Set<MetadataProvider> providers = metadataProviders.get(key);
providers.add(provider);
} | java | private void addMetadataProviderForMedia(String key, MetadataProvider provider) {
if (!metadataProviders.containsKey(key)) {
metadataProviders.put(key, Collections.newSetFromMap(new ConcurrentHashMap<MetadataProvider, Boolean>()));
}
Set<MetadataProvider> providers = metadataProviders.get(key);
providers.add(provider);
} | [
"private",
"void",
"addMetadataProviderForMedia",
"(",
"String",
"key",
",",
"MetadataProvider",
"provider",
")",
"{",
"if",
"(",
"!",
"metadataProviders",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"metadataProviders",
".",
"put",
"(",
"key",
",",
"Collections",
".",
"newSetFromMap",
"(",
"new",
"ConcurrentHashMap",
"<",
"MetadataProvider",
",",
"Boolean",
">",
"(",
")",
")",
")",
";",
"}",
"Set",
"<",
"MetadataProvider",
">",
"providers",
"=",
"metadataProviders",
".",
"get",
"(",
"key",
")",
";",
"providers",
".",
"add",
"(",
"provider",
")",
";",
"}"
] | Internal method that adds a metadata provider to the set associated with a particular hash key, creating the
set if needed.
@param key the hashKey identifying the media for which this provider can offer metadata (or the empty string if
it can offer metadata for all media)
@param provider the metadata provider to be added to the active set | [
"Internal",
"method",
"that",
"adds",
"a",
"metadata",
"provider",
"to",
"the",
"set",
"associated",
"with",
"a",
"particular",
"hash",
"key",
"creating",
"the",
"set",
"if",
"needed",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1082-L1088 |
163,889 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.removeMetadataProvider | public void removeMetadataProvider(MetadataProvider provider) {
for (Set<MetadataProvider> providers : metadataProviders.values()) {
providers.remove(provider);
}
} | java | public void removeMetadataProvider(MetadataProvider provider) {
for (Set<MetadataProvider> providers : metadataProviders.values()) {
providers.remove(provider);
}
} | [
"public",
"void",
"removeMetadataProvider",
"(",
"MetadataProvider",
"provider",
")",
"{",
"for",
"(",
"Set",
"<",
"MetadataProvider",
">",
"providers",
":",
"metadataProviders",
".",
"values",
"(",
")",
")",
"{",
"providers",
".",
"remove",
"(",
"provider",
")",
";",
"}",
"}"
] | Removes a metadata provider so it will no longer be consulted to provide metadata for tracks loaded from any
media.
@param provider the metadata provider to remove. | [
"Removes",
"a",
"metadata",
"provider",
"so",
"it",
"will",
"no",
"longer",
"be",
"consulted",
"to",
"provide",
"metadata",
"for",
"tracks",
"loaded",
"from",
"any",
"media",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1096-L1100 |
163,890 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.getMetadataProviders | public Set<MetadataProvider> getMetadataProviders(MediaDetails sourceMedia) {
String key = (sourceMedia == null)? "" : sourceMedia.hashKey();
Set<MetadataProvider> result = metadataProviders.get(key);
if (result == null) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new HashSet<MetadataProvider>(result));
} | java | public Set<MetadataProvider> getMetadataProviders(MediaDetails sourceMedia) {
String key = (sourceMedia == null)? "" : sourceMedia.hashKey();
Set<MetadataProvider> result = metadataProviders.get(key);
if (result == null) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new HashSet<MetadataProvider>(result));
} | [
"public",
"Set",
"<",
"MetadataProvider",
">",
"getMetadataProviders",
"(",
"MediaDetails",
"sourceMedia",
")",
"{",
"String",
"key",
"=",
"(",
"sourceMedia",
"==",
"null",
")",
"?",
"\"\"",
":",
"sourceMedia",
".",
"hashKey",
"(",
")",
";",
"Set",
"<",
"MetadataProvider",
">",
"result",
"=",
"metadataProviders",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"emptySet",
"(",
")",
";",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"new",
"HashSet",
"<",
"MetadataProvider",
">",
"(",
"result",
")",
")",
";",
"}"
] | Get the set of metadata providers that can offer metadata for tracks loaded from the specified media.
@param sourceMedia the media whose metadata providers are desired, or {@code null} to get the set of
metadata providers that can offer metadata for all media.
@return any registered metadata providers that reported themselves as supporting tracks from that media | [
"Get",
"the",
"set",
"of",
"metadata",
"providers",
"that",
"can",
"offer",
"metadata",
"for",
"tracks",
"loaded",
"from",
"the",
"specified",
"media",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1110-L1117 |
163,891 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java | MetadataFinder.handleUpdate | private void handleUpdate(final CdjStatus update) {
// First see if any metadata caches need evicting or mount sets need updating.
if (update.isLocalUsbEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalUsbLoaded()) {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT));
}
if (update.isLocalSdEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalSdLoaded()){
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT));
}
if (update.isDiscSlotEmpty()) {
removeMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
} else {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
}
// Now see if a track has changed that needs new metadata.
if (update.getTrackType() == CdjStatus.TrackType.UNKNOWN ||
update.getTrackType() == CdjStatus.TrackType.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.UNKNOWN ||
update.getRekordboxId() == 0) { // We no longer have metadata for this device.
clearDeck(update);
} else { // We can offer metadata for this device; check if we already looked up this track.
final TrackMetadata lastMetadata = hotCache.get(DeckReference.getDeckReference(update.getDeviceNumber(), 0));
final DataReference trackReference = new DataReference(update.getTrackSourcePlayer(),
update.getTrackSourceSlot(), update.getRekordboxId());
if (lastMetadata == null || !lastMetadata.trackReference.equals(trackReference)) { // We have something new!
// First see if we can find the new track in the hot cache as a hot cue
for (TrackMetadata cached : hotCache.values()) {
if (cached.trackReference.equals(trackReference)) { // Found a hot cue hit, use it.
updateMetadata(update, cached);
return;
}
}
// Not in the hot cache so try actually retrieving it.
if (activeRequests.add(update.getTrackSourcePlayer())) {
// We had to make sure we were not already asking for this track.
clearDeck(update); // We won't know what it is until our request completes.
new Thread(new Runnable() {
@Override
public void run() {
try {
TrackMetadata data = requestMetadataInternal(trackReference, update.getTrackType(), true);
if (data != null) {
updateMetadata(update, data);
}
} catch (Exception e) {
logger.warn("Problem requesting track metadata from update" + update, e);
} finally {
activeRequests.remove(update.getTrackSourcePlayer());
}
}
}, "MetadataFinder metadata request").start();
}
}
}
} | java | private void handleUpdate(final CdjStatus update) {
// First see if any metadata caches need evicting or mount sets need updating.
if (update.isLocalUsbEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalUsbLoaded()) {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.USB_SLOT));
}
if (update.isLocalSdEmpty()) {
final SlotReference slot = SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT);
detachMetadataCache(slot);
flushHotCacheSlot(slot);
removeMount(slot);
} else if (update.isLocalSdLoaded()){
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.SD_SLOT));
}
if (update.isDiscSlotEmpty()) {
removeMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
} else {
recordMount(SlotReference.getSlotReference(update.getDeviceNumber(), CdjStatus.TrackSourceSlot.CD_SLOT));
}
// Now see if a track has changed that needs new metadata.
if (update.getTrackType() == CdjStatus.TrackType.UNKNOWN ||
update.getTrackType() == CdjStatus.TrackType.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.NO_TRACK ||
update.getTrackSourceSlot() == CdjStatus.TrackSourceSlot.UNKNOWN ||
update.getRekordboxId() == 0) { // We no longer have metadata for this device.
clearDeck(update);
} else { // We can offer metadata for this device; check if we already looked up this track.
final TrackMetadata lastMetadata = hotCache.get(DeckReference.getDeckReference(update.getDeviceNumber(), 0));
final DataReference trackReference = new DataReference(update.getTrackSourcePlayer(),
update.getTrackSourceSlot(), update.getRekordboxId());
if (lastMetadata == null || !lastMetadata.trackReference.equals(trackReference)) { // We have something new!
// First see if we can find the new track in the hot cache as a hot cue
for (TrackMetadata cached : hotCache.values()) {
if (cached.trackReference.equals(trackReference)) { // Found a hot cue hit, use it.
updateMetadata(update, cached);
return;
}
}
// Not in the hot cache so try actually retrieving it.
if (activeRequests.add(update.getTrackSourcePlayer())) {
// We had to make sure we were not already asking for this track.
clearDeck(update); // We won't know what it is until our request completes.
new Thread(new Runnable() {
@Override
public void run() {
try {
TrackMetadata data = requestMetadataInternal(trackReference, update.getTrackType(), true);
if (data != null) {
updateMetadata(update, data);
}
} catch (Exception e) {
logger.warn("Problem requesting track metadata from update" + update, e);
} finally {
activeRequests.remove(update.getTrackSourcePlayer());
}
}
}, "MetadataFinder metadata request").start();
}
}
}
} | [
"private",
"void",
"handleUpdate",
"(",
"final",
"CdjStatus",
"update",
")",
"{",
"// First see if any metadata caches need evicting or mount sets need updating.",
"if",
"(",
"update",
".",
"isLocalUsbEmpty",
"(",
")",
")",
"{",
"final",
"SlotReference",
"slot",
"=",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"USB_SLOT",
")",
";",
"detachMetadataCache",
"(",
"slot",
")",
";",
"flushHotCacheSlot",
"(",
"slot",
")",
";",
"removeMount",
"(",
"slot",
")",
";",
"}",
"else",
"if",
"(",
"update",
".",
"isLocalUsbLoaded",
"(",
")",
")",
"{",
"recordMount",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"USB_SLOT",
")",
")",
";",
"}",
"if",
"(",
"update",
".",
"isLocalSdEmpty",
"(",
")",
")",
"{",
"final",
"SlotReference",
"slot",
"=",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"SD_SLOT",
")",
";",
"detachMetadataCache",
"(",
"slot",
")",
";",
"flushHotCacheSlot",
"(",
"slot",
")",
";",
"removeMount",
"(",
"slot",
")",
";",
"}",
"else",
"if",
"(",
"update",
".",
"isLocalSdLoaded",
"(",
")",
")",
"{",
"recordMount",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"SD_SLOT",
")",
")",
";",
"}",
"if",
"(",
"update",
".",
"isDiscSlotEmpty",
"(",
")",
")",
"{",
"removeMount",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"CD_SLOT",
")",
")",
";",
"}",
"else",
"{",
"recordMount",
"(",
"SlotReference",
".",
"getSlotReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"CD_SLOT",
")",
")",
";",
"}",
"// Now see if a track has changed that needs new metadata.",
"if",
"(",
"update",
".",
"getTrackType",
"(",
")",
"==",
"CdjStatus",
".",
"TrackType",
".",
"UNKNOWN",
"||",
"update",
".",
"getTrackType",
"(",
")",
"==",
"CdjStatus",
".",
"TrackType",
".",
"NO_TRACK",
"||",
"update",
".",
"getTrackSourceSlot",
"(",
")",
"==",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"NO_TRACK",
"||",
"update",
".",
"getTrackSourceSlot",
"(",
")",
"==",
"CdjStatus",
".",
"TrackSourceSlot",
".",
"UNKNOWN",
"||",
"update",
".",
"getRekordboxId",
"(",
")",
"==",
"0",
")",
"{",
"// We no longer have metadata for this device.",
"clearDeck",
"(",
"update",
")",
";",
"}",
"else",
"{",
"// We can offer metadata for this device; check if we already looked up this track.",
"final",
"TrackMetadata",
"lastMetadata",
"=",
"hotCache",
".",
"get",
"(",
"DeckReference",
".",
"getDeckReference",
"(",
"update",
".",
"getDeviceNumber",
"(",
")",
",",
"0",
")",
")",
";",
"final",
"DataReference",
"trackReference",
"=",
"new",
"DataReference",
"(",
"update",
".",
"getTrackSourcePlayer",
"(",
")",
",",
"update",
".",
"getTrackSourceSlot",
"(",
")",
",",
"update",
".",
"getRekordboxId",
"(",
")",
")",
";",
"if",
"(",
"lastMetadata",
"==",
"null",
"||",
"!",
"lastMetadata",
".",
"trackReference",
".",
"equals",
"(",
"trackReference",
")",
")",
"{",
"// We have something new!",
"// First see if we can find the new track in the hot cache as a hot cue",
"for",
"(",
"TrackMetadata",
"cached",
":",
"hotCache",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"cached",
".",
"trackReference",
".",
"equals",
"(",
"trackReference",
")",
")",
"{",
"// Found a hot cue hit, use it.",
"updateMetadata",
"(",
"update",
",",
"cached",
")",
";",
"return",
";",
"}",
"}",
"// Not in the hot cache so try actually retrieving it.",
"if",
"(",
"activeRequests",
".",
"add",
"(",
"update",
".",
"getTrackSourcePlayer",
"(",
")",
")",
")",
"{",
"// We had to make sure we were not already asking for this track.",
"clearDeck",
"(",
"update",
")",
";",
"// We won't know what it is until our request completes.",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"TrackMetadata",
"data",
"=",
"requestMetadataInternal",
"(",
"trackReference",
",",
"update",
".",
"getTrackType",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"data",
"!=",
"null",
")",
"{",
"updateMetadata",
"(",
"update",
",",
"data",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Problem requesting track metadata from update\"",
"+",
"update",
",",
"e",
")",
";",
"}",
"finally",
"{",
"activeRequests",
".",
"remove",
"(",
"update",
".",
"getTrackSourcePlayer",
"(",
")",
")",
";",
"}",
"}",
"}",
",",
"\"MetadataFinder metadata request\"",
")",
".",
"start",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Process an update packet from one of the CDJs. See if it has a valid track loaded; if not, clear any
metadata we had stored for that player. If so, see if it is the same track we already know about; if not,
request the metadata associated with that track.
Also clears out any metadata caches that were attached for slots that no longer have media mounted in them,
and updates the sets of which players have media mounted in which slots.
If any of these reflect a change in state, any registered listeners will be informed.
@param update an update packet we received from a CDJ | [
"Process",
"an",
"update",
"packet",
"from",
"one",
"of",
"the",
"CDJs",
".",
"See",
"if",
"it",
"has",
"a",
"valid",
"track",
"loaded",
";",
"if",
"not",
"clear",
"any",
"metadata",
"we",
"had",
"stored",
"for",
"that",
"player",
".",
"If",
"so",
"see",
"if",
"it",
"is",
"the",
"same",
"track",
"we",
"already",
"know",
"about",
";",
"if",
"not",
"request",
"the",
"metadata",
"associated",
"with",
"that",
"track",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataFinder.java#L1246-L1314 |
163,892 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/WaveformDetail.java | WaveformDetail.getColorWaveformBits | private int getColorWaveformBits(final ByteBuffer waveBytes, final int segment) {
final int base = (segment * 2);
final int big = Util.unsign(waveBytes.get(base));
final int small = Util.unsign(waveBytes.get(base + 1));
return big * 256 + small;
} | java | private int getColorWaveformBits(final ByteBuffer waveBytes, final int segment) {
final int base = (segment * 2);
final int big = Util.unsign(waveBytes.get(base));
final int small = Util.unsign(waveBytes.get(base + 1));
return big * 256 + small;
} | [
"private",
"int",
"getColorWaveformBits",
"(",
"final",
"ByteBuffer",
"waveBytes",
",",
"final",
"int",
"segment",
")",
"{",
"final",
"int",
"base",
"=",
"(",
"segment",
"*",
"2",
")",
";",
"final",
"int",
"big",
"=",
"Util",
".",
"unsign",
"(",
"waveBytes",
".",
"get",
"(",
"base",
")",
")",
";",
"final",
"int",
"small",
"=",
"Util",
".",
"unsign",
"(",
"waveBytes",
".",
"get",
"(",
"base",
"+",
"1",
")",
")",
";",
"return",
"big",
"*",
"256",
"+",
"small",
";",
"}"
] | Color waveforms are represented by a series of sixteen bit integers into which color and height information are
packed. This function returns the integer corresponding to a particular half-frame in the waveform.
@param waveBytes the raw data making up the waveform
@param segment the index of hte half-frame of interest
@return the sixteen-bit number encoding the height and RGB values of that segment | [
"Color",
"waveforms",
"are",
"represented",
"by",
"a",
"series",
"of",
"sixteen",
"bit",
"integers",
"into",
"which",
"color",
"and",
"height",
"information",
"are",
"packed",
".",
"This",
"function",
"returns",
"the",
"integer",
"corresponding",
"to",
"a",
"particular",
"half",
"-",
"frame",
"in",
"the",
"waveform",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/WaveformDetail.java#L208-L213 |
163,893 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.addCacheFormatEntry | private static void addCacheFormatEntry(List<Message> trackListEntries, int playlistId, ZipOutputStream zos) throws IOException {
// Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
// that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
// Since we are doing this anyway, we can also provide information about the nature of the cache, and
// how many metadata entries it contains, which is useful for auto-attachment.
zos.putNextEntry(new ZipEntry(CACHE_FORMAT_ENTRY));
String formatEntry = CACHE_FORMAT_IDENTIFIER + ":" + playlistId + ":" + trackListEntries.size();
zos.write(formatEntry.getBytes("UTF-8"));
} | java | private static void addCacheFormatEntry(List<Message> trackListEntries, int playlistId, ZipOutputStream zos) throws IOException {
// Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
// that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
// Since we are doing this anyway, we can also provide information about the nature of the cache, and
// how many metadata entries it contains, which is useful for auto-attachment.
zos.putNextEntry(new ZipEntry(CACHE_FORMAT_ENTRY));
String formatEntry = CACHE_FORMAT_IDENTIFIER + ":" + playlistId + ":" + trackListEntries.size();
zos.write(formatEntry.getBytes("UTF-8"));
} | [
"private",
"static",
"void",
"addCacheFormatEntry",
"(",
"List",
"<",
"Message",
">",
"trackListEntries",
",",
"int",
"playlistId",
",",
"ZipOutputStream",
"zos",
")",
"throws",
"IOException",
"{",
"// Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but",
"// that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.",
"// Since we are doing this anyway, we can also provide information about the nature of the cache, and",
"// how many metadata entries it contains, which is useful for auto-attachment.",
"zos",
".",
"putNextEntry",
"(",
"new",
"ZipEntry",
"(",
"CACHE_FORMAT_ENTRY",
")",
")",
";",
"String",
"formatEntry",
"=",
"CACHE_FORMAT_IDENTIFIER",
"+",
"\":\"",
"+",
"playlistId",
"+",
"\":\"",
"+",
"trackListEntries",
".",
"size",
"(",
")",
";",
"zos",
".",
"write",
"(",
"formatEntry",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
")",
";",
"}"
] | Add a marker so we can recognize this as a metadata archive. I would use the ZipFile comment, but
that is not available until Java 7, and Beat Link is supposed to be backwards compatible with Java 6.
Since we are doing this anyway, we can also provide information about the nature of the cache, and
how many metadata entries it contains, which is useful for auto-attachment.
@param trackListEntries the tracks contained in the cache, so we can record the number
@param playlistId the playlist contained in the cache, or 0 if it is all tracks from the media
@param zos the stream to which the ZipFile is being written
@throws IOException if there is a problem creating the format entry | [
"Add",
"a",
"marker",
"so",
"we",
"can",
"recognize",
"this",
"as",
"a",
"metadata",
"archive",
".",
"I",
"would",
"use",
"the",
"ZipFile",
"comment",
"but",
"that",
"is",
"not",
"available",
"until",
"Java",
"7",
"and",
"Beat",
"Link",
"is",
"supposed",
"to",
"be",
"backwards",
"compatible",
"with",
"Java",
"6",
".",
"Since",
"we",
"are",
"doing",
"this",
"anyway",
"we",
"can",
"also",
"provide",
"information",
"about",
"the",
"nature",
"of",
"the",
"cache",
"and",
"how",
"many",
"metadata",
"entries",
"it",
"contains",
"which",
"is",
"useful",
"for",
"auto",
"-",
"attachment",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L344-L352 |
163,894 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.addCacheDetailsEntry | private static void addCacheDetailsEntry(SlotReference slot, ZipOutputStream zos, WritableByteChannel channel) throws IOException {
// Record the details of the media being cached, to make it easier to recognize now that we can.
MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null) {
zos.putNextEntry(new ZipEntry(CACHE_DETAILS_ENTRY));
Util.writeFully(details.getRawBytes(), channel);
}
} | java | private static void addCacheDetailsEntry(SlotReference slot, ZipOutputStream zos, WritableByteChannel channel) throws IOException {
// Record the details of the media being cached, to make it easier to recognize now that we can.
MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null) {
zos.putNextEntry(new ZipEntry(CACHE_DETAILS_ENTRY));
Util.writeFully(details.getRawBytes(), channel);
}
} | [
"private",
"static",
"void",
"addCacheDetailsEntry",
"(",
"SlotReference",
"slot",
",",
"ZipOutputStream",
"zos",
",",
"WritableByteChannel",
"channel",
")",
"throws",
"IOException",
"{",
"// Record the details of the media being cached, to make it easier to recognize now that we can.",
"MediaDetails",
"details",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMediaDetailsFor",
"(",
"slot",
")",
";",
"if",
"(",
"details",
"!=",
"null",
")",
"{",
"zos",
".",
"putNextEntry",
"(",
"new",
"ZipEntry",
"(",
"CACHE_DETAILS_ENTRY",
")",
")",
";",
"Util",
".",
"writeFully",
"(",
"details",
".",
"getRawBytes",
"(",
")",
",",
"channel",
")",
";",
"}",
"}"
] | Record the details of the media being cached, to make it easier to recognize, now that we have access to that
information.
@param slot the slot from which a metadata cache is being created
@param zos the stream to which the ZipFile is being written
@param channel the low-level channel to which the cache is being written
@throws IOException if there is a problem writing the media details entry | [
"Record",
"the",
"details",
"of",
"the",
"media",
"being",
"cached",
"to",
"make",
"it",
"easier",
"to",
"recognize",
"now",
"that",
"we",
"have",
"access",
"to",
"that",
"information",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L364-L371 |
163,895 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.getCacheFormatEntry | private String getCacheFormatEntry() throws IOException {
ZipEntry zipEntry = zipFile.getEntry(CACHE_FORMAT_ENTRY);
InputStream is = zipFile.getInputStream(zipEntry);
try {
Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
String tag = null;
if (s.hasNext()) tag = s.next();
return tag;
} finally {
is.close();
}
} | java | private String getCacheFormatEntry() throws IOException {
ZipEntry zipEntry = zipFile.getEntry(CACHE_FORMAT_ENTRY);
InputStream is = zipFile.getInputStream(zipEntry);
try {
Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
String tag = null;
if (s.hasNext()) tag = s.next();
return tag;
} finally {
is.close();
}
} | [
"private",
"String",
"getCacheFormatEntry",
"(",
")",
"throws",
"IOException",
"{",
"ZipEntry",
"zipEntry",
"=",
"zipFile",
".",
"getEntry",
"(",
"CACHE_FORMAT_ENTRY",
")",
";",
"InputStream",
"is",
"=",
"zipFile",
".",
"getInputStream",
"(",
"zipEntry",
")",
";",
"try",
"{",
"Scanner",
"s",
"=",
"new",
"Scanner",
"(",
"is",
",",
"\"UTF-8\"",
")",
".",
"useDelimiter",
"(",
"\"\\\\A\"",
")",
";",
"String",
"tag",
"=",
"null",
";",
"if",
"(",
"s",
".",
"hasNext",
"(",
")",
")",
"tag",
"=",
"s",
".",
"next",
"(",
")",
";",
"return",
"tag",
";",
"}",
"finally",
"{",
"is",
".",
"close",
"(",
")",
";",
"}",
"}"
] | Find and read the cache format entry in a metadata cache file.
@return the content of the format entry, or {@code null} if none was found
@throws IOException if there is a problem reading the file | [
"Find",
"and",
"read",
"the",
"cache",
"format",
"entry",
"in",
"a",
"metadata",
"cache",
"file",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L454-L465 |
163,896 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.getTrackIds | public List<Integer> getTrackIds() {
ArrayList<Integer> results = new ArrayList<Integer>(trackCount);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().startsWith(CACHE_METADATA_ENTRY_PREFIX)) {
String idPart = entry.getName().substring(CACHE_METADATA_ENTRY_PREFIX.length());
if (idPart.length() > 0) {
results.add(Integer.valueOf(idPart));
}
}
}
return Collections.unmodifiableList(results);
} | java | public List<Integer> getTrackIds() {
ArrayList<Integer> results = new ArrayList<Integer>(trackCount);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().startsWith(CACHE_METADATA_ENTRY_PREFIX)) {
String idPart = entry.getName().substring(CACHE_METADATA_ENTRY_PREFIX.length());
if (idPart.length() > 0) {
results.add(Integer.valueOf(idPart));
}
}
}
return Collections.unmodifiableList(results);
} | [
"public",
"List",
"<",
"Integer",
">",
"getTrackIds",
"(",
")",
"{",
"ArrayList",
"<",
"Integer",
">",
"results",
"=",
"new",
"ArrayList",
"<",
"Integer",
">",
"(",
"trackCount",
")",
";",
"Enumeration",
"<",
"?",
"extends",
"ZipEntry",
">",
"entries",
"=",
"zipFile",
".",
"entries",
"(",
")",
";",
"while",
"(",
"entries",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"ZipEntry",
"entry",
"=",
"entries",
".",
"nextElement",
"(",
")",
";",
"if",
"(",
"entry",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"CACHE_METADATA_ENTRY_PREFIX",
")",
")",
"{",
"String",
"idPart",
"=",
"entry",
".",
"getName",
"(",
")",
".",
"substring",
"(",
"CACHE_METADATA_ENTRY_PREFIX",
".",
"length",
"(",
")",
")",
";",
"if",
"(",
"idPart",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"results",
".",
"add",
"(",
"Integer",
".",
"valueOf",
"(",
"idPart",
")",
")",
";",
"}",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"results",
")",
";",
"}"
] | Returns a list of the rekordbox IDs of the tracks contained in the cache.
@return a list containing the rekordbox ID for each track present in the cache, in the order they appear | [
"Returns",
"a",
"list",
"of",
"the",
"rekordbox",
"IDs",
"of",
"the",
"tracks",
"contained",
"in",
"the",
"cache",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L502-L516 |
163,897 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.createMetadataCache | public static void createMetadataCache(SlotReference slot, int playlistId, File cache) throws Exception {
createMetadataCache(slot, playlistId, cache, null);
} | java | public static void createMetadataCache(SlotReference slot, int playlistId, File cache) throws Exception {
createMetadataCache(slot, playlistId, cache, null);
} | [
"public",
"static",
"void",
"createMetadataCache",
"(",
"SlotReference",
"slot",
",",
"int",
"playlistId",
",",
"File",
"cache",
")",
"throws",
"Exception",
"{",
"createMetadataCache",
"(",
"slot",
",",
"playlistId",
",",
"cache",
",",
"null",
")",
";",
"}"
] | Creates a metadata cache archive file of all tracks in the specified slot on the specified player. Any
previous contents of the specified file will be replaced.
@param slot the slot in which the media to be cached can be found
@param playlistId the id of playlist to be cached, or 0 of all tracks should be cached
@param cache the file into which the metadata cache should be written
@throws Exception if there is a problem communicating with the player or writing the cache file. | [
"Creates",
"a",
"metadata",
"cache",
"archive",
"file",
"of",
"all",
"tracks",
"in",
"the",
"specified",
"slot",
"on",
"the",
"specified",
"player",
".",
"Any",
"previous",
"contents",
"of",
"the",
"specified",
"file",
"will",
"be",
"replaced",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L692-L694 |
163,898 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.tryAutoAttaching | static void tryAutoAttaching(final SlotReference slot) {
if (!MetadataFinder.getInstance().getMountedMediaSlots().contains(slot)) {
logger.error("Unable to auto-attach cache to empty slot {}", slot);
return;
}
if (MetadataFinder.getInstance().getMetadataCache(slot) != null) {
logger.info("Not auto-attaching to slot {}; already has a cache attached.", slot);
return;
}
if (MetadataFinder.getInstance().getAutoAttachCacheFiles().isEmpty()) {
logger.debug("No auto-attach files configured.");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5); // Give us a chance to find out what type of media is in the new mount.
final MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null && details.mediaType == CdjStatus.TrackType.REKORDBOX) {
// First stage attempt: See if we can match based on stored media details, which is both more reliable and
// less disruptive than trying to sample the player database to compare entries.
boolean attached = false;
for (File file : MetadataFinder.getInstance().getAutoAttachCacheFiles()) {
final MetadataCache cache = new MetadataCache(file);
try {
if (cache.sourceMedia != null && cache.sourceMedia.hashKey().equals(details.hashKey())) {
// We found a solid match, no need to probe tracks.
final boolean changed = cache.sourceMedia.hasChanged(details);
logger.info("Auto-attaching metadata cache " + cache.getName() + " to slot " + slot +
" based on media details " + (changed? "(changed since created)!" : "(unchanged)."));
MetadataFinder.getInstance().attachMetadataCacheInternal(slot, cache);
attached = true;
return;
}
} finally {
if (!attached) {
cache.close();
}
}
}
// Could not match based on media details; fall back to older method based on probing track metadata.
ConnectionManager.ClientTask<Object> task = new ConnectionManager.ClientTask<Object>() {
@Override
public Object useClient(Client client) throws Exception {
tryAutoAttachingWithConnection(slot, client);
return null;
}
};
ConnectionManager.getInstance().invokeWithClientSession(slot.player, task, "trying to auto-attach metadata cache");
}
} catch (Exception e) {
logger.error("Problem trying to auto-attach metadata cache for slot " + slot, e);
}
}
}, "Metadata cache file auto-attachment attempt").start();
} | java | static void tryAutoAttaching(final SlotReference slot) {
if (!MetadataFinder.getInstance().getMountedMediaSlots().contains(slot)) {
logger.error("Unable to auto-attach cache to empty slot {}", slot);
return;
}
if (MetadataFinder.getInstance().getMetadataCache(slot) != null) {
logger.info("Not auto-attaching to slot {}; already has a cache attached.", slot);
return;
}
if (MetadataFinder.getInstance().getAutoAttachCacheFiles().isEmpty()) {
logger.debug("No auto-attach files configured.");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5); // Give us a chance to find out what type of media is in the new mount.
final MediaDetails details = MetadataFinder.getInstance().getMediaDetailsFor(slot);
if (details != null && details.mediaType == CdjStatus.TrackType.REKORDBOX) {
// First stage attempt: See if we can match based on stored media details, which is both more reliable and
// less disruptive than trying to sample the player database to compare entries.
boolean attached = false;
for (File file : MetadataFinder.getInstance().getAutoAttachCacheFiles()) {
final MetadataCache cache = new MetadataCache(file);
try {
if (cache.sourceMedia != null && cache.sourceMedia.hashKey().equals(details.hashKey())) {
// We found a solid match, no need to probe tracks.
final boolean changed = cache.sourceMedia.hasChanged(details);
logger.info("Auto-attaching metadata cache " + cache.getName() + " to slot " + slot +
" based on media details " + (changed? "(changed since created)!" : "(unchanged)."));
MetadataFinder.getInstance().attachMetadataCacheInternal(slot, cache);
attached = true;
return;
}
} finally {
if (!attached) {
cache.close();
}
}
}
// Could not match based on media details; fall back to older method based on probing track metadata.
ConnectionManager.ClientTask<Object> task = new ConnectionManager.ClientTask<Object>() {
@Override
public Object useClient(Client client) throws Exception {
tryAutoAttachingWithConnection(slot, client);
return null;
}
};
ConnectionManager.getInstance().invokeWithClientSession(slot.player, task, "trying to auto-attach metadata cache");
}
} catch (Exception e) {
logger.error("Problem trying to auto-attach metadata cache for slot " + slot, e);
}
}
}, "Metadata cache file auto-attachment attempt").start();
} | [
"static",
"void",
"tryAutoAttaching",
"(",
"final",
"SlotReference",
"slot",
")",
"{",
"if",
"(",
"!",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMountedMediaSlots",
"(",
")",
".",
"contains",
"(",
"slot",
")",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to auto-attach cache to empty slot {}\"",
",",
"slot",
")",
";",
"return",
";",
"}",
"if",
"(",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMetadataCache",
"(",
"slot",
")",
"!=",
"null",
")",
"{",
"logger",
".",
"info",
"(",
"\"Not auto-attaching to slot {}; already has a cache attached.\"",
",",
"slot",
")",
";",
"return",
";",
"}",
"if",
"(",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getAutoAttachCacheFiles",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"No auto-attach files configured.\"",
")",
";",
"return",
";",
"}",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"5",
")",
";",
"// Give us a chance to find out what type of media is in the new mount.",
"final",
"MediaDetails",
"details",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getMediaDetailsFor",
"(",
"slot",
")",
";",
"if",
"(",
"details",
"!=",
"null",
"&&",
"details",
".",
"mediaType",
"==",
"CdjStatus",
".",
"TrackType",
".",
"REKORDBOX",
")",
"{",
"// First stage attempt: See if we can match based on stored media details, which is both more reliable and",
"// less disruptive than trying to sample the player database to compare entries.",
"boolean",
"attached",
"=",
"false",
";",
"for",
"(",
"File",
"file",
":",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getAutoAttachCacheFiles",
"(",
")",
")",
"{",
"final",
"MetadataCache",
"cache",
"=",
"new",
"MetadataCache",
"(",
"file",
")",
";",
"try",
"{",
"if",
"(",
"cache",
".",
"sourceMedia",
"!=",
"null",
"&&",
"cache",
".",
"sourceMedia",
".",
"hashKey",
"(",
")",
".",
"equals",
"(",
"details",
".",
"hashKey",
"(",
")",
")",
")",
"{",
"// We found a solid match, no need to probe tracks.",
"final",
"boolean",
"changed",
"=",
"cache",
".",
"sourceMedia",
".",
"hasChanged",
"(",
"details",
")",
";",
"logger",
".",
"info",
"(",
"\"Auto-attaching metadata cache \"",
"+",
"cache",
".",
"getName",
"(",
")",
"+",
"\" to slot \"",
"+",
"slot",
"+",
"\" based on media details \"",
"+",
"(",
"changed",
"?",
"\"(changed since created)!\"",
":",
"\"(unchanged).\"",
")",
")",
";",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"attachMetadataCacheInternal",
"(",
"slot",
",",
"cache",
")",
";",
"attached",
"=",
"true",
";",
"return",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"!",
"attached",
")",
"{",
"cache",
".",
"close",
"(",
")",
";",
"}",
"}",
"}",
"// Could not match based on media details; fall back to older method based on probing track metadata.",
"ConnectionManager",
".",
"ClientTask",
"<",
"Object",
">",
"task",
"=",
"new",
"ConnectionManager",
".",
"ClientTask",
"<",
"Object",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Object",
"useClient",
"(",
"Client",
"client",
")",
"throws",
"Exception",
"{",
"tryAutoAttachingWithConnection",
"(",
"slot",
",",
"client",
")",
";",
"return",
"null",
";",
"}",
"}",
";",
"ConnectionManager",
".",
"getInstance",
"(",
")",
".",
"invokeWithClientSession",
"(",
"slot",
".",
"player",
",",
"task",
",",
"\"trying to auto-attach metadata cache\"",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Problem trying to auto-attach metadata cache for slot \"",
"+",
"slot",
",",
"e",
")",
";",
"}",
"}",
"}",
",",
"\"Metadata cache file auto-attachment attempt\"",
")",
".",
"start",
"(",
")",
";",
"}"
] | See if there is an auto-attach cache file that seems to match the media in the specified slot, and if so,
attach it.
@param slot the player slot that is under consideration for automatic cache attachment | [
"See",
"if",
"there",
"is",
"an",
"auto",
"-",
"attach",
"cache",
"file",
"that",
"seems",
"to",
"match",
"the",
"media",
"in",
"the",
"specified",
"slot",
"and",
"if",
"so",
"attach",
"it",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L776-L835 |
163,899 | Deep-Symmetry/beat-link | src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java | MetadataCache.gatherCandidateAttachmentGroups | private static Map<Integer, LinkedList<MetadataCache>> gatherCandidateAttachmentGroups() {
Map<Integer,LinkedList<MetadataCache>> candidateGroups = new TreeMap<Integer, LinkedList<MetadataCache>>();
final Iterator<File> iterator = MetadataFinder.getInstance().getAutoAttachCacheFiles().iterator();
while (iterator.hasNext()) {
final File file = iterator.next();
try {
final MetadataCache candidate = new MetadataCache(file);
if (candidateGroups.get(candidate.sourcePlaylist) == null) {
candidateGroups.put(candidate.sourcePlaylist, new LinkedList<MetadataCache>());
}
candidateGroups.get(candidate.sourcePlaylist).add(candidate);
} catch (Exception e) {
logger.error("Unable to open metadata cache file " + file + ", discarding", e);
iterator.remove();
}
}
return candidateGroups;
} | java | private static Map<Integer, LinkedList<MetadataCache>> gatherCandidateAttachmentGroups() {
Map<Integer,LinkedList<MetadataCache>> candidateGroups = new TreeMap<Integer, LinkedList<MetadataCache>>();
final Iterator<File> iterator = MetadataFinder.getInstance().getAutoAttachCacheFiles().iterator();
while (iterator.hasNext()) {
final File file = iterator.next();
try {
final MetadataCache candidate = new MetadataCache(file);
if (candidateGroups.get(candidate.sourcePlaylist) == null) {
candidateGroups.put(candidate.sourcePlaylist, new LinkedList<MetadataCache>());
}
candidateGroups.get(candidate.sourcePlaylist).add(candidate);
} catch (Exception e) {
logger.error("Unable to open metadata cache file " + file + ", discarding", e);
iterator.remove();
}
}
return candidateGroups;
} | [
"private",
"static",
"Map",
"<",
"Integer",
",",
"LinkedList",
"<",
"MetadataCache",
">",
">",
"gatherCandidateAttachmentGroups",
"(",
")",
"{",
"Map",
"<",
"Integer",
",",
"LinkedList",
"<",
"MetadataCache",
">",
">",
"candidateGroups",
"=",
"new",
"TreeMap",
"<",
"Integer",
",",
"LinkedList",
"<",
"MetadataCache",
">",
">",
"(",
")",
";",
"final",
"Iterator",
"<",
"File",
">",
"iterator",
"=",
"MetadataFinder",
".",
"getInstance",
"(",
")",
".",
"getAutoAttachCacheFiles",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"final",
"File",
"file",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"try",
"{",
"final",
"MetadataCache",
"candidate",
"=",
"new",
"MetadataCache",
"(",
"file",
")",
";",
"if",
"(",
"candidateGroups",
".",
"get",
"(",
"candidate",
".",
"sourcePlaylist",
")",
"==",
"null",
")",
"{",
"candidateGroups",
".",
"put",
"(",
"candidate",
".",
"sourcePlaylist",
",",
"new",
"LinkedList",
"<",
"MetadataCache",
">",
"(",
")",
")",
";",
"}",
"candidateGroups",
".",
"get",
"(",
"candidate",
".",
"sourcePlaylist",
")",
".",
"add",
"(",
"candidate",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"\"Unable to open metadata cache file \"",
"+",
"file",
"+",
"\", discarding\"",
",",
"e",
")",
";",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
"return",
"candidateGroups",
";",
"}"
] | Groups all of the metadata cache files that are candidates for auto-attachment to player slots into lists
that are keyed by the playlist ID used to create the cache file. Files that cache all tracks have a playlist
ID of 0.
@return a map from playlist ID to the caches holding tracks from that playlist | [
"Groups",
"all",
"of",
"the",
"metadata",
"cache",
"files",
"that",
"are",
"candidates",
"for",
"auto",
"-",
"attachment",
"to",
"player",
"slots",
"into",
"lists",
"that",
"are",
"keyed",
"by",
"the",
"playlist",
"ID",
"used",
"to",
"create",
"the",
"cache",
"file",
".",
"Files",
"that",
"cache",
"all",
"tracks",
"have",
"a",
"playlist",
"ID",
"of",
"0",
"."
] | f958a2a70e8a87a31a75326d7b4db77c2f0b4212 | https://github.com/Deep-Symmetry/beat-link/blob/f958a2a70e8a87a31a75326d7b4db77c2f0b4212/src/main/java/org/deepsymmetry/beatlink/data/MetadataCache.java#L948-L965 |
Subsets and Splits