bunch of PMD-induced fixes
(now the PMD report is clean) git-svn-id: http://google-refine.googlecode.com/svn/trunk@430 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
759824e1b4
commit
d3d40d608a
@ -262,8 +262,7 @@
|
||||
classname="net.sourceforge.pmd.ant.PMDTask"
|
||||
classpathref="pmd.path"
|
||||
/>
|
||||
<pmd targetjdk="1.6" encoding="UTF-8">
|
||||
<ruleset>basic</ruleset>
|
||||
<pmd rulesetfiles="${conf.dir}/pmd.rules.xml" targetjdk="1.6" encoding="UTF-8">
|
||||
<formatter type="html" toFile="${reports.dir}/pmd.html" toConsole="true"/>
|
||||
<fileset dir="${server.src.dir}">
|
||||
<include name="**/*.java"/>
|
||||
|
@ -576,6 +576,8 @@ findbugs() {
|
||||
|
||||
ANT_PARAMS="-Dfindbugs.dir=${GRIDWORKS_TOOLS_DIR}/${FINDBUGS_DIR}"
|
||||
ant findbugs
|
||||
|
||||
open "$GRIDWORKS_BUILD_DIR/reports/findbugs.html"
|
||||
}
|
||||
|
||||
pmd() {
|
||||
@ -583,6 +585,8 @@ pmd() {
|
||||
|
||||
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
|
||||
ant pmd
|
||||
|
||||
open "$GRIDWORKS_BUILD_DIR/reports/pmd.html"
|
||||
}
|
||||
|
||||
cpd() {
|
||||
@ -590,6 +594,8 @@ cpd() {
|
||||
|
||||
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
|
||||
ant cpd
|
||||
|
||||
open "$GRIDWORKS_BUILD_DIR/reports/cpd.txt"
|
||||
}
|
||||
|
||||
jslint() {
|
||||
@ -597,6 +603,8 @@ jslint() {
|
||||
|
||||
ANT_PARAMS="-Djslint.dir=${GRIDWORKS_TOOLS_DIR}/${JSLINT_DIR}"
|
||||
ant jslint
|
||||
|
||||
open "$GRIDWORKS_BUILD_DIR/reports/jslint.txt"
|
||||
}
|
||||
|
||||
# -------------------------- script -----------------------------
|
||||
|
33
src/conf/pmd.rules.xml
Normal file
33
src/conf/pmd.rules.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Gridworks PMD Ruleset"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
<description>Gridworks PMD Ruleset</description>
|
||||
|
||||
<rule ref="rulesets/basic.xml">
|
||||
<exclude name="EmptyCatchBlock"/>
|
||||
<exclude name="AvoidUsingHardCodedIP"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/braces.xml">
|
||||
<exclude name="IfStmtsMustUseBraces"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/unusedcode.xml"/>
|
||||
<rule ref="rulesets/imports.xml"/>
|
||||
<rule ref="rulesets/strings.xml">
|
||||
<exclude name="ConsecutiveLiteralAppends"/>
|
||||
<exclude name="AvoidDuplicateLiterals"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="rulesets/junit.xml"/>
|
||||
<rule ref="rulesets/unusedcode.xml"/>
|
||||
<rule ref="rulesets/clone.xml"/>
|
||||
|
||||
<rule ref="rulesets/migrating.xml">
|
||||
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -429,50 +429,50 @@ public class ProjectManager {
|
||||
}
|
||||
|
||||
protected void load() {
|
||||
try {
|
||||
loadFromFile(new File(_workspaceDir, "workspace.json"));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
loadFromFile(new File(_workspaceDir, "workspace.temp.json"));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
loadFromFile(new File(_workspaceDir, "workspace.old.json"));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (loadFromFile(new File(_workspaceDir, "workspace.json"))) return;
|
||||
if (loadFromFile(new File(_workspaceDir, "workspace.temp.json"))) return;
|
||||
if (loadFromFile(new File(_workspaceDir, "workspace.old.json"))) return;
|
||||
}
|
||||
|
||||
protected void loadFromFile(File file) throws IOException, JSONException {
|
||||
protected boolean loadFromFile(File file) {
|
||||
Gridworks.log("Loading workspace from " + file.getAbsolutePath());
|
||||
|
||||
_projectsMetadata.clear();
|
||||
_expressions.clear();
|
||||
|
||||
FileReader reader = new FileReader(file);
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(reader);
|
||||
JSONObject obj = (JSONObject) tokener.nextValue();
|
||||
if (file.exists() || file.canRead()) {
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(file);
|
||||
JSONTokener tokener = new JSONTokener(reader);
|
||||
JSONObject obj = (JSONObject) tokener.nextValue();
|
||||
|
||||
JSONArray a = obj.getJSONArray("projectIDs");
|
||||
int count = a.length();
|
||||
for (int i = 0; i < count; i++) {
|
||||
long id = a.getLong(i);
|
||||
JSONArray a = obj.getJSONArray("projectIDs");
|
||||
int count = a.length();
|
||||
for (int i = 0; i < count; i++) {
|
||||
long id = a.getLong(i);
|
||||
|
||||
File projectDir = getProjectDir(id);
|
||||
ProjectMetadata metadata = ProjectMetadata.load(projectDir);
|
||||
File projectDir = getProjectDir(id);
|
||||
ProjectMetadata metadata = ProjectMetadata.load(projectDir);
|
||||
|
||||
_projectsMetadata.put(id, metadata);
|
||||
_projectsMetadata.put(id, metadata);
|
||||
}
|
||||
|
||||
JSONUtilities.getStringList(obj, "expressions", _expressions);
|
||||
return true;
|
||||
} catch (JSONException e) {
|
||||
Gridworks.warn("Error reading " + file, e);
|
||||
} catch (IOException e) {
|
||||
Gridworks.warn("Error reading " + file, e);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
Gridworks.warn("Exception closing file",e);
|
||||
}
|
||||
}
|
||||
|
||||
JSONUtilities.getStringList(obj, "expressions", _expressions);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ public class Engine implements Jsonizable {
|
||||
protected List<Facet> _facets = new LinkedList<Facet>();
|
||||
protected boolean _includeDependent;
|
||||
|
||||
public final static String INCLUDE_DEPENDENT = "includeDependent";
|
||||
|
||||
public Engine(Project project) {
|
||||
_project = project;
|
||||
}
|
||||
@ -75,8 +77,8 @@ public class Engine implements Jsonizable {
|
||||
}
|
||||
}
|
||||
|
||||
if (o.has("includeDependent") && !o.isNull("includeDependent")) {
|
||||
_includeDependent = o.getBoolean("includeDependent");
|
||||
if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
|
||||
_includeDependent = o.getBoolean(INCLUDE_DEPENDENT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +100,7 @@ public class Engine implements Jsonizable {
|
||||
facet.write(writer, options);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.key("includeDependent"); writer.value(_includeDependent);
|
||||
writer.key(INCLUDE_DEPENDENT); writer.value(_includeDependent);
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class RangeFacet implements Facet {
|
||||
protected String _name; // name of facet
|
||||
protected String _expression; // expression to compute numeric value(s) per row
|
||||
protected String _columnName; // column to base expression on, if any
|
||||
protected String _mode; // "range", "min", "max"
|
||||
protected String _mode; // "range", MIN, MAX
|
||||
|
||||
protected double _from; // the numeric selection
|
||||
protected double _to;
|
||||
@ -59,6 +59,11 @@ public class RangeFacet implements Facet {
|
||||
public RangeFacet() {
|
||||
}
|
||||
|
||||
private static final String MIN = "min";
|
||||
private static final String MAX = "max";
|
||||
private static final String TO = "to";
|
||||
private static final String FROM = "from";
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
@ -72,8 +77,8 @@ public class RangeFacet implements Facet {
|
||||
writer.key("error"); writer.value(_errorMessage);
|
||||
} else {
|
||||
if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) {
|
||||
writer.key("min"); writer.value(_min);
|
||||
writer.key("max"); writer.value(_max);
|
||||
writer.key(MIN); writer.value(_min);
|
||||
writer.key(MAX); writer.value(_max);
|
||||
writer.key("step"); writer.value(_step);
|
||||
|
||||
writer.key("bins"); writer.array();
|
||||
@ -88,13 +93,13 @@ public class RangeFacet implements Facet {
|
||||
}
|
||||
writer.endArray();
|
||||
|
||||
if ("min".equals(_mode)) {
|
||||
writer.key("from"); writer.value(_from);
|
||||
} else if ("max".equals(_mode)) {
|
||||
writer.key("to"); writer.value(_to);
|
||||
if (MIN.equals(_mode)) {
|
||||
writer.key(FROM); writer.value(_from);
|
||||
} else if (MAX.equals(_mode)) {
|
||||
writer.key(TO); writer.value(_to);
|
||||
} else {
|
||||
writer.key("from"); writer.value(_from);
|
||||
writer.key("to"); writer.value(_to);
|
||||
writer.key(FROM); writer.value(_from);
|
||||
writer.key(TO); writer.value(_to);
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,20 +134,20 @@ public class RangeFacet implements Facet {
|
||||
}
|
||||
|
||||
_mode = o.getString("mode");
|
||||
if ("min".equals(_mode)) {
|
||||
if (o.has("from")) {
|
||||
_from = o.getDouble("from");
|
||||
if (MIN.equals(_mode)) {
|
||||
if (o.has(FROM)) {
|
||||
_from = o.getDouble(FROM);
|
||||
_selected = true;
|
||||
}
|
||||
} else if ("max".equals(_mode)) {
|
||||
if (o.has("to")) {
|
||||
_to = o.getDouble("to");
|
||||
} else if (MAX.equals(_mode)) {
|
||||
if (o.has(TO)) {
|
||||
_to = o.getDouble(TO);
|
||||
_selected = true;
|
||||
}
|
||||
} else {
|
||||
if (o.has("from") && o.has("to")) {
|
||||
_from = o.getDouble("from");
|
||||
_to = o.getDouble("to");
|
||||
if (o.has(FROM) && o.has(TO)) {
|
||||
_from = o.getDouble(FROM);
|
||||
_to = o.getDouble(TO);
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
@ -159,7 +164,7 @@ public class RangeFacet implements Facet {
|
||||
|
||||
public RowFilter getRowFilter() {
|
||||
if (_eval != null && _errorMessage == null && _selected) {
|
||||
if ("min".equals(_mode)) {
|
||||
if (MIN.equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(
|
||||
_eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
|
||||
|
||||
@ -167,7 +172,7 @@ public class RangeFacet implements Facet {
|
||||
return d >= _from;
|
||||
};
|
||||
};
|
||||
} else if ("max".equals(_mode)) {
|
||||
} else if (MAX.equals(_mode)) {
|
||||
return new ExpressionNumberComparisonRowFilter(
|
||||
_eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
|
||||
|
||||
|
@ -332,7 +332,7 @@ public class CreateProjectCommand extends Command {
|
||||
|
||||
private String[] getExtension(String filename) {
|
||||
String[] result = new String[2];
|
||||
int ext_index = filename.lastIndexOf(".");
|
||||
int ext_index = filename.lastIndexOf('.');
|
||||
result[0] = (ext_index == -1) ? filename : filename.substring(0,ext_index);
|
||||
result[1] = (ext_index == -1) ? "" : filename.substring(ext_index + 1);
|
||||
return result;
|
||||
|
@ -125,7 +125,7 @@ public class GuessTypesOfColumnCommand extends Command {
|
||||
}
|
||||
jsonWriter.endObject();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append("http://api.freebase.com/api/service/search?queries=");
|
||||
sb.append(ParsingUtilities.encode(stringWriter.toString()));
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class PreviewProtographCommand extends Command {
|
||||
JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString);
|
||||
Protograph protograph = Protograph.reconstruct(json);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuffer sb = new StringBuffer(2048);
|
||||
sb.append("{ ");
|
||||
|
||||
{
|
||||
|
@ -22,10 +22,13 @@ public class JythonEvaluable implements Evaluable {
|
||||
// indent and create a function out of the code
|
||||
String[] lines = s.split("\r\n|\r|\n");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("def " + s_functionName + "(value, cell, cells, row, rowIndex):");
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append("def ");
|
||||
sb.append(s_functionName);
|
||||
sb.append("(value, cell, cells, row, rowIndex):");
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sb.append("\n " + lines[i]);
|
||||
sb.append("\n ");
|
||||
sb.append(lines[i]);
|
||||
}
|
||||
|
||||
_engine.exec(sb.toString());
|
||||
|
@ -18,6 +18,7 @@ public class ToDate implements Function {
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length == 0) {
|
||||
// missing value, can this happen?
|
||||
return null;
|
||||
}
|
||||
if (!(args[0] instanceof String)) {
|
||||
// ignore cell values that aren't strings
|
||||
|
@ -40,6 +40,8 @@ public class HistoryEntry implements Jsonizable {
|
||||
// the actual change, loaded on demand
|
||||
transient protected Change _change;
|
||||
|
||||
private final static String OPERATION = "operation";
|
||||
|
||||
public HistoryEntry(Project project, String description, AbstractOperation operation, Change change) {
|
||||
this.id = Math.round(Math.random() * 1000000) + System.currentTimeMillis();
|
||||
this.projectID = project.id;
|
||||
@ -66,7 +68,7 @@ public class HistoryEntry implements Jsonizable {
|
||||
writer.key("description"); writer.value(description);
|
||||
writer.key("time"); writer.value(ParsingUtilities.dateToString(time));
|
||||
if ("save".equals(options.getProperty("mode")) && operation != null) {
|
||||
writer.key("operation"); operation.write(writer, options);
|
||||
writer.key(OPERATION); operation.write(writer, options);
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
@ -121,8 +123,8 @@ public class HistoryEntry implements Jsonizable {
|
||||
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||
|
||||
AbstractOperation operation = null;
|
||||
if (obj.has("operation") && !obj.isNull("operation")) {
|
||||
operation = OperationRegistry.reconstruct(project, obj.getJSONObject("operation"));
|
||||
if (obj.has(OPERATION) && !obj.isNull(OPERATION)) {
|
||||
operation = OperationRegistry.reconstruct(project, obj.getJSONObject(OPERATION));
|
||||
}
|
||||
|
||||
return new HistoryEntry(
|
||||
|
@ -20,6 +20,8 @@ public class HistoryProcess extends Process {
|
||||
|
||||
protected boolean _done = false;
|
||||
|
||||
private final static String WARN = "Not a long-running process";
|
||||
|
||||
public HistoryProcess(Project project, long lastDoneID) {
|
||||
_project = project;
|
||||
_lastDoneID = lastDoneID;
|
||||
@ -33,7 +35,7 @@ public class HistoryProcess extends Process {
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
throw new RuntimeException("Not a long-running process");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
public boolean isImmediate() {
|
||||
@ -48,7 +50,7 @@ public class HistoryProcess extends Process {
|
||||
}
|
||||
|
||||
public void startPerforming(ProcessManager manager) {
|
||||
throw new RuntimeException("Not a long-running process");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
@ -62,10 +64,10 @@ public class HistoryProcess extends Process {
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
throw new RuntimeException("Not a long-running process");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
throw new RuntimeException("Not a long-running process");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class TsvCsvImporter implements Importer {
|
||||
|
||||
int rowsWithData = 0;
|
||||
while ((line = lnReader.readLine()) != null) {
|
||||
if (line.trim().length() == 0) {
|
||||
if (StringUtils.isBlank(line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,9 @@ public class Row implements HasFields, Jsonizable {
|
||||
transient public int[] contextRowSlots;
|
||||
transient public int[] contextCellSlots;
|
||||
|
||||
private static final String FLAGGED = "flagged";
|
||||
private static final String STARRED = "starred";
|
||||
|
||||
public Row(int cellCount) {
|
||||
cells = new ArrayList<Cell>(cellCount);
|
||||
}
|
||||
@ -39,9 +42,9 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
|
||||
public Object getField(String name, Properties bindings) {
|
||||
if ("flagged".equals(name)) {
|
||||
if (FLAGGED.equals(name)) {
|
||||
return flagged;
|
||||
} else if ("starred".equals(name)) {
|
||||
} else if (STARRED.equals(name)) {
|
||||
return starred;
|
||||
}
|
||||
return null;
|
||||
@ -105,8 +108,8 @@ public class Row implements HasFields, Jsonizable {
|
||||
throws JSONException {
|
||||
|
||||
writer.object();
|
||||
writer.key("flagged"); writer.value(flagged);
|
||||
writer.key("starred"); writer.value(starred);
|
||||
writer.key(FLAGGED); writer.value(flagged);
|
||||
writer.key(STARRED); writer.value(starred);
|
||||
|
||||
writer.key("cells"); writer.array();
|
||||
for (Cell cell : cells) {
|
||||
@ -166,11 +169,11 @@ public class Row implements HasFields, Jsonizable {
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.has("starred")) {
|
||||
row.starred = obj.getBoolean("starred");
|
||||
if (obj.has(STARRED)) {
|
||||
row.starred = obj.getBoolean(STARRED);
|
||||
}
|
||||
if (obj.has("flagged")) {
|
||||
row.flagged = obj.getBoolean("flagged");
|
||||
if (obj.has(FLAGGED)) {
|
||||
row.flagged = obj.getBoolean(FLAGGED);
|
||||
}
|
||||
|
||||
return row;
|
||||
|
@ -16,6 +16,8 @@ import com.metaweb.gridworks.protograph.FreebaseType;
|
||||
public class DataExtensionReconConfig extends StrictReconConfig {
|
||||
final public FreebaseType type;
|
||||
|
||||
private final static String WARN = "Not implemented";
|
||||
|
||||
static public ReconConfig reconstruct(JSONObject obj) throws Exception {
|
||||
JSONObject type = obj.getJSONObject("type");
|
||||
|
||||
@ -34,17 +36,15 @@ public class DataExtensionReconConfig extends StrictReconConfig {
|
||||
@Override
|
||||
public ReconJob createJob(Project project, int rowIndex, Row row,
|
||||
String columnName, Cell cell) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
throw new RuntimeException("Not implemented");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
||||
public void write(JSONWriter writer, Properties options) throws JSONException {
|
||||
writer.object();
|
||||
writer.key("mode"); writer.value("extend");
|
||||
writer.key("type"); type.write(writer, options);
|
||||
@ -53,12 +53,11 @@ public class DataExtensionReconConfig extends StrictReconConfig {
|
||||
|
||||
@Override
|
||||
public List<Recon> batchRecon(List<ReconJob> jobs) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBriefDescription(Project project, String columnName) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
throw new RuntimeException(WARN);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,8 +111,9 @@ public class GuidBasedReconConfig extends StrictReconConfig {
|
||||
query = stringWriter.toString();
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(s_mqlreadService + "?query=");
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append(s_mqlreadService);
|
||||
sb.append("?query=");
|
||||
sb.append(ParsingUtilities.encode(query));
|
||||
|
||||
URL url = new URL(sb.toString());
|
||||
|
@ -222,7 +222,7 @@ public class HeuristicReconConfig extends ReconConfig {
|
||||
}
|
||||
jsonWriter.endObject();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append("http://api.freebase.com/api/service/search?indent=1&queries=");
|
||||
sb.append(ParsingUtilities.encode(stringWriter.toString()));
|
||||
|
||||
|
@ -115,8 +115,9 @@ public class IdBasedReconConfig extends StrictReconConfig {
|
||||
query = stringWriter.toString();
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(s_mqlreadService + "?query=");
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append(s_mqlreadService);
|
||||
sb.append("?query=");
|
||||
sb.append(ParsingUtilities.encode(query));
|
||||
|
||||
URL url = new URL(sb.toString());
|
||||
|
@ -129,8 +129,9 @@ public class KeyBasedReconConfig extends StrictReconConfig {
|
||||
query = stringWriter.toString();
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(s_mqlreadService + "?query=");
|
||||
StringBuffer sb = new StringBuffer(1024);
|
||||
sb.append(s_mqlreadService);
|
||||
sb.append("?query=");
|
||||
sb.append(ParsingUtilities.encode(query));
|
||||
|
||||
URL url = new URL(sb.toString());
|
||||
|
@ -21,6 +21,14 @@ import com.metaweb.gridworks.protograph.ValueNode;
|
||||
public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
protected List<JSONObject> rootObjects = new LinkedList<JSONObject>();
|
||||
|
||||
private static final String TYPE = "type";
|
||||
private static final String ID = "id";
|
||||
private static final String NAME = "name";
|
||||
private static final String CREATE = "create";
|
||||
private static final String VALUE = "value";
|
||||
private static final String CONNECT = "connect";
|
||||
private static final String LANG = "connect";
|
||||
|
||||
public JSONArray getJSON() {
|
||||
return new JSONArray(rootObjects);
|
||||
}
|
||||
@ -58,9 +66,9 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (obj == null) {
|
||||
obj = new JSONObject();
|
||||
try {
|
||||
obj.put("type", this.node.type.id);
|
||||
obj.put("id", (String) null);
|
||||
obj.put("create", "unconditional");
|
||||
obj.put(TYPE, this.node.type.id);
|
||||
obj.put(ID, (String) null);
|
||||
obj.put(CREATE, "unconditional");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -89,12 +97,12 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (cell.recon != null &&
|
||||
cell.recon.judgment == Recon.Judgment.Matched &&
|
||||
cell.recon.match != null) {
|
||||
obj.put("id", cell.recon.match.topicID);
|
||||
obj.put(ID, cell.recon.match.topicID);
|
||||
} else {
|
||||
obj.put("id", (String) null);
|
||||
obj.put("name", cell.value.toString());
|
||||
obj.put("type", node.type.id);
|
||||
obj.put("create", "unless_exists");
|
||||
obj.put(ID, (String) null);
|
||||
obj.put(NAME, cell.value.toString());
|
||||
obj.put(TYPE, node.type.id);
|
||||
obj.put(CREATE, "unless_exists");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -118,13 +126,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (obj == null) {
|
||||
obj = new JSONObject();
|
||||
try {
|
||||
obj.put("value", cell.value.toString());
|
||||
obj.put("type", node.valueType);
|
||||
obj.put(VALUE, cell.value.toString());
|
||||
obj.put(TYPE, node.valueType);
|
||||
if ("/type/text".equals(node.lang)) {
|
||||
obj.put("lang", node.lang);
|
||||
obj.put(LANG, node.lang);
|
||||
}
|
||||
|
||||
obj.put("connect", "insert");
|
||||
obj.put(CONNECT, "insert");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -147,13 +155,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (obj == null) {
|
||||
obj = new JSONObject();
|
||||
try {
|
||||
obj.put("value", cell.value.toString());
|
||||
obj.put(VALUE, cell.value.toString());
|
||||
|
||||
JSONObject nsObj = new JSONObject();
|
||||
nsObj.put("id", node.namespace.id);
|
||||
nsObj.put(ID, node.namespace.id);
|
||||
|
||||
obj.put("namespace", nsObj);
|
||||
obj.put("connect", "insert");
|
||||
obj.put(CONNECT, "insert");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -174,7 +182,7 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (obj == null) {
|
||||
obj = new JSONObject();
|
||||
try {
|
||||
obj.put("id", node.topic.id);
|
||||
obj.put(ID, node.topic.id);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -195,13 +203,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
|
||||
if (obj == null) {
|
||||
obj = new JSONObject();
|
||||
try {
|
||||
obj.put("value", node.value);
|
||||
obj.put("type", node.valueType);
|
||||
obj.put(VALUE, node.value);
|
||||
obj.put(TYPE, node.valueType);
|
||||
if ("/type/text".equals(node.lang)) {
|
||||
obj.put("lang", node.lang);
|
||||
obj.put(LANG, node.lang);
|
||||
}
|
||||
|
||||
obj.put("connect", "insert");
|
||||
obj.put(CONNECT, "insert");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
|
||||
|
||||
protected class AnonymousTransposedNode extends TransposedNodeWithChildren {
|
||||
|
||||
protected AnonymousTransposedNode(AnonymousNode node) { }
|
||||
//protected AnonymousTransposedNode(AnonymousNode node) { }
|
||||
|
||||
public String write(String subject, String predicate) {
|
||||
if (children.size() == 0 || subject == null) {
|
||||
@ -249,7 +249,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
|
||||
FreebaseProperty property,
|
||||
AnonymousNode node) {
|
||||
|
||||
WritingTransposedNode tnode = new AnonymousTransposedNode(node);
|
||||
WritingTransposedNode tnode = new AnonymousTransposedNode();
|
||||
|
||||
processTransposedNode(tnode, parentNode, property);
|
||||
|
||||
|
@ -5,35 +5,35 @@ package com.metaweb.gridworks;
|
||||
*/
|
||||
public class Configurations {
|
||||
|
||||
public static String get(String name) {
|
||||
public static String get(final String name) {
|
||||
return System.getProperty(name);
|
||||
}
|
||||
|
||||
public static String get(String name, String def) {
|
||||
String val = get(name);
|
||||
public static String get(final String name, final String def) {
|
||||
final String val = get(name);
|
||||
return (val == null) ? def : val;
|
||||
}
|
||||
|
||||
public static boolean getBoolean(String name, boolean def) {
|
||||
String val = get(name);
|
||||
public static boolean getBoolean(final String name, final boolean def) {
|
||||
final String val = get(name);
|
||||
return (val == null) ? def : Boolean.parseBoolean(val);
|
||||
}
|
||||
|
||||
public static int getInteger(String name, int def) {
|
||||
String val = get(name);
|
||||
public static int getInteger(final String name, final int def) {
|
||||
final String val = get(name);
|
||||
try {
|
||||
return (val == null) ? def : Integer.parseInt(val);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("Could not parse '" + val + "' as an integer number.");
|
||||
throw new RuntimeException("Could not parse '" + val + "' as an integer number.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static float getFloat(String name, float def) {
|
||||
String val = get(name);
|
||||
public static float getFloat(final String name, final float def) {
|
||||
final String val = get(name);
|
||||
try {
|
||||
return (val == null) ? def : Float.parseFloat(val);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("Could not parse '" + val + "' as a floating point number.");
|
||||
throw new RuntimeException("Could not parse '" + val + "' as a floating point number.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ import org.mortbay.log.Log;
|
||||
import org.mortbay.util.Scanner;
|
||||
|
||||
import com.metaweb.util.logging.IndentingLayout;
|
||||
import com.metaweb.util.signal.SignalHandler;
|
||||
import com.metaweb.util.signal.AbstractSignalHandler;
|
||||
import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
|
||||
|
||||
public class Gridworks {
|
||||
@ -298,7 +298,7 @@ class GridworksClient extends JFrame implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
class ShutdownSignalHandler extends SignalHandler {
|
||||
class ShutdownSignalHandler extends AbstractSignalHandler {
|
||||
|
||||
private Server _server;
|
||||
|
||||
|
@ -48,7 +48,6 @@ public class IndentingLayout extends Layout {
|
||||
protected static final int CONTEXT_SIZE = 25;
|
||||
protected static final long MAX_DELTA = 10000;
|
||||
|
||||
protected final StringBuffer buf = new StringBuffer(256);
|
||||
protected Calendar calendar = Calendar.getInstance();
|
||||
protected long previousTime = 0;
|
||||
protected int indentation = 0;
|
||||
@ -67,7 +66,7 @@ public class IndentingLayout extends Layout {
|
||||
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) this.indentation--;
|
||||
|
||||
// Reset buf
|
||||
buf.setLength(0);
|
||||
StringBuffer buf = new StringBuffer(256);
|
||||
|
||||
Date date = new Date();
|
||||
long now = date.getTime();
|
||||
@ -134,7 +133,7 @@ public class IndentingLayout extends Layout {
|
||||
|
||||
private void pad(StringBuffer buffer, int pads, char padchar) {
|
||||
for (int i = 0; i < pads; i++) {
|
||||
buf.append(padchar);
|
||||
buffer.append(padchar);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.metaweb.util.signal;
|
||||
|
||||
public abstract class SignalHandler {
|
||||
public abstract class AbstractSignalHandler {
|
||||
|
||||
SignalHandlerWrapper _wrapper;
|
||||
|
||||
public SignalHandler(String signalName) {
|
||||
public AbstractSignalHandler(final String signalName) {
|
||||
try {
|
||||
_wrapper = new SignalHandlerWrapper(signalName, this);
|
||||
new SignalHandlerWrapper(signalName, this);
|
||||
} catch (Throwable e) {
|
||||
throw new java.lang.RuntimeException("Signal handling facilities are not available in this JVM.");
|
||||
throw new java.lang.RuntimeException("Signal handling facilities are not available in this JVM.", e);
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,25 @@
|
||||
package com.metaweb.util.signal;
|
||||
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
/*
|
||||
* This class allows our own SignalHandler class to fail more gracefully
|
||||
* in case the "sun.misc.Signal*" classes are not found in the current jvm.
|
||||
*/
|
||||
final class SignalHandlerWrapper implements sun.misc.SignalHandler {
|
||||
final class SignalHandlerWrapper implements SignalHandler {
|
||||
|
||||
private final sun.misc.SignalHandler existingHandler;
|
||||
private transient final SignalHandler existingHandler;
|
||||
|
||||
private final SignalHandler handler;
|
||||
private transient final AbstractSignalHandler handler;
|
||||
|
||||
SignalHandlerWrapper(String signalName, SignalHandler handler) {
|
||||
SignalHandlerWrapper(final String signalName, final AbstractSignalHandler handler) {
|
||||
this.handler = handler;
|
||||
sun.misc.Signal signal = new sun.misc.Signal(signalName);
|
||||
existingHandler = sun.misc.Signal.handle(signal, this);
|
||||
final Signal signal = new Signal(signalName);
|
||||
existingHandler = Signal.handle(signal, this);
|
||||
}
|
||||
|
||||
public void handle(sun.misc.Signal sig) {
|
||||
public void handle(final Signal sig) {
|
||||
if (handler.handle(sig.getName()) && (existingHandler != null)) {
|
||||
existingHandler.handle(sig);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user