id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
29,100
Waikato/moa
moa/src/main/java/moa/clusterers/CobWeb.java
CobWeb.determineNumberOfClusters
protected void determineNumberOfClusters() { if (!m_numberOfClustersDetermined && (m_cobwebTree != null)) { int[] numClusts = new int[1]; numClusts[0] = 0; // try { m_cobwebTree.assignClusterNums(numClusts); // } // catch (Exception e) { // e.printStackTrace(); // numClusts[0] = 0; // } m_numberOfClusters = numClusts[0]; m_numberOfClustersDetermined = true; } }
java
protected void determineNumberOfClusters() { if (!m_numberOfClustersDetermined && (m_cobwebTree != null)) { int[] numClusts = new int[1]; numClusts[0] = 0; // try { m_cobwebTree.assignClusterNums(numClusts); // } // catch (Exception e) { // e.printStackTrace(); // numClusts[0] = 0; // } m_numberOfClusters = numClusts[0]; m_numberOfClustersDetermined = true; } }
[ "protected", "void", "determineNumberOfClusters", "(", ")", "{", "if", "(", "!", "m_numberOfClustersDetermined", "&&", "(", "m_cobwebTree", "!=", "null", ")", ")", "{", "int", "[", "]", "numClusts", "=", "new", "int", "[", "1", "]", ";", "numClusts", "[", "0", "]", "=", "0", ";", "// try {", "m_cobwebTree", ".", "assignClusterNums", "(", "numClusts", ")", ";", "// }", "// catch (Exception e) {", "//\te.printStackTrace();", "//\tnumClusts[0] = 0;", "// }", "m_numberOfClusters", "=", "numClusts", "[", "0", "]", ";", "m_numberOfClustersDetermined", "=", "true", ";", "}", "}" ]
determines the number of clusters if necessary @see #m_numberOfClusters @see #m_numberOfClustersDetermined
[ "determines", "the", "number", "of", "clusters", "if", "necessary" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/CobWeb.java#L852-L868
29,101
Waikato/moa
moa/src/main/java/moa/clusterers/CobWeb.java
CobWeb.graph
public String graph() {// throws Exception { StringBuffer text = new StringBuffer(); text.append("digraph CobwebTree {\n"); m_cobwebTree.graphTree(text); text.append("}\n"); return text.toString(); }
java
public String graph() {// throws Exception { StringBuffer text = new StringBuffer(); text.append("digraph CobwebTree {\n"); m_cobwebTree.graphTree(text); text.append("}\n"); return text.toString(); }
[ "public", "String", "graph", "(", ")", "{", "// throws Exception {", "StringBuffer", "text", "=", "new", "StringBuffer", "(", ")", ";", "text", ".", "append", "(", "\"digraph CobwebTree {\\n\"", ")", ";", "m_cobwebTree", ".", "graphTree", "(", "text", ")", ";", "text", ".", "append", "(", "\"}\\n\"", ")", ";", "return", "text", ".", "toString", "(", ")", ";", "}" ]
Generates the graph string of the Cobweb tree @return a <code>String</code> value @throws Exception if an error occurs
[ "Generates", "the", "graph", "string", "of", "the", "Cobweb", "tree" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/CobWeb.java#L916-L923
29,102
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/EuclideanDistance.java
EuclideanDistance.sqDifference
public double sqDifference(int index, double val1, double val2) { double val = difference(index, val1, val2); return val*val; }
java
public double sqDifference(int index, double val1, double val2) { double val = difference(index, val1, val2); return val*val; }
[ "public", "double", "sqDifference", "(", "int", "index", ",", "double", "val1", ",", "double", "val2", ")", "{", "double", "val", "=", "difference", "(", "index", ",", "val1", ",", "val2", ")", ";", "return", "val", "*", "val", ";", "}" ]
Returns the squared difference of two values of an attribute. @param index the attribute index @param val1 the first value @param val2 the second value @return the squared difference
[ "Returns", "the", "squared", "difference", "of", "two", "values", "of", "an", "attribute", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/EuclideanDistance.java#L171-L174
29,103
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/EuclideanDistance.java
EuclideanDistance.closestPoint
public int closestPoint(Instance instance, Instances allPoints, int[] pointList) throws Exception { double minDist = Integer.MAX_VALUE; int bestPoint = 0; for (int i = 0; i < pointList.length; i++) { double dist = distance(instance, allPoints.instance(pointList[i]), Double.POSITIVE_INFINITY); if (dist < minDist) { minDist = dist; bestPoint = i; } } return pointList[bestPoint]; }
java
public int closestPoint(Instance instance, Instances allPoints, int[] pointList) throws Exception { double minDist = Integer.MAX_VALUE; int bestPoint = 0; for (int i = 0; i < pointList.length; i++) { double dist = distance(instance, allPoints.instance(pointList[i]), Double.POSITIVE_INFINITY); if (dist < minDist) { minDist = dist; bestPoint = i; } } return pointList[bestPoint]; }
[ "public", "int", "closestPoint", "(", "Instance", "instance", ",", "Instances", "allPoints", ",", "int", "[", "]", "pointList", ")", "throws", "Exception", "{", "double", "minDist", "=", "Integer", ".", "MAX_VALUE", ";", "int", "bestPoint", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointList", ".", "length", ";", "i", "++", ")", "{", "double", "dist", "=", "distance", "(", "instance", ",", "allPoints", ".", "instance", "(", "pointList", "[", "i", "]", ")", ",", "Double", ".", "POSITIVE_INFINITY", ")", ";", "if", "(", "dist", "<", "minDist", ")", "{", "minDist", "=", "dist", ";", "bestPoint", "=", "i", ";", "}", "}", "return", "pointList", "[", "bestPoint", "]", ";", "}" ]
Returns the index of the closest point to the current instance. Index is index in Instances object that is the second parameter. @param instance the instance to assign a cluster to @param allPoints all points @param pointList the list of points @return the index of the closest point @throws Exception if something goes wrong
[ "Returns", "the", "index", "of", "the", "closest", "point", "to", "the", "current", "instance", ".", "Index", "is", "index", "in", "Instances", "object", "that", "is", "the", "second", "parameter", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/EuclideanDistance.java#L198-L210
29,104
Waikato/moa
moa/src/main/java/moa/gui/experimentertab/TaskManagerTabPanel.java
TaskManagerTabPanel.openConfig
public void openConfig(String path) { Properties properties = new Properties(); try { properties.load(new FileInputStream(path)); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Problems reading the properties file", "Error", JOptionPane.ERROR_MESSAGE); } // read datasets this.jTextFieldProcess.setText(properties.getProperty("processors")); this.jTextFieldTask.setText(properties.getProperty("task")); try { this.currentTask = (MainTask) ClassOption.cliStringToObject( this.jTextFieldTask.getText(), MainTask.class, null); } catch (Exception ex) { Logger.getLogger(TaskManagerTabPanel.class.getName()).log(Level.SEVERE, null, ex); } this.jTextFieldDir.setText(properties.getProperty("ResultsDir")); this.resultsPath = this.jTextFieldDir.getText(); String[] streamShortNames = properties.getProperty("streamShortNames").split(","); String[] streamCommand = properties.getProperty("streamCommand").split(","); String[] algShortNames = properties.getProperty("algorithmShortNames").split(","); String[] algorithmCommand = properties.getProperty("algorithmCommand").split(","); cleanTables(); for (int i = 0; i < streamShortNames.length; i++) { this.streamModel.addRow(new Object[]{streamCommand[i], streamShortNames[i]}); } for (int i = 0; i < algShortNames.length; i++) { this.algoritmModel.addRow(new Object[]{algorithmCommand[i], algShortNames[i]}); } }
java
public void openConfig(String path) { Properties properties = new Properties(); try { properties.load(new FileInputStream(path)); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Problems reading the properties file", "Error", JOptionPane.ERROR_MESSAGE); } // read datasets this.jTextFieldProcess.setText(properties.getProperty("processors")); this.jTextFieldTask.setText(properties.getProperty("task")); try { this.currentTask = (MainTask) ClassOption.cliStringToObject( this.jTextFieldTask.getText(), MainTask.class, null); } catch (Exception ex) { Logger.getLogger(TaskManagerTabPanel.class.getName()).log(Level.SEVERE, null, ex); } this.jTextFieldDir.setText(properties.getProperty("ResultsDir")); this.resultsPath = this.jTextFieldDir.getText(); String[] streamShortNames = properties.getProperty("streamShortNames").split(","); String[] streamCommand = properties.getProperty("streamCommand").split(","); String[] algShortNames = properties.getProperty("algorithmShortNames").split(","); String[] algorithmCommand = properties.getProperty("algorithmCommand").split(","); cleanTables(); for (int i = 0; i < streamShortNames.length; i++) { this.streamModel.addRow(new Object[]{streamCommand[i], streamShortNames[i]}); } for (int i = 0; i < algShortNames.length; i++) { this.algoritmModel.addRow(new Object[]{algorithmCommand[i], algShortNames[i]}); } }
[ "public", "void", "openConfig", "(", "String", "path", ")", "{", "Properties", "properties", "=", "new", "Properties", "(", ")", ";", "try", "{", "properties", ".", "load", "(", "new", "FileInputStream", "(", "path", ")", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", "JOptionPane", ".", "showMessageDialog", "(", "this", ",", "\"Problems reading the properties file\"", ",", "\"Error\"", ",", "JOptionPane", ".", "ERROR_MESSAGE", ")", ";", "}", "// read datasets", "this", ".", "jTextFieldProcess", ".", "setText", "(", "properties", ".", "getProperty", "(", "\"processors\"", ")", ")", ";", "this", ".", "jTextFieldTask", ".", "setText", "(", "properties", ".", "getProperty", "(", "\"task\"", ")", ")", ";", "try", "{", "this", ".", "currentTask", "=", "(", "MainTask", ")", "ClassOption", ".", "cliStringToObject", "(", "this", ".", "jTextFieldTask", ".", "getText", "(", ")", ",", "MainTask", ".", "class", ",", "null", ")", ";", "}", "catch", "(", "Exception", "ex", ")", "{", "Logger", ".", "getLogger", "(", "TaskManagerTabPanel", ".", "class", ".", "getName", "(", ")", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "null", ",", "ex", ")", ";", "}", "this", ".", "jTextFieldDir", ".", "setText", "(", "properties", ".", "getProperty", "(", "\"ResultsDir\"", ")", ")", ";", "this", ".", "resultsPath", "=", "this", ".", "jTextFieldDir", ".", "getText", "(", ")", ";", "String", "[", "]", "streamShortNames", "=", "properties", ".", "getProperty", "(", "\"streamShortNames\"", ")", ".", "split", "(", "\",\"", ")", ";", "String", "[", "]", "streamCommand", "=", "properties", ".", "getProperty", "(", "\"streamCommand\"", ")", ".", "split", "(", "\",\"", ")", ";", "String", "[", "]", "algShortNames", "=", "properties", ".", "getProperty", "(", "\"algorithmShortNames\"", ")", ".", "split", "(", "\",\"", ")", ";", "String", "[", "]", "algorithmCommand", "=", "properties", ".", "getProperty", "(", "\"algorithmCommand\"", ")", ".", "split", "(", "\",\"", ")", ";", "cleanTables", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "streamShortNames", ".", "length", ";", "i", "++", ")", "{", "this", ".", "streamModel", ".", "addRow", "(", "new", "Object", "[", "]", "{", "streamCommand", "[", "i", "]", ",", "streamShortNames", "[", "i", "]", "}", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "algShortNames", ".", "length", ";", "i", "++", ")", "{", "this", ".", "algoritmModel", ".", "addRow", "(", "new", "Object", "[", "]", "{", "algorithmCommand", "[", "i", "]", ",", "algShortNames", "[", "i", "]", "}", ")", ";", "}", "}" ]
Opens a previously saved configuration @param path
[ "Opens", "a", "previously", "saved", "configuration" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/TaskManagerTabPanel.java#L1281-L1313
29,105
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.initializeAttributeIndices
protected void initializeAttributeIndices() { //m_AttributeIndices.setUpper(m_Data.numAttributes() - 1); m_ActiveIndices = new boolean[m_Data.numAttributes()]; for (int i = 0; i < m_ActiveIndices.length; i++) m_ActiveIndices[i] = true; //m_AttributeIndices.isInRange(i); }
java
protected void initializeAttributeIndices() { //m_AttributeIndices.setUpper(m_Data.numAttributes() - 1); m_ActiveIndices = new boolean[m_Data.numAttributes()]; for (int i = 0; i < m_ActiveIndices.length; i++) m_ActiveIndices[i] = true; //m_AttributeIndices.isInRange(i); }
[ "protected", "void", "initializeAttributeIndices", "(", ")", "{", "//m_AttributeIndices.setUpper(m_Data.numAttributes() - 1);", "m_ActiveIndices", "=", "new", "boolean", "[", "m_Data", ".", "numAttributes", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_ActiveIndices", ".", "length", ";", "i", "++", ")", "m_ActiveIndices", "[", "i", "]", "=", "true", ";", "//m_AttributeIndices.isInRange(i);", "}" ]
initializes the attribute indices.
[ "initializes", "the", "attribute", "indices", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L221-L226
29,106
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.norm
protected double norm(double x, int i) { if (Double.isNaN(m_Ranges[i][R_MIN]) || (m_Ranges[i][R_MAX] == m_Ranges[i][R_MIN])) return 0; else return (x - m_Ranges[i][R_MIN]) / (m_Ranges[i][R_WIDTH]); }
java
protected double norm(double x, int i) { if (Double.isNaN(m_Ranges[i][R_MIN]) || (m_Ranges[i][R_MAX] == m_Ranges[i][R_MIN])) return 0; else return (x - m_Ranges[i][R_MIN]) / (m_Ranges[i][R_WIDTH]); }
[ "protected", "double", "norm", "(", "double", "x", ",", "int", "i", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "m_Ranges", "[", "i", "]", "[", "R_MIN", "]", ")", "||", "(", "m_Ranges", "[", "i", "]", "[", "R_MAX", "]", "==", "m_Ranges", "[", "i", "]", "[", "R_MIN", "]", ")", ")", "return", "0", ";", "else", "return", "(", "x", "-", "m_Ranges", "[", "i", "]", "[", "R_MIN", "]", ")", "/", "(", "m_Ranges", "[", "i", "]", "[", "R_WIDTH", "]", ")", ";", "}" ]
Normalizes a given value of a numeric attribute. @param x the value to be normalized @param i the attribute's index @return the normalized value
[ "Normalizes", "a", "given", "value", "of", "a", "numeric", "attribute", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L380-L385
29,107
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.difference
protected double difference(int index, double val1, double val2) { //switch (m_Data.attribute(index).type()) { //case Attribute.NOMINAL: if (m_Data.attribute(index).isNominal() == true){ if (isMissingValue(val1) || isMissingValue(val2) || ((int) val1 != (int) val2)) { return 1; } else { return 0; } } else { //case Attribute.NUMERIC: if (isMissingValue(val1) || isMissingValue(val2)) { if (isMissingValue(val1) && isMissingValue(val2)) { if (!m_DontNormalize) //We are doing normalization return 1; else return (m_Ranges[index][R_MAX] - m_Ranges[index][R_MIN]); } else { double diff; if (isMissingValue(val2)) { diff = (!m_DontNormalize) ? norm(val1, index) : val1; } else { diff = (!m_DontNormalize) ? norm(val2, index) : val2; } if (!m_DontNormalize && diff < 0.5) { diff = 1.0 - diff; } else if (m_DontNormalize) { if ((m_Ranges[index][R_MAX]-diff) > (diff-m_Ranges[index][R_MIN])) return m_Ranges[index][R_MAX]-diff; else return diff-m_Ranges[index][R_MIN]; } return diff; } } else { return (!m_DontNormalize) ? (norm(val1, index) - norm(val2, index)) : (val1 - val2); } //default: // return 0; } }
java
protected double difference(int index, double val1, double val2) { //switch (m_Data.attribute(index).type()) { //case Attribute.NOMINAL: if (m_Data.attribute(index).isNominal() == true){ if (isMissingValue(val1) || isMissingValue(val2) || ((int) val1 != (int) val2)) { return 1; } else { return 0; } } else { //case Attribute.NUMERIC: if (isMissingValue(val1) || isMissingValue(val2)) { if (isMissingValue(val1) && isMissingValue(val2)) { if (!m_DontNormalize) //We are doing normalization return 1; else return (m_Ranges[index][R_MAX] - m_Ranges[index][R_MIN]); } else { double diff; if (isMissingValue(val2)) { diff = (!m_DontNormalize) ? norm(val1, index) : val1; } else { diff = (!m_DontNormalize) ? norm(val2, index) : val2; } if (!m_DontNormalize && diff < 0.5) { diff = 1.0 - diff; } else if (m_DontNormalize) { if ((m_Ranges[index][R_MAX]-diff) > (diff-m_Ranges[index][R_MIN])) return m_Ranges[index][R_MAX]-diff; else return diff-m_Ranges[index][R_MIN]; } return diff; } } else { return (!m_DontNormalize) ? (norm(val1, index) - norm(val2, index)) : (val1 - val2); } //default: // return 0; } }
[ "protected", "double", "difference", "(", "int", "index", ",", "double", "val1", ",", "double", "val2", ")", "{", "//switch (m_Data.attribute(index).type()) {", "//case Attribute.NOMINAL:", "if", "(", "m_Data", ".", "attribute", "(", "index", ")", ".", "isNominal", "(", ")", "==", "true", ")", "{", "if", "(", "isMissingValue", "(", "val1", ")", "||", "isMissingValue", "(", "val2", ")", "||", "(", "(", "int", ")", "val1", "!=", "(", "int", ")", "val2", ")", ")", "{", "return", "1", ";", "}", "else", "{", "return", "0", ";", "}", "}", "else", "{", "//case Attribute.NUMERIC:", "if", "(", "isMissingValue", "(", "val1", ")", "||", "isMissingValue", "(", "val2", ")", ")", "{", "if", "(", "isMissingValue", "(", "val1", ")", "&&", "isMissingValue", "(", "val2", ")", ")", "{", "if", "(", "!", "m_DontNormalize", ")", "//We are doing normalization", "return", "1", ";", "else", "return", "(", "m_Ranges", "[", "index", "]", "[", "R_MAX", "]", "-", "m_Ranges", "[", "index", "]", "[", "R_MIN", "]", ")", ";", "}", "else", "{", "double", "diff", ";", "if", "(", "isMissingValue", "(", "val2", ")", ")", "{", "diff", "=", "(", "!", "m_DontNormalize", ")", "?", "norm", "(", "val1", ",", "index", ")", ":", "val1", ";", "}", "else", "{", "diff", "=", "(", "!", "m_DontNormalize", ")", "?", "norm", "(", "val2", ",", "index", ")", ":", "val2", ";", "}", "if", "(", "!", "m_DontNormalize", "&&", "diff", "<", "0.5", ")", "{", "diff", "=", "1.0", "-", "diff", ";", "}", "else", "if", "(", "m_DontNormalize", ")", "{", "if", "(", "(", "m_Ranges", "[", "index", "]", "[", "R_MAX", "]", "-", "diff", ")", ">", "(", "diff", "-", "m_Ranges", "[", "index", "]", "[", "R_MIN", "]", ")", ")", "return", "m_Ranges", "[", "index", "]", "[", "R_MAX", "]", "-", "diff", ";", "else", "return", "diff", "-", "m_Ranges", "[", "index", "]", "[", "R_MIN", "]", ";", "}", "return", "diff", ";", "}", "}", "else", "{", "return", "(", "!", "m_DontNormalize", ")", "?", "(", "norm", "(", "val1", ",", "index", ")", "-", "norm", "(", "val2", ",", "index", ")", ")", ":", "(", "val1", "-", "val2", ")", ";", "}", "//default:", "// return 0;", "}", "}" ]
Computes the difference between two given attribute values. @param index the attribute index @param val1 the first value @param val2 the second value @return the difference
[ "Computes", "the", "difference", "between", "two", "given", "attribute", "values", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L396-L448
29,108
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.initializeRanges
public double[][] initializeRanges() { if (m_Data == null) { m_Ranges = null; return m_Ranges; } int numAtt = m_Data.numAttributes(); double[][] ranges = new double [numAtt][3]; if (m_Data.numInstances() <= 0) { initializeRangesEmpty(numAtt, ranges); m_Ranges = ranges; return m_Ranges; } else { // initialize ranges using the first instance updateRangesFirst(m_Data.instance(0), numAtt, ranges); } // update ranges, starting from the second for (int i = 1; i < m_Data.numInstances(); i++) updateRanges(m_Data.instance(i), numAtt, ranges); m_Ranges = ranges; return m_Ranges; }
java
public double[][] initializeRanges() { if (m_Data == null) { m_Ranges = null; return m_Ranges; } int numAtt = m_Data.numAttributes(); double[][] ranges = new double [numAtt][3]; if (m_Data.numInstances() <= 0) { initializeRangesEmpty(numAtt, ranges); m_Ranges = ranges; return m_Ranges; } else { // initialize ranges using the first instance updateRangesFirst(m_Data.instance(0), numAtt, ranges); } // update ranges, starting from the second for (int i = 1; i < m_Data.numInstances(); i++) updateRanges(m_Data.instance(i), numAtt, ranges); m_Ranges = ranges; return m_Ranges; }
[ "public", "double", "[", "]", "[", "]", "initializeRanges", "(", ")", "{", "if", "(", "m_Data", "==", "null", ")", "{", "m_Ranges", "=", "null", ";", "return", "m_Ranges", ";", "}", "int", "numAtt", "=", "m_Data", ".", "numAttributes", "(", ")", ";", "double", "[", "]", "[", "]", "ranges", "=", "new", "double", "[", "numAtt", "]", "[", "3", "]", ";", "if", "(", "m_Data", ".", "numInstances", "(", ")", "<=", "0", ")", "{", "initializeRangesEmpty", "(", "numAtt", ",", "ranges", ")", ";", "m_Ranges", "=", "ranges", ";", "return", "m_Ranges", ";", "}", "else", "{", "// initialize ranges using the first instance", "updateRangesFirst", "(", "m_Data", ".", "instance", "(", "0", ")", ",", "numAtt", ",", "ranges", ")", ";", "}", "// update ranges, starting from the second", "for", "(", "int", "i", "=", "1", ";", "i", "<", "m_Data", ".", "numInstances", "(", ")", ";", "i", "++", ")", "updateRanges", "(", "m_Data", ".", "instance", "(", "i", ")", "", ",", "numAtt", ",", "ranges", ")", ";", "m_Ranges", "=", "ranges", ";", "return", "m_Ranges", ";", "}" ]
Initializes the ranges using all instances of the dataset. Sets m_Ranges. @return the ranges
[ "Initializes", "the", "ranges", "using", "all", "instances", "of", "the", "dataset", ".", "Sets", "m_Ranges", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L456-L482
29,109
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.updateRangesFirst
public void updateRangesFirst(Instance instance, int numAtt, double[][] ranges) { for (int j = 0; j < numAtt; j++) { if (!instance.isMissing(j)) { ranges[j][R_MIN] = instance.value(j); ranges[j][R_MAX] = instance.value(j); ranges[j][R_WIDTH] = 0.0; } else { // if value was missing ranges[j][R_MIN] = Double.POSITIVE_INFINITY; ranges[j][R_MAX] = -Double.POSITIVE_INFINITY; ranges[j][R_WIDTH] = Double.POSITIVE_INFINITY; } } }
java
public void updateRangesFirst(Instance instance, int numAtt, double[][] ranges) { for (int j = 0; j < numAtt; j++) { if (!instance.isMissing(j)) { ranges[j][R_MIN] = instance.value(j); ranges[j][R_MAX] = instance.value(j); ranges[j][R_WIDTH] = 0.0; } else { // if value was missing ranges[j][R_MIN] = Double.POSITIVE_INFINITY; ranges[j][R_MAX] = -Double.POSITIVE_INFINITY; ranges[j][R_WIDTH] = Double.POSITIVE_INFINITY; } } }
[ "public", "void", "updateRangesFirst", "(", "Instance", "instance", ",", "int", "numAtt", ",", "double", "[", "]", "[", "]", "ranges", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "numAtt", ";", "j", "++", ")", "{", "if", "(", "!", "instance", ".", "isMissing", "(", "j", ")", ")", "{", "ranges", "[", "j", "]", "[", "R_MIN", "]", "=", "instance", ".", "value", "(", "j", ")", ";", "ranges", "[", "j", "]", "[", "R_MAX", "]", "=", "instance", ".", "value", "(", "j", ")", ";", "ranges", "[", "j", "]", "[", "R_WIDTH", "]", "=", "0.0", ";", "}", "else", "{", "// if value was missing", "ranges", "[", "j", "]", "[", "R_MIN", "]", "=", "Double", ".", "POSITIVE_INFINITY", ";", "ranges", "[", "j", "]", "[", "R_MAX", "]", "=", "-", "Double", ".", "POSITIVE_INFINITY", ";", "ranges", "[", "j", "]", "[", "R_WIDTH", "]", "=", "Double", ".", "POSITIVE_INFINITY", ";", "}", "}", "}" ]
Used to initialize the ranges. For this the values of the first instance is used to save time. Sets low and high to the values of the first instance and width to zero. @param instance the new instance @param numAtt number of attributes in the model @param ranges low, high and width values for all attributes
[ "Used", "to", "initialize", "the", "ranges", ".", "For", "this", "the", "values", "of", "the", "first", "instance", "is", "used", "to", "save", "time", ".", "Sets", "low", "and", "high", "to", "the", "values", "of", "the", "first", "instance", "and", "width", "to", "zero", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L494-L507
29,110
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.initializeRangesEmpty
public void initializeRangesEmpty(int numAtt, double[][] ranges) { for (int j = 0; j < numAtt; j++) { ranges[j][R_MIN] = Double.POSITIVE_INFINITY; ranges[j][R_MAX] = -Double.POSITIVE_INFINITY; ranges[j][R_WIDTH] = Double.POSITIVE_INFINITY; } }
java
public void initializeRangesEmpty(int numAtt, double[][] ranges) { for (int j = 0; j < numAtt; j++) { ranges[j][R_MIN] = Double.POSITIVE_INFINITY; ranges[j][R_MAX] = -Double.POSITIVE_INFINITY; ranges[j][R_WIDTH] = Double.POSITIVE_INFINITY; } }
[ "public", "void", "initializeRangesEmpty", "(", "int", "numAtt", ",", "double", "[", "]", "[", "]", "ranges", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "numAtt", ";", "j", "++", ")", "{", "ranges", "[", "j", "]", "[", "R_MIN", "]", "=", "Double", ".", "POSITIVE_INFINITY", ";", "ranges", "[", "j", "]", "[", "R_MAX", "]", "=", "-", "Double", ".", "POSITIVE_INFINITY", ";", "ranges", "[", "j", "]", "[", "R_WIDTH", "]", "=", "Double", ".", "POSITIVE_INFINITY", ";", "}", "}" ]
Used to initialize the ranges. @param numAtt number of attributes in the model @param ranges low, high and width values for all attributes
[ "Used", "to", "initialize", "the", "ranges", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L546-L552
29,111
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.updateRanges
public double[][] updateRanges(Instance instance, double[][] ranges) { // updateRangesFirst must have been called on ranges for (int j = 0; j < ranges.length; j++) { double value = instance.value(j); if (!instance.isMissing(j)) { if (value < ranges[j][R_MIN]) { ranges[j][R_MIN] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } else { if (instance.value(j) > ranges[j][R_MAX]) { ranges[j][R_MAX] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } } } } return ranges; }
java
public double[][] updateRanges(Instance instance, double[][] ranges) { // updateRangesFirst must have been called on ranges for (int j = 0; j < ranges.length; j++) { double value = instance.value(j); if (!instance.isMissing(j)) { if (value < ranges[j][R_MIN]) { ranges[j][R_MIN] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } else { if (instance.value(j) > ranges[j][R_MAX]) { ranges[j][R_MAX] = value; ranges[j][R_WIDTH] = ranges[j][R_MAX] - ranges[j][R_MIN]; } } } } return ranges; }
[ "public", "double", "[", "]", "[", "]", "updateRanges", "(", "Instance", "instance", ",", "double", "[", "]", "[", "]", "ranges", ")", "{", "// updateRangesFirst must have been called on ranges", "for", "(", "int", "j", "=", "0", ";", "j", "<", "ranges", ".", "length", ";", "j", "++", ")", "{", "double", "value", "=", "instance", ".", "value", "(", "j", ")", ";", "if", "(", "!", "instance", ".", "isMissing", "(", "j", ")", ")", "{", "if", "(", "value", "<", "ranges", "[", "j", "]", "[", "R_MIN", "]", ")", "{", "ranges", "[", "j", "]", "[", "R_MIN", "]", "=", "value", ";", "ranges", "[", "j", "]", "[", "R_WIDTH", "]", "=", "ranges", "[", "j", "]", "[", "R_MAX", "]", "-", "ranges", "[", "j", "]", "[", "R_MIN", "]", ";", "}", "else", "{", "if", "(", "instance", ".", "value", "(", "j", ")", ">", "ranges", "[", "j", "]", "[", "R_MAX", "]", ")", "{", "ranges", "[", "j", "]", "[", "R_MAX", "]", "=", "value", ";", "ranges", "[", "j", "]", "[", "R_WIDTH", "]", "=", "ranges", "[", "j", "]", "[", "R_MAX", "]", "-", "ranges", "[", "j", "]", "[", "R_MIN", "]", ";", "}", "}", "}", "}", "return", "ranges", ";", "}" ]
Updates the ranges given a new instance. @param instance the new instance @param ranges low, high and width values for all attributes @return the updated ranges
[ "Updates", "the", "ranges", "given", "a", "new", "instance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L561-L579
29,112
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.initializeRanges
public double[][] initializeRanges(int[] instList) throws Exception { if (m_Data == null) throw new Exception("No instances supplied."); int numAtt = m_Data.numAttributes(); double[][] ranges = new double [numAtt][3]; if (m_Data.numInstances() <= 0) { initializeRangesEmpty(numAtt, ranges); return ranges; } else { // initialize ranges using the first instance updateRangesFirst(m_Data.instance(instList[0]), numAtt, ranges); // update ranges, starting from the second for (int i = 1; i < instList.length; i++) { updateRanges(m_Data.instance(instList[i]), numAtt, ranges); } } return ranges; }
java
public double[][] initializeRanges(int[] instList) throws Exception { if (m_Data == null) throw new Exception("No instances supplied."); int numAtt = m_Data.numAttributes(); double[][] ranges = new double [numAtt][3]; if (m_Data.numInstances() <= 0) { initializeRangesEmpty(numAtt, ranges); return ranges; } else { // initialize ranges using the first instance updateRangesFirst(m_Data.instance(instList[0]), numAtt, ranges); // update ranges, starting from the second for (int i = 1; i < instList.length; i++) { updateRanges(m_Data.instance(instList[i]), numAtt, ranges); } } return ranges; }
[ "public", "double", "[", "]", "[", "]", "initializeRanges", "(", "int", "[", "]", "instList", ")", "throws", "Exception", "{", "if", "(", "m_Data", "==", "null", ")", "throw", "new", "Exception", "(", "\"No instances supplied.\"", ")", ";", "int", "numAtt", "=", "m_Data", ".", "numAttributes", "(", ")", ";", "double", "[", "]", "[", "]", "ranges", "=", "new", "double", "[", "numAtt", "]", "[", "3", "]", ";", "if", "(", "m_Data", ".", "numInstances", "(", ")", "<=", "0", ")", "{", "initializeRangesEmpty", "(", "numAtt", ",", "ranges", ")", ";", "return", "ranges", ";", "}", "else", "{", "// initialize ranges using the first instance", "updateRangesFirst", "(", "m_Data", ".", "instance", "(", "instList", "[", "0", "]", ")", ",", "numAtt", ",", "ranges", ")", ";", "// update ranges, starting from the second", "for", "(", "int", "i", "=", "1", ";", "i", "<", "instList", ".", "length", ";", "i", "++", ")", "{", "updateRanges", "(", "m_Data", ".", "instance", "(", "instList", "[", "i", "]", ")", ",", "numAtt", ",", "ranges", ")", ";", "}", "}", "return", "ranges", ";", "}" ]
Initializes the ranges of a subset of the instances of this dataset. Therefore m_Ranges is not set. @param instList list of indexes of the subset @return the ranges @throws Exception if something goes wrong
[ "Initializes", "the", "ranges", "of", "a", "subset", "of", "the", "instances", "of", "this", "dataset", ".", "Therefore", "m_Ranges", "is", "not", "set", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L589-L609
29,113
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java
NormalizableDistance.inRanges
public boolean inRanges(Instance instance, double[][] ranges) { boolean isIn = true; // updateRangesFirst must have been called on ranges for (int j = 0; isIn && (j < ranges.length); j++) { if (!instance.isMissing(j)) { double value = instance.value(j); isIn = value <= ranges[j][R_MAX]; if (isIn) isIn = value >= ranges[j][R_MIN]; } } return isIn; }
java
public boolean inRanges(Instance instance, double[][] ranges) { boolean isIn = true; // updateRangesFirst must have been called on ranges for (int j = 0; isIn && (j < ranges.length); j++) { if (!instance.isMissing(j)) { double value = instance.value(j); isIn = value <= ranges[j][R_MAX]; if (isIn) isIn = value >= ranges[j][R_MIN]; } } return isIn; }
[ "public", "boolean", "inRanges", "(", "Instance", "instance", ",", "double", "[", "]", "[", "]", "ranges", ")", "{", "boolean", "isIn", "=", "true", ";", "// updateRangesFirst must have been called on ranges", "for", "(", "int", "j", "=", "0", ";", "isIn", "&&", "(", "j", "<", "ranges", ".", "length", ")", ";", "j", "++", ")", "{", "if", "(", "!", "instance", ".", "isMissing", "(", "j", ")", ")", "{", "double", "value", "=", "instance", ".", "value", "(", "j", ")", ";", "isIn", "=", "value", "<=", "ranges", "[", "j", "]", "[", "R_MAX", "]", ";", "if", "(", "isIn", ")", "isIn", "=", "value", ">=", "ranges", "[", "j", "]", "[", "R_MIN", "]", ";", "}", "}", "return", "isIn", ";", "}" ]
Test if an instance is within the given ranges. @param instance the instance @param ranges the ranges the instance is tested to be in @return true if instance is within the ranges
[ "Test", "if", "an", "instance", "is", "within", "the", "given", "ranges", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NormalizableDistance.java#L665-L678
29,114
AgNO3/jcifs-ng
src/main/java/jcifs/http/Handler.java
Handler.setURLStreamHandlerFactory
public static void setURLStreamHandlerFactory ( URLStreamHandlerFactory factory ) { synchronized ( PROTOCOL_HANDLERS ) { if ( Handler.factory != null ) { throw new IllegalStateException("URLStreamHandlerFactory already set."); } PROTOCOL_HANDLERS.clear(); Handler.factory = factory; } }
java
public static void setURLStreamHandlerFactory ( URLStreamHandlerFactory factory ) { synchronized ( PROTOCOL_HANDLERS ) { if ( Handler.factory != null ) { throw new IllegalStateException("URLStreamHandlerFactory already set."); } PROTOCOL_HANDLERS.clear(); Handler.factory = factory; } }
[ "public", "static", "void", "setURLStreamHandlerFactory", "(", "URLStreamHandlerFactory", "factory", ")", "{", "synchronized", "(", "PROTOCOL_HANDLERS", ")", "{", "if", "(", "Handler", ".", "factory", "!=", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"URLStreamHandlerFactory already set.\"", ")", ";", "}", "PROTOCOL_HANDLERS", ".", "clear", "(", ")", ";", "Handler", ".", "factory", "=", "factory", ";", "}", "}" ]
Sets the URL stream handler factory for the environment. This allows specification of the factory used in creating underlying stream handlers. This can be called once per JVM instance. @param factory The URL stream handler factory.
[ "Sets", "the", "URL", "stream", "handler", "factory", "for", "the", "environment", ".", "This", "allows", "specification", "of", "the", "factory", "used", "in", "creating", "underlying", "stream", "handlers", ".", "This", "can", "be", "called", "once", "per", "JVM", "instance", "." ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/http/Handler.java#L86-L94
29,115
AgNO3/jcifs-ng
src/main/java/jcifs/dcerpc/DcerpcHandle.java
DcerpcHandle.bind
public void bind () throws DcerpcException, IOException { synchronized ( this ) { try { this.state = 1; DcerpcMessage bind = new DcerpcBind(this.binding, this); sendrecv(bind); } catch ( IOException ioe ) { this.state = 0; throw ioe; } } }
java
public void bind () throws DcerpcException, IOException { synchronized ( this ) { try { this.state = 1; DcerpcMessage bind = new DcerpcBind(this.binding, this); sendrecv(bind); } catch ( IOException ioe ) { this.state = 0; throw ioe; } } }
[ "public", "void", "bind", "(", ")", "throws", "DcerpcException", ",", "IOException", "{", "synchronized", "(", "this", ")", "{", "try", "{", "this", ".", "state", "=", "1", ";", "DcerpcMessage", "bind", "=", "new", "DcerpcBind", "(", "this", ".", "binding", ",", "this", ")", ";", "sendrecv", "(", "bind", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "this", ".", "state", "=", "0", ";", "throw", "ioe", ";", "}", "}", "}" ]
Bind the handle @throws DcerpcException @throws IOException
[ "Bind", "the", "handle" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/dcerpc/DcerpcHandle.java#L212-L224
29,116
AgNO3/jcifs-ng
src/main/java/jcifs/smb/SmbFile.java
SmbFile.list
public String[] list () throws SmbException { return SmbEnumerationUtil.list(this, "*", ATTR_DIRECTORY | ATTR_HIDDEN | ATTR_SYSTEM, null, null); }
java
public String[] list () throws SmbException { return SmbEnumerationUtil.list(this, "*", ATTR_DIRECTORY | ATTR_HIDDEN | ATTR_SYSTEM, null, null); }
[ "public", "String", "[", "]", "list", "(", ")", "throws", "SmbException", "{", "return", "SmbEnumerationUtil", ".", "list", "(", "this", ",", "\"*\"", ",", "ATTR_DIRECTORY", "|", "ATTR_HIDDEN", "|", "ATTR_SYSTEM", ",", "null", ",", "null", ")", ";", "}" ]
List the contents of this SMB resource. The list returned by this method will be; <ul> <li>files and directories contained within this resource if the resource is a normal disk file directory, <li>all available NetBIOS workgroups or domains if this resource is the top level URL <code>smb://</code>, <li>all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a <code>smb://workgroup/</code> URL, <li>all browseable shares of a server including printers, IPC services, or disk volumes if this resource is a server URL in the form <code>smb://server/</code>, <li>or <code>null</code> if the resource cannot be resolved. </ul> @return A <code>String[]</code> array of files and directories, workgroups, servers, or shares depending on the context of the resource URL @throws SmbException
[ "List", "the", "contents", "of", "this", "SMB", "resource", ".", "The", "list", "returned", "by", "this", "method", "will", "be", ";" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/smb/SmbFile.java#L1140-L1142
29,117
AgNO3/jcifs-ng
src/main/java/jcifs/internal/smb1/SMB1SigningDigest.java
SMB1SigningDigest.update
public void update ( byte[] input, int offset, int len ) { if ( log.isTraceEnabled() ) { log.trace("update: " + this.updates + " " + offset + ":" + len); log.trace(Hexdump.toHexString(input, offset, Math.min(len, 256))); } if ( len == 0 ) { return; /* CRITICAL */ } this.digest.update(input, offset, len); this.updates++; }
java
public void update ( byte[] input, int offset, int len ) { if ( log.isTraceEnabled() ) { log.trace("update: " + this.updates + " " + offset + ":" + len); log.trace(Hexdump.toHexString(input, offset, Math.min(len, 256))); } if ( len == 0 ) { return; /* CRITICAL */ } this.digest.update(input, offset, len); this.updates++; }
[ "public", "void", "update", "(", "byte", "[", "]", "input", ",", "int", "offset", ",", "int", "len", ")", "{", "if", "(", "log", ".", "isTraceEnabled", "(", ")", ")", "{", "log", ".", "trace", "(", "\"update: \"", "+", "this", ".", "updates", "+", "\" \"", "+", "offset", "+", "\":\"", "+", "len", ")", ";", "log", ".", "trace", "(", "Hexdump", ".", "toHexString", "(", "input", ",", "offset", ",", "Math", ".", "min", "(", "len", ",", "256", ")", ")", ")", ";", "}", "if", "(", "len", "==", "0", ")", "{", "return", ";", "/* CRITICAL */", "}", "this", ".", "digest", ".", "update", "(", "input", ",", "offset", ",", "len", ")", ";", "this", ".", "updates", "++", ";", "}" ]
Update digest with data @param input @param offset @param len
[ "Update", "digest", "with", "data" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/internal/smb1/SMB1SigningDigest.java#L161-L171
29,118
AgNO3/jcifs-ng
src/main/java/jcifs/ntlmssp/Type3Message.java
Type3Message.setupMIC
public void setupMIC ( byte[] type1, byte[] type2 ) throws GeneralSecurityException, IOException { byte[] sk = this.masterKey; if ( sk == null ) { return; } MessageDigest mac = Crypto.getHMACT64(sk); mac.update(type1); mac.update(type2); byte[] type3 = toByteArray(); mac.update(type3); setMic(mac.digest()); }
java
public void setupMIC ( byte[] type1, byte[] type2 ) throws GeneralSecurityException, IOException { byte[] sk = this.masterKey; if ( sk == null ) { return; } MessageDigest mac = Crypto.getHMACT64(sk); mac.update(type1); mac.update(type2); byte[] type3 = toByteArray(); mac.update(type3); setMic(mac.digest()); }
[ "public", "void", "setupMIC", "(", "byte", "[", "]", "type1", ",", "byte", "[", "]", "type2", ")", "throws", "GeneralSecurityException", ",", "IOException", "{", "byte", "[", "]", "sk", "=", "this", ".", "masterKey", ";", "if", "(", "sk", "==", "null", ")", "{", "return", ";", "}", "MessageDigest", "mac", "=", "Crypto", ".", "getHMACT64", "(", "sk", ")", ";", "mac", ".", "update", "(", "type1", ")", ";", "mac", ".", "update", "(", "type2", ")", ";", "byte", "[", "]", "type3", "=", "toByteArray", "(", ")", ";", "mac", ".", "update", "(", "type3", ")", ";", "setMic", "(", "mac", ".", "digest", "(", ")", ")", ";", "}" ]
Sets the MIC @param type1 @param type2 @throws GeneralSecurityException @throws IOException
[ "Sets", "the", "MIC" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/ntlmssp/Type3Message.java#L297-L308
29,119
AgNO3/jcifs-ng
src/main/java/jcifs/ntlmssp/Type3Message.java
Type3Message.getDefaultFlags
public static int getDefaultFlags ( CIFSContext tc ) { return NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION | ( tc.getConfig().isUseUnicode() ? NTLMSSP_NEGOTIATE_UNICODE : NTLMSSP_NEGOTIATE_OEM ); }
java
public static int getDefaultFlags ( CIFSContext tc ) { return NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION | ( tc.getConfig().isUseUnicode() ? NTLMSSP_NEGOTIATE_UNICODE : NTLMSSP_NEGOTIATE_OEM ); }
[ "public", "static", "int", "getDefaultFlags", "(", "CIFSContext", "tc", ")", "{", "return", "NTLMSSP_NEGOTIATE_NTLM", "|", "NTLMSSP_NEGOTIATE_VERSION", "|", "(", "tc", ".", "getConfig", "(", ")", ".", "isUseUnicode", "(", ")", "?", "NTLMSSP_NEGOTIATE_UNICODE", ":", "NTLMSSP_NEGOTIATE_OEM", ")", ";", "}" ]
Returns the default flags for a generic Type-3 message in the current environment. @param tc context to use @return An <code>int</code> containing the default flags.
[ "Returns", "the", "default", "flags", "for", "a", "generic", "Type", "-", "3", "message", "in", "the", "current", "environment", "." ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/ntlmssp/Type3Message.java#L359-L362
29,120
AgNO3/jcifs-ng
src/main/java/jcifs/ntlmssp/av/AvPairs.java
AvPairs.decode
public static List<AvPair> decode ( byte[] data ) throws CIFSException { List<AvPair> pairs = new LinkedList<>(); int pos = 0; boolean foundEnd = false; while ( pos + 4 <= data.length ) { int avId = SMBUtil.readInt2(data, pos); int avLen = SMBUtil.readInt2(data, pos + 2); pos += 4; if ( avId == AvPair.MsvAvEOL ) { if ( avLen != 0 ) { throw new CIFSException("Invalid avLen for AvEOL"); } foundEnd = true; break; } byte[] raw = new byte[avLen]; System.arraycopy(data, pos, raw, 0, avLen); pairs.add(parseAvPair(avId, raw)); pos += avLen; } if ( !foundEnd ) { throw new CIFSException("Missing AvEOL"); } return pairs; }
java
public static List<AvPair> decode ( byte[] data ) throws CIFSException { List<AvPair> pairs = new LinkedList<>(); int pos = 0; boolean foundEnd = false; while ( pos + 4 <= data.length ) { int avId = SMBUtil.readInt2(data, pos); int avLen = SMBUtil.readInt2(data, pos + 2); pos += 4; if ( avId == AvPair.MsvAvEOL ) { if ( avLen != 0 ) { throw new CIFSException("Invalid avLen for AvEOL"); } foundEnd = true; break; } byte[] raw = new byte[avLen]; System.arraycopy(data, pos, raw, 0, avLen); pairs.add(parseAvPair(avId, raw)); pos += avLen; } if ( !foundEnd ) { throw new CIFSException("Missing AvEOL"); } return pairs; }
[ "public", "static", "List", "<", "AvPair", ">", "decode", "(", "byte", "[", "]", "data", ")", "throws", "CIFSException", "{", "List", "<", "AvPair", ">", "pairs", "=", "new", "LinkedList", "<>", "(", ")", ";", "int", "pos", "=", "0", ";", "boolean", "foundEnd", "=", "false", ";", "while", "(", "pos", "+", "4", "<=", "data", ".", "length", ")", "{", "int", "avId", "=", "SMBUtil", ".", "readInt2", "(", "data", ",", "pos", ")", ";", "int", "avLen", "=", "SMBUtil", ".", "readInt2", "(", "data", ",", "pos", "+", "2", ")", ";", "pos", "+=", "4", ";", "if", "(", "avId", "==", "AvPair", ".", "MsvAvEOL", ")", "{", "if", "(", "avLen", "!=", "0", ")", "{", "throw", "new", "CIFSException", "(", "\"Invalid avLen for AvEOL\"", ")", ";", "}", "foundEnd", "=", "true", ";", "break", ";", "}", "byte", "[", "]", "raw", "=", "new", "byte", "[", "avLen", "]", ";", "System", ".", "arraycopy", "(", "data", ",", "pos", ",", "raw", ",", "0", ",", "avLen", ")", ";", "pairs", ".", "add", "(", "parseAvPair", "(", "avId", ",", "raw", ")", ")", ";", "pos", "+=", "avLen", ";", "}", "if", "(", "!", "foundEnd", ")", "{", "throw", "new", "CIFSException", "(", "\"Missing AvEOL\"", ")", ";", "}", "return", "pairs", ";", "}" ]
Decode a list of AvPairs @param data @return individual pairs @throws CIFSException
[ "Decode", "a", "list", "of", "AvPairs" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/ntlmssp/av/AvPairs.java#L45-L72
29,121
AgNO3/jcifs-ng
src/main/java/jcifs/ntlmssp/av/AvPairs.java
AvPairs.remove
public static void remove ( List<AvPair> pairs, int type ) { Iterator<AvPair> it = pairs.iterator(); while ( it.hasNext() ) { AvPair p = it.next(); if ( p.getType() == type ) { it.remove(); } } }
java
public static void remove ( List<AvPair> pairs, int type ) { Iterator<AvPair> it = pairs.iterator(); while ( it.hasNext() ) { AvPair p = it.next(); if ( p.getType() == type ) { it.remove(); } } }
[ "public", "static", "void", "remove", "(", "List", "<", "AvPair", ">", "pairs", ",", "int", "type", ")", "{", "Iterator", "<", "AvPair", ">", "it", "=", "pairs", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "AvPair", "p", "=", "it", ".", "next", "(", ")", ";", "if", "(", "p", ".", "getType", "(", ")", "==", "type", ")", "{", "it", ".", "remove", "(", ")", ";", "}", "}", "}" ]
Remove all occurances of the given type @param pairs @param type
[ "Remove", "all", "occurances", "of", "the", "given", "type" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/ntlmssp/av/AvPairs.java#L118-L126
29,122
AgNO3/jcifs-ng
src/main/java/jcifs/ntlmssp/av/AvPairs.java
AvPairs.replace
public static void replace ( List<AvPair> pairs, AvPair rep ) { remove(pairs, rep.getType()); pairs.add(rep); }
java
public static void replace ( List<AvPair> pairs, AvPair rep ) { remove(pairs, rep.getType()); pairs.add(rep); }
[ "public", "static", "void", "replace", "(", "List", "<", "AvPair", ">", "pairs", ",", "AvPair", "rep", ")", "{", "remove", "(", "pairs", ",", "rep", ".", "getType", "(", ")", ")", ";", "pairs", ".", "add", "(", "rep", ")", ";", "}" ]
Replace all occurances of the given type @param pairs @param rep
[ "Replace", "all", "occurances", "of", "the", "given", "type" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/ntlmssp/av/AvPairs.java#L135-L138
29,123
AgNO3/jcifs-ng
src/main/java/jcifs/smb/SmbFileOutputStream.java
SmbFileOutputStream.close
@Override public void close () throws IOException { try { if ( this.handle.isValid() ) { this.handle.close(); } } finally { this.file.clearAttributeCache(); this.tmp = null; } }
java
@Override public void close () throws IOException { try { if ( this.handle.isValid() ) { this.handle.close(); } } finally { this.file.clearAttributeCache(); this.tmp = null; } }
[ "@", "Override", "public", "void", "close", "(", ")", "throws", "IOException", "{", "try", "{", "if", "(", "this", ".", "handle", ".", "isValid", "(", ")", ")", "{", "this", ".", "handle", ".", "close", "(", ")", ";", "}", "}", "finally", "{", "this", ".", "file", ".", "clearAttributeCache", "(", ")", ";", "this", ".", "tmp", "=", "null", ";", "}", "}" ]
Closes this output stream and releases any system resources associated with it. @throws IOException if a network error occurs
[ "Closes", "this", "output", "stream", "and", "releases", "any", "system", "resources", "associated", "with", "it", "." ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/smb/SmbFileOutputStream.java#L199-L210
29,124
AgNO3/jcifs-ng
src/main/java/jcifs/smb/SmbSessionImpl.java
SmbSessionImpl.treeConnectLogon
@Override public void treeConnectLogon () throws SmbException { String logonShare = getContext().getConfig().getLogonShare(); if ( logonShare == null || logonShare.isEmpty() ) { throw new SmbException("Logon share is not defined"); } try ( SmbTreeImpl t = getSmbTree(logonShare, null) ) { t.treeConnect(null, null); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
java
@Override public void treeConnectLogon () throws SmbException { String logonShare = getContext().getConfig().getLogonShare(); if ( logonShare == null || logonShare.isEmpty() ) { throw new SmbException("Logon share is not defined"); } try ( SmbTreeImpl t = getSmbTree(logonShare, null) ) { t.treeConnect(null, null); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
[ "@", "Override", "public", "void", "treeConnectLogon", "(", ")", "throws", "SmbException", "{", "String", "logonShare", "=", "getContext", "(", ")", ".", "getConfig", "(", ")", ".", "getLogonShare", "(", ")", ";", "if", "(", "logonShare", "==", "null", "||", "logonShare", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "SmbException", "(", "\"Logon share is not defined\"", ")", ";", "}", "try", "(", "SmbTreeImpl", "t", "=", "getSmbTree", "(", "logonShare", ",", "null", ")", ")", "{", "t", ".", "treeConnect", "(", "null", ",", "null", ")", ";", "}", "catch", "(", "CIFSException", "e", ")", "{", "throw", "SmbException", ".", "wrap", "(", "e", ")", ";", "}", "}" ]
Establish a tree connection with the configured logon share @throws SmbException
[ "Establish", "a", "tree", "connection", "with", "the", "configured", "logon", "share" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/smb/SmbSessionImpl.java#L280-L292
29,125
AgNO3/jcifs-ng
src/main/java/jcifs/util/transport/Transport.java
Transport.readn
public static int readn ( InputStream in, byte[] b, int off, int len ) throws IOException { int i = 0, n = -5; if ( off + len > b.length ) { throw new IOException("Buffer too short, bufsize " + b.length + " read " + len); } while ( i < len ) { n = in.read(b, off + i, len - i); if ( n <= 0 ) { break; } i += n; } return i; }
java
public static int readn ( InputStream in, byte[] b, int off, int len ) throws IOException { int i = 0, n = -5; if ( off + len > b.length ) { throw new IOException("Buffer too short, bufsize " + b.length + " read " + len); } while ( i < len ) { n = in.read(b, off + i, len - i); if ( n <= 0 ) { break; } i += n; } return i; }
[ "public", "static", "int", "readn", "(", "InputStream", "in", ",", "byte", "[", "]", "b", ",", "int", "off", ",", "int", "len", ")", "throws", "IOException", "{", "int", "i", "=", "0", ",", "n", "=", "-", "5", ";", "if", "(", "off", "+", "len", ">", "b", ".", "length", ")", "{", "throw", "new", "IOException", "(", "\"Buffer too short, bufsize \"", "+", "b", ".", "length", "+", "\" read \"", "+", "len", ")", ";", "}", "while", "(", "i", "<", "len", ")", "{", "n", "=", "in", ".", "read", "(", "b", ",", "off", "+", "i", ",", "len", "-", "i", ")", ";", "if", "(", "n", "<=", "0", ")", "{", "break", ";", "}", "i", "+=", "n", ";", "}", "return", "i", ";", "}" ]
Read bytes from the input stream into a buffer @param in @param b @param off @param len @return number of bytes read @throws IOException
[ "Read", "bytes", "from", "the", "input", "stream", "into", "a", "buffer" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/util/transport/Transport.java#L62-L78
29,126
AgNO3/jcifs-ng
src/main/java/jcifs/util/transport/Transport.java
Transport.sendrecv
public <T extends Response> T sendrecv ( Request request, T response, Set<RequestParam> params ) throws IOException { if ( isDisconnected() && this.state != 5 ) { throw new TransportException("Transport is disconnected " + this.name); } try { long timeout = !params.contains(RequestParam.NO_TIMEOUT) ? getResponseTimeout(request) : 0; long firstKey = doSend(request, response, params, timeout); if ( Thread.currentThread() == this.thread ) { // we are in the transport thread, ie. on idle disconnecting // this is synchronous operation // This does not handle compound requests synchronized ( this.inLock ) { Long peekKey = peekKey(); if ( peekKey == firstKey ) { doRecv(response); response.received(); return response; } doSkip(peekKey); } } return waitForResponses(request, response, timeout); } catch ( IOException ioe ) { log.warn("sendrecv failed", ioe); try { disconnect(true); } catch ( IOException ioe2 ) { ioe.addSuppressed(ioe2); log.info("disconnect failed", ioe2); } throw ioe; } catch ( InterruptedException ie ) { throw new TransportException(ie); } finally { Response curResp = response; Request curReq = request; while ( curResp != null ) { this.response_map.remove(curResp.getMid()); Request next = curReq.getNext(); if ( next != null ) { curReq = next; curResp = next.getResponse(); } else { break; } } } }
java
public <T extends Response> T sendrecv ( Request request, T response, Set<RequestParam> params ) throws IOException { if ( isDisconnected() && this.state != 5 ) { throw new TransportException("Transport is disconnected " + this.name); } try { long timeout = !params.contains(RequestParam.NO_TIMEOUT) ? getResponseTimeout(request) : 0; long firstKey = doSend(request, response, params, timeout); if ( Thread.currentThread() == this.thread ) { // we are in the transport thread, ie. on idle disconnecting // this is synchronous operation // This does not handle compound requests synchronized ( this.inLock ) { Long peekKey = peekKey(); if ( peekKey == firstKey ) { doRecv(response); response.received(); return response; } doSkip(peekKey); } } return waitForResponses(request, response, timeout); } catch ( IOException ioe ) { log.warn("sendrecv failed", ioe); try { disconnect(true); } catch ( IOException ioe2 ) { ioe.addSuppressed(ioe2); log.info("disconnect failed", ioe2); } throw ioe; } catch ( InterruptedException ie ) { throw new TransportException(ie); } finally { Response curResp = response; Request curReq = request; while ( curResp != null ) { this.response_map.remove(curResp.getMid()); Request next = curReq.getNext(); if ( next != null ) { curReq = next; curResp = next.getResponse(); } else { break; } } } }
[ "public", "<", "T", "extends", "Response", ">", "T", "sendrecv", "(", "Request", "request", ",", "T", "response", ",", "Set", "<", "RequestParam", ">", "params", ")", "throws", "IOException", "{", "if", "(", "isDisconnected", "(", ")", "&&", "this", ".", "state", "!=", "5", ")", "{", "throw", "new", "TransportException", "(", "\"Transport is disconnected \"", "+", "this", ".", "name", ")", ";", "}", "try", "{", "long", "timeout", "=", "!", "params", ".", "contains", "(", "RequestParam", ".", "NO_TIMEOUT", ")", "?", "getResponseTimeout", "(", "request", ")", ":", "0", ";", "long", "firstKey", "=", "doSend", "(", "request", ",", "response", ",", "params", ",", "timeout", ")", ";", "if", "(", "Thread", ".", "currentThread", "(", ")", "==", "this", ".", "thread", ")", "{", "// we are in the transport thread, ie. on idle disconnecting", "// this is synchronous operation", "// This does not handle compound requests", "synchronized", "(", "this", ".", "inLock", ")", "{", "Long", "peekKey", "=", "peekKey", "(", ")", ";", "if", "(", "peekKey", "==", "firstKey", ")", "{", "doRecv", "(", "response", ")", ";", "response", ".", "received", "(", ")", ";", "return", "response", ";", "}", "doSkip", "(", "peekKey", ")", ";", "}", "}", "return", "waitForResponses", "(", "request", ",", "response", ",", "timeout", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "log", ".", "warn", "(", "\"sendrecv failed\"", ",", "ioe", ")", ";", "try", "{", "disconnect", "(", "true", ")", ";", "}", "catch", "(", "IOException", "ioe2", ")", "{", "ioe", ".", "addSuppressed", "(", "ioe2", ")", ";", "log", ".", "info", "(", "\"disconnect failed\"", ",", "ioe2", ")", ";", "}", "throw", "ioe", ";", "}", "catch", "(", "InterruptedException", "ie", ")", "{", "throw", "new", "TransportException", "(", "ie", ")", ";", "}", "finally", "{", "Response", "curResp", "=", "response", ";", "Request", "curReq", "=", "request", ";", "while", "(", "curResp", "!=", "null", ")", "{", "this", ".", "response_map", ".", "remove", "(", "curResp", ".", "getMid", "(", ")", ")", ";", "Request", "next", "=", "curReq", ".", "getNext", "(", ")", ";", "if", "(", "next", "!=", "null", ")", "{", "curReq", "=", "next", ";", "curResp", "=", "next", ".", "getResponse", "(", ")", ";", "}", "else", "{", "break", ";", "}", "}", "}", "}" ]
Send a request message and recieve response @param request @param response @param params @return the response @throws IOException
[ "Send", "a", "request", "message", "and", "recieve", "response" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/util/transport/Transport.java#L208-L263
29,127
AgNO3/jcifs-ng
src/main/java/jcifs/util/transport/Transport.java
Transport.disconnect
public synchronized boolean disconnect ( boolean hard, boolean inUse ) throws IOException { IOException ioe = null; switch ( this.state ) { case 0: /* not connected - just return */ case 5: case 6: return false; case 2: hard = true; case 3: /* connected - go ahead and disconnect */ if ( this.response_map.size() != 0 && !hard && inUse ) { break; /* outstanding requests */ } try { this.state = 5; boolean wasInUse = doDisconnect(hard, inUse); this.state = 6; return wasInUse; } catch ( IOException ioe0 ) { this.state = 6; ioe = ioe0; } case 4: /* failed to connect - reset the transport */ // thread is cleaned up by connect routine, joining it here causes a deadlock this.thread = null; this.state = 6; break; default: log.error("Invalid state: " + this.state); this.thread = null; this.state = 6; break; } if ( ioe != null ) throw ioe; return false; }
java
public synchronized boolean disconnect ( boolean hard, boolean inUse ) throws IOException { IOException ioe = null; switch ( this.state ) { case 0: /* not connected - just return */ case 5: case 6: return false; case 2: hard = true; case 3: /* connected - go ahead and disconnect */ if ( this.response_map.size() != 0 && !hard && inUse ) { break; /* outstanding requests */ } try { this.state = 5; boolean wasInUse = doDisconnect(hard, inUse); this.state = 6; return wasInUse; } catch ( IOException ioe0 ) { this.state = 6; ioe = ioe0; } case 4: /* failed to connect - reset the transport */ // thread is cleaned up by connect routine, joining it here causes a deadlock this.thread = null; this.state = 6; break; default: log.error("Invalid state: " + this.state); this.thread = null; this.state = 6; break; } if ( ioe != null ) throw ioe; return false; }
[ "public", "synchronized", "boolean", "disconnect", "(", "boolean", "hard", ",", "boolean", "inUse", ")", "throws", "IOException", "{", "IOException", "ioe", "=", "null", ";", "switch", "(", "this", ".", "state", ")", "{", "case", "0", ":", "/* not connected - just return */", "case", "5", ":", "case", "6", ":", "return", "false", ";", "case", "2", ":", "hard", "=", "true", ";", "case", "3", ":", "/* connected - go ahead and disconnect */", "if", "(", "this", ".", "response_map", ".", "size", "(", ")", "!=", "0", "&&", "!", "hard", "&&", "inUse", ")", "{", "break", ";", "/* outstanding requests */", "}", "try", "{", "this", ".", "state", "=", "5", ";", "boolean", "wasInUse", "=", "doDisconnect", "(", "hard", ",", "inUse", ")", ";", "this", ".", "state", "=", "6", ";", "return", "wasInUse", ";", "}", "catch", "(", "IOException", "ioe0", ")", "{", "this", ".", "state", "=", "6", ";", "ioe", "=", "ioe0", ";", "}", "case", "4", ":", "/* failed to connect - reset the transport */", "// thread is cleaned up by connect routine, joining it here causes a deadlock", "this", ".", "thread", "=", "null", ";", "this", ".", "state", "=", "6", ";", "break", ";", "default", ":", "log", ".", "error", "(", "\"Invalid state: \"", "+", "this", ".", "state", ")", ";", "this", ".", "thread", "=", "null", ";", "this", ".", "state", "=", "6", ";", "break", ";", "}", "if", "(", "ioe", "!=", "null", ")", "throw", "ioe", ";", "return", "false", ";", "}" ]
Disconnect the transport @param hard @param inUse whether the caller is holding a usage reference on the transport @return whether conenction was in use @throws IOException
[ "Disconnect", "the", "transport" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/util/transport/Transport.java#L677-L717
29,128
AgNO3/jcifs-ng
src/main/java/jcifs/smb/SmbTransportImpl.java
SmbTransportImpl.doRecv
@Override protected void doRecv ( Response response ) throws IOException { CommonServerMessageBlock resp = (CommonServerMessageBlock) response; this.negotiated.setupResponse(response); try { if ( this.smb2 ) { doRecvSMB2(resp); } else { doRecvSMB1(resp); } } catch ( Exception e ) { log.warn("Failure decoding message, disconnecting transport", e); response.exception(e); synchronized ( response ) { response.notifyAll(); } throw e; } }
java
@Override protected void doRecv ( Response response ) throws IOException { CommonServerMessageBlock resp = (CommonServerMessageBlock) response; this.negotiated.setupResponse(response); try { if ( this.smb2 ) { doRecvSMB2(resp); } else { doRecvSMB1(resp); } } catch ( Exception e ) { log.warn("Failure decoding message, disconnecting transport", e); response.exception(e); synchronized ( response ) { response.notifyAll(); } throw e; } }
[ "@", "Override", "protected", "void", "doRecv", "(", "Response", "response", ")", "throws", "IOException", "{", "CommonServerMessageBlock", "resp", "=", "(", "CommonServerMessageBlock", ")", "response", ";", "this", ".", "negotiated", ".", "setupResponse", "(", "response", ")", ";", "try", "{", "if", "(", "this", ".", "smb2", ")", "{", "doRecvSMB2", "(", "resp", ")", ";", "}", "else", "{", "doRecvSMB1", "(", "resp", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "log", ".", "warn", "(", "\"Failure decoding message, disconnecting transport\"", ",", "e", ")", ";", "response", ".", "exception", "(", "e", ")", ";", "synchronized", "(", "response", ")", "{", "response", ".", "notifyAll", "(", ")", ";", "}", "throw", "e", ";", "}", "}" ]
must be synchronized with peekKey
[ "must", "be", "synchronized", "with", "peekKey" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/smb/SmbTransportImpl.java#L1137-L1158
29,129
AgNO3/jcifs-ng
src/main/java/jcifs/netbios/UniAddress.java
UniAddress.isDotQuadIP
public static boolean isDotQuadIP ( String hostname ) { if ( Character.isDigit(hostname.charAt(0)) ) { int i, len, dots; char[] data; i = dots = 0; /* quick IP address validation */ len = hostname.length(); data = hostname.toCharArray(); while ( i < len && Character.isDigit(data[ i++ ]) ) { if ( i == len && dots == 3 ) { // probably an IP address return true; } if ( i < len && data[ i ] == '.' ) { dots++; i++; } } } return false; }
java
public static boolean isDotQuadIP ( String hostname ) { if ( Character.isDigit(hostname.charAt(0)) ) { int i, len, dots; char[] data; i = dots = 0; /* quick IP address validation */ len = hostname.length(); data = hostname.toCharArray(); while ( i < len && Character.isDigit(data[ i++ ]) ) { if ( i == len && dots == 3 ) { // probably an IP address return true; } if ( i < len && data[ i ] == '.' ) { dots++; i++; } } } return false; }
[ "public", "static", "boolean", "isDotQuadIP", "(", "String", "hostname", ")", "{", "if", "(", "Character", ".", "isDigit", "(", "hostname", ".", "charAt", "(", "0", ")", ")", ")", "{", "int", "i", ",", "len", ",", "dots", ";", "char", "[", "]", "data", ";", "i", "=", "dots", "=", "0", ";", "/* quick IP address validation */", "len", "=", "hostname", ".", "length", "(", ")", ";", "data", "=", "hostname", ".", "toCharArray", "(", ")", ";", "while", "(", "i", "<", "len", "&&", "Character", ".", "isDigit", "(", "data", "[", "i", "++", "]", ")", ")", "{", "if", "(", "i", "==", "len", "&&", "dots", "==", "3", ")", "{", "// probably an IP address", "return", "true", ";", "}", "if", "(", "i", "<", "len", "&&", "data", "[", "i", "]", "==", "'", "'", ")", "{", "dots", "++", ";", "i", "++", ";", "}", "}", "}", "return", "false", ";", "}" ]
Check whether a hostname is actually an ip address @param hostname @return whether this is an IP address
[ "Check", "whether", "a", "hostname", "is", "actually", "an", "ip", "address" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/netbios/UniAddress.java#L57-L78
29,130
AgNO3/jcifs-ng
src/main/java/jcifs/context/SingletonContext.java
SingletonContext.init
public static synchronized final void init ( Properties props ) throws CIFSException { if ( INSTANCE != null ) { throw new CIFSException("Singleton context is already initialized"); } Properties p = new Properties(); try { String filename = System.getProperty("jcifs.properties"); if ( filename != null && filename.length() > 1 ) { try ( FileInputStream in = new FileInputStream(filename) ) { p.load(in); } } } catch ( IOException ioe ) { log.error("Failed to load config", ioe); //$NON-NLS-1$ } p.putAll(System.getProperties()); if ( props != null ) { p.putAll(props); } INSTANCE = new SingletonContext(p); }
java
public static synchronized final void init ( Properties props ) throws CIFSException { if ( INSTANCE != null ) { throw new CIFSException("Singleton context is already initialized"); } Properties p = new Properties(); try { String filename = System.getProperty("jcifs.properties"); if ( filename != null && filename.length() > 1 ) { try ( FileInputStream in = new FileInputStream(filename) ) { p.load(in); } } } catch ( IOException ioe ) { log.error("Failed to load config", ioe); //$NON-NLS-1$ } p.putAll(System.getProperties()); if ( props != null ) { p.putAll(props); } INSTANCE = new SingletonContext(p); }
[ "public", "static", "synchronized", "final", "void", "init", "(", "Properties", "props", ")", "throws", "CIFSException", "{", "if", "(", "INSTANCE", "!=", "null", ")", "{", "throw", "new", "CIFSException", "(", "\"Singleton context is already initialized\"", ")", ";", "}", "Properties", "p", "=", "new", "Properties", "(", ")", ";", "try", "{", "String", "filename", "=", "System", ".", "getProperty", "(", "\"jcifs.properties\"", ")", ";", "if", "(", "filename", "!=", "null", "&&", "filename", ".", "length", "(", ")", ">", "1", ")", "{", "try", "(", "FileInputStream", "in", "=", "new", "FileInputStream", "(", "filename", ")", ")", "{", "p", ".", "load", "(", "in", ")", ";", "}", "}", "}", "catch", "(", "IOException", "ioe", ")", "{", "log", ".", "error", "(", "\"Failed to load config\"", ",", "ioe", ")", ";", "//$NON-NLS-1$", "}", "p", ".", "putAll", "(", "System", ".", "getProperties", "(", ")", ")", ";", "if", "(", "props", "!=", "null", ")", "{", "p", ".", "putAll", "(", "props", ")", ";", "}", "INSTANCE", "=", "new", "SingletonContext", "(", "p", ")", ";", "}" ]
Initialize singleton context using custom properties This method can only be called once. @param props @throws CIFSException
[ "Initialize", "singleton", "context", "using", "custom", "properties" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/context/SingletonContext.java#L54-L77
29,131
AgNO3/jcifs-ng
src/main/java/jcifs/context/SingletonContext.java
SingletonContext.getInstance
public static synchronized final SingletonContext getInstance () { if ( INSTANCE == null ) { try { log.debug("Initializing singleton context"); init(null); } catch ( CIFSException e ) { log.error("Failed to create singleton JCIFS context", e); } } return INSTANCE; }
java
public static synchronized final SingletonContext getInstance () { if ( INSTANCE == null ) { try { log.debug("Initializing singleton context"); init(null); } catch ( CIFSException e ) { log.error("Failed to create singleton JCIFS context", e); } } return INSTANCE; }
[ "public", "static", "synchronized", "final", "SingletonContext", "getInstance", "(", ")", "{", "if", "(", "INSTANCE", "==", "null", ")", "{", "try", "{", "log", ".", "debug", "(", "\"Initializing singleton context\"", ")", ";", "init", "(", "null", ")", ";", "}", "catch", "(", "CIFSException", "e", ")", "{", "log", ".", "error", "(", "\"Failed to create singleton JCIFS context\"", ",", "e", ")", ";", "}", "}", "return", "INSTANCE", ";", "}" ]
Get singleton context The singleton context will use system properties for configuration as well as values specified in a file specified through this <tt>jcifs.properties</tt> system property. @return a global context, initialized on first call
[ "Get", "singleton", "context" ]
0311107a077ea372527ae74839eec8042197332f
https://github.com/AgNO3/jcifs-ng/blob/0311107a077ea372527ae74839eec8042197332f/src/main/java/jcifs/context/SingletonContext.java#L88-L99
29,132
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/util/stats/NumberUtil.java
NumberUtil.getPowerOf2
public static int getPowerOf2(long value) { Preconditions.checkArgument(isPowerOf2(value)); return Long.SIZE-(Long.numberOfLeadingZeros(value)+1); }
java
public static int getPowerOf2(long value) { Preconditions.checkArgument(isPowerOf2(value)); return Long.SIZE-(Long.numberOfLeadingZeros(value)+1); }
[ "public", "static", "int", "getPowerOf2", "(", "long", "value", ")", "{", "Preconditions", ".", "checkArgument", "(", "isPowerOf2", "(", "value", ")", ")", ";", "return", "Long", ".", "SIZE", "-", "(", "Long", ".", "numberOfLeadingZeros", "(", "value", ")", "+", "1", ")", ";", "}" ]
Returns an integer X such that 2^X=value. Throws an exception if value is not a power of 2. @param value @return
[ "Returns", "an", "integer", "X", "such", "that", "2^X", "=", "value", ".", "Throws", "an", "exception", "if", "value", "is", "not", "a", "power", "of", "2", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/util/stats/NumberUtil.java#L21-L24
29,133
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/BackendTransaction.java
BackendTransaction.rollback
@Override public void rollback() throws BackendException { Throwable excep = null; for (IndexTransaction itx : indexTx.values()) { try { itx.rollback(); } catch (Throwable e) { excep = e; } } storeTx.rollback(); if (excep!=null) { //throw any encountered index transaction rollback exceptions if (excep instanceof BackendException) throw (BackendException)excep; else throw new PermanentBackendException("Unexpected exception",excep); } }
java
@Override public void rollback() throws BackendException { Throwable excep = null; for (IndexTransaction itx : indexTx.values()) { try { itx.rollback(); } catch (Throwable e) { excep = e; } } storeTx.rollback(); if (excep!=null) { //throw any encountered index transaction rollback exceptions if (excep instanceof BackendException) throw (BackendException)excep; else throw new PermanentBackendException("Unexpected exception",excep); } }
[ "@", "Override", "public", "void", "rollback", "(", ")", "throws", "BackendException", "{", "Throwable", "excep", "=", "null", ";", "for", "(", "IndexTransaction", "itx", ":", "indexTx", ".", "values", "(", ")", ")", "{", "try", "{", "itx", ".", "rollback", "(", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "excep", "=", "e", ";", "}", "}", "storeTx", ".", "rollback", "(", ")", ";", "if", "(", "excep", "!=", "null", ")", "{", "//throw any encountered index transaction rollback exceptions", "if", "(", "excep", "instanceof", "BackendException", ")", "throw", "(", "BackendException", ")", "excep", ";", "else", "throw", "new", "PermanentBackendException", "(", "\"Unexpected exception\"", ",", "excep", ")", ";", "}", "}" ]
Rolls back all transactions and makes sure that this does not get cut short by exceptions. If exceptions occur, the storage exception takes priority on re-throw. @throws BackendException
[ "Rolls", "back", "all", "transactions", "and", "makes", "sure", "that", "this", "does", "not", "get", "cut", "short", "by", "exceptions", ".", "If", "exceptions", "occur", "the", "storage", "exception", "takes", "priority", "on", "re", "-", "throw", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/BackendTransaction.java#L144-L159
29,134
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/database/idassigner/placement/PartitionIDRange.java
PartitionIDRange.contains
public boolean contains(int partitionId) { if (lowerID < upperID) { //"Proper" id range return lowerID <= partitionId && upperID > partitionId; } else { //Id range "wraps around" return (lowerID <= partitionId && partitionId < idUpperBound) || (upperID > partitionId && partitionId >= 0); } }
java
public boolean contains(int partitionId) { if (lowerID < upperID) { //"Proper" id range return lowerID <= partitionId && upperID > partitionId; } else { //Id range "wraps around" return (lowerID <= partitionId && partitionId < idUpperBound) || (upperID > partitionId && partitionId >= 0); } }
[ "public", "boolean", "contains", "(", "int", "partitionId", ")", "{", "if", "(", "lowerID", "<", "upperID", ")", "{", "//\"Proper\" id range", "return", "lowerID", "<=", "partitionId", "&&", "upperID", ">", "partitionId", ";", "}", "else", "{", "//Id range \"wraps around\"", "return", "(", "lowerID", "<=", "partitionId", "&&", "partitionId", "<", "idUpperBound", ")", "||", "(", "upperID", ">", "partitionId", "&&", "partitionId", ">=", "0", ")", ";", "}", "}" ]
Returns true of the given partitionId lies within this partition id range, else false. @param partitionId @return
[ "Returns", "true", "of", "the", "given", "partitionId", "lies", "within", "this", "partition", "id", "range", "else", "false", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/database/idassigner/placement/PartitionIDRange.java#L88-L95
29,135
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/database/idassigner/placement/PartitionIDRange.java
PartitionIDRange.getRandomID
public int getRandomID() { //Compute the width of the partition... int partitionWidth; if (lowerID < upperID) partitionWidth = upperID - lowerID; //... for "proper" ranges else partitionWidth = (idUpperBound - lowerID) + upperID; //... and those that "wrap around" Preconditions.checkArgument(partitionWidth > 0, partitionWidth); return (random.nextInt(partitionWidth) + lowerID) % idUpperBound; }
java
public int getRandomID() { //Compute the width of the partition... int partitionWidth; if (lowerID < upperID) partitionWidth = upperID - lowerID; //... for "proper" ranges else partitionWidth = (idUpperBound - lowerID) + upperID; //... and those that "wrap around" Preconditions.checkArgument(partitionWidth > 0, partitionWidth); return (random.nextInt(partitionWidth) + lowerID) % idUpperBound; }
[ "public", "int", "getRandomID", "(", ")", "{", "//Compute the width of the partition...", "int", "partitionWidth", ";", "if", "(", "lowerID", "<", "upperID", ")", "partitionWidth", "=", "upperID", "-", "lowerID", ";", "//... for \"proper\" ranges", "else", "partitionWidth", "=", "(", "idUpperBound", "-", "lowerID", ")", "+", "upperID", ";", "//... and those that \"wrap around\"", "Preconditions", ".", "checkArgument", "(", "partitionWidth", ">", "0", ",", "partitionWidth", ")", ";", "return", "(", "random", ".", "nextInt", "(", "partitionWidth", ")", "+", "lowerID", ")", "%", "idUpperBound", ";", "}" ]
Returns a random partition id that lies within this partition id range. @return
[ "Returns", "a", "random", "partition", "id", "that", "lies", "within", "this", "partition", "id", "range", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/database/idassigner/placement/PartitionIDRange.java#L107-L114
29,136
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/util/stats/ObjectAccumulator.java
ObjectAccumulator.incBy
public double incBy(K o, double inc) { Counter c = countMap.get(o); if (c == null) { c = new Counter(); countMap.put(o, c); } c.count += inc; return c.count; }
java
public double incBy(K o, double inc) { Counter c = countMap.get(o); if (c == null) { c = new Counter(); countMap.put(o, c); } c.count += inc; return c.count; }
[ "public", "double", "incBy", "(", "K", "o", ",", "double", "inc", ")", "{", "Counter", "c", "=", "countMap", ".", "get", "(", "o", ")", ";", "if", "(", "c", "==", "null", ")", "{", "c", "=", "new", "Counter", "(", ")", ";", "countMap", ".", "put", "(", "o", ",", "c", ")", ";", "}", "c", ".", "count", "+=", "inc", ";", "return", "c", ".", "count", ";", "}" ]
Increases the count of object o by inc and returns the new count value @param o @param inc @return
[ "Increases", "the", "count", "of", "object", "o", "by", "inc", "and", "returns", "the", "new", "count", "value" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/util/stats/ObjectAccumulator.java#L36-L44
29,137
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/configuration/GraphDatabaseConfiguration.java
GraphDatabaseConfiguration.getHomeDirectory
public File getHomeDirectory() { if (!configuration.has(STORAGE_DIRECTORY)) throw new UnsupportedOperationException("No home directory specified"); File dir = new File(configuration.get(STORAGE_DIRECTORY)); Preconditions.checkArgument(dir.isDirectory(), "Not a directory"); return dir; }
java
public File getHomeDirectory() { if (!configuration.has(STORAGE_DIRECTORY)) throw new UnsupportedOperationException("No home directory specified"); File dir = new File(configuration.get(STORAGE_DIRECTORY)); Preconditions.checkArgument(dir.isDirectory(), "Not a directory"); return dir; }
[ "public", "File", "getHomeDirectory", "(", ")", "{", "if", "(", "!", "configuration", ".", "has", "(", "STORAGE_DIRECTORY", ")", ")", "throw", "new", "UnsupportedOperationException", "(", "\"No home directory specified\"", ")", ";", "File", "dir", "=", "new", "File", "(", "configuration", ".", "get", "(", "STORAGE_DIRECTORY", ")", ")", ";", "Preconditions", ".", "checkArgument", "(", "dir", ".", "isDirectory", "(", ")", ",", "\"Not a directory\"", ")", ";", "return", "dir", ";", "}" ]
Returns the home directory for the graph database initialized in this configuration @return Home directory for this graph database configuration
[ "Returns", "the", "home", "directory", "for", "the", "graph", "database", "initialized", "in", "this", "configuration" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/configuration/GraphDatabaseConfiguration.java#L1858-L1864
29,138
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/kcvs/KCVSLog.java
KCVSLog.close
@Override public synchronized void close() throws BackendException { if (!isOpen) return; this.isOpen = false; if (readExecutor!=null) readExecutor.shutdown(); if (sendThread!=null) sendThread.close(CLOSE_DOWN_WAIT); if (readExecutor!=null) { try { readExecutor.awaitTermination(1,TimeUnit.SECONDS); } catch (InterruptedException e) { log.error("Could not terminate reader thread pool for KCVSLog "+name+" due to interruption"); } if (!readExecutor.isTerminated()) { readExecutor.shutdownNow(); log.error("Reader thread pool for KCVSLog "+name+" did not shut down in time - could not clean up or set read markers"); } else { for (MessagePuller puller : msgPullers) { puller.close(); } } } writeSetting(manager.senderId, MESSAGE_COUNTER_COLUMN, numMsgCounter.get()); store.close(); manager.closedLog(this); }
java
@Override public synchronized void close() throws BackendException { if (!isOpen) return; this.isOpen = false; if (readExecutor!=null) readExecutor.shutdown(); if (sendThread!=null) sendThread.close(CLOSE_DOWN_WAIT); if (readExecutor!=null) { try { readExecutor.awaitTermination(1,TimeUnit.SECONDS); } catch (InterruptedException e) { log.error("Could not terminate reader thread pool for KCVSLog "+name+" due to interruption"); } if (!readExecutor.isTerminated()) { readExecutor.shutdownNow(); log.error("Reader thread pool for KCVSLog "+name+" did not shut down in time - could not clean up or set read markers"); } else { for (MessagePuller puller : msgPullers) { puller.close(); } } } writeSetting(manager.senderId, MESSAGE_COUNTER_COLUMN, numMsgCounter.get()); store.close(); manager.closedLog(this); }
[ "@", "Override", "public", "synchronized", "void", "close", "(", ")", "throws", "BackendException", "{", "if", "(", "!", "isOpen", ")", "return", ";", "this", ".", "isOpen", "=", "false", ";", "if", "(", "readExecutor", "!=", "null", ")", "readExecutor", ".", "shutdown", "(", ")", ";", "if", "(", "sendThread", "!=", "null", ")", "sendThread", ".", "close", "(", "CLOSE_DOWN_WAIT", ")", ";", "if", "(", "readExecutor", "!=", "null", ")", "{", "try", "{", "readExecutor", ".", "awaitTermination", "(", "1", ",", "TimeUnit", ".", "SECONDS", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "log", ".", "error", "(", "\"Could not terminate reader thread pool for KCVSLog \"", "+", "name", "+", "\" due to interruption\"", ")", ";", "}", "if", "(", "!", "readExecutor", ".", "isTerminated", "(", ")", ")", "{", "readExecutor", ".", "shutdownNow", "(", ")", ";", "log", ".", "error", "(", "\"Reader thread pool for KCVSLog \"", "+", "name", "+", "\" did not shut down in time - could not clean up or set read markers\"", ")", ";", "}", "else", "{", "for", "(", "MessagePuller", "puller", ":", "msgPullers", ")", "{", "puller", ".", "close", "(", ")", ";", "}", "}", "}", "writeSetting", "(", "manager", ".", "senderId", ",", "MESSAGE_COUNTER_COLUMN", ",", "numMsgCounter", ".", "get", "(", ")", ")", ";", "store", ".", "close", "(", ")", ";", "manager", ".", "closedLog", "(", "this", ")", ";", "}" ]
Closes the log by terminating all threads and waiting for their termination. @throws com.thinkaurelius.titan.diskstorage.BackendException
[ "Closes", "the", "log", "by", "terminating", "all", "threads", "and", "waiting", "for", "their", "termination", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/kcvs/KCVSLog.java#L272-L296
29,139
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/kcvs/KCVSLog.java
KCVSLog.sendMessages
private void sendMessages(final List<MessageEnvelope> msgEnvelopes) { try { boolean success=BackendOperation.execute(new BackendOperation.Transactional<Boolean>() { @Override public Boolean call(StoreTransaction txh) throws BackendException { ListMultimap<StaticBuffer,Entry> mutations = ArrayListMultimap.create(); for (MessageEnvelope env : msgEnvelopes) { mutations.put(env.key,env.entry); long ts = env.entry.getColumn().getLong(0); log.debug("Preparing to write {} to storage with column/timestamp {}", env, times.getTime(ts)); } Map<StaticBuffer,KCVMutation> muts = new HashMap<StaticBuffer, KCVMutation>(mutations.keySet().size()); for (StaticBuffer key : mutations.keySet()) { muts.put(key,new KCVMutation(mutations.get(key),KeyColumnValueStore.NO_DELETIONS)); log.debug("Built mutation on key {} with {} additions", key, mutations.get(key).size()); } manager.storeManager.mutateMany(ImmutableMap.of(store.getName(),muts),txh); log.debug("Wrote {} total envelopes with operation timestamp {}", msgEnvelopes.size(), txh.getConfiguration().getCommitTime()); return Boolean.TRUE; } @Override public String toString() { return "messageSending"; } },this, times, maxWriteTime); Preconditions.checkState(success); log.debug("Wrote {} messages to backend",msgEnvelopes.size()); for (MessageEnvelope msgEnvelope : msgEnvelopes) msgEnvelope.message.delivered(); } catch (TitanException e) { for (MessageEnvelope msgEnvelope : msgEnvelopes) msgEnvelope.message.failed(e); throw e; } }
java
private void sendMessages(final List<MessageEnvelope> msgEnvelopes) { try { boolean success=BackendOperation.execute(new BackendOperation.Transactional<Boolean>() { @Override public Boolean call(StoreTransaction txh) throws BackendException { ListMultimap<StaticBuffer,Entry> mutations = ArrayListMultimap.create(); for (MessageEnvelope env : msgEnvelopes) { mutations.put(env.key,env.entry); long ts = env.entry.getColumn().getLong(0); log.debug("Preparing to write {} to storage with column/timestamp {}", env, times.getTime(ts)); } Map<StaticBuffer,KCVMutation> muts = new HashMap<StaticBuffer, KCVMutation>(mutations.keySet().size()); for (StaticBuffer key : mutations.keySet()) { muts.put(key,new KCVMutation(mutations.get(key),KeyColumnValueStore.NO_DELETIONS)); log.debug("Built mutation on key {} with {} additions", key, mutations.get(key).size()); } manager.storeManager.mutateMany(ImmutableMap.of(store.getName(),muts),txh); log.debug("Wrote {} total envelopes with operation timestamp {}", msgEnvelopes.size(), txh.getConfiguration().getCommitTime()); return Boolean.TRUE; } @Override public String toString() { return "messageSending"; } },this, times, maxWriteTime); Preconditions.checkState(success); log.debug("Wrote {} messages to backend",msgEnvelopes.size()); for (MessageEnvelope msgEnvelope : msgEnvelopes) msgEnvelope.message.delivered(); } catch (TitanException e) { for (MessageEnvelope msgEnvelope : msgEnvelopes) msgEnvelope.message.failed(e); throw e; } }
[ "private", "void", "sendMessages", "(", "final", "List", "<", "MessageEnvelope", ">", "msgEnvelopes", ")", "{", "try", "{", "boolean", "success", "=", "BackendOperation", ".", "execute", "(", "new", "BackendOperation", ".", "Transactional", "<", "Boolean", ">", "(", ")", "{", "@", "Override", "public", "Boolean", "call", "(", "StoreTransaction", "txh", ")", "throws", "BackendException", "{", "ListMultimap", "<", "StaticBuffer", ",", "Entry", ">", "mutations", "=", "ArrayListMultimap", ".", "create", "(", ")", ";", "for", "(", "MessageEnvelope", "env", ":", "msgEnvelopes", ")", "{", "mutations", ".", "put", "(", "env", ".", "key", ",", "env", ".", "entry", ")", ";", "long", "ts", "=", "env", ".", "entry", ".", "getColumn", "(", ")", ".", "getLong", "(", "0", ")", ";", "log", ".", "debug", "(", "\"Preparing to write {} to storage with column/timestamp {}\"", ",", "env", ",", "times", ".", "getTime", "(", "ts", ")", ")", ";", "}", "Map", "<", "StaticBuffer", ",", "KCVMutation", ">", "muts", "=", "new", "HashMap", "<", "StaticBuffer", ",", "KCVMutation", ">", "(", "mutations", ".", "keySet", "(", ")", ".", "size", "(", ")", ")", ";", "for", "(", "StaticBuffer", "key", ":", "mutations", ".", "keySet", "(", ")", ")", "{", "muts", ".", "put", "(", "key", ",", "new", "KCVMutation", "(", "mutations", ".", "get", "(", "key", ")", ",", "KeyColumnValueStore", ".", "NO_DELETIONS", ")", ")", ";", "log", ".", "debug", "(", "\"Built mutation on key {} with {} additions\"", ",", "key", ",", "mutations", ".", "get", "(", "key", ")", ".", "size", "(", ")", ")", ";", "}", "manager", ".", "storeManager", ".", "mutateMany", "(", "ImmutableMap", ".", "of", "(", "store", ".", "getName", "(", ")", ",", "muts", ")", ",", "txh", ")", ";", "log", ".", "debug", "(", "\"Wrote {} total envelopes with operation timestamp {}\"", ",", "msgEnvelopes", ".", "size", "(", ")", ",", "txh", ".", "getConfiguration", "(", ")", ".", "getCommitTime", "(", ")", ")", ";", "return", "Boolean", ".", "TRUE", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"messageSending\"", ";", "}", "}", ",", "this", ",", "times", ",", "maxWriteTime", ")", ";", "Preconditions", ".", "checkState", "(", "success", ")", ";", "log", ".", "debug", "(", "\"Wrote {} messages to backend\"", ",", "msgEnvelopes", ".", "size", "(", ")", ")", ";", "for", "(", "MessageEnvelope", "msgEnvelope", ":", "msgEnvelopes", ")", "msgEnvelope", ".", "message", ".", "delivered", "(", ")", ";", "}", "catch", "(", "TitanException", "e", ")", "{", "for", "(", "MessageEnvelope", "msgEnvelope", ":", "msgEnvelopes", ")", "msgEnvelope", ".", "message", ".", "failed", "(", ")", ";", "throw", "e", ";", "}", "}" ]
Sends a batch of messages by persisting them to the storage backend. @param msgEnvelopes
[ "Sends", "a", "batch", "of", "messages", "by", "persisting", "them", "to", "the", "storage", "backend", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/kcvs/KCVSLog.java#L456-L491
29,140
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java
Mutation.addition
public void addition(E entry) { if (additions==null) additions = new ArrayList<E>(); additions.add(entry); }
java
public void addition(E entry) { if (additions==null) additions = new ArrayList<E>(); additions.add(entry); }
[ "public", "void", "addition", "(", "E", "entry", ")", "{", "if", "(", "additions", "==", "null", ")", "additions", "=", "new", "ArrayList", "<", "E", ">", "(", ")", ";", "additions", ".", "add", "(", "entry", ")", ";", "}" ]
Adds a new entry as an addition to this mutation @param entry
[ "Adds", "a", "new", "entry", "as", "an", "addition", "to", "this", "mutation" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java#L79-L82
29,141
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java
Mutation.deletion
public void deletion(K key) { if (deletions==null) deletions = new ArrayList<K>(); deletions.add(key); }
java
public void deletion(K key) { if (deletions==null) deletions = new ArrayList<K>(); deletions.add(key); }
[ "public", "void", "deletion", "(", "K", "key", ")", "{", "if", "(", "deletions", "==", "null", ")", "deletions", "=", "new", "ArrayList", "<", "K", ">", "(", ")", ";", "deletions", ".", "add", "(", "key", ")", ";", "}" ]
Adds a new key as a deletion to this mutation @param key
[ "Adds", "a", "new", "key", "as", "a", "deletion", "to", "this", "mutation" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java#L89-L92
29,142
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java
Mutation.merge
public void merge(Mutation<E,K> m) { Preconditions.checkNotNull(m); if (null != m.additions) { if (null == additions) additions = m.additions; else additions.addAll(m.additions); } if (null != m.deletions) { if (null == deletions) deletions = m.deletions; else deletions.addAll(m.deletions); } }
java
public void merge(Mutation<E,K> m) { Preconditions.checkNotNull(m); if (null != m.additions) { if (null == additions) additions = m.additions; else additions.addAll(m.additions); } if (null != m.deletions) { if (null == deletions) deletions = m.deletions; else deletions.addAll(m.deletions); } }
[ "public", "void", "merge", "(", "Mutation", "<", "E", ",", "K", ">", "m", ")", "{", "Preconditions", ".", "checkNotNull", "(", "m", ")", ";", "if", "(", "null", "!=", "m", ".", "additions", ")", "{", "if", "(", "null", "==", "additions", ")", "additions", "=", "m", ".", "additions", ";", "else", "additions", ".", "addAll", "(", "m", ".", "additions", ")", ";", "}", "if", "(", "null", "!=", "m", ".", "deletions", ")", "{", "if", "(", "null", "==", "deletions", ")", "deletions", "=", "m", ".", "deletions", ";", "else", "deletions", ".", "addAll", "(", "m", ".", "deletions", ")", ";", "}", "}" ]
Merges another mutation into this mutation. Ensures that all additions and deletions are added to this mutation. Does not remove duplicates if such exist - this needs to be ensured by the caller. @param m
[ "Merges", "another", "mutation", "into", "this", "mutation", ".", "Ensures", "that", "all", "additions", "and", "deletions", "are", "added", "to", "this", "mutation", ".", "Does", "not", "remove", "duplicates", "if", "such", "exist", "-", "this", "needs", "to", "be", "ensured", "by", "the", "caller", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Mutation.java#L100-L112
29,143
thinkaurelius/titan
titan-cassandra/src/main/java/com/thinkaurelius/titan/diskstorage/cassandra/thrift/thriftpool/CTConnectionFactory.java
CTConnectionFactory.makeRawConnection
public CTConnection makeRawConnection() throws TTransportException { final Config cfg = cfgRef.get(); String hostname = cfg.getRandomHost(); log.debug("Creating TSocket({}, {}, {}, {}, {})", hostname, cfg.port, cfg.username, cfg.password, cfg.timeoutMS); TSocket socket; if (null != cfg.sslTruststoreLocation && !cfg.sslTruststoreLocation.isEmpty()) { TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters() {{ setTrustStore(cfg.sslTruststoreLocation, cfg.sslTruststorePassword); }}; socket = TSSLTransportFactory.getClientSocket(hostname, cfg.port, cfg.timeoutMS, params); } else { socket = new TSocket(hostname, cfg.port, cfg.timeoutMS); } TTransport transport = new TFramedTransport(socket, cfg.frameSize); log.trace("Created transport {}", transport); TBinaryProtocol protocol = new TBinaryProtocol(transport); Cassandra.Client client = new Cassandra.Client(protocol); if (!transport.isOpen()) { transport.open(); } if (cfg.username != null) { Map<String, String> credentials = new HashMap<String, String>() {{ put(IAuthenticator.USERNAME_KEY, cfg.username); put(IAuthenticator.PASSWORD_KEY, cfg.password); }}; try { client.login(new AuthenticationRequest(credentials)); } catch (Exception e) { // TTransportException will propagate authentication/authorization failure throw new TTransportException(e); } } return new CTConnection(transport, client, cfg); }
java
public CTConnection makeRawConnection() throws TTransportException { final Config cfg = cfgRef.get(); String hostname = cfg.getRandomHost(); log.debug("Creating TSocket({}, {}, {}, {}, {})", hostname, cfg.port, cfg.username, cfg.password, cfg.timeoutMS); TSocket socket; if (null != cfg.sslTruststoreLocation && !cfg.sslTruststoreLocation.isEmpty()) { TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters() {{ setTrustStore(cfg.sslTruststoreLocation, cfg.sslTruststorePassword); }}; socket = TSSLTransportFactory.getClientSocket(hostname, cfg.port, cfg.timeoutMS, params); } else { socket = new TSocket(hostname, cfg.port, cfg.timeoutMS); } TTransport transport = new TFramedTransport(socket, cfg.frameSize); log.trace("Created transport {}", transport); TBinaryProtocol protocol = new TBinaryProtocol(transport); Cassandra.Client client = new Cassandra.Client(protocol); if (!transport.isOpen()) { transport.open(); } if (cfg.username != null) { Map<String, String> credentials = new HashMap<String, String>() {{ put(IAuthenticator.USERNAME_KEY, cfg.username); put(IAuthenticator.PASSWORD_KEY, cfg.password); }}; try { client.login(new AuthenticationRequest(credentials)); } catch (Exception e) { // TTransportException will propagate authentication/authorization failure throw new TTransportException(e); } } return new CTConnection(transport, client, cfg); }
[ "public", "CTConnection", "makeRawConnection", "(", ")", "throws", "TTransportException", "{", "final", "Config", "cfg", "=", "cfgRef", ".", "get", "(", ")", ";", "String", "hostname", "=", "cfg", ".", "getRandomHost", "(", ")", ";", "log", ".", "debug", "(", "\"Creating TSocket({}, {}, {}, {}, {})\"", ",", "hostname", ",", "cfg", ".", "port", ",", "cfg", ".", "username", ",", "cfg", ".", "password", ",", "cfg", ".", "timeoutMS", ")", ";", "TSocket", "socket", ";", "if", "(", "null", "!=", "cfg", ".", "sslTruststoreLocation", "&&", "!", "cfg", ".", "sslTruststoreLocation", ".", "isEmpty", "(", ")", ")", "{", "TSSLTransportFactory", ".", "TSSLTransportParameters", "params", "=", "new", "TSSLTransportFactory", ".", "TSSLTransportParameters", "(", ")", "{", "{", "setTrustStore", "(", "cfg", ".", "sslTruststoreLocation", ",", "cfg", ".", "sslTruststorePassword", ")", ";", "}", "}", ";", "socket", "=", "TSSLTransportFactory", ".", "getClientSocket", "(", "hostname", ",", "cfg", ".", "port", ",", "cfg", ".", "timeoutMS", ",", "params", ")", ";", "}", "else", "{", "socket", "=", "new", "TSocket", "(", "hostname", ",", "cfg", ".", "port", ",", "cfg", ".", "timeoutMS", ")", ";", "}", "TTransport", "transport", "=", "new", "TFramedTransport", "(", "socket", ",", "cfg", ".", "frameSize", ")", ";", "log", ".", "trace", "(", "\"Created transport {}\"", ",", "transport", ")", ";", "TBinaryProtocol", "protocol", "=", "new", "TBinaryProtocol", "(", "transport", ")", ";", "Cassandra", ".", "Client", "client", "=", "new", "Cassandra", ".", "Client", "(", "protocol", ")", ";", "if", "(", "!", "transport", ".", "isOpen", "(", ")", ")", "{", "transport", ".", "open", "(", ")", ";", "}", "if", "(", "cfg", ".", "username", "!=", "null", ")", "{", "Map", "<", "String", ",", "String", ">", "credentials", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", "{", "{", "put", "(", "IAuthenticator", ".", "USERNAME_KEY", ",", "cfg", ".", "username", ")", ";", "put", "(", "IAuthenticator", ".", "PASSWORD_KEY", ",", "cfg", ".", "password", ")", ";", "}", "}", ";", "try", "{", "client", ".", "login", "(", "new", "AuthenticationRequest", "(", "credentials", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "// TTransportException will propagate authentication/authorization failure", "throw", "new", "TTransportException", "(", "e", ")", ";", "}", "}", "return", "new", "CTConnection", "(", "transport", ",", "client", ",", "cfg", ")", ";", "}" ]
Create a Cassandra-Thrift connection, but do not attempt to set a keyspace on the connection. @return A CTConnection ready to talk to a Cassandra cluster @throws TTransportException on any Thrift transport failure
[ "Create", "a", "Cassandra", "-", "Thrift", "connection", "but", "do", "not", "attempt", "to", "set", "a", "keyspace", "on", "the", "connection", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-cassandra/src/main/java/com/thinkaurelius/titan/diskstorage/cassandra/thrift/thriftpool/CTConnectionFactory.java#L66-L104
29,144
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/query/vertex/BasicVertexCentricQueryBuilder.java
BasicVertexCentricQueryBuilder.profiler
public Q profiler(QueryProfiler profiler) { Preconditions.checkNotNull(profiler); this.profiler=profiler; return getThis(); }
java
public Q profiler(QueryProfiler profiler) { Preconditions.checkNotNull(profiler); this.profiler=profiler; return getThis(); }
[ "public", "Q", "profiler", "(", "QueryProfiler", "profiler", ")", "{", "Preconditions", ".", "checkNotNull", "(", "profiler", ")", ";", "this", ".", "profiler", "=", "profiler", ";", "return", "getThis", "(", ")", ";", "}" ]
Sets the query profiler to observe this query. Must be set before the query is executed to take effect. @param profiler @return
[ "Sets", "the", "query", "profiler", "to", "observe", "this", "query", ".", "Must", "be", "set", "before", "the", "query", "is", "executed", "to", "take", "effect", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/query/vertex/BasicVertexCentricQueryBuilder.java#L105-L109
29,145
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/core/attribute/Geoshape.java
Geoshape.point
public static final Geoshape point(final float latitude, final float longitude) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); return new Geoshape(new float[][]{ new float[]{latitude}, new float[]{longitude}}); }
java
public static final Geoshape point(final float latitude, final float longitude) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); return new Geoshape(new float[][]{ new float[]{latitude}, new float[]{longitude}}); }
[ "public", "static", "final", "Geoshape", "point", "(", "final", "float", "latitude", ",", "final", "float", "longitude", ")", "{", "Preconditions", ".", "checkArgument", "(", "isValidCoordinate", "(", "latitude", ",", "longitude", ")", ",", "\"Invalid coordinate provided\"", ")", ";", "return", "new", "Geoshape", "(", "new", "float", "[", "]", "[", "]", "{", "new", "float", "[", "]", "{", "latitude", "}", ",", "new", "float", "[", "]", "{", "longitude", "}", "}", ")", ";", "}" ]
Constructs a point from its latitude and longitude information @param latitude @param longitude @return
[ "Constructs", "a", "point", "from", "its", "latitude", "and", "longitude", "information" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/core/attribute/Geoshape.java#L244-L247
29,146
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/core/attribute/Geoshape.java
Geoshape.circle
public static final Geoshape circle(final float latitude, final float longitude, final float radiusInKM) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); Preconditions.checkArgument(radiusInKM>0,"Invalid radius provided [%s]",radiusInKM); return new Geoshape(new float[][]{ new float[]{latitude, Float.NaN}, new float[]{longitude, radiusInKM}}); }
java
public static final Geoshape circle(final float latitude, final float longitude, final float radiusInKM) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); Preconditions.checkArgument(radiusInKM>0,"Invalid radius provided [%s]",radiusInKM); return new Geoshape(new float[][]{ new float[]{latitude, Float.NaN}, new float[]{longitude, radiusInKM}}); }
[ "public", "static", "final", "Geoshape", "circle", "(", "final", "float", "latitude", ",", "final", "float", "longitude", ",", "final", "float", "radiusInKM", ")", "{", "Preconditions", ".", "checkArgument", "(", "isValidCoordinate", "(", "latitude", ",", "longitude", ")", ",", "\"Invalid coordinate provided\"", ")", ";", "Preconditions", ".", "checkArgument", "(", "radiusInKM", ">", "0", ",", "\"Invalid radius provided [%s]\"", ",", "radiusInKM", ")", ";", "return", "new", "Geoshape", "(", "new", "float", "[", "]", "[", "]", "{", "new", "float", "[", "]", "{", "latitude", ",", "Float", ".", "NaN", "}", ",", "new", "float", "[", "]", "{", "longitude", ",", "radiusInKM", "}", "}", ")", ";", "}" ]
Constructs a circle from a given center point and a radius in kilometer @param latitude @param longitude @param radiusInKM @return
[ "Constructs", "a", "circle", "from", "a", "given", "center", "point", "and", "a", "radius", "in", "kilometer" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/core/attribute/Geoshape.java#L266-L270
29,147
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/core/util/ManagementUtil.java
ManagementUtil.awaitGraphIndexUpdate
public static void awaitGraphIndexUpdate(TitanGraph g, String indexName, long time, TemporalUnit unit) { awaitIndexUpdate(g,indexName,null,time,unit); }
java
public static void awaitGraphIndexUpdate(TitanGraph g, String indexName, long time, TemporalUnit unit) { awaitIndexUpdate(g,indexName,null,time,unit); }
[ "public", "static", "void", "awaitGraphIndexUpdate", "(", "TitanGraph", "g", ",", "String", "indexName", ",", "long", "time", ",", "TemporalUnit", "unit", ")", "{", "awaitIndexUpdate", "(", "g", ",", "indexName", ",", "null", ",", "time", ",", "unit", ")", ";", "}" ]
This method blocks and waits until the provided index has been updated across the entire Titan cluster and reached a stable state. This method will wait for the given period of time and throw an exception if the index did not reach a final state within that time. The method simply returns when the index has reached the final state prior to the time period expiring. This is a utility method to be invoked between two {@link com.thinkaurelius.titan.core.schema.TitanManagement#updateIndex(TitanIndex, com.thinkaurelius.titan.core.schema.SchemaAction)} calls to ensure that the previous update has successfully persisted. @param g @param indexName @param time @param unit
[ "This", "method", "blocks", "and", "waits", "until", "the", "provided", "index", "has", "been", "updated", "across", "the", "entire", "Titan", "cluster", "and", "reached", "a", "stable", "state", ".", "This", "method", "will", "wait", "for", "the", "given", "period", "of", "time", "and", "throw", "an", "exception", "if", "the", "index", "did", "not", "reach", "a", "final", "state", "within", "that", "time", ".", "The", "method", "simply", "returns", "when", "the", "index", "has", "reached", "the", "final", "state", "prior", "to", "the", "time", "period", "expiring", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/core/util/ManagementUtil.java#L42-L44
29,148
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/core/util/TitanCleanup.java
TitanCleanup.clear
public static final void clear(TitanGraph graph) { Preconditions.checkNotNull(graph); Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass()); StandardTitanGraph g = (StandardTitanGraph)graph; Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared."); final GraphDatabaseConfiguration config = g.getConfiguration(); BackendOperation.execute(new Callable<Boolean>(){ @Override public Boolean call() throws Exception { config.getBackend().clearStorage(); return true; } @Override public String toString() { return "ClearBackend"; } }, Duration.ofSeconds(20)); }
java
public static final void clear(TitanGraph graph) { Preconditions.checkNotNull(graph); Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass()); StandardTitanGraph g = (StandardTitanGraph)graph; Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared."); final GraphDatabaseConfiguration config = g.getConfiguration(); BackendOperation.execute(new Callable<Boolean>(){ @Override public Boolean call() throws Exception { config.getBackend().clearStorage(); return true; } @Override public String toString() { return "ClearBackend"; } }, Duration.ofSeconds(20)); }
[ "public", "static", "final", "void", "clear", "(", "TitanGraph", "graph", ")", "{", "Preconditions", ".", "checkNotNull", "(", "graph", ")", ";", "Preconditions", ".", "checkArgument", "(", "graph", "instanceof", "StandardTitanGraph", ",", "\"Invalid graph instance detected: %s\"", ",", "graph", ".", "getClass", "(", ")", ")", ";", "StandardTitanGraph", "g", "=", "(", "StandardTitanGraph", ")", "graph", ";", "Preconditions", ".", "checkArgument", "(", "!", "g", ".", "isOpen", "(", ")", ",", "\"Graph needs to be shut down before it can be cleared.\"", ")", ";", "final", "GraphDatabaseConfiguration", "config", "=", "g", ".", "getConfiguration", "(", ")", ";", "BackendOperation", ".", "execute", "(", "new", "Callable", "<", "Boolean", ">", "(", ")", "{", "@", "Override", "public", "Boolean", "call", "(", ")", "throws", "Exception", "{", "config", ".", "getBackend", "(", ")", ".", "clearStorage", "(", ")", ";", "return", "true", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"ClearBackend\"", ";", "}", "}", ",", "Duration", ".", "ofSeconds", "(", "20", ")", ")", ";", "}" ]
Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be recoverable. This method is intended only for development and testing use. @param graph @throws IllegalArgumentException if the graph has not been shut down @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
[ "Clears", "out", "the", "entire", "graph", ".", "This", "will", "delete", "ALL", "of", "the", "data", "stored", "in", "this", "graph", "and", "the", "data", "will", "NOT", "be", "recoverable", ".", "This", "method", "is", "intended", "only", "for", "development", "and", "testing", "use", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/core/util/TitanCleanup.java#L29-L44
29,149
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/util/ElementHelper.java
ElementHelper.attachProperties
public static void attachProperties(final TitanVertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
java
public static void attachProperties(final TitanVertex vertex, final Object... propertyKeyValues) { if (null == vertex) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label)) vertex.property((String) propertyKeyValues[i], propertyKeyValues[i + 1]); } }
[ "public", "static", "void", "attachProperties", "(", "final", "TitanVertex", "vertex", ",", "final", "Object", "...", "propertyKeyValues", ")", "{", "if", "(", "null", "==", "vertex", ")", "throw", "Graph", ".", "Exceptions", ".", "argumentCanNotBeNull", "(", "\"vertex\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "propertyKeyValues", ".", "length", ";", "i", "=", "i", "+", "2", ")", "{", "if", "(", "!", "propertyKeyValues", "[", "i", "]", ".", "equals", "(", "T", ".", "id", ")", "&&", "!", "propertyKeyValues", "[", "i", "]", ".", "equals", "(", "T", ".", "label", ")", ")", "vertex", ".", "property", "(", "(", "String", ")", "propertyKeyValues", "[", "i", "]", ",", "propertyKeyValues", "[", "i", "+", "1", "]", ")", ";", "}", "}" ]
This is essentially an adjusted copy&paste from TinkerPop's ElementHelper class. The reason for copying it is so that we can determine the cardinality of a property key based on Titan's schema which is tied to this particular transaction and not the graph. @param vertex @param propertyKeyValues
[ "This", "is", "essentially", "an", "adjusted", "copy&paste", "from", "TinkerPop", "s", "ElementHelper", "class", ".", "The", "reason", "for", "copying", "it", "is", "so", "that", "we", "can", "determine", "the", "cardinality", "of", "a", "property", "key", "based", "on", "Titan", "s", "schema", "which", "is", "tied", "to", "this", "particular", "transaction", "and", "not", "the", "graph", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/util/ElementHelper.java#L60-L68
29,150
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/internal/OrderList.java
OrderList.hasCommonOrder
public boolean hasCommonOrder() { Order lastOrder = null; for (OrderEntry oe : list) { if (lastOrder==null) lastOrder=oe.order; else if (lastOrder!=oe.order) return false; } return true; }
java
public boolean hasCommonOrder() { Order lastOrder = null; for (OrderEntry oe : list) { if (lastOrder==null) lastOrder=oe.order; else if (lastOrder!=oe.order) return false; } return true; }
[ "public", "boolean", "hasCommonOrder", "(", ")", "{", "Order", "lastOrder", "=", "null", ";", "for", "(", "OrderEntry", "oe", ":", "list", ")", "{", "if", "(", "lastOrder", "==", "null", ")", "lastOrder", "=", "oe", ".", "order", ";", "else", "if", "(", "lastOrder", "!=", "oe", ".", "order", ")", "return", "false", ";", "}", "return", "true", ";", "}" ]
Whether all individual orders are the same @return
[ "Whether", "all", "individual", "orders", "are", "the", "same" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/internal/OrderList.java#L64-L71
29,151
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/ReadMarker.java
ReadMarker.getStartTime
public synchronized Instant getStartTime(TimestampProvider times) { if (startTime==null) { startTime = times.getTime(); } return startTime; }
java
public synchronized Instant getStartTime(TimestampProvider times) { if (startTime==null) { startTime = times.getTime(); } return startTime; }
[ "public", "synchronized", "Instant", "getStartTime", "(", "TimestampProvider", "times", ")", "{", "if", "(", "startTime", "==", "null", ")", "{", "startTime", "=", "times", ".", "getTime", "(", ")", ";", "}", "return", "startTime", ";", "}" ]
Returns the start time of this marker if such has been defined or the current time if not @return
[ "Returns", "the", "start", "time", "of", "this", "marker", "if", "such", "has", "been", "defined", "or", "the", "current", "time", "if", "not" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/log/ReadMarker.java#L50-L55
29,152
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/util/datastructures/CompactMap.java
CompactMap.deduplicateKeys
private static final String[] deduplicateKeys(String[] keys) { synchronized (KEY_CACHE) { KEY_HULL.setKeys(keys); KeyContainer retrieved = KEY_CACHE.get(KEY_HULL); if (retrieved==null) { retrieved = new KeyContainer(keys); KEY_CACHE.put(retrieved, retrieved); } return retrieved.getKeys(); } }
java
private static final String[] deduplicateKeys(String[] keys) { synchronized (KEY_CACHE) { KEY_HULL.setKeys(keys); KeyContainer retrieved = KEY_CACHE.get(KEY_HULL); if (retrieved==null) { retrieved = new KeyContainer(keys); KEY_CACHE.put(retrieved, retrieved); } return retrieved.getKeys(); } }
[ "private", "static", "final", "String", "[", "]", "deduplicateKeys", "(", "String", "[", "]", "keys", ")", "{", "synchronized", "(", "KEY_CACHE", ")", "{", "KEY_HULL", ".", "setKeys", "(", "keys", ")", ";", "KeyContainer", "retrieved", "=", "KEY_CACHE", ".", "get", "(", "KEY_HULL", ")", ";", "if", "(", "retrieved", "==", "null", ")", "{", "retrieved", "=", "new", "KeyContainer", "(", "keys", ")", ";", "KEY_CACHE", ".", "put", "(", "retrieved", ",", "retrieved", ")", ";", "}", "return", "retrieved", ".", "getKeys", "(", ")", ";", "}", "}" ]
Deduplicates keys arrays to keep the memory footprint on CompactMap to a minimum. This implementation is blocking for simplicity. To improve performance in multi-threaded environments, use a thread-local KEY_HULL and a concurrent hash map for KEY_CACHE. @param keys String array to deduplicate by checking against KEY_CACHE @return A deduplicated version of the given keys array
[ "Deduplicates", "keys", "arrays", "to", "keep", "the", "memory", "footprint", "on", "CompactMap", "to", "a", "minimum", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/util/datastructures/CompactMap.java#L47-L57
29,153
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/KCVSUtil.java
KCVSUtil.get
public static StaticBuffer get(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { KeySliceQuery query = new KeySliceQuery(key, column, BufferUtil.nextBiggerBuffer(column)).setLimit(2); List<Entry> result = store.getSlice(query, txh); if (result.size() > 1) log.warn("GET query returned more than 1 result: store {} | key {} | column {}", new Object[]{store.getName(), key, column}); if (result.isEmpty()) return null; else return result.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); }
java
public static StaticBuffer get(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { KeySliceQuery query = new KeySliceQuery(key, column, BufferUtil.nextBiggerBuffer(column)).setLimit(2); List<Entry> result = store.getSlice(query, txh); if (result.size() > 1) log.warn("GET query returned more than 1 result: store {} | key {} | column {}", new Object[]{store.getName(), key, column}); if (result.isEmpty()) return null; else return result.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); }
[ "public", "static", "StaticBuffer", "get", "(", "KeyColumnValueStore", "store", ",", "StaticBuffer", "key", ",", "StaticBuffer", "column", ",", "StoreTransaction", "txh", ")", "throws", "BackendException", "{", "KeySliceQuery", "query", "=", "new", "KeySliceQuery", "(", "key", ",", "column", ",", "BufferUtil", ".", "nextBiggerBuffer", "(", "column", ")", ")", ".", "setLimit", "(", "2", ")", ";", "List", "<", "Entry", ">", "result", "=", "store", ".", "getSlice", "(", "query", ",", "txh", ")", ";", "if", "(", "result", ".", "size", "(", ")", ">", "1", ")", "log", ".", "warn", "(", "\"GET query returned more than 1 result: store {} | key {} | column {}\"", ",", "new", "Object", "[", "]", "{", "store", ".", "getName", "(", ")", ",", "key", ",", "column", "}", ")", ";", "if", "(", "result", ".", "isEmpty", "(", ")", ")", "return", "null", ";", "else", "return", "result", ".", "get", "(", "0", ")", ".", "getValueAs", "(", "StaticBuffer", ".", "STATIC_FACTORY", ")", ";", "}" ]
Retrieves the value for the specified column and key under the given transaction from the store if such exists, otherwise returns NULL @param store Store @param key Key @param column Column @param txh Transaction @return Value for key and column or NULL if such does not exist
[ "Retrieves", "the", "value", "for", "the", "specified", "column", "and", "key", "under", "the", "given", "transaction", "from", "the", "store", "if", "such", "exists", "otherwise", "returns", "NULL" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/KCVSUtil.java#L37-L46
29,154
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/KCVSUtil.java
KCVSUtil.containsKeyColumn
public static boolean containsKeyColumn(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { return get(store, key, column, txh) != null; }
java
public static boolean containsKeyColumn(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { return get(store, key, column, txh) != null; }
[ "public", "static", "boolean", "containsKeyColumn", "(", "KeyColumnValueStore", "store", ",", "StaticBuffer", "key", ",", "StaticBuffer", "column", ",", "StoreTransaction", "txh", ")", "throws", "BackendException", "{", "return", "get", "(", "store", ",", "key", ",", "column", ",", "txh", ")", "!=", "null", ";", "}" ]
Returns true if the specified key-column pair exists in the store. @param store Store @param key Key @param column Column @param txh Transaction @return TRUE, if key has at least one column-value pair, else FALSE
[ "Returns", "true", "if", "the", "specified", "key", "-", "column", "pair", "exists", "in", "the", "store", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/keycolumnvalue/KCVSUtil.java#L70-L72
29,155
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/configuration/backend/KCVSConfiguration.java
KCVSConfiguration.get
@Override public <O> O get(final String key, final Class<O> datatype) { StaticBuffer column = string2StaticBuffer(key); final KeySliceQuery query = new KeySliceQuery(rowKey,column, BufferUtil.nextBiggerBuffer(column)); StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() { @Override public StaticBuffer call(StoreTransaction txh) throws BackendException { List<Entry> entries = store.getSlice(query,txh); if (entries.isEmpty()) return null; return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); } @Override public String toString() { return "getConfiguration"; } }, txProvider, times, maxOperationWaitTime); if (result==null) return null; return staticBuffer2Object(result, datatype); }
java
@Override public <O> O get(final String key, final Class<O> datatype) { StaticBuffer column = string2StaticBuffer(key); final KeySliceQuery query = new KeySliceQuery(rowKey,column, BufferUtil.nextBiggerBuffer(column)); StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() { @Override public StaticBuffer call(StoreTransaction txh) throws BackendException { List<Entry> entries = store.getSlice(query,txh); if (entries.isEmpty()) return null; return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); } @Override public String toString() { return "getConfiguration"; } }, txProvider, times, maxOperationWaitTime); if (result==null) return null; return staticBuffer2Object(result, datatype); }
[ "@", "Override", "public", "<", "O", ">", "O", "get", "(", "final", "String", "key", ",", "final", "Class", "<", "O", ">", "datatype", ")", "{", "StaticBuffer", "column", "=", "string2StaticBuffer", "(", "key", ")", ";", "final", "KeySliceQuery", "query", "=", "new", "KeySliceQuery", "(", "rowKey", ",", "column", ",", "BufferUtil", ".", "nextBiggerBuffer", "(", "column", ")", ")", ";", "StaticBuffer", "result", "=", "BackendOperation", ".", "execute", "(", "new", "BackendOperation", ".", "Transactional", "<", "StaticBuffer", ">", "(", ")", "{", "@", "Override", "public", "StaticBuffer", "call", "(", "StoreTransaction", "txh", ")", "throws", "BackendException", "{", "List", "<", "Entry", ">", "entries", "=", "store", ".", "getSlice", "(", "query", ",", "txh", ")", ";", "if", "(", "entries", ".", "isEmpty", "(", ")", ")", "return", "null", ";", "return", "entries", ".", "get", "(", "0", ")", ".", "getValueAs", "(", "StaticBuffer", ".", "STATIC_FACTORY", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"getConfiguration\"", ";", "}", "}", ",", "txProvider", ",", "times", ",", "maxOperationWaitTime", ")", ";", "if", "(", "result", "==", "null", ")", "return", "null", ";", "return", "staticBuffer2Object", "(", "result", ",", "datatype", ")", ";", "}" ]
Reads the configuration property for this StoreManager @param key Key identifying the configuration property @return Value stored for the key or null if the configuration property has not (yet) been defined. @throws com.thinkaurelius.titan.diskstorage.BackendException
[ "Reads", "the", "configuration", "property", "for", "this", "StoreManager" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/configuration/backend/KCVSConfiguration.java#L84-L103
29,156
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/configuration/backend/KCVSConfiguration.java
KCVSConfiguration.set
@Override public <O> void set(String key, O value) { set(key,value,null,false); }
java
@Override public <O> void set(String key, O value) { set(key,value,null,false); }
[ "@", "Override", "public", "<", "O", ">", "void", "set", "(", "String", "key", ",", "O", "value", ")", "{", "set", "(", "key", ",", "value", ",", "null", ",", "false", ")", ";", "}" ]
Sets a configuration property for this StoreManager. @param key Key identifying the configuration property @param value Value to be stored for the key @throws com.thinkaurelius.titan.diskstorage.BackendException
[ "Sets", "a", "configuration", "property", "for", "this", "StoreManager", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/configuration/backend/KCVSConfiguration.java#L116-L119
29,157
thinkaurelius/titan
titan-hbase-parent/titan-hbase-core/src/main/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseStoreManager.java
HBaseStoreManager.convertToCommands
private Map<StaticBuffer, Pair<Put, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentBackendException { Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<StaticBuffer, Pair<Put, Delete>>(); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) { String cfString = getCfNameForStoreName(entry.getKey()); byte[] cfName = cfString.getBytes(); for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) { byte[] key = m.getKey().as(StaticBuffer.ARRAY_FACTORY); KCVMutation mutation = m.getValue(); Pair<Put, Delete> commands = commandsPerKey.get(m.getKey()); if (commands == null) { commands = new Pair<Put, Delete>(); commandsPerKey.put(m.getKey(), commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) { Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); } for (StaticBuffer b : mutation.getDeletions()) { commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); } } if (mutation.hasAdditions()) { if (commands.getFirst() == null) { Put p = new Put(key, putTimestamp); commands.setFirst(p); } for (Entry e : mutation.getAdditions()) { commands.getFirst().add(cfName, e.getColumnAs(StaticBuffer.ARRAY_FACTORY), putTimestamp, e.getValueAs(StaticBuffer.ARRAY_FACTORY)); } } } } return commandsPerKey; }
java
private Map<StaticBuffer, Pair<Put, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentBackendException { Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<StaticBuffer, Pair<Put, Delete>>(); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) { String cfString = getCfNameForStoreName(entry.getKey()); byte[] cfName = cfString.getBytes(); for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) { byte[] key = m.getKey().as(StaticBuffer.ARRAY_FACTORY); KCVMutation mutation = m.getValue(); Pair<Put, Delete> commands = commandsPerKey.get(m.getKey()); if (commands == null) { commands = new Pair<Put, Delete>(); commandsPerKey.put(m.getKey(), commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) { Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); } for (StaticBuffer b : mutation.getDeletions()) { commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); } } if (mutation.hasAdditions()) { if (commands.getFirst() == null) { Put p = new Put(key, putTimestamp); commands.setFirst(p); } for (Entry e : mutation.getAdditions()) { commands.getFirst().add(cfName, e.getColumnAs(StaticBuffer.ARRAY_FACTORY), putTimestamp, e.getValueAs(StaticBuffer.ARRAY_FACTORY)); } } } } return commandsPerKey; }
[ "private", "Map", "<", "StaticBuffer", ",", "Pair", "<", "Put", ",", "Delete", ">", ">", "convertToCommands", "(", "Map", "<", "String", ",", "Map", "<", "StaticBuffer", ",", "KCVMutation", ">", ">", "mutations", ",", "final", "long", "putTimestamp", ",", "final", "long", "delTimestamp", ")", "throws", "PermanentBackendException", "{", "Map", "<", "StaticBuffer", ",", "Pair", "<", "Put", ",", "Delete", ">", ">", "commandsPerKey", "=", "new", "HashMap", "<", "StaticBuffer", ",", "Pair", "<", "Put", ",", "Delete", ">", ">", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Map", "<", "StaticBuffer", ",", "KCVMutation", ">", ">", "entry", ":", "mutations", ".", "entrySet", "(", ")", ")", "{", "String", "cfString", "=", "getCfNameForStoreName", "(", "entry", ".", "getKey", "(", ")", ")", ";", "byte", "[", "]", "cfName", "=", "cfString", ".", "getBytes", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "StaticBuffer", ",", "KCVMutation", ">", "m", ":", "entry", ".", "getValue", "(", ")", ".", "entrySet", "(", ")", ")", "{", "byte", "[", "]", "key", "=", "m", ".", "getKey", "(", ")", ".", "as", "(", "StaticBuffer", ".", "ARRAY_FACTORY", ")", ";", "KCVMutation", "mutation", "=", "m", ".", "getValue", "(", ")", ";", "Pair", "<", "Put", ",", "Delete", ">", "commands", "=", "commandsPerKey", ".", "get", "(", "m", ".", "getKey", "(", ")", ")", ";", "if", "(", "commands", "==", "null", ")", "{", "commands", "=", "new", "Pair", "<", "Put", ",", "Delete", ">", "(", ")", ";", "commandsPerKey", ".", "put", "(", "m", ".", "getKey", "(", ")", ",", "commands", ")", ";", "}", "if", "(", "mutation", ".", "hasDeletions", "(", ")", ")", "{", "if", "(", "commands", ".", "getSecond", "(", ")", "==", "null", ")", "{", "Delete", "d", "=", "new", "Delete", "(", "key", ")", ";", "compat", ".", "setTimestamp", "(", "d", ",", "delTimestamp", ")", ";", "commands", ".", "setSecond", "(", "d", ")", ";", "}", "for", "(", "StaticBuffer", "b", ":", "mutation", ".", "getDeletions", "(", ")", ")", "{", "commands", ".", "getSecond", "(", ")", ".", "deleteColumns", "(", "cfName", ",", "b", ".", "as", "(", "StaticBuffer", ".", "ARRAY_FACTORY", ")", ",", "delTimestamp", ")", ";", "}", "}", "if", "(", "mutation", ".", "hasAdditions", "(", ")", ")", "{", "if", "(", "commands", ".", "getFirst", "(", ")", "==", "null", ")", "{", "Put", "p", "=", "new", "Put", "(", "key", ",", "putTimestamp", ")", ";", "commands", ".", "setFirst", "(", "p", ")", ";", "}", "for", "(", "Entry", "e", ":", "mutation", ".", "getAdditions", "(", ")", ")", "{", "commands", ".", "getFirst", "(", ")", ".", "add", "(", "cfName", ",", "e", ".", "getColumnAs", "(", "StaticBuffer", ".", "ARRAY_FACTORY", ")", ",", "putTimestamp", ",", "e", ".", "getValueAs", "(", "StaticBuffer", ".", "ARRAY_FACTORY", ")", ")", ";", "}", "}", "}", "}", "return", "commandsPerKey", ";", "}" ]
Convert Titan internal Mutation representation into HBase native commands. @param mutations Mutations to convert into HBase commands. @param putTimestamp The timestamp to use for Put commands. @param delTimestamp The timestamp to use for Delete commands. @return Commands sorted by key converted from Titan internal representation. @throws com.thinkaurelius.titan.diskstorage.PermanentBackendException
[ "Convert", "Titan", "internal", "Mutation", "representation", "into", "HBase", "native", "commands", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-hbase-parent/titan-hbase-core/src/main/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseStoreManager.java#L895-L945
29,158
thinkaurelius/titan
titan-core/src/main/java/com/thinkaurelius/titan/graphdb/olap/job/IndexRepairJob.java
IndexRepairJob.validateIndexStatus
@Override protected void validateIndexStatus() { TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index); Set<SchemaStatus> acceptableStatuses = SchemaAction.REINDEX.getApplicableStatus(); boolean isValidIndex = true; String invalidIndexHint; if (index instanceof RelationTypeIndex || (index instanceof TitanGraphIndex && ((TitanGraphIndex)index).isCompositeIndex()) ) { SchemaStatus actualStatus = schemaVertex.getStatus(); isValidIndex = acceptableStatuses.contains(actualStatus); invalidIndexHint = String.format( "The index has status %s, but one of %s is required", actualStatus, acceptableStatuses); } else { Preconditions.checkArgument(index instanceof TitanGraphIndex,"Unexpected index: %s",index); TitanGraphIndex gindex = (TitanGraphIndex)index; Preconditions.checkArgument(gindex.isMixedIndex()); Map<String, SchemaStatus> invalidKeyStatuses = new HashMap<>(); int acceptableFields = 0; for (PropertyKey key : gindex.getFieldKeys()) { SchemaStatus status = gindex.getIndexStatus(key); if (status!=SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) { isValidIndex=false; invalidKeyStatuses.put(key.name(), status); log.warn("Index {} has key {} in an invalid status {}",index,key,status); } if (acceptableStatuses.contains(status)) acceptableFields++; } invalidIndexHint = String.format( "The following index keys have invalid status: %s (status must be one of %s)", Joiner.on(",").withKeyValueSeparator(" has status ").join(invalidKeyStatuses), acceptableStatuses); if (isValidIndex && acceptableFields==0) { isValidIndex = false; invalidIndexHint = "The index does not contain any valid keys"; } } Preconditions.checkArgument(isValidIndex, "The index %s is in an invalid state and cannot be indexed. %s", indexName, invalidIndexHint); // TODO consider retrieving the current Job object and calling killJob() if !isValidIndex -- would be more efficient than throwing an exception on the first pair processed by each mapper log.debug("Index {} is valid for re-indexing"); }
java
@Override protected void validateIndexStatus() { TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index); Set<SchemaStatus> acceptableStatuses = SchemaAction.REINDEX.getApplicableStatus(); boolean isValidIndex = true; String invalidIndexHint; if (index instanceof RelationTypeIndex || (index instanceof TitanGraphIndex && ((TitanGraphIndex)index).isCompositeIndex()) ) { SchemaStatus actualStatus = schemaVertex.getStatus(); isValidIndex = acceptableStatuses.contains(actualStatus); invalidIndexHint = String.format( "The index has status %s, but one of %s is required", actualStatus, acceptableStatuses); } else { Preconditions.checkArgument(index instanceof TitanGraphIndex,"Unexpected index: %s",index); TitanGraphIndex gindex = (TitanGraphIndex)index; Preconditions.checkArgument(gindex.isMixedIndex()); Map<String, SchemaStatus> invalidKeyStatuses = new HashMap<>(); int acceptableFields = 0; for (PropertyKey key : gindex.getFieldKeys()) { SchemaStatus status = gindex.getIndexStatus(key); if (status!=SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) { isValidIndex=false; invalidKeyStatuses.put(key.name(), status); log.warn("Index {} has key {} in an invalid status {}",index,key,status); } if (acceptableStatuses.contains(status)) acceptableFields++; } invalidIndexHint = String.format( "The following index keys have invalid status: %s (status must be one of %s)", Joiner.on(",").withKeyValueSeparator(" has status ").join(invalidKeyStatuses), acceptableStatuses); if (isValidIndex && acceptableFields==0) { isValidIndex = false; invalidIndexHint = "The index does not contain any valid keys"; } } Preconditions.checkArgument(isValidIndex, "The index %s is in an invalid state and cannot be indexed. %s", indexName, invalidIndexHint); // TODO consider retrieving the current Job object and calling killJob() if !isValidIndex -- would be more efficient than throwing an exception on the first pair processed by each mapper log.debug("Index {} is valid for re-indexing"); }
[ "@", "Override", "protected", "void", "validateIndexStatus", "(", ")", "{", "TitanSchemaVertex", "schemaVertex", "=", "mgmt", ".", "getSchemaVertex", "(", "index", ")", ";", "Set", "<", "SchemaStatus", ">", "acceptableStatuses", "=", "SchemaAction", ".", "REINDEX", ".", "getApplicableStatus", "(", ")", ";", "boolean", "isValidIndex", "=", "true", ";", "String", "invalidIndexHint", ";", "if", "(", "index", "instanceof", "RelationTypeIndex", "||", "(", "index", "instanceof", "TitanGraphIndex", "&&", "(", "(", "TitanGraphIndex", ")", "index", ")", ".", "isCompositeIndex", "(", ")", ")", ")", "{", "SchemaStatus", "actualStatus", "=", "schemaVertex", ".", "getStatus", "(", ")", ";", "isValidIndex", "=", "acceptableStatuses", ".", "contains", "(", "actualStatus", ")", ";", "invalidIndexHint", "=", "String", ".", "format", "(", "\"The index has status %s, but one of %s is required\"", ",", "actualStatus", ",", "acceptableStatuses", ")", ";", "}", "else", "{", "Preconditions", ".", "checkArgument", "(", "index", "instanceof", "TitanGraphIndex", ",", "\"Unexpected index: %s\"", ",", "index", ")", ";", "TitanGraphIndex", "gindex", "=", "(", "TitanGraphIndex", ")", "index", ";", "Preconditions", ".", "checkArgument", "(", "gindex", ".", "isMixedIndex", "(", ")", ")", ";", "Map", "<", "String", ",", "SchemaStatus", ">", "invalidKeyStatuses", "=", "new", "HashMap", "<>", "(", ")", ";", "int", "acceptableFields", "=", "0", ";", "for", "(", "PropertyKey", "key", ":", "gindex", ".", "getFieldKeys", "(", ")", ")", "{", "SchemaStatus", "status", "=", "gindex", ".", "getIndexStatus", "(", "key", ")", ";", "if", "(", "status", "!=", "SchemaStatus", ".", "DISABLED", "&&", "!", "acceptableStatuses", ".", "contains", "(", "status", ")", ")", "{", "isValidIndex", "=", "false", ";", "invalidKeyStatuses", ".", "put", "(", "key", ".", "name", "(", ")", ",", "status", ")", ";", "log", ".", "warn", "(", "\"Index {} has key {} in an invalid status {}\"", ",", "index", ",", "key", ",", "status", ")", ";", "}", "if", "(", "acceptableStatuses", ".", "contains", "(", "status", ")", ")", "acceptableFields", "++", ";", "}", "invalidIndexHint", "=", "String", ".", "format", "(", "\"The following index keys have invalid status: %s (status must be one of %s)\"", ",", "Joiner", ".", "on", "(", "\",\"", ")", ".", "withKeyValueSeparator", "(", "\" has status \"", ")", ".", "join", "(", "invalidKeyStatuses", ")", ",", "acceptableStatuses", ")", ";", "if", "(", "isValidIndex", "&&", "acceptableFields", "==", "0", ")", "{", "isValidIndex", "=", "false", ";", "invalidIndexHint", "=", "\"The index does not contain any valid keys\"", ";", "}", "}", "Preconditions", ".", "checkArgument", "(", "isValidIndex", ",", "\"The index %s is in an invalid state and cannot be indexed. %s\"", ",", "indexName", ",", "invalidIndexHint", ")", ";", "// TODO consider retrieving the current Job object and calling killJob() if !isValidIndex -- would be more efficient than throwing an exception on the first pair processed by each mapper", "log", ".", "debug", "(", "\"Index {} is valid for re-indexing\"", ")", ";", "}" ]
Check that our target index is in either the ENABLED or REGISTERED state.
[ "Check", "that", "our", "target", "index", "is", "in", "either", "the", "ENABLED", "or", "REGISTERED", "state", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/olap/job/IndexRepairJob.java#L73-L112
29,159
thinkaurelius/titan
titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java
SolrIndex.register
@Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { if (mode==Mode.CLOUD) { CloudSolrClient client = (CloudSolrClient) solrClient; try { createCollectionIfNotExists(client, configuration, store); } catch (IOException e) { throw new PermanentBackendException(e); } catch (SolrServerException e) { throw new PermanentBackendException(e); } catch (InterruptedException e) { throw new PermanentBackendException(e); } catch (KeeperException e) { throw new PermanentBackendException(e); } } //Since all data types must be defined in the schema.xml, pre-registering a type does not work }
java
@Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { if (mode==Mode.CLOUD) { CloudSolrClient client = (CloudSolrClient) solrClient; try { createCollectionIfNotExists(client, configuration, store); } catch (IOException e) { throw new PermanentBackendException(e); } catch (SolrServerException e) { throw new PermanentBackendException(e); } catch (InterruptedException e) { throw new PermanentBackendException(e); } catch (KeeperException e) { throw new PermanentBackendException(e); } } //Since all data types must be defined in the schema.xml, pre-registering a type does not work }
[ "@", "Override", "public", "void", "register", "(", "String", "store", ",", "String", "key", ",", "KeyInformation", "information", ",", "BaseTransaction", "tx", ")", "throws", "BackendException", "{", "if", "(", "mode", "==", "Mode", ".", "CLOUD", ")", "{", "CloudSolrClient", "client", "=", "(", "CloudSolrClient", ")", "solrClient", ";", "try", "{", "createCollectionIfNotExists", "(", "client", ",", "configuration", ",", "store", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "PermanentBackendException", "(", "e", ")", ";", "}", "catch", "(", "SolrServerException", "e", ")", "{", "throw", "new", "PermanentBackendException", "(", "e", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "throw", "new", "PermanentBackendException", "(", "e", ")", ";", "}", "catch", "(", "KeeperException", "e", ")", "{", "throw", "new", "PermanentBackendException", "(", "e", ")", ";", "}", "}", "//Since all data types must be defined in the schema.xml, pre-registering a type does not work", "}" ]
Unlike the ElasticSearch Index, which is schema free, Solr requires a schema to support searching. This means that you will need to modify the solr schema with the appropriate field definitions in order to work properly. If you have a running instance of Solr and you modify its schema with new fields, don't forget to re-index! @param store Index store @param key New key to register @param information Datatype to register for the key @param tx enclosing transaction @throws com.thinkaurelius.titan.diskstorage.BackendException
[ "Unlike", "the", "ElasticSearch", "Index", "which", "is", "schema", "free", "Solr", "requires", "a", "schema", "to", "support", "searching", ".", "This", "means", "that", "you", "will", "need", "to", "modify", "the", "solr", "schema", "with", "the", "appropriate", "field", "definitions", "in", "order", "to", "work", "properly", ".", "If", "you", "have", "a", "running", "instance", "of", "Solr", "and", "you", "modify", "its", "schema", "with", "new", "fields", "don", "t", "forget", "to", "re", "-", "index!" ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java#L224-L241
29,160
thinkaurelius/titan
titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java
SolrIndex.checkIfCollectionExists
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
java
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
[ "private", "static", "boolean", "checkIfCollectionExists", "(", "CloudSolrClient", "server", ",", "String", "collection", ")", "throws", "KeeperException", ",", "InterruptedException", "{", "ZkStateReader", "zkStateReader", "=", "server", ".", "getZkStateReader", "(", ")", ";", "zkStateReader", ".", "updateClusterState", "(", "true", ")", ";", "ClusterState", "clusterState", "=", "zkStateReader", ".", "getClusterState", "(", ")", ";", "return", "clusterState", ".", "getCollectionOrNull", "(", "collection", ")", "!=", "null", ";", "}" ]
Checks if the collection has already been created in Solr.
[ "Checks", "if", "the", "collection", "has", "already", "been", "created", "in", "Solr", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java#L896-L901
29,161
thinkaurelius/titan
titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java
SolrIndex.waitForRecoveriesToFinish
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); try { boolean cont = true; while (cont) { boolean sawLiveRecovering = false; zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); Map<String, Slice> slices = clusterState.getSlicesMap(collection); Preconditions.checkNotNull("Could not find collection:" + collection, slices); // change paths for Replica.State per Solr refactoring // remove SYNC state per: http://tinyurl.com/pag6rwt for (Map.Entry<String, Slice> entry : slices.entrySet()) { Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (Map.Entry<String, Replica> shard : shards.entrySet()) { String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN)) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true; } } } if (!sawLiveRecovering) { cont = false; } else { Thread.sleep(1000); } } } finally { logger.info("Exiting solr wait"); } }
java
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); try { boolean cont = true; while (cont) { boolean sawLiveRecovering = false; zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); Map<String, Slice> slices = clusterState.getSlicesMap(collection); Preconditions.checkNotNull("Could not find collection:" + collection, slices); // change paths for Replica.State per Solr refactoring // remove SYNC state per: http://tinyurl.com/pag6rwt for (Map.Entry<String, Slice> entry : slices.entrySet()) { Map<String, Replica> shards = entry.getValue().getReplicasMap(); for (Map.Entry<String, Replica> shard : shards.entrySet()) { String state = shard.getValue().getStr(ZkStateReader.STATE_PROP); if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN)) && clusterState.liveNodesContain(shard.getValue().getStr( ZkStateReader.NODE_NAME_PROP))) { sawLiveRecovering = true; } } } if (!sawLiveRecovering) { cont = false; } else { Thread.sleep(1000); } } } finally { logger.info("Exiting solr wait"); } }
[ "private", "static", "void", "waitForRecoveriesToFinish", "(", "CloudSolrClient", "server", ",", "String", "collection", ")", "throws", "KeeperException", ",", "InterruptedException", "{", "ZkStateReader", "zkStateReader", "=", "server", ".", "getZkStateReader", "(", ")", ";", "try", "{", "boolean", "cont", "=", "true", ";", "while", "(", "cont", ")", "{", "boolean", "sawLiveRecovering", "=", "false", ";", "zkStateReader", ".", "updateClusterState", "(", "true", ")", ";", "ClusterState", "clusterState", "=", "zkStateReader", ".", "getClusterState", "(", ")", ";", "Map", "<", "String", ",", "Slice", ">", "slices", "=", "clusterState", ".", "getSlicesMap", "(", "collection", ")", ";", "Preconditions", ".", "checkNotNull", "(", "\"Could not find collection:\"", "+", "collection", ",", "slices", ")", ";", "// change paths for Replica.State per Solr refactoring", "// remove SYNC state per: http://tinyurl.com/pag6rwt", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Slice", ">", "entry", ":", "slices", ".", "entrySet", "(", ")", ")", "{", "Map", "<", "String", ",", "Replica", ">", "shards", "=", "entry", ".", "getValue", "(", ")", ".", "getReplicasMap", "(", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Replica", ">", "shard", ":", "shards", ".", "entrySet", "(", ")", ")", "{", "String", "state", "=", "shard", ".", "getValue", "(", ")", ".", "getStr", "(", "ZkStateReader", ".", "STATE_PROP", ")", ";", "if", "(", "(", "state", ".", "equals", "(", "Replica", ".", "State", ".", "RECOVERING", ")", "||", "state", ".", "equals", "(", "Replica", ".", "State", ".", "DOWN", ")", ")", "&&", "clusterState", ".", "liveNodesContain", "(", "shard", ".", "getValue", "(", ")", ".", "getStr", "(", "ZkStateReader", ".", "NODE_NAME_PROP", ")", ")", ")", "{", "sawLiveRecovering", "=", "true", ";", "}", "}", "}", "if", "(", "!", "sawLiveRecovering", ")", "{", "cont", "=", "false", ";", "}", "else", "{", "Thread", ".", "sleep", "(", "1000", ")", ";", "}", "}", "}", "finally", "{", "logger", ".", "info", "(", "\"Exiting solr wait\"", ")", ";", "}", "}" ]
Wait for all the collection shards to be ready.
[ "Wait", "for", "all", "the", "collection", "shards", "to", "be", "ready", "." ]
ee226e52415b8bf43b700afac75fa5b9767993a5
https://github.com/thinkaurelius/titan/blob/ee226e52415b8bf43b700afac75fa5b9767993a5/titan-solr/src/main/java/com/thinkaurelius/titan/diskstorage/solr/SolrIndex.java#L906-L942
29,162
jhunters/jprotobuf
jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/AbstractExecMojo.java
AbstractExecMojo.parseCommandlineArgs
protected String[] parseCommandlineArgs() throws MojoExecutionException { if ( commandlineArgs == null ) { return null; } else { try { return CommandLineUtils.translateCommandline( commandlineArgs ); } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage() ); } } }
java
protected String[] parseCommandlineArgs() throws MojoExecutionException { if ( commandlineArgs == null ) { return null; } else { try { return CommandLineUtils.translateCommandline( commandlineArgs ); } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage() ); } } }
[ "protected", "String", "[", "]", "parseCommandlineArgs", "(", ")", "throws", "MojoExecutionException", "{", "if", "(", "commandlineArgs", "==", "null", ")", "{", "return", "null", ";", "}", "else", "{", "try", "{", "return", "CommandLineUtils", ".", "translateCommandline", "(", "commandlineArgs", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "MojoExecutionException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}", "}" ]
Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER. PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using ESCAPE_CHAR. @return Array of String representing the arguments @throws MojoExecutionException for wrong formatted arguments
[ "Parses", "the", "argument", "string", "given", "by", "the", "user", ".", "Strings", "are", "recognized", "as", "everything", "between", "STRING_WRAPPER", ".", "PARAMETER_DELIMITER", "is", "ignored", "inside", "a", "string", ".", "STRING_WRAPPER", "and", "PARAMETER_DELIMITER", "can", "be", "escaped", "using", "ESCAPE_CHAR", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/AbstractExecMojo.java#L134-L152
29,163
jhunters/jprotobuf
jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/AbstractExecMojo.java
AbstractExecMojo.registerSourceRoots
protected void registerSourceRoots() { if ( sourceRoot != null ) { getLog().info( "Registering compile source root " + sourceRoot ); project.addCompileSourceRoot( sourceRoot.toString() ); } if ( testSourceRoot != null ) { getLog().info( "Registering compile test source root " + testSourceRoot ); project.addTestCompileSourceRoot( testSourceRoot.toString() ); } }
java
protected void registerSourceRoots() { if ( sourceRoot != null ) { getLog().info( "Registering compile source root " + sourceRoot ); project.addCompileSourceRoot( sourceRoot.toString() ); } if ( testSourceRoot != null ) { getLog().info( "Registering compile test source root " + testSourceRoot ); project.addTestCompileSourceRoot( testSourceRoot.toString() ); } }
[ "protected", "void", "registerSourceRoots", "(", ")", "{", "if", "(", "sourceRoot", "!=", "null", ")", "{", "getLog", "(", ")", ".", "info", "(", "\"Registering compile source root \"", "+", "sourceRoot", ")", ";", "project", ".", "addCompileSourceRoot", "(", "sourceRoot", ".", "toString", "(", ")", ")", ";", "}", "if", "(", "testSourceRoot", "!=", "null", ")", "{", "getLog", "(", ")", ".", "info", "(", "\"Registering compile test source root \"", "+", "testSourceRoot", ")", ";", "project", ".", "addTestCompileSourceRoot", "(", "testSourceRoot", ".", "toString", "(", ")", ")", ";", "}", "}" ]
Register compile and compile tests source roots if necessary
[ "Register", "compile", "and", "compile", "tests", "source", "roots", "if", "necessary" ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/AbstractExecMojo.java#L165-L178
29,164
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/TemplateCodeGenerator.java
TemplateCodeGenerator.genImportCode
private void genImportCode() { Set<String> imports = new HashSet<String>(); imports.add("java.util.*"); imports.add("java.io.IOException"); imports.add("java.lang.reflect.*"); imports.add("com.baidu.bjf.remoting.protobuf.code.*"); imports.add("com.baidu.bjf.remoting.protobuf.utils.*"); imports.add("com.baidu.bjf.remoting.protobuf.*"); imports.add("com.google.protobuf.*"); if (!StringUtils.isEmpty(getPackage())) { imports.add(getTargetProxyClassname()); } for (String pkg : imports) { templator.setVariable("importPackage", pkg); templator.addBlock("imports"); } }
java
private void genImportCode() { Set<String> imports = new HashSet<String>(); imports.add("java.util.*"); imports.add("java.io.IOException"); imports.add("java.lang.reflect.*"); imports.add("com.baidu.bjf.remoting.protobuf.code.*"); imports.add("com.baidu.bjf.remoting.protobuf.utils.*"); imports.add("com.baidu.bjf.remoting.protobuf.*"); imports.add("com.google.protobuf.*"); if (!StringUtils.isEmpty(getPackage())) { imports.add(getTargetProxyClassname()); } for (String pkg : imports) { templator.setVariable("importPackage", pkg); templator.addBlock("imports"); } }
[ "private", "void", "genImportCode", "(", ")", "{", "Set", "<", "String", ">", "imports", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "imports", ".", "add", "(", "\"java.util.*\"", ")", ";", "imports", ".", "add", "(", "\"java.io.IOException\"", ")", ";", "imports", ".", "add", "(", "\"java.lang.reflect.*\"", ")", ";", "imports", ".", "add", "(", "\"com.baidu.bjf.remoting.protobuf.code.*\"", ")", ";", "imports", ".", "add", "(", "\"com.baidu.bjf.remoting.protobuf.utils.*\"", ")", ";", "imports", ".", "add", "(", "\"com.baidu.bjf.remoting.protobuf.*\"", ")", ";", "imports", ".", "add", "(", "\"com.google.protobuf.*\"", ")", ";", "if", "(", "!", "StringUtils", ".", "isEmpty", "(", "getPackage", "(", ")", ")", ")", "{", "imports", ".", "add", "(", "getTargetProxyClassname", "(", ")", ")", ";", "}", "for", "(", "String", "pkg", ":", "imports", ")", "{", "templator", ".", "setVariable", "(", "\"importPackage\"", ",", "pkg", ")", ";", "templator", ".", "addBlock", "(", "\"imports\"", ")", ";", "}", "}" ]
Gen import code.
[ "Gen", "import", "code", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/TemplateCodeGenerator.java#L397-L415
29,165
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.reset
public void reset() { if (varValuesTab == null) { varValuesTab = new String[mtp.varTabCnt]; } else { for (int varNo = 0; varNo < mtp.varTabCnt; varNo++) { varValuesTab[varNo] = null; } } if (blockDynTab == null) { blockDynTab = new BlockDynTabRec[mtp.blockTabCnt]; } for (int blockNo = 0; blockNo < mtp.blockTabCnt; blockNo++) { BlockDynTabRec bdtr = blockDynTab[blockNo]; if (bdtr == null) { bdtr = new BlockDynTabRec(); blockDynTab[blockNo] = bdtr; } bdtr.instances = 0; bdtr.firstBlockInstNo = -1; bdtr.lastBlockInstNo = -1; } blockInstTabCnt = 0; }
java
public void reset() { if (varValuesTab == null) { varValuesTab = new String[mtp.varTabCnt]; } else { for (int varNo = 0; varNo < mtp.varTabCnt; varNo++) { varValuesTab[varNo] = null; } } if (blockDynTab == null) { blockDynTab = new BlockDynTabRec[mtp.blockTabCnt]; } for (int blockNo = 0; blockNo < mtp.blockTabCnt; blockNo++) { BlockDynTabRec bdtr = blockDynTab[blockNo]; if (bdtr == null) { bdtr = new BlockDynTabRec(); blockDynTab[blockNo] = bdtr; } bdtr.instances = 0; bdtr.firstBlockInstNo = -1; bdtr.lastBlockInstNo = -1; } blockInstTabCnt = 0; }
[ "public", "void", "reset", "(", ")", "{", "if", "(", "varValuesTab", "==", "null", ")", "{", "varValuesTab", "=", "new", "String", "[", "mtp", ".", "varTabCnt", "]", ";", "}", "else", "{", "for", "(", "int", "varNo", "=", "0", ";", "varNo", "<", "mtp", ".", "varTabCnt", ";", "varNo", "++", ")", "{", "varValuesTab", "[", "varNo", "]", "=", "null", ";", "}", "}", "if", "(", "blockDynTab", "==", "null", ")", "{", "blockDynTab", "=", "new", "BlockDynTabRec", "[", "mtp", ".", "blockTabCnt", "]", ";", "}", "for", "(", "int", "blockNo", "=", "0", ";", "blockNo", "<", "mtp", ".", "blockTabCnt", ";", "blockNo", "++", ")", "{", "BlockDynTabRec", "bdtr", "=", "blockDynTab", "[", "blockNo", "]", ";", "if", "(", "bdtr", "==", "null", ")", "{", "bdtr", "=", "new", "BlockDynTabRec", "(", ")", ";", "blockDynTab", "[", "blockNo", "]", "=", "bdtr", ";", "}", "bdtr", ".", "instances", "=", "0", ";", "bdtr", ".", "firstBlockInstNo", "=", "-", "1", ";", "bdtr", ".", "lastBlockInstNo", "=", "-", "1", ";", "}", "blockInstTabCnt", "=", "0", ";", "}" ]
Resets the MiniTemplator object to the initial state. All variable values are cleared and all added block instances are deleted. This method can be used to produce another HTML page with the same template. It is faster than creating another MiniTemplator object, because the template does not have to be read and parsed again.
[ "Resets", "the", "MiniTemplator", "object", "to", "the", "initial", "state", ".", "All", "variable", "values", "are", "cleared", "and", "all", "added", "block", "instances", "are", "deleted", ".", "This", "method", "can", "be", "used", "to", "produce", "another", "HTML", "page", "with", "the", "same", "template", ".", "It", "is", "faster", "than", "creating", "another", "MiniTemplator", "object", "because", "the", "template", "does", "not", "have", "to", "be", "read", "and", "parsed", "again", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L312-L334
29,166
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.getVariables
public Map<String, String> getVariables() { HashMap<String, String> map = new HashMap<String, String>(mtp.varTabCnt); for (int varNo = 0; varNo < mtp.varTabCnt; varNo++) map.put(mtp.varTab[varNo], varValuesTab[varNo]); return map; }
java
public Map<String, String> getVariables() { HashMap<String, String> map = new HashMap<String, String>(mtp.varTabCnt); for (int varNo = 0; varNo < mtp.varTabCnt; varNo++) map.put(mtp.varTab[varNo], varValuesTab[varNo]); return map; }
[ "public", "Map", "<", "String", ",", "String", ">", "getVariables", "(", ")", "{", "HashMap", "<", "String", ",", "String", ">", "map", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", "mtp", ".", "varTabCnt", ")", ";", "for", "(", "int", "varNo", "=", "0", ";", "varNo", "<", "mtp", ".", "varTabCnt", ";", "varNo", "++", ")", "map", ".", "put", "(", "mtp", ".", "varTab", "[", "varNo", "]", ",", "varValuesTab", "[", "varNo", "]", ")", ";", "return", "map", ";", "}" ]
Returns a map with the names and current values of the template variables.
[ "Returns", "a", "map", "with", "the", "names", "and", "current", "values", "of", "the", "template", "variables", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L501-L506
29,167
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.registerBlockInstance
private int registerBlockInstance() { int blockInstNo = blockInstTabCnt++; if (blockInstTab == null) { blockInstTab = new BlockInstTabRec[64]; } if (blockInstTabCnt > blockInstTab.length) { blockInstTab = (BlockInstTabRec[]) MiniTemplatorParser.resizeArray(blockInstTab, 2 * blockInstTabCnt); } blockInstTab[blockInstNo] = new BlockInstTabRec(); return blockInstNo; }
java
private int registerBlockInstance() { int blockInstNo = blockInstTabCnt++; if (blockInstTab == null) { blockInstTab = new BlockInstTabRec[64]; } if (blockInstTabCnt > blockInstTab.length) { blockInstTab = (BlockInstTabRec[]) MiniTemplatorParser.resizeArray(blockInstTab, 2 * blockInstTabCnt); } blockInstTab[blockInstNo] = new BlockInstTabRec(); return blockInstNo; }
[ "private", "int", "registerBlockInstance", "(", ")", "{", "int", "blockInstNo", "=", "blockInstTabCnt", "++", ";", "if", "(", "blockInstTab", "==", "null", ")", "{", "blockInstTab", "=", "new", "BlockInstTabRec", "[", "64", "]", ";", "}", "if", "(", "blockInstTabCnt", ">", "blockInstTab", ".", "length", ")", "{", "blockInstTab", "=", "(", "BlockInstTabRec", "[", "]", ")", "MiniTemplatorParser", ".", "resizeArray", "(", "blockInstTab", ",", "2", "*", "blockInstTabCnt", ")", ";", "}", "blockInstTab", "[", "blockInstNo", "]", "=", "new", "BlockInstTabRec", "(", ")", ";", "return", "blockInstNo", ";", "}" ]
Returns the block instance number.
[ "Returns", "the", "block", "instance", "number", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L590-L600
29,168
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.generateOutput
public void generateOutput(String outputFileName) throws IOException { FileOutputStream stream = null; OutputStreamWriter writer = null; try { stream = new FileOutputStream(outputFileName); writer = new OutputStreamWriter(stream, charset); generateOutput(writer); } finally { if (writer != null) { writer.close(); } if (stream != null) { stream.close(); } } }
java
public void generateOutput(String outputFileName) throws IOException { FileOutputStream stream = null; OutputStreamWriter writer = null; try { stream = new FileOutputStream(outputFileName); writer = new OutputStreamWriter(stream, charset); generateOutput(writer); } finally { if (writer != null) { writer.close(); } if (stream != null) { stream.close(); } } }
[ "public", "void", "generateOutput", "(", "String", "outputFileName", ")", "throws", "IOException", "{", "FileOutputStream", "stream", "=", "null", ";", "OutputStreamWriter", "writer", "=", "null", ";", "try", "{", "stream", "=", "new", "FileOutputStream", "(", "outputFileName", ")", ";", "writer", "=", "new", "OutputStreamWriter", "(", "stream", ",", "charset", ")", ";", "generateOutput", "(", "writer", ")", ";", "}", "finally", "{", "if", "(", "writer", "!=", "null", ")", "{", "writer", ".", "close", "(", ")", ";", "}", "if", "(", "stream", "!=", "null", ")", "{", "stream", ".", "close", "(", ")", ";", "}", "}", "}" ]
Generates the HTML page and writes it into a file. @param outputFileName name of the file to which the generated HTML page will be written. @throws IOException when an i/o error occurs while writing to the file.
[ "Generates", "the", "HTML", "page", "and", "writes", "it", "into", "a", "file", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L621-L636
29,169
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.generateOutput
public void generateOutput(Writer outputWriter) throws IOException { String s = generateOutput(); outputWriter.write(s); }
java
public void generateOutput(Writer outputWriter) throws IOException { String s = generateOutput(); outputWriter.write(s); }
[ "public", "void", "generateOutput", "(", "Writer", "outputWriter", ")", "throws", "IOException", "{", "String", "s", "=", "generateOutput", "(", ")", ";", "outputWriter", ".", "write", "(", "s", ")", ";", "}" ]
Generates the HTML page and writes it to a character stream. @param outputWriter a character stream (<code>writer</code>) to which the HTML page will be written. @throws IOException when an i/o error occurs while writing to the stream.
[ "Generates", "the", "HTML", "page", "and", "writes", "it", "to", "a", "character", "stream", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L644-L647
29,170
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.generateOutput
public String generateOutput() { if (blockDynTab[0].instances == 0) { addBlockByNo(0); } // add main block for (int blockNo = 0; blockNo < mtp.blockTabCnt; blockNo++) { BlockDynTabRec bdtr = blockDynTab[blockNo]; bdtr.currBlockInstNo = bdtr.firstBlockInstNo; } StringBuilder out = new StringBuilder(); writeBlockInstances(out, 0, -1); return out.toString(); }
java
public String generateOutput() { if (blockDynTab[0].instances == 0) { addBlockByNo(0); } // add main block for (int blockNo = 0; blockNo < mtp.blockTabCnt; blockNo++) { BlockDynTabRec bdtr = blockDynTab[blockNo]; bdtr.currBlockInstNo = bdtr.firstBlockInstNo; } StringBuilder out = new StringBuilder(); writeBlockInstances(out, 0, -1); return out.toString(); }
[ "public", "String", "generateOutput", "(", ")", "{", "if", "(", "blockDynTab", "[", "0", "]", ".", "instances", "==", "0", ")", "{", "addBlockByNo", "(", "0", ")", ";", "}", "// add main block\r", "for", "(", "int", "blockNo", "=", "0", ";", "blockNo", "<", "mtp", ".", "blockTabCnt", ";", "blockNo", "++", ")", "{", "BlockDynTabRec", "bdtr", "=", "blockDynTab", "[", "blockNo", "]", ";", "bdtr", ".", "currBlockInstNo", "=", "bdtr", ".", "firstBlockInstNo", ";", "}", "StringBuilder", "out", "=", "new", "StringBuilder", "(", ")", ";", "writeBlockInstances", "(", "out", ",", "0", ",", "-", "1", ")", ";", "return", "out", ".", "toString", "(", ")", ";", "}" ]
Generates the HTML page and returns it as a string. @return A string that contains the generated HTML page.
[ "Generates", "the", "HTML", "page", "and", "returns", "it", "as", "a", "string", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L654-L665
29,171
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplator.writeBlockInstances
private void writeBlockInstances(StringBuilder out, int blockNo, int parentInstLevel) { BlockDynTabRec bdtr = blockDynTab[blockNo]; while (true) { int blockInstNo = bdtr.currBlockInstNo; if (blockInstNo == -1) { break; } BlockInstTabRec bitr = blockInstTab[blockInstNo]; if (bitr.parentInstLevel < parentInstLevel) { throw new AssertionError(); } if (bitr.parentInstLevel > parentInstLevel) { break; } writeBlockInstance(out, blockInstNo); bdtr.currBlockInstNo = bitr.nextBlockInstNo; } }
java
private void writeBlockInstances(StringBuilder out, int blockNo, int parentInstLevel) { BlockDynTabRec bdtr = blockDynTab[blockNo]; while (true) { int blockInstNo = bdtr.currBlockInstNo; if (blockInstNo == -1) { break; } BlockInstTabRec bitr = blockInstTab[blockInstNo]; if (bitr.parentInstLevel < parentInstLevel) { throw new AssertionError(); } if (bitr.parentInstLevel > parentInstLevel) { break; } writeBlockInstance(out, blockInstNo); bdtr.currBlockInstNo = bitr.nextBlockInstNo; } }
[ "private", "void", "writeBlockInstances", "(", "StringBuilder", "out", ",", "int", "blockNo", ",", "int", "parentInstLevel", ")", "{", "BlockDynTabRec", "bdtr", "=", "blockDynTab", "[", "blockNo", "]", ";", "while", "(", "true", ")", "{", "int", "blockInstNo", "=", "bdtr", ".", "currBlockInstNo", ";", "if", "(", "blockInstNo", "==", "-", "1", ")", "{", "break", ";", "}", "BlockInstTabRec", "bitr", "=", "blockInstTab", "[", "blockInstNo", "]", ";", "if", "(", "bitr", ".", "parentInstLevel", "<", "parentInstLevel", ")", "{", "throw", "new", "AssertionError", "(", ")", ";", "}", "if", "(", "bitr", ".", "parentInstLevel", ">", "parentInstLevel", ")", "{", "break", ";", "}", "writeBlockInstance", "(", "out", ",", "blockInstNo", ")", ";", "bdtr", ".", "currBlockInstNo", "=", "bitr", ".", "nextBlockInstNo", ";", "}", "}" ]
Called recursively.
[ "Called", "recursively", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L670-L687
29,172
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.beginMainBlock
private void beginMainBlock() { int blockNo = registerBlock(null); // =0 BlockTabRec btr = blockTab[blockNo]; btr.tPosBegin = 0; btr.tPosContentsBegin = 0; openBlocksTab[currentNestingLevel] = blockNo; currentNestingLevel++; }
java
private void beginMainBlock() { int blockNo = registerBlock(null); // =0 BlockTabRec btr = blockTab[blockNo]; btr.tPosBegin = 0; btr.tPosContentsBegin = 0; openBlocksTab[currentNestingLevel] = blockNo; currentNestingLevel++; }
[ "private", "void", "beginMainBlock", "(", ")", "{", "int", "blockNo", "=", "registerBlock", "(", "null", ")", ";", "// =0\r", "BlockTabRec", "btr", "=", "blockTab", "[", "blockNo", "]", ";", "btr", ".", "tPosBegin", "=", "0", ";", "btr", ".", "tPosContentsBegin", "=", "0", ";", "openBlocksTab", "[", "currentNestingLevel", "]", "=", "blockNo", ";", "currentNestingLevel", "++", ";", "}" ]
The main block is an implicitly defined block that covers the whole template.
[ "The", "main", "block", "is", "an", "implicitly", "defined", "block", "that", "covers", "the", "whole", "template", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L992-L999
29,173
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.endMainBlock
private void endMainBlock() { BlockTabRec btr = blockTab[0]; btr.tPosContentsEnd = templateText.length(); btr.tPosEnd = templateText.length(); btr.definitionIsOpen = false; currentNestingLevel--; }
java
private void endMainBlock() { BlockTabRec btr = blockTab[0]; btr.tPosContentsEnd = templateText.length(); btr.tPosEnd = templateText.length(); btr.definitionIsOpen = false; currentNestingLevel--; }
[ "private", "void", "endMainBlock", "(", ")", "{", "BlockTabRec", "btr", "=", "blockTab", "[", "0", "]", ";", "btr", ".", "tPosContentsEnd", "=", "templateText", ".", "length", "(", ")", ";", "btr", ".", "tPosEnd", "=", "templateText", ".", "length", "(", ")", ";", "btr", ".", "definitionIsOpen", "=", "false", ";", "currentNestingLevel", "--", ";", "}" ]
Completes the main block registration.
[ "Completes", "the", "main", "block", "registration", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1002-L1008
29,174
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.processTemplateCommand
private boolean processTemplateCommand(String cmdLine, int cmdTPosBegin, int cmdTPosEnd) throws MiniTemplator.TemplateSyntaxException { int p0 = skipBlanks(cmdLine, 0); if (p0 >= cmdLine.length()) { return false; } int p = skipNonBlanks(cmdLine, p0); String cmd = cmdLine.substring(p0, p); String parms = cmdLine.substring(p); /* select */ if (cmd.equalsIgnoreCase("$beginBlock")) { processBeginBlockCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$endBlock")) { processEndBlockCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$include")) { processIncludeCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$if")) { processIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$elseIf")) { processElseIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$else")) { processElseCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$endIf")) { processEndIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { if (cmd.startsWith("$") && !cmd.startsWith("${")) { throw new MiniTemplator.TemplateSyntaxException( "Unknown command \"" + cmd + "\" in template at offset " + cmdTPosBegin + "."); } else { return false; } } return true; }
java
private boolean processTemplateCommand(String cmdLine, int cmdTPosBegin, int cmdTPosEnd) throws MiniTemplator.TemplateSyntaxException { int p0 = skipBlanks(cmdLine, 0); if (p0 >= cmdLine.length()) { return false; } int p = skipNonBlanks(cmdLine, p0); String cmd = cmdLine.substring(p0, p); String parms = cmdLine.substring(p); /* select */ if (cmd.equalsIgnoreCase("$beginBlock")) { processBeginBlockCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$endBlock")) { processEndBlockCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$include")) { processIncludeCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$if")) { processIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$elseIf")) { processElseIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$else")) { processElseCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equalsIgnoreCase("$endIf")) { processEndIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { if (cmd.startsWith("$") && !cmd.startsWith("${")) { throw new MiniTemplator.TemplateSyntaxException( "Unknown command \"" + cmd + "\" in template at offset " + cmdTPosBegin + "."); } else { return false; } } return true; }
[ "private", "boolean", "processTemplateCommand", "(", "String", "cmdLine", ",", "int", "cmdTPosBegin", ",", "int", "cmdTPosEnd", ")", "throws", "MiniTemplator", ".", "TemplateSyntaxException", "{", "int", "p0", "=", "skipBlanks", "(", "cmdLine", ",", "0", ")", ";", "if", "(", "p0", ">=", "cmdLine", ".", "length", "(", ")", ")", "{", "return", "false", ";", "}", "int", "p", "=", "skipNonBlanks", "(", "cmdLine", ",", "p0", ")", ";", "String", "cmd", "=", "cmdLine", ".", "substring", "(", "p0", ",", "p", ")", ";", "String", "parms", "=", "cmdLine", ".", "substring", "(", "p", ")", ";", "/* select */", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$beginBlock\"", ")", ")", "{", "processBeginBlockCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$endBlock\"", ")", ")", "{", "processEndBlockCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$include\"", ")", ")", "{", "processIncludeCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$if\"", ")", ")", "{", "processIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$elseIf\"", ")", ")", "{", "processElseIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$else\"", ")", ")", "{", "processElseCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equalsIgnoreCase", "(", "\"$endIf\"", ")", ")", "{", "processEndIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "{", "if", "(", "cmd", ".", "startsWith", "(", "\"$\"", ")", "&&", "!", "cmd", ".", "startsWith", "(", "\"${\"", ")", ")", "{", "throw", "new", "MiniTemplator", ".", "TemplateSyntaxException", "(", "\"Unknown command \\\"\"", "+", "cmd", "+", "\"\\\" in template at offset \"", "+", "cmdTPosBegin", "+", "\".\"", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Returns false if the command should be treatet as normal template text.
[ "Returns", "false", "if", "the", "command", "should", "be", "treatet", "as", "normal", "template", "text", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1069-L1102
29,175
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.processShortFormTemplateCommand
private boolean processShortFormTemplateCommand(String cmdLine, int cmdTPosBegin, int cmdTPosEnd) throws MiniTemplator.TemplateSyntaxException { int p0 = skipBlanks(cmdLine, 0); if (p0 >= cmdLine.length()) { return false; } int p = p0; char cmd1 = cmdLine.charAt(p++); if (cmd1 == '/' && p < cmdLine.length() && !Character.isWhitespace(cmdLine.charAt(p))) { p++; } String cmd = cmdLine.substring(p0, p); String parms = cmdLine.substring(p).trim(); /* select */ if (cmd.equals("?")) { processIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equals(":")) { if (parms.length() > 0) { processElseIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { processElseCmd(parms, cmdTPosBegin, cmdTPosEnd); } } else if (cmd.equals("/?")) { processEndIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { return false; } return true; }
java
private boolean processShortFormTemplateCommand(String cmdLine, int cmdTPosBegin, int cmdTPosEnd) throws MiniTemplator.TemplateSyntaxException { int p0 = skipBlanks(cmdLine, 0); if (p0 >= cmdLine.length()) { return false; } int p = p0; char cmd1 = cmdLine.charAt(p++); if (cmd1 == '/' && p < cmdLine.length() && !Character.isWhitespace(cmdLine.charAt(p))) { p++; } String cmd = cmdLine.substring(p0, p); String parms = cmdLine.substring(p).trim(); /* select */ if (cmd.equals("?")) { processIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else if (cmd.equals(":")) { if (parms.length() > 0) { processElseIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { processElseCmd(parms, cmdTPosBegin, cmdTPosEnd); } } else if (cmd.equals("/?")) { processEndIfCmd(parms, cmdTPosBegin, cmdTPosEnd); } else { return false; } return true; }
[ "private", "boolean", "processShortFormTemplateCommand", "(", "String", "cmdLine", ",", "int", "cmdTPosBegin", ",", "int", "cmdTPosEnd", ")", "throws", "MiniTemplator", ".", "TemplateSyntaxException", "{", "int", "p0", "=", "skipBlanks", "(", "cmdLine", ",", "0", ")", ";", "if", "(", "p0", ">=", "cmdLine", ".", "length", "(", ")", ")", "{", "return", "false", ";", "}", "int", "p", "=", "p0", ";", "char", "cmd1", "=", "cmdLine", ".", "charAt", "(", "p", "++", ")", ";", "if", "(", "cmd1", "==", "'", "'", "&&", "p", "<", "cmdLine", ".", "length", "(", ")", "&&", "!", "Character", ".", "isWhitespace", "(", "cmdLine", ".", "charAt", "(", "p", ")", ")", ")", "{", "p", "++", ";", "}", "String", "cmd", "=", "cmdLine", ".", "substring", "(", "p0", ",", "p", ")", ";", "String", "parms", "=", "cmdLine", ".", "substring", "(", "p", ")", ".", "trim", "(", ")", ";", "/* select */", "if", "(", "cmd", ".", "equals", "(", "\"?\"", ")", ")", "{", "processIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "if", "(", "cmd", ".", "equals", "(", "\":\"", ")", ")", "{", "if", "(", "parms", ".", "length", "(", ")", ">", "0", ")", "{", "processElseIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "{", "processElseCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "}", "else", "if", "(", "cmd", ".", "equals", "(", "\"/?\"", ")", ")", "{", "processEndIfCmd", "(", "parms", ",", "cmdTPosBegin", ",", "cmdTPosEnd", ")", ";", "}", "else", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Returns false if the command is not recognized and should be treatet as normal temlate text.
[ "Returns", "false", "if", "the", "command", "is", "not", "recognized", "and", "should", "be", "treatet", "as", "normal", "temlate", "text", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1105-L1133
29,176
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.registerBlock
private int registerBlock(String blockName) { int blockNo = blockTabCnt++; if (blockTabCnt > blockTab.length) { blockTab = (BlockTabRec[]) resizeArray(blockTab, 2 * blockTabCnt); } BlockTabRec btr = new BlockTabRec(); blockTab[blockNo] = btr; btr.blockName = blockName; if (blockName != null) { btr.nextWithSameName = lookupBlockName(blockName); } else { btr.nextWithSameName = -1; } btr.nestingLevel = currentNestingLevel; if (currentNestingLevel > 0) { btr.parentBlockNo = openBlocksTab[currentNestingLevel - 1]; } else { btr.parentBlockNo = -1; } btr.definitionIsOpen = true; btr.blockVarCnt = 0; btr.firstVarRefNo = -1; btr.blockVarNoToVarNoMap = new int[32]; btr.dummy = false; if (blockName != null) { blockNameToNoMap.put(blockName.toUpperCase(), new Integer(blockNo)); } return blockNo; }
java
private int registerBlock(String blockName) { int blockNo = blockTabCnt++; if (blockTabCnt > blockTab.length) { blockTab = (BlockTabRec[]) resizeArray(blockTab, 2 * blockTabCnt); } BlockTabRec btr = new BlockTabRec(); blockTab[blockNo] = btr; btr.blockName = blockName; if (blockName != null) { btr.nextWithSameName = lookupBlockName(blockName); } else { btr.nextWithSameName = -1; } btr.nestingLevel = currentNestingLevel; if (currentNestingLevel > 0) { btr.parentBlockNo = openBlocksTab[currentNestingLevel - 1]; } else { btr.parentBlockNo = -1; } btr.definitionIsOpen = true; btr.blockVarCnt = 0; btr.firstVarRefNo = -1; btr.blockVarNoToVarNoMap = new int[32]; btr.dummy = false; if (blockName != null) { blockNameToNoMap.put(blockName.toUpperCase(), new Integer(blockNo)); } return blockNo; }
[ "private", "int", "registerBlock", "(", "String", "blockName", ")", "{", "int", "blockNo", "=", "blockTabCnt", "++", ";", "if", "(", "blockTabCnt", ">", "blockTab", ".", "length", ")", "{", "blockTab", "=", "(", "BlockTabRec", "[", "]", ")", "resizeArray", "(", "blockTab", ",", "2", "*", "blockTabCnt", ")", ";", "}", "BlockTabRec", "btr", "=", "new", "BlockTabRec", "(", ")", ";", "blockTab", "[", "blockNo", "]", "=", "btr", ";", "btr", ".", "blockName", "=", "blockName", ";", "if", "(", "blockName", "!=", "null", ")", "{", "btr", ".", "nextWithSameName", "=", "lookupBlockName", "(", "blockName", ")", ";", "}", "else", "{", "btr", ".", "nextWithSameName", "=", "-", "1", ";", "}", "btr", ".", "nestingLevel", "=", "currentNestingLevel", ";", "if", "(", "currentNestingLevel", ">", "0", ")", "{", "btr", ".", "parentBlockNo", "=", "openBlocksTab", "[", "currentNestingLevel", "-", "1", "]", ";", "}", "else", "{", "btr", ".", "parentBlockNo", "=", "-", "1", ";", "}", "btr", ".", "definitionIsOpen", "=", "true", ";", "btr", ".", "blockVarCnt", "=", "0", ";", "btr", ".", "firstVarRefNo", "=", "-", "1", ";", "btr", ".", "blockVarNoToVarNoMap", "=", "new", "int", "[", "32", "]", ";", "btr", ".", "dummy", "=", "false", ";", "if", "(", "blockName", "!=", "null", ")", "{", "blockNameToNoMap", ".", "put", "(", "blockName", ".", "toUpperCase", "(", ")", ",", "new", "Integer", "(", "blockNo", ")", ")", ";", "}", "return", "blockNo", ";", "}" ]
Returns the block number of the newly registered block.
[ "Returns", "the", "block", "number", "of", "the", "newly", "registered", "block", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1203-L1231
29,177
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.excludeTemplateRange
private void excludeTemplateRange(int tPosBegin, int tPosEnd) { if (blockTabCnt > 0) { // Check whether we can extend the previous block. BlockTabRec btr = blockTab[blockTabCnt - 1]; if (btr.dummy && btr.tPosEnd == tPosBegin) { btr.tPosContentsEnd = tPosEnd; btr.tPosEnd = tPosEnd; return; } } int blockNo = registerBlock(null); BlockTabRec btr = blockTab[blockNo]; btr.tPosBegin = tPosBegin; btr.tPosContentsBegin = tPosBegin; btr.tPosContentsEnd = tPosEnd; btr.tPosEnd = tPosEnd; btr.definitionIsOpen = false; btr.dummy = true; }
java
private void excludeTemplateRange(int tPosBegin, int tPosEnd) { if (blockTabCnt > 0) { // Check whether we can extend the previous block. BlockTabRec btr = blockTab[blockTabCnt - 1]; if (btr.dummy && btr.tPosEnd == tPosBegin) { btr.tPosContentsEnd = tPosEnd; btr.tPosEnd = tPosEnd; return; } } int blockNo = registerBlock(null); BlockTabRec btr = blockTab[blockNo]; btr.tPosBegin = tPosBegin; btr.tPosContentsBegin = tPosBegin; btr.tPosContentsEnd = tPosEnd; btr.tPosEnd = tPosEnd; btr.definitionIsOpen = false; btr.dummy = true; }
[ "private", "void", "excludeTemplateRange", "(", "int", "tPosBegin", ",", "int", "tPosEnd", ")", "{", "if", "(", "blockTabCnt", ">", "0", ")", "{", "// Check whether we can extend the previous block.\r", "BlockTabRec", "btr", "=", "blockTab", "[", "blockTabCnt", "-", "1", "]", ";", "if", "(", "btr", ".", "dummy", "&&", "btr", ".", "tPosEnd", "==", "tPosBegin", ")", "{", "btr", ".", "tPosContentsEnd", "=", "tPosEnd", ";", "btr", ".", "tPosEnd", "=", "tPosEnd", ";", "return", ";", "}", "}", "int", "blockNo", "=", "registerBlock", "(", "null", ")", ";", "BlockTabRec", "btr", "=", "blockTab", "[", "blockNo", "]", ";", "btr", ".", "tPosBegin", "=", "tPosBegin", ";", "btr", ".", "tPosContentsBegin", "=", "tPosBegin", ";", "btr", ".", "tPosContentsEnd", "=", "tPosEnd", ";", "btr", ".", "tPosEnd", "=", "tPosEnd", ";", "btr", ".", "definitionIsOpen", "=", "false", ";", "btr", ".", "dummy", "=", "true", ";", "}" ]
Registers a dummy block to exclude a range within the template text.
[ "Registers", "a", "dummy", "block", "to", "exclude", "a", "range", "within", "the", "template", "text", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1234-L1252
29,178
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.checkBlockDefinitionsComplete
private void checkBlockDefinitionsComplete() throws MiniTemplator.TemplateSyntaxException { for (int blockNo = 0; blockNo < blockTabCnt; blockNo++) { BlockTabRec btr = blockTab[blockNo]; if (btr.definitionIsOpen) { throw new MiniTemplator.TemplateSyntaxException( "Missing $EndBlock command in template for block \"" + btr.blockName + "\"."); } } if (currentNestingLevel != 0) { throw new MiniTemplator.TemplateSyntaxException("Block nesting level error at end of template."); } }
java
private void checkBlockDefinitionsComplete() throws MiniTemplator.TemplateSyntaxException { for (int blockNo = 0; blockNo < blockTabCnt; blockNo++) { BlockTabRec btr = blockTab[blockNo]; if (btr.definitionIsOpen) { throw new MiniTemplator.TemplateSyntaxException( "Missing $EndBlock command in template for block \"" + btr.blockName + "\"."); } } if (currentNestingLevel != 0) { throw new MiniTemplator.TemplateSyntaxException("Block nesting level error at end of template."); } }
[ "private", "void", "checkBlockDefinitionsComplete", "(", ")", "throws", "MiniTemplator", ".", "TemplateSyntaxException", "{", "for", "(", "int", "blockNo", "=", "0", ";", "blockNo", "<", "blockTabCnt", ";", "blockNo", "++", ")", "{", "BlockTabRec", "btr", "=", "blockTab", "[", "blockNo", "]", ";", "if", "(", "btr", ".", "definitionIsOpen", ")", "{", "throw", "new", "MiniTemplator", ".", "TemplateSyntaxException", "(", "\"Missing $EndBlock command in template for block \\\"\"", "+", "btr", ".", "blockName", "+", "\"\\\".\"", ")", ";", "}", "}", "if", "(", "currentNestingLevel", "!=", "0", ")", "{", "throw", "new", "MiniTemplator", ".", "TemplateSyntaxException", "(", "\"Block nesting level error at end of template.\"", ")", ";", "}", "}" ]
Checks that all block definitions are closed.
[ "Checks", "that", "all", "block", "definitions", "are", "closed", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1255-L1266
29,179
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.conditionalExclude
private boolean conditionalExclude(int tPosBegin, int tPosEnd) { if (isCondEnabled(condLevel)) { return false; } excludeTemplateRange(tPosBegin, tPosEnd); return true; }
java
private boolean conditionalExclude(int tPosBegin, int tPosEnd) { if (isCondEnabled(condLevel)) { return false; } excludeTemplateRange(tPosBegin, tPosEnd); return true; }
[ "private", "boolean", "conditionalExclude", "(", "int", "tPosBegin", ",", "int", "tPosEnd", ")", "{", "if", "(", "isCondEnabled", "(", "condLevel", ")", ")", "{", "return", "false", ";", "}", "excludeTemplateRange", "(", "tPosBegin", ",", "tPosEnd", ")", ";", "return", "true", ";", "}" ]
Otherwise nothing is done and false is returned.
[ "Otherwise", "nothing", "is", "done", "and", "false", "is", "returned", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1335-L1341
29,180
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.evaluateConditionFlags
private boolean evaluateConditionFlags(String flags) { int p = 0; while (true) { p = skipBlanks(flags, p); if (p >= flags.length()) { break; } boolean complement = false; if (flags.charAt(p) == '!') { complement = true; p++; } p = skipBlanks(flags, p); if (p >= flags.length()) { break; } int p0 = p; p = skipNonBlanks(flags, p0 + 1); String flag = flags.substring(p0, p).toUpperCase(); if ((conditionFlags != null && conditionFlags.contains(flag)) ^ complement) { return true; } } return false; }
java
private boolean evaluateConditionFlags(String flags) { int p = 0; while (true) { p = skipBlanks(flags, p); if (p >= flags.length()) { break; } boolean complement = false; if (flags.charAt(p) == '!') { complement = true; p++; } p = skipBlanks(flags, p); if (p >= flags.length()) { break; } int p0 = p; p = skipNonBlanks(flags, p0 + 1); String flag = flags.substring(p0, p).toUpperCase(); if ((conditionFlags != null && conditionFlags.contains(flag)) ^ complement) { return true; } } return false; }
[ "private", "boolean", "evaluateConditionFlags", "(", "String", "flags", ")", "{", "int", "p", "=", "0", ";", "while", "(", "true", ")", "{", "p", "=", "skipBlanks", "(", "flags", ",", "p", ")", ";", "if", "(", "p", ">=", "flags", ".", "length", "(", ")", ")", "{", "break", ";", "}", "boolean", "complement", "=", "false", ";", "if", "(", "flags", ".", "charAt", "(", "p", ")", "==", "'", "'", ")", "{", "complement", "=", "true", ";", "p", "++", ";", "}", "p", "=", "skipBlanks", "(", "flags", ",", "p", ")", ";", "if", "(", "p", ">=", "flags", ".", "length", "(", ")", ")", "{", "break", ";", "}", "int", "p0", "=", "p", ";", "p", "=", "skipNonBlanks", "(", "flags", ",", "p0", "+", "1", ")", ";", "String", "flag", "=", "flags", ".", "substring", "(", "p0", ",", "p", ")", ".", "toUpperCase", "(", ")", ";", "if", "(", "(", "conditionFlags", "!=", "null", "&&", "conditionFlags", ".", "contains", "(", "flag", ")", ")", "^", "complement", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true the condition is met.
[ "Returns", "true", "the", "condition", "is", "met", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1346-L1370
29,181
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.associateVariablesWithBlocks
private void associateVariablesWithBlocks() { int varRefNo = 0; int activeBlockNo = 0; int nextBlockNo = 1; while (varRefNo < varRefTabCnt) { VarRefTabRec vrtr = varRefTab[varRefNo]; int varRefTPos = vrtr.tPosBegin; int varNo = vrtr.varNo; if (varRefTPos >= blockTab[activeBlockNo].tPosEnd) { activeBlockNo = blockTab[activeBlockNo].parentBlockNo; continue; } if (nextBlockNo < blockTabCnt && varRefTPos >= blockTab[nextBlockNo].tPosBegin) { activeBlockNo = nextBlockNo; nextBlockNo++; continue; } BlockTabRec btr = blockTab[activeBlockNo]; if (varRefTPos < btr.tPosBegin) { throw new AssertionError(); } int blockVarNo = btr.blockVarCnt++; if (btr.blockVarCnt > btr.blockVarNoToVarNoMap.length) { btr.blockVarNoToVarNoMap = (int[]) resizeArray(btr.blockVarNoToVarNoMap, 2 * btr.blockVarCnt); } btr.blockVarNoToVarNoMap[blockVarNo] = varNo; if (btr.firstVarRefNo == -1) { btr.firstVarRefNo = varRefNo; } vrtr.blockNo = activeBlockNo; vrtr.blockVarNo = blockVarNo; varRefNo++; } }
java
private void associateVariablesWithBlocks() { int varRefNo = 0; int activeBlockNo = 0; int nextBlockNo = 1; while (varRefNo < varRefTabCnt) { VarRefTabRec vrtr = varRefTab[varRefNo]; int varRefTPos = vrtr.tPosBegin; int varNo = vrtr.varNo; if (varRefTPos >= blockTab[activeBlockNo].tPosEnd) { activeBlockNo = blockTab[activeBlockNo].parentBlockNo; continue; } if (nextBlockNo < blockTabCnt && varRefTPos >= blockTab[nextBlockNo].tPosBegin) { activeBlockNo = nextBlockNo; nextBlockNo++; continue; } BlockTabRec btr = blockTab[activeBlockNo]; if (varRefTPos < btr.tPosBegin) { throw new AssertionError(); } int blockVarNo = btr.blockVarCnt++; if (btr.blockVarCnt > btr.blockVarNoToVarNoMap.length) { btr.blockVarNoToVarNoMap = (int[]) resizeArray(btr.blockVarNoToVarNoMap, 2 * btr.blockVarCnt); } btr.blockVarNoToVarNoMap[blockVarNo] = varNo; if (btr.firstVarRefNo == -1) { btr.firstVarRefNo = varRefNo; } vrtr.blockNo = activeBlockNo; vrtr.blockVarNo = blockVarNo; varRefNo++; } }
[ "private", "void", "associateVariablesWithBlocks", "(", ")", "{", "int", "varRefNo", "=", "0", ";", "int", "activeBlockNo", "=", "0", ";", "int", "nextBlockNo", "=", "1", ";", "while", "(", "varRefNo", "<", "varRefTabCnt", ")", "{", "VarRefTabRec", "vrtr", "=", "varRefTab", "[", "varRefNo", "]", ";", "int", "varRefTPos", "=", "vrtr", ".", "tPosBegin", ";", "int", "varNo", "=", "vrtr", ".", "varNo", ";", "if", "(", "varRefTPos", ">=", "blockTab", "[", "activeBlockNo", "]", ".", "tPosEnd", ")", "{", "activeBlockNo", "=", "blockTab", "[", "activeBlockNo", "]", ".", "parentBlockNo", ";", "continue", ";", "}", "if", "(", "nextBlockNo", "<", "blockTabCnt", "&&", "varRefTPos", ">=", "blockTab", "[", "nextBlockNo", "]", ".", "tPosBegin", ")", "{", "activeBlockNo", "=", "nextBlockNo", ";", "nextBlockNo", "++", ";", "continue", ";", "}", "BlockTabRec", "btr", "=", "blockTab", "[", "activeBlockNo", "]", ";", "if", "(", "varRefTPos", "<", "btr", ".", "tPosBegin", ")", "{", "throw", "new", "AssertionError", "(", ")", ";", "}", "int", "blockVarNo", "=", "btr", ".", "blockVarCnt", "++", ";", "if", "(", "btr", ".", "blockVarCnt", ">", "btr", ".", "blockVarNoToVarNoMap", ".", "length", ")", "{", "btr", ".", "blockVarNoToVarNoMap", "=", "(", "int", "[", "]", ")", "resizeArray", "(", "btr", ".", "blockVarNoToVarNoMap", ",", "2", "*", "btr", ".", "blockVarCnt", ")", ";", "}", "btr", ".", "blockVarNoToVarNoMap", "[", "blockVarNo", "]", "=", "varNo", ";", "if", "(", "btr", ".", "firstVarRefNo", "==", "-", "1", ")", "{", "btr", ".", "firstVarRefNo", "=", "varRefNo", ";", "}", "vrtr", ".", "blockNo", "=", "activeBlockNo", ";", "vrtr", ".", "blockVarNo", "=", "blockVarNo", ";", "varRefNo", "++", ";", "}", "}" ]
Associates variable references with blocks.
[ "Associates", "variable", "references", "with", "blocks", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1432-L1465
29,182
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.registerVariable
private int registerVariable(String varName) { int varNo = varTabCnt++; if (varTabCnt > varTab.length) { varTab = (String[]) resizeArray(varTab, 2 * varTabCnt); } varTab[varNo] = varName; varNameToNoMap.put(varName.toUpperCase(), new Integer(varNo)); return varNo; }
java
private int registerVariable(String varName) { int varNo = varTabCnt++; if (varTabCnt > varTab.length) { varTab = (String[]) resizeArray(varTab, 2 * varTabCnt); } varTab[varNo] = varName; varNameToNoMap.put(varName.toUpperCase(), new Integer(varNo)); return varNo; }
[ "private", "int", "registerVariable", "(", "String", "varName", ")", "{", "int", "varNo", "=", "varTabCnt", "++", ";", "if", "(", "varTabCnt", ">", "varTab", ".", "length", ")", "{", "varTab", "=", "(", "String", "[", "]", ")", "resizeArray", "(", "varTab", ",", "2", "*", "varTabCnt", ")", ";", "}", "varTab", "[", "varNo", "]", "=", "varName", ";", "varNameToNoMap", ".", "put", "(", "varName", ".", "toUpperCase", "(", ")", ",", "new", "Integer", "(", "varNo", ")", ")", ";", "return", "varNo", ";", "}" ]
Returns the variable number of the newly registered variable.
[ "Returns", "the", "variable", "number", "of", "the", "newly", "registered", "variable", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1509-L1517
29,183
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.lookupVariableName
public int lookupVariableName(String varName) { Integer varNoWrapper = varNameToNoMap.get(varName.toUpperCase()); if (varNoWrapper == null) { return -1; } int varNo = varNoWrapper.intValue(); return varNo; }
java
public int lookupVariableName(String varName) { Integer varNoWrapper = varNameToNoMap.get(varName.toUpperCase()); if (varNoWrapper == null) { return -1; } int varNo = varNoWrapper.intValue(); return varNo; }
[ "public", "int", "lookupVariableName", "(", "String", "varName", ")", "{", "Integer", "varNoWrapper", "=", "varNameToNoMap", ".", "get", "(", "varName", ".", "toUpperCase", "(", ")", ")", ";", "if", "(", "varNoWrapper", "==", "null", ")", "{", "return", "-", "1", ";", "}", "int", "varNo", "=", "varNoWrapper", ".", "intValue", "(", ")", ";", "return", "varNo", ";", "}" ]
Returns -1 if the variable name is not found.
[ "Returns", "-", "1", "if", "the", "variable", "name", "is", "not", "found", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1523-L1530
29,184
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java
MiniTemplatorParser.lookupBlockName
public int lookupBlockName(String blockName) { Integer blockNoWrapper = blockNameToNoMap.get(blockName.toUpperCase()); if (blockNoWrapper == null) { return -1; } int blockNo = blockNoWrapper.intValue(); return blockNo; }
java
public int lookupBlockName(String blockName) { Integer blockNoWrapper = blockNameToNoMap.get(blockName.toUpperCase()); if (blockNoWrapper == null) { return -1; } int blockNo = blockNoWrapper.intValue(); return blockNo; }
[ "public", "int", "lookupBlockName", "(", "String", "blockName", ")", "{", "Integer", "blockNoWrapper", "=", "blockNameToNoMap", ".", "get", "(", "blockName", ".", "toUpperCase", "(", ")", ")", ";", "if", "(", "blockNoWrapper", "==", "null", ")", "{", "return", "-", "1", ";", "}", "int", "blockNo", "=", "blockNoWrapper", ".", "intValue", "(", ")", ";", "return", "blockNo", ";", "}" ]
Returns -1 if the block name is not found.
[ "Returns", "-", "1", "if", "the", "block", "name", "is", "not", "found", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/MiniTemplator.java#L1536-L1543
29,185
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/TemplateCodeGenerator.java
TemplateCodeGenerator.initEncodeMethodTemplateVariable
protected void initEncodeMethodTemplateVariable() { Set<Integer> orders = new HashSet<Integer>(); // encode method for (FieldInfo field : fields) { boolean isList = field.isList(); // check type if (!isList) { checkType(field.getFieldType(), field.getField()); } if (orders.contains(field.getOrder())) { throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field" + field.getField().getName() + " already exsit."); } // define field FieldType fieldType = field.getFieldType(); String accessByField = getAccessByField("t", field.getField(), cls); String fieldName = CodedConstant.getFieldName(field.getOrder()); String encodeFieldType = CodedConstant.getFiledType(fieldType, isList); templator.setVariable("encodeFieldType", encodeFieldType); templator.setVariable("encodeFieldName", fieldName); templator.setVariable("encodeFieldGetter", accessByField); String writeValueToField = CodedConstant.getWriteValueToField(fieldType, accessByField, isList); templator.setVariable("writeValueToField", writeValueToField); if (field.isRequired()) { templator.setVariableOpt("checkNull", CodedConstant.getRequiredCheck(field.getOrder(), field.getField())); } else { templator.setVariable("checkNull", ""); } String calcSize = CodedConstant.getMappedTypeSize(field, field.getOrder(), field.getFieldType(), isList, debug, outputPath); templator.setVariable("calcSize", calcSize); // set write to byte String encodeWriteFieldValue = CodedConstant.getMappedWriteCode(field, "output", field.getOrder(), field.getFieldType(), isList); templator.setVariable("encodeWriteFieldValue", encodeWriteFieldValue); templator.addBlock("encodeFields"); } }
java
protected void initEncodeMethodTemplateVariable() { Set<Integer> orders = new HashSet<Integer>(); // encode method for (FieldInfo field : fields) { boolean isList = field.isList(); // check type if (!isList) { checkType(field.getFieldType(), field.getField()); } if (orders.contains(field.getOrder())) { throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field" + field.getField().getName() + " already exsit."); } // define field FieldType fieldType = field.getFieldType(); String accessByField = getAccessByField("t", field.getField(), cls); String fieldName = CodedConstant.getFieldName(field.getOrder()); String encodeFieldType = CodedConstant.getFiledType(fieldType, isList); templator.setVariable("encodeFieldType", encodeFieldType); templator.setVariable("encodeFieldName", fieldName); templator.setVariable("encodeFieldGetter", accessByField); String writeValueToField = CodedConstant.getWriteValueToField(fieldType, accessByField, isList); templator.setVariable("writeValueToField", writeValueToField); if (field.isRequired()) { templator.setVariableOpt("checkNull", CodedConstant.getRequiredCheck(field.getOrder(), field.getField())); } else { templator.setVariable("checkNull", ""); } String calcSize = CodedConstant.getMappedTypeSize(field, field.getOrder(), field.getFieldType(), isList, debug, outputPath); templator.setVariable("calcSize", calcSize); // set write to byte String encodeWriteFieldValue = CodedConstant.getMappedWriteCode(field, "output", field.getOrder(), field.getFieldType(), isList); templator.setVariable("encodeWriteFieldValue", encodeWriteFieldValue); templator.addBlock("encodeFields"); } }
[ "protected", "void", "initEncodeMethodTemplateVariable", "(", ")", "{", "Set", "<", "Integer", ">", "orders", "=", "new", "HashSet", "<", "Integer", ">", "(", ")", ";", "// encode method\r", "for", "(", "FieldInfo", "field", ":", "fields", ")", "{", "boolean", "isList", "=", "field", ".", "isList", "(", ")", ";", "// check type\r", "if", "(", "!", "isList", ")", "{", "checkType", "(", "field", ".", "getFieldType", "(", ")", ",", "field", ".", "getField", "(", ")", ")", ";", "}", "if", "(", "orders", ".", "contains", "(", "field", ".", "getOrder", "(", ")", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Field order '\"", "+", "field", ".", "getOrder", "(", ")", "+", "\"' on field\"", "+", "field", ".", "getField", "(", ")", ".", "getName", "(", ")", "+", "\" already exsit.\"", ")", ";", "}", "// define field\r", "FieldType", "fieldType", "=", "field", ".", "getFieldType", "(", ")", ";", "String", "accessByField", "=", "getAccessByField", "(", "\"t\"", ",", "field", ".", "getField", "(", ")", ",", "cls", ")", ";", "String", "fieldName", "=", "CodedConstant", ".", "getFieldName", "(", "field", ".", "getOrder", "(", ")", ")", ";", "String", "encodeFieldType", "=", "CodedConstant", ".", "getFiledType", "(", "fieldType", ",", "isList", ")", ";", "templator", ".", "setVariable", "(", "\"encodeFieldType\"", ",", "encodeFieldType", ")", ";", "templator", ".", "setVariable", "(", "\"encodeFieldName\"", ",", "fieldName", ")", ";", "templator", ".", "setVariable", "(", "\"encodeFieldGetter\"", ",", "accessByField", ")", ";", "String", "writeValueToField", "=", "CodedConstant", ".", "getWriteValueToField", "(", "fieldType", ",", "accessByField", ",", "isList", ")", ";", "templator", ".", "setVariable", "(", "\"writeValueToField\"", ",", "writeValueToField", ")", ";", "if", "(", "field", ".", "isRequired", "(", ")", ")", "{", "templator", ".", "setVariableOpt", "(", "\"checkNull\"", ",", "CodedConstant", ".", "getRequiredCheck", "(", "field", ".", "getOrder", "(", ")", ",", "field", ".", "getField", "(", ")", ")", ")", ";", "}", "else", "{", "templator", ".", "setVariable", "(", "\"checkNull\"", ",", "\"\"", ")", ";", "}", "String", "calcSize", "=", "CodedConstant", ".", "getMappedTypeSize", "(", "field", ",", "field", ".", "getOrder", "(", ")", ",", "field", ".", "getFieldType", "(", ")", ",", "isList", ",", "debug", ",", "outputPath", ")", ";", "templator", ".", "setVariable", "(", "\"calcSize\"", ",", "calcSize", ")", ";", "// set write to byte\r", "String", "encodeWriteFieldValue", "=", "CodedConstant", ".", "getMappedWriteCode", "(", "field", ",", "\"output\"", ",", "field", ".", "getOrder", "(", ")", ",", "field", ".", "getFieldType", "(", ")", ",", "isList", ")", ";", "templator", ".", "setVariable", "(", "\"encodeWriteFieldValue\"", ",", "encodeWriteFieldValue", ")", ";", "templator", ".", "addBlock", "(", "\"encodeFields\"", ")", ";", "}", "}" ]
Inits the encode method template variable.
[ "Inits", "the", "encode", "method", "template", "variable", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/TemplateCodeGenerator.java#L136-L182
29,186
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java
CodedConstant.getWriteValueToField
public static String getWriteValueToField(FieldType type, String express, boolean isList) { if ((type == FieldType.STRING || type == FieldType.BYTES) && !isList) { String method = "copyFromUtf8"; if (type == FieldType.BYTES) { method = "copyFrom"; } return "com.google.protobuf.ByteString." + method + "(" + express + ")"; } return express; }
java
public static String getWriteValueToField(FieldType type, String express, boolean isList) { if ((type == FieldType.STRING || type == FieldType.BYTES) && !isList) { String method = "copyFromUtf8"; if (type == FieldType.BYTES) { method = "copyFrom"; } return "com.google.protobuf.ByteString." + method + "(" + express + ")"; } return express; }
[ "public", "static", "String", "getWriteValueToField", "(", "FieldType", "type", ",", "String", "express", ",", "boolean", "isList", ")", "{", "if", "(", "(", "type", "==", "FieldType", ".", "STRING", "||", "type", "==", "FieldType", ".", "BYTES", ")", "&&", "!", "isList", ")", "{", "String", "method", "=", "\"copyFromUtf8\"", ";", "if", "(", "type", "==", "FieldType", ".", "BYTES", ")", "{", "method", "=", "\"copyFrom\"", ";", "}", "return", "\"com.google.protobuf.ByteString.\"", "+", "method", "+", "\"(\"", "+", "express", "+", "\")\"", ";", "}", "return", "express", ";", "}" ]
Gets the write value to field. @param type the type @param express the express @param isList the is list @return the write value to field
[ "Gets", "the", "write", "value", "to", "field", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L155-L166
29,187
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java
CodedConstant.getRequiredCheck
public static String getRequiredCheck(int order, Field field) { String fieldName = getFieldName(order); String code = "if (" + fieldName + "== null) {\n"; code += "throw new UninitializedMessageException(CodedConstant.asList(\"" + field.getName() + "\"))" + ClassCode.JAVA_LINE_BREAK; code += "}\n"; return code; }
java
public static String getRequiredCheck(int order, Field field) { String fieldName = getFieldName(order); String code = "if (" + fieldName + "== null) {\n"; code += "throw new UninitializedMessageException(CodedConstant.asList(\"" + field.getName() + "\"))" + ClassCode.JAVA_LINE_BREAK; code += "}\n"; return code; }
[ "public", "static", "String", "getRequiredCheck", "(", "int", "order", ",", "Field", "field", ")", "{", "String", "fieldName", "=", "getFieldName", "(", "order", ")", ";", "String", "code", "=", "\"if (\"", "+", "fieldName", "+", "\"== null) {\\n\"", ";", "code", "+=", "\"throw new UninitializedMessageException(CodedConstant.asList(\\\"\"", "+", "field", ".", "getName", "(", ")", "+", "\"\\\"))\"", "+", "ClassCode", ".", "JAVA_LINE_BREAK", ";", "code", "+=", "\"}\\n\"", ";", "return", "code", ";", "}" ]
get required field check java expression. @param order field order @param field java field @return full java expression
[ "get", "required", "field", "check", "java", "expression", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L477-L485
29,188
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java
CodedConstant.getEnumName
public static String getEnumName(Enum[] e, int value) { if (e != null) { int toCompareValue; for (Enum en : e) { if (en instanceof EnumReadable) { toCompareValue = ((EnumReadable) en).value(); } else { toCompareValue = en.ordinal(); } if (value == toCompareValue) { return en.name(); } } } return ""; }
java
public static String getEnumName(Enum[] e, int value) { if (e != null) { int toCompareValue; for (Enum en : e) { if (en instanceof EnumReadable) { toCompareValue = ((EnumReadable) en).value(); } else { toCompareValue = en.ordinal(); } if (value == toCompareValue) { return en.name(); } } } return ""; }
[ "public", "static", "String", "getEnumName", "(", "Enum", "[", "]", "e", ",", "int", "value", ")", "{", "if", "(", "e", "!=", "null", ")", "{", "int", "toCompareValue", ";", "for", "(", "Enum", "en", ":", "e", ")", "{", "if", "(", "en", "instanceof", "EnumReadable", ")", "{", "toCompareValue", "=", "(", "(", "EnumReadable", ")", "en", ")", ".", "value", "(", ")", ";", "}", "else", "{", "toCompareValue", "=", "en", ".", "ordinal", "(", ")", ";", "}", "if", "(", "value", "==", "toCompareValue", ")", "{", "return", "en", ".", "name", "(", ")", ";", "}", "}", "}", "return", "\"\"", ";", "}" ]
Gets the enum name. @param e the e @param value the value @return the enum name
[ "Gets", "the", "enum", "name", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L632-L647
29,189
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java
CodedConstant.getEnumValue
public static <T extends Enum<T>> T getEnumValue(Class<T> enumType, String name) { if (StringUtils.isEmpty(name)) { return null; } try { T v = Enum.valueOf(enumType, name); return v; } catch (IllegalArgumentException e) { return null; } }
java
public static <T extends Enum<T>> T getEnumValue(Class<T> enumType, String name) { if (StringUtils.isEmpty(name)) { return null; } try { T v = Enum.valueOf(enumType, name); return v; } catch (IllegalArgumentException e) { return null; } }
[ "public", "static", "<", "T", "extends", "Enum", "<", "T", ">", ">", "T", "getEnumValue", "(", "Class", "<", "T", ">", "enumType", ",", "String", "name", ")", "{", "if", "(", "StringUtils", ".", "isEmpty", "(", "name", ")", ")", "{", "return", "null", ";", "}", "try", "{", "T", "v", "=", "Enum", ".", "valueOf", "(", "enumType", ",", "name", ")", ";", "return", "v", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "return", "null", ";", "}", "}" ]
Gets the enumeration value. @param <T> the generic type @param enumType the enum type @param name the name @return the enum value
[ "Gets", "the", "enumeration", "value", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L658-L670
29,190
jhunters/jprotobuf
src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java
CodedConstant.convertList
private static List<Integer> convertList(List<String> list) { if (list == null) { return null; } List<Integer> ret = new ArrayList<Integer>(list.size()); for (String v : list) { ret.add(StringUtils.toInt(v)); } return ret; }
java
private static List<Integer> convertList(List<String> list) { if (list == null) { return null; } List<Integer> ret = new ArrayList<Integer>(list.size()); for (String v : list) { ret.add(StringUtils.toInt(v)); } return ret; }
[ "private", "static", "List", "<", "Integer", ">", "convertList", "(", "List", "<", "String", ">", "list", ")", "{", "if", "(", "list", "==", "null", ")", "{", "return", "null", ";", "}", "List", "<", "Integer", ">", "ret", "=", "new", "ArrayList", "<", "Integer", ">", "(", "list", ".", "size", "(", ")", ")", ";", "for", "(", "String", "v", ":", "list", ")", "{", "ret", ".", "add", "(", "StringUtils", ".", "toInt", "(", "v", ")", ")", ";", "}", "return", "ret", ";", "}" ]
Convert list. @param list the list @return the list
[ "Convert", "list", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L867-L877
29,191
jhunters/jprotobuf
jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/JprotobufPreCompileMain.java
JprotobufPreCompileMain.isStartWith
private static boolean isStartWith(String testString, String[] targetStrings) { for (String s : targetStrings) { if (testString.startsWith(s)) { return true; } } return false; }
java
private static boolean isStartWith(String testString, String[] targetStrings) { for (String s : targetStrings) { if (testString.startsWith(s)) { return true; } } return false; }
[ "private", "static", "boolean", "isStartWith", "(", "String", "testString", ",", "String", "[", "]", "targetStrings", ")", "{", "for", "(", "String", "s", ":", "targetStrings", ")", "{", "if", "(", "testString", ".", "startsWith", "(", "s", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if is start with. @param testString the test string @param targetStrings the target strings @return true, if is start with
[ "Checks", "if", "is", "start", "with", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/JprotobufPreCompileMain.java#L112-L120
29,192
jhunters/jprotobuf
jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/JprotobufPreCompileMain.java
JprotobufPreCompileMain.getByClass
private static Class getByClass(String name) { try { return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (Throwable e) { } return null; }
java
private static Class getByClass(String name) { try { return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (Throwable e) { } return null; }
[ "private", "static", "Class", "getByClass", "(", "String", "name", ")", "{", "try", "{", "return", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ".", "loadClass", "(", "name", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "}", "return", "null", ";", "}" ]
Gets the by class. @param name the name @return the by class
[ "Gets", "the", "by", "class", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/JprotobufPreCompileMain.java#L128-L134
29,193
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java
MapEntryLite.newDefaultInstance
public static <K, V> MapEntryLite<K, V> newDefaultInstance(WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) { return new MapEntryLite<K, V>(keyType, defaultKey, valueType, defaultValue); }
java
public static <K, V> MapEntryLite<K, V> newDefaultInstance(WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) { return new MapEntryLite<K, V>(keyType, defaultKey, valueType, defaultValue); }
[ "public", "static", "<", "K", ",", "V", ">", "MapEntryLite", "<", "K", ",", "V", ">", "newDefaultInstance", "(", "WireFormat", ".", "FieldType", "keyType", ",", "K", "defaultKey", ",", "WireFormat", ".", "FieldType", "valueType", ",", "V", "defaultValue", ")", "{", "return", "new", "MapEntryLite", "<", "K", ",", "V", ">", "(", "keyType", ",", "defaultKey", ",", "valueType", ",", "defaultValue", ")", ";", "}" ]
Creates a default MapEntryLite message instance. This method is used by generated code to create the default instance for a map entry message. The created default instance should be used to create new map entry messages of the same type. For each map entry message, only one default instance should be created. @param <K> the key type @param <V> the value type @param keyType the key type @param defaultKey the default key @param valueType the value type @param defaultValue the default value @return the map entry lite
[ "Creates", "a", "default", "MapEntryLite", "message", "instance", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java#L154-L157
29,194
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java
MapEntryLite.writeTo
static <K, V> void writeTo(CodedOutputStream output, Metadata<K, V> metadata, K key, V value) throws IOException { CodedConstant.writeElement(output, metadata.keyType, KEY_FIELD_NUMBER, key); CodedConstant.writeElement(output, metadata.valueType, VALUE_FIELD_NUMBER, value); }
java
static <K, V> void writeTo(CodedOutputStream output, Metadata<K, V> metadata, K key, V value) throws IOException { CodedConstant.writeElement(output, metadata.keyType, KEY_FIELD_NUMBER, key); CodedConstant.writeElement(output, metadata.valueType, VALUE_FIELD_NUMBER, value); }
[ "static", "<", "K", ",", "V", ">", "void", "writeTo", "(", "CodedOutputStream", "output", ",", "Metadata", "<", "K", ",", "V", ">", "metadata", ",", "K", "key", ",", "V", "value", ")", "throws", "IOException", "{", "CodedConstant", ".", "writeElement", "(", "output", ",", "metadata", ".", "keyType", ",", "KEY_FIELD_NUMBER", ",", "key", ")", ";", "CodedConstant", ".", "writeElement", "(", "output", ",", "metadata", ".", "valueType", ",", "VALUE_FIELD_NUMBER", ",", "value", ")", ";", "}" ]
Write to. @param <K> the key type @param <V> the value type @param output the output @param metadata the metadata @param key the key @param value the value @throws IOException Signals that an I/O exception has occurred.
[ "Write", "to", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java#L170-L173
29,195
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java
MapEntryLite.computeSerializedSize
static <K, V> int computeSerializedSize(Metadata<K, V> metadata, K key, V value) { return CodedConstant.computeElementSize(metadata.keyType, KEY_FIELD_NUMBER, key) + CodedConstant.computeElementSize(metadata.valueType, VALUE_FIELD_NUMBER, value); }
java
static <K, V> int computeSerializedSize(Metadata<K, V> metadata, K key, V value) { return CodedConstant.computeElementSize(metadata.keyType, KEY_FIELD_NUMBER, key) + CodedConstant.computeElementSize(metadata.valueType, VALUE_FIELD_NUMBER, value); }
[ "static", "<", "K", ",", "V", ">", "int", "computeSerializedSize", "(", "Metadata", "<", "K", ",", "V", ">", "metadata", ",", "K", "key", ",", "V", "value", ")", "{", "return", "CodedConstant", ".", "computeElementSize", "(", "metadata", ".", "keyType", ",", "KEY_FIELD_NUMBER", ",", "key", ")", "+", "CodedConstant", ".", "computeElementSize", "(", "metadata", ".", "valueType", ",", "VALUE_FIELD_NUMBER", ",", "value", ")", ";", "}" ]
Compute serialized size. @param <K> the key type @param <V> the value type @param metadata the metadata @param key the key @param value the value @return the int
[ "Compute", "serialized", "size", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java#L185-L188
29,196
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java
MapEntryLite.parseField
@SuppressWarnings("unchecked") static <T> T parseField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, WireFormat.FieldType type, T value) throws IOException { switch (type) { case MESSAGE: int length = input.readRawVarint32(); final int oldLimit = input.pushLimit(length); Codec<? extends Object> codec = ProtobufProxy.create(value.getClass()); T ret = (T) codec.decode(input.readRawBytes(length)); input.popLimit(oldLimit); return ret; case ENUM: return (T) (java.lang.Integer) input.readEnum(); case GROUP: throw new RuntimeException("Groups are not allowed in maps."); default: return (T) CodedConstant.readPrimitiveField(input, type, true); } }
java
@SuppressWarnings("unchecked") static <T> T parseField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, WireFormat.FieldType type, T value) throws IOException { switch (type) { case MESSAGE: int length = input.readRawVarint32(); final int oldLimit = input.pushLimit(length); Codec<? extends Object> codec = ProtobufProxy.create(value.getClass()); T ret = (T) codec.decode(input.readRawBytes(length)); input.popLimit(oldLimit); return ret; case ENUM: return (T) (java.lang.Integer) input.readEnum(); case GROUP: throw new RuntimeException("Groups are not allowed in maps."); default: return (T) CodedConstant.readPrimitiveField(input, type, true); } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "static", "<", "T", ">", "T", "parseField", "(", "CodedInputStream", "input", ",", "ExtensionRegistryLite", "extensionRegistry", ",", "WireFormat", ".", "FieldType", "type", ",", "T", "value", ")", "throws", "IOException", "{", "switch", "(", "type", ")", "{", "case", "MESSAGE", ":", "int", "length", "=", "input", ".", "readRawVarint32", "(", ")", ";", "final", "int", "oldLimit", "=", "input", ".", "pushLimit", "(", "length", ")", ";", "Codec", "<", "?", "extends", "Object", ">", "codec", "=", "ProtobufProxy", ".", "create", "(", "value", ".", "getClass", "(", ")", ")", ";", "T", "ret", "=", "(", "T", ")", "codec", ".", "decode", "(", "input", ".", "readRawBytes", "(", "length", ")", ")", ";", "input", ".", "popLimit", "(", "oldLimit", ")", ";", "return", "ret", ";", "case", "ENUM", ":", "return", "(", "T", ")", "(", "java", ".", "lang", ".", "Integer", ")", "input", ".", "readEnum", "(", ")", ";", "case", "GROUP", ":", "throw", "new", "RuntimeException", "(", "\"Groups are not allowed in maps.\"", ")", ";", "default", ":", "return", "(", "T", ")", "CodedConstant", ".", "readPrimitiveField", "(", "input", ",", "type", ",", "true", ")", ";", "}", "}" ]
Parses the field. @param <T> the generic type @param input the input @param extensionRegistry the extension registry @param type the type @param value the value @return the t @throws IOException Signals that an I/O exception has occurred.
[ "Parses", "the", "field", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java#L201-L219
29,197
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java
MapEntryLite.parseEntry
static <K, V> Map.Entry<K, V> parseEntry(CodedInputStream input, Metadata<K, V> metadata, ExtensionRegistryLite extensionRegistry) throws IOException { K key = metadata.defaultKey; V value = metadata.defaultValue; while (true) { int tag = input.readTag(); if (tag == 0) { break; } if (tag == CodedConstant.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) { key = parseField(input, extensionRegistry, metadata.keyType, key); } else if (tag == CodedConstant.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) { value = parseField(input, extensionRegistry, metadata.valueType, value); } else { if (!input.skipField(tag)) { break; } } } return new AbstractMap.SimpleImmutableEntry<K, V>(key, value); }
java
static <K, V> Map.Entry<K, V> parseEntry(CodedInputStream input, Metadata<K, V> metadata, ExtensionRegistryLite extensionRegistry) throws IOException { K key = metadata.defaultKey; V value = metadata.defaultValue; while (true) { int tag = input.readTag(); if (tag == 0) { break; } if (tag == CodedConstant.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) { key = parseField(input, extensionRegistry, metadata.keyType, key); } else if (tag == CodedConstant.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) { value = parseField(input, extensionRegistry, metadata.valueType, value); } else { if (!input.skipField(tag)) { break; } } } return new AbstractMap.SimpleImmutableEntry<K, V>(key, value); }
[ "static", "<", "K", ",", "V", ">", "Map", ".", "Entry", "<", "K", ",", "V", ">", "parseEntry", "(", "CodedInputStream", "input", ",", "Metadata", "<", "K", ",", "V", ">", "metadata", ",", "ExtensionRegistryLite", "extensionRegistry", ")", "throws", "IOException", "{", "K", "key", "=", "metadata", ".", "defaultKey", ";", "V", "value", "=", "metadata", ".", "defaultValue", ";", "while", "(", "true", ")", "{", "int", "tag", "=", "input", ".", "readTag", "(", ")", ";", "if", "(", "tag", "==", "0", ")", "{", "break", ";", "}", "if", "(", "tag", "==", "CodedConstant", ".", "makeTag", "(", "KEY_FIELD_NUMBER", ",", "metadata", ".", "keyType", ".", "getWireType", "(", ")", ")", ")", "{", "key", "=", "parseField", "(", "input", ",", "extensionRegistry", ",", "metadata", ".", "keyType", ",", "key", ")", ";", "}", "else", "if", "(", "tag", "==", "CodedConstant", ".", "makeTag", "(", "VALUE_FIELD_NUMBER", ",", "metadata", ".", "valueType", ".", "getWireType", "(", ")", ")", ")", "{", "value", "=", "parseField", "(", "input", ",", "extensionRegistry", ",", "metadata", ".", "valueType", ",", "value", ")", ";", "}", "else", "{", "if", "(", "!", "input", ".", "skipField", "(", "tag", ")", ")", "{", "break", ";", "}", "}", "}", "return", "new", "AbstractMap", ".", "SimpleImmutableEntry", "<", "K", ",", "V", ">", "(", "key", ",", "value", ")", ";", "}" ]
Parses the entry. @param <K> the key type @param <V> the value type @param input the input @param metadata the metadata @param extensionRegistry the extension registry @return the map. entry @throws IOException Signals that an I/O exception has occurred.
[ "Parses", "the", "entry", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntryLite.java#L277-L297
29,198
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java
IDLProxyObject.newInstnace
public IDLProxyObject newInstnace() { try { Object object = cls.newInstance(); return new IDLProxyObject(codec, object, cls); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
java
public IDLProxyObject newInstnace() { try { Object object = cls.newInstance(); return new IDLProxyObject(codec, object, cls); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
[ "public", "IDLProxyObject", "newInstnace", "(", ")", "{", "try", "{", "Object", "object", "=", "cls", ".", "newInstance", "(", ")", ";", "return", "new", "IDLProxyObject", "(", "codec", ",", "object", ",", "cls", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
New instnace. @return the IDL proxy object
[ "New", "instnace", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java#L97-L104
29,199
jhunters/jprotobuf
v3/src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java
IDLProxyObject.doSetFieldValue
private IDLProxyObject doSetFieldValue(String fullField, String field, Object value, Object object, boolean useCache, Map<String, ReflectInfo> cachedFields) { Field f; // check cache if (useCache) { ReflectInfo info = cachedFields.get(fullField); if (info != null) { setField(value, info.target, info.field); return this; } } int index = field.indexOf('.'); if (index != -1) { String parent = field.substring(0, index); String sub = field.substring(index + 1); try { f = FieldUtils.findField(object.getClass(), parent); if (f == null) { throw new RuntimeException( "No field '" + parent + "' found at class " + object.getClass().getName()); } Class<?> type = f.getType(); f.setAccessible(true); Object o = f.get(object); if (o == null) { boolean memberClass = type.isMemberClass(); if (memberClass && Modifier.isStatic(type.getModifiers())) { Constructor<?> constructor = type.getConstructor(new Class[0]); constructor.setAccessible(true); o = constructor.newInstance(new Object[0]); } else if (memberClass) { Constructor<?> constructor = type.getConstructor(new Class[] { object.getClass() }); constructor.setAccessible(true); o = constructor.newInstance(new Object[] { object }); } else { o = type.newInstance(); } f.set(object, o); } return put(fullField, sub, value, o); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } f = FieldUtils.findField(object.getClass(), field); if (f == null) { throw new RuntimeException("No field '" + field + "' found at class " + object.getClass().getName()); } if (useCache && !cachedFields.containsKey(fullField)) { cachedFields.put(fullField, new ReflectInfo(f, object)); } setField(value, object, f); return this; }
java
private IDLProxyObject doSetFieldValue(String fullField, String field, Object value, Object object, boolean useCache, Map<String, ReflectInfo> cachedFields) { Field f; // check cache if (useCache) { ReflectInfo info = cachedFields.get(fullField); if (info != null) { setField(value, info.target, info.field); return this; } } int index = field.indexOf('.'); if (index != -1) { String parent = field.substring(0, index); String sub = field.substring(index + 1); try { f = FieldUtils.findField(object.getClass(), parent); if (f == null) { throw new RuntimeException( "No field '" + parent + "' found at class " + object.getClass().getName()); } Class<?> type = f.getType(); f.setAccessible(true); Object o = f.get(object); if (o == null) { boolean memberClass = type.isMemberClass(); if (memberClass && Modifier.isStatic(type.getModifiers())) { Constructor<?> constructor = type.getConstructor(new Class[0]); constructor.setAccessible(true); o = constructor.newInstance(new Object[0]); } else if (memberClass) { Constructor<?> constructor = type.getConstructor(new Class[] { object.getClass() }); constructor.setAccessible(true); o = constructor.newInstance(new Object[] { object }); } else { o = type.newInstance(); } f.set(object, o); } return put(fullField, sub, value, o); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } f = FieldUtils.findField(object.getClass(), field); if (f == null) { throw new RuntimeException("No field '" + field + "' found at class " + object.getClass().getName()); } if (useCache && !cachedFields.containsKey(fullField)) { cachedFields.put(fullField, new ReflectInfo(f, object)); } setField(value, object, f); return this; }
[ "private", "IDLProxyObject", "doSetFieldValue", "(", "String", "fullField", ",", "String", "field", ",", "Object", "value", ",", "Object", "object", ",", "boolean", "useCache", ",", "Map", "<", "String", ",", "ReflectInfo", ">", "cachedFields", ")", "{", "Field", "f", ";", "// check cache\r", "if", "(", "useCache", ")", "{", "ReflectInfo", "info", "=", "cachedFields", ".", "get", "(", "fullField", ")", ";", "if", "(", "info", "!=", "null", ")", "{", "setField", "(", "value", ",", "info", ".", "target", ",", "info", ".", "field", ")", ";", "return", "this", ";", "}", "}", "int", "index", "=", "field", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "index", "!=", "-", "1", ")", "{", "String", "parent", "=", "field", ".", "substring", "(", "0", ",", "index", ")", ";", "String", "sub", "=", "field", ".", "substring", "(", "index", "+", "1", ")", ";", "try", "{", "f", "=", "FieldUtils", ".", "findField", "(", "object", ".", "getClass", "(", ")", ",", "parent", ")", ";", "if", "(", "f", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"No field '\"", "+", "parent", "+", "\"' found at class \"", "+", "object", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "}", "Class", "<", "?", ">", "type", "=", "f", ".", "getType", "(", ")", ";", "f", ".", "setAccessible", "(", "true", ")", ";", "Object", "o", "=", "f", ".", "get", "(", "object", ")", ";", "if", "(", "o", "==", "null", ")", "{", "boolean", "memberClass", "=", "type", ".", "isMemberClass", "(", ")", ";", "if", "(", "memberClass", "&&", "Modifier", ".", "isStatic", "(", "type", ".", "getModifiers", "(", ")", ")", ")", "{", "Constructor", "<", "?", ">", "constructor", "=", "type", ".", "getConstructor", "(", "new", "Class", "[", "0", "]", ")", ";", "constructor", ".", "setAccessible", "(", "true", ")", ";", "o", "=", "constructor", ".", "newInstance", "(", "new", "Object", "[", "0", "]", ")", ";", "}", "else", "if", "(", "memberClass", ")", "{", "Constructor", "<", "?", ">", "constructor", "=", "type", ".", "getConstructor", "(", "new", "Class", "[", "]", "{", "object", ".", "getClass", "(", ")", "}", ")", ";", "constructor", ".", "setAccessible", "(", "true", ")", ";", "o", "=", "constructor", ".", "newInstance", "(", "new", "Object", "[", "]", "{", "object", "}", ")", ";", "}", "else", "{", "o", "=", "type", ".", "newInstance", "(", ")", ";", "}", "f", ".", "set", "(", "object", ",", "o", ")", ";", "}", "return", "put", "(", "fullField", ",", "sub", ",", "value", ",", "o", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}", "f", "=", "FieldUtils", ".", "findField", "(", "object", ".", "getClass", "(", ")", ",", "field", ")", ";", "if", "(", "f", "==", "null", ")", "{", "throw", "new", "RuntimeException", "(", "\"No field '\"", "+", "field", "+", "\"' found at class \"", "+", "object", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ";", "}", "if", "(", "useCache", "&&", "!", "cachedFields", ".", "containsKey", "(", "fullField", ")", ")", "{", "cachedFields", ".", "put", "(", "fullField", ",", "new", "ReflectInfo", "(", "f", ",", "object", ")", ")", ";", "}", "setField", "(", "value", ",", "object", ",", "f", ")", ";", "return", "this", ";", "}" ]
Do set field value. @param fullField the full field @param field the field @param value the value @param object the object @param useCache the use cache @param cachedFields the cached fields @return the IDL proxy object
[ "Do", "set", "field", "value", "." ]
55832c9b4792afb128e5b35139d8a3891561d8a3
https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java#L117-L174