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:
Stefano Mazzocchi 2010-04-09 00:14:11 +00:00
parent 759824e1b4
commit d3d40d608a
27 changed files with 217 additions and 149 deletions

View File

@ -262,8 +262,7 @@
classname="net.sourceforge.pmd.ant.PMDTask" classname="net.sourceforge.pmd.ant.PMDTask"
classpathref="pmd.path" classpathref="pmd.path"
/> />
<pmd targetjdk="1.6" encoding="UTF-8"> <pmd rulesetfiles="${conf.dir}/pmd.rules.xml" targetjdk="1.6" encoding="UTF-8">
<ruleset>basic</ruleset>
<formatter type="html" toFile="${reports.dir}/pmd.html" toConsole="true"/> <formatter type="html" toFile="${reports.dir}/pmd.html" toConsole="true"/>
<fileset dir="${server.src.dir}"> <fileset dir="${server.src.dir}">
<include name="**/*.java"/> <include name="**/*.java"/>

View File

@ -576,6 +576,8 @@ findbugs() {
ANT_PARAMS="-Dfindbugs.dir=${GRIDWORKS_TOOLS_DIR}/${FINDBUGS_DIR}" ANT_PARAMS="-Dfindbugs.dir=${GRIDWORKS_TOOLS_DIR}/${FINDBUGS_DIR}"
ant findbugs ant findbugs
open "$GRIDWORKS_BUILD_DIR/reports/findbugs.html"
} }
pmd() { pmd() {
@ -583,6 +585,8 @@ pmd() {
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}" ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
ant pmd ant pmd
open "$GRIDWORKS_BUILD_DIR/reports/pmd.html"
} }
cpd() { cpd() {
@ -590,6 +594,8 @@ cpd() {
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}" ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
ant cpd ant cpd
open "$GRIDWORKS_BUILD_DIR/reports/cpd.txt"
} }
jslint() { jslint() {
@ -597,6 +603,8 @@ jslint() {
ANT_PARAMS="-Djslint.dir=${GRIDWORKS_TOOLS_DIR}/${JSLINT_DIR}" ANT_PARAMS="-Djslint.dir=${GRIDWORKS_TOOLS_DIR}/${JSLINT_DIR}"
ant jslint ant jslint
open "$GRIDWORKS_BUILD_DIR/reports/jslint.txt"
} }
# -------------------------- script ----------------------------- # -------------------------- script -----------------------------

33
src/conf/pmd.rules.xml Normal file
View 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>

View File

@ -429,33 +429,21 @@ public class ProjectManager {
} }
protected void load() { protected void load() {
try { if (loadFromFile(new File(_workspaceDir, "workspace.json"))) return;
loadFromFile(new File(_workspaceDir, "workspace.json")); if (loadFromFile(new File(_workspaceDir, "workspace.temp.json"))) return;
return; if (loadFromFile(new File(_workspaceDir, "workspace.old.json"))) return;
} catch (Exception e) {
} }
try { protected boolean loadFromFile(File file) {
loadFromFile(new File(_workspaceDir, "workspace.temp.json"));
return;
} catch (Exception e) {
}
try {
loadFromFile(new File(_workspaceDir, "workspace.old.json"));
return;
} catch (Exception e) {
}
}
protected void loadFromFile(File file) throws IOException, JSONException {
Gridworks.log("Loading workspace from " + file.getAbsolutePath()); Gridworks.log("Loading workspace from " + file.getAbsolutePath());
_projectsMetadata.clear(); _projectsMetadata.clear();
_expressions.clear(); _expressions.clear();
FileReader reader = new FileReader(file); if (file.exists() || file.canRead()) {
FileReader reader = null;
try { try {
reader = new FileReader(file);
JSONTokener tokener = new JSONTokener(reader); JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue(); JSONObject obj = (JSONObject) tokener.nextValue();
@ -471,8 +459,20 @@ public class ProjectManager {
} }
JSONUtilities.getStringList(obj, "expressions", _expressions); 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 { } finally {
try {
reader.close(); reader.close();
} catch (IOException e) {
Gridworks.warn("Exception closing file",e);
} }
} }
} }
return false;
}
}

View File

@ -25,6 +25,8 @@ public class Engine implements Jsonizable {
protected List<Facet> _facets = new LinkedList<Facet>(); protected List<Facet> _facets = new LinkedList<Facet>();
protected boolean _includeDependent; protected boolean _includeDependent;
public final static String INCLUDE_DEPENDENT = "includeDependent";
public Engine(Project project) { public Engine(Project project) {
_project = project; _project = project;
} }
@ -75,8 +77,8 @@ public class Engine implements Jsonizable {
} }
} }
if (o.has("includeDependent") && !o.isNull("includeDependent")) { if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
_includeDependent = o.getBoolean("includeDependent"); _includeDependent = o.getBoolean(INCLUDE_DEPENDENT);
} }
} }
@ -98,7 +100,7 @@ public class Engine implements Jsonizable {
facet.write(writer, options); facet.write(writer, options);
} }
writer.endArray(); writer.endArray();
writer.key("includeDependent"); writer.value(_includeDependent); writer.key(INCLUDE_DEPENDENT); writer.value(_includeDependent);
writer.endObject(); writer.endObject();
} }
} }

View File

@ -23,7 +23,7 @@ public class RangeFacet implements Facet {
protected String _name; // name of facet protected String _name; // name of facet
protected String _expression; // expression to compute numeric value(s) per row protected String _expression; // expression to compute numeric value(s) per row
protected String _columnName; // column to base expression on, if any 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 _from; // the numeric selection
protected double _to; protected double _to;
@ -59,6 +59,11 @@ public class RangeFacet implements Facet {
public RangeFacet() { 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) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
@ -72,8 +77,8 @@ public class RangeFacet implements Facet {
writer.key("error"); writer.value(_errorMessage); writer.key("error"); writer.value(_errorMessage);
} else { } else {
if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) { if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) {
writer.key("min"); writer.value(_min); writer.key(MIN); writer.value(_min);
writer.key("max"); writer.value(_max); writer.key(MAX); writer.value(_max);
writer.key("step"); writer.value(_step); writer.key("step"); writer.value(_step);
writer.key("bins"); writer.array(); writer.key("bins"); writer.array();
@ -88,13 +93,13 @@ public class RangeFacet implements Facet {
} }
writer.endArray(); writer.endArray();
if ("min".equals(_mode)) { if (MIN.equals(_mode)) {
writer.key("from"); writer.value(_from); writer.key(FROM); writer.value(_from);
} else if ("max".equals(_mode)) { } else if (MAX.equals(_mode)) {
writer.key("to"); writer.value(_to); writer.key(TO); writer.value(_to);
} else { } else {
writer.key("from"); writer.value(_from); writer.key(FROM); writer.value(_from);
writer.key("to"); writer.value(_to); writer.key(TO); writer.value(_to);
} }
} }
@ -129,20 +134,20 @@ public class RangeFacet implements Facet {
} }
_mode = o.getString("mode"); _mode = o.getString("mode");
if ("min".equals(_mode)) { if (MIN.equals(_mode)) {
if (o.has("from")) { if (o.has(FROM)) {
_from = o.getDouble("from"); _from = o.getDouble(FROM);
_selected = true; _selected = true;
} }
} else if ("max".equals(_mode)) { } else if (MAX.equals(_mode)) {
if (o.has("to")) { if (o.has(TO)) {
_to = o.getDouble("to"); _to = o.getDouble(TO);
_selected = true; _selected = true;
} }
} else { } else {
if (o.has("from") && o.has("to")) { if (o.has(FROM) && o.has(TO)) {
_from = o.getDouble("from"); _from = o.getDouble(FROM);
_to = o.getDouble("to"); _to = o.getDouble(TO);
_selected = true; _selected = true;
} }
} }
@ -159,7 +164,7 @@ public class RangeFacet implements Facet {
public RowFilter getRowFilter() { public RowFilter getRowFilter() {
if (_eval != null && _errorMessage == null && _selected) { if (_eval != null && _errorMessage == null && _selected) {
if ("min".equals(_mode)) { if (MIN.equals(_mode)) {
return new ExpressionNumberComparisonRowFilter( return new ExpressionNumberComparisonRowFilter(
_eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) { _eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
@ -167,7 +172,7 @@ public class RangeFacet implements Facet {
return d >= _from; return d >= _from;
}; };
}; };
} else if ("max".equals(_mode)) { } else if (MAX.equals(_mode)) {
return new ExpressionNumberComparisonRowFilter( return new ExpressionNumberComparisonRowFilter(
_eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) { _eval, _columnName, _cellIndex, _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {

View File

@ -332,7 +332,7 @@ public class CreateProjectCommand extends Command {
private String[] getExtension(String filename) { private String[] getExtension(String filename) {
String[] result = new String[2]; 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[0] = (ext_index == -1) ? filename : filename.substring(0,ext_index);
result[1] = (ext_index == -1) ? "" : filename.substring(ext_index + 1); result[1] = (ext_index == -1) ? "" : filename.substring(ext_index + 1);
return result; return result;

View File

@ -125,7 +125,7 @@ public class GuessTypesOfColumnCommand extends Command {
} }
jsonWriter.endObject(); jsonWriter.endObject();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(1024);
sb.append("http://api.freebase.com/api/service/search?queries="); sb.append("http://api.freebase.com/api/service/search?queries=");
sb.append(ParsingUtilities.encode(stringWriter.toString())); sb.append(ParsingUtilities.encode(stringWriter.toString()));

View File

@ -33,7 +33,7 @@ public class PreviewProtographCommand extends Command {
JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString); JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString);
Protograph protograph = Protograph.reconstruct(json); Protograph protograph = Protograph.reconstruct(json);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(2048);
sb.append("{ "); sb.append("{ ");
{ {

View File

@ -22,10 +22,13 @@ public class JythonEvaluable implements Evaluable {
// indent and create a function out of the code // indent and create a function out of the code
String[] lines = s.split("\r\n|\r|\n"); String[] lines = s.split("\r\n|\r|\n");
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(1024);
sb.append("def " + s_functionName + "(value, cell, cells, row, rowIndex):"); sb.append("def ");
sb.append(s_functionName);
sb.append("(value, cell, cells, row, rowIndex):");
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
sb.append("\n " + lines[i]); sb.append("\n ");
sb.append(lines[i]);
} }
_engine.exec(sb.toString()); _engine.exec(sb.toString());

View File

@ -18,6 +18,7 @@ public class ToDate implements Function {
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 0) { if (args.length == 0) {
// missing value, can this happen? // missing value, can this happen?
return null;
} }
if (!(args[0] instanceof String)) { if (!(args[0] instanceof String)) {
// ignore cell values that aren't strings // ignore cell values that aren't strings

View File

@ -40,6 +40,8 @@ public class HistoryEntry implements Jsonizable {
// the actual change, loaded on demand // the actual change, loaded on demand
transient protected Change _change; transient protected Change _change;
private final static String OPERATION = "operation";
public HistoryEntry(Project project, String description, AbstractOperation operation, Change change) { public HistoryEntry(Project project, String description, AbstractOperation operation, Change change) {
this.id = Math.round(Math.random() * 1000000) + System.currentTimeMillis(); this.id = Math.round(Math.random() * 1000000) + System.currentTimeMillis();
this.projectID = project.id; this.projectID = project.id;
@ -66,7 +68,7 @@ public class HistoryEntry implements Jsonizable {
writer.key("description"); writer.value(description); writer.key("description"); writer.value(description);
writer.key("time"); writer.value(ParsingUtilities.dateToString(time)); writer.key("time"); writer.value(ParsingUtilities.dateToString(time));
if ("save".equals(options.getProperty("mode")) && operation != null) { if ("save".equals(options.getProperty("mode")) && operation != null) {
writer.key("operation"); operation.write(writer, options); writer.key(OPERATION); operation.write(writer, options);
} }
writer.endObject(); writer.endObject();
} }
@ -121,8 +123,8 @@ public class HistoryEntry implements Jsonizable {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
AbstractOperation operation = null; AbstractOperation operation = null;
if (obj.has("operation") && !obj.isNull("operation")) { if (obj.has(OPERATION) && !obj.isNull(OPERATION)) {
operation = OperationRegistry.reconstruct(project, obj.getJSONObject("operation")); operation = OperationRegistry.reconstruct(project, obj.getJSONObject(OPERATION));
} }
return new HistoryEntry( return new HistoryEntry(

View File

@ -20,6 +20,8 @@ public class HistoryProcess extends Process {
protected boolean _done = false; protected boolean _done = false;
private final static String WARN = "Not a long-running process";
public HistoryProcess(Project project, long lastDoneID) { public HistoryProcess(Project project, long lastDoneID) {
_project = project; _project = project;
_lastDoneID = lastDoneID; _lastDoneID = lastDoneID;
@ -33,7 +35,7 @@ public class HistoryProcess extends Process {
} }
public void cancel() { public void cancel() {
throw new RuntimeException("Not a long-running process"); throw new RuntimeException(WARN);
} }
public boolean isImmediate() { public boolean isImmediate() {
@ -48,7 +50,7 @@ public class HistoryProcess extends Process {
} }
public void startPerforming(ProcessManager manager) { public void startPerforming(ProcessManager manager) {
throw new RuntimeException("Not a long-running process"); throw new RuntimeException(WARN);
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
@ -62,10 +64,10 @@ public class HistoryProcess extends Process {
} }
public boolean isDone() { public boolean isDone() {
throw new RuntimeException("Not a long-running process"); throw new RuntimeException(WARN);
} }
public boolean isRunning() { public boolean isRunning() {
throw new RuntimeException("Not a long-running process"); throw new RuntimeException(WARN);
} }
} }

View File

@ -31,7 +31,7 @@ public class TsvCsvImporter implements Importer {
int rowsWithData = 0; int rowsWithData = 0;
while ((line = lnReader.readLine()) != null) { while ((line = lnReader.readLine()) != null) {
if (line.trim().length() == 0) { if (StringUtils.isBlank(line)) {
continue; continue;
} }

View File

@ -26,6 +26,9 @@ public class Row implements HasFields, Jsonizable {
transient public int[] contextRowSlots; transient public int[] contextRowSlots;
transient public int[] contextCellSlots; transient public int[] contextCellSlots;
private static final String FLAGGED = "flagged";
private static final String STARRED = "starred";
public Row(int cellCount) { public Row(int cellCount) {
cells = new ArrayList<Cell>(cellCount); cells = new ArrayList<Cell>(cellCount);
} }
@ -39,9 +42,9 @@ public class Row implements HasFields, Jsonizable {
} }
public Object getField(String name, Properties bindings) { public Object getField(String name, Properties bindings) {
if ("flagged".equals(name)) { if (FLAGGED.equals(name)) {
return flagged; return flagged;
} else if ("starred".equals(name)) { } else if (STARRED.equals(name)) {
return starred; return starred;
} }
return null; return null;
@ -105,8 +108,8 @@ public class Row implements HasFields, Jsonizable {
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("flagged"); writer.value(flagged); writer.key(FLAGGED); writer.value(flagged);
writer.key("starred"); writer.value(starred); writer.key(STARRED); writer.value(starred);
writer.key("cells"); writer.array(); writer.key("cells"); writer.array();
for (Cell cell : cells) { for (Cell cell : cells) {
@ -166,11 +169,11 @@ public class Row implements HasFields, Jsonizable {
} }
} }
if (obj.has("starred")) { if (obj.has(STARRED)) {
row.starred = obj.getBoolean("starred"); row.starred = obj.getBoolean(STARRED);
} }
if (obj.has("flagged")) { if (obj.has(FLAGGED)) {
row.flagged = obj.getBoolean("flagged"); row.flagged = obj.getBoolean(FLAGGED);
} }
return row; return row;

View File

@ -16,6 +16,8 @@ import com.metaweb.gridworks.protograph.FreebaseType;
public class DataExtensionReconConfig extends StrictReconConfig { public class DataExtensionReconConfig extends StrictReconConfig {
final public FreebaseType type; final public FreebaseType type;
private final static String WARN = "Not implemented";
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {
JSONObject type = obj.getJSONObject("type"); JSONObject type = obj.getJSONObject("type");
@ -34,17 +36,15 @@ public class DataExtensionReconConfig extends StrictReconConfig {
@Override @Override
public ReconJob createJob(Project project, int rowIndex, Row row, public ReconJob createJob(Project project, int rowIndex, Row row,
String columnName, Cell cell) { String columnName, Cell cell) {
throw new RuntimeException("Not implemented"); throw new RuntimeException(WARN);
} }
@Override @Override
public int getBatchSize() { public int getBatchSize() {
throw new RuntimeException("Not implemented"); throw new RuntimeException(WARN);
} }
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options) throws JSONException {
throws JSONException {
writer.object(); writer.object();
writer.key("mode"); writer.value("extend"); writer.key("mode"); writer.value("extend");
writer.key("type"); type.write(writer, options); writer.key("type"); type.write(writer, options);
@ -53,12 +53,11 @@ public class DataExtensionReconConfig extends StrictReconConfig {
@Override @Override
public List<Recon> batchRecon(List<ReconJob> jobs) { public List<Recon> batchRecon(List<ReconJob> jobs) {
throw new RuntimeException("Not implemented"); throw new RuntimeException(WARN);
} }
@Override @Override
public String getBriefDescription(Project project, String columnName) { public String getBriefDescription(Project project, String columnName) {
throw new RuntimeException("Not implemented"); throw new RuntimeException(WARN);
} }
} }

View File

@ -111,8 +111,9 @@ public class GuidBasedReconConfig extends StrictReconConfig {
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService + "?query="); sb.append(s_mqlreadService);
sb.append("?query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -222,7 +222,7 @@ public class HeuristicReconConfig extends ReconConfig {
} }
jsonWriter.endObject(); 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("http://api.freebase.com/api/service/search?indent=1&queries=");
sb.append(ParsingUtilities.encode(stringWriter.toString())); sb.append(ParsingUtilities.encode(stringWriter.toString()));

View File

@ -115,8 +115,9 @@ public class IdBasedReconConfig extends StrictReconConfig {
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService + "?query="); sb.append(s_mqlreadService);
sb.append("?query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -129,8 +129,9 @@ public class KeyBasedReconConfig extends StrictReconConfig {
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService + "?query="); sb.append(s_mqlreadService);
sb.append("?query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -21,6 +21,14 @@ import com.metaweb.gridworks.protograph.ValueNode;
public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory { public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
protected List<JSONObject> rootObjects = new LinkedList<JSONObject>(); 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() { public JSONArray getJSON() {
return new JSONArray(rootObjects); return new JSONArray(rootObjects);
} }
@ -58,9 +66,9 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (obj == null) { if (obj == null) {
obj = new JSONObject(); obj = new JSONObject();
try { try {
obj.put("type", this.node.type.id); obj.put(TYPE, this.node.type.id);
obj.put("id", (String) null); obj.put(ID, (String) null);
obj.put("create", "unconditional"); obj.put(CREATE, "unconditional");
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -89,12 +97,12 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (cell.recon != null && if (cell.recon != null &&
cell.recon.judgment == Recon.Judgment.Matched && cell.recon.judgment == Recon.Judgment.Matched &&
cell.recon.match != null) { cell.recon.match != null) {
obj.put("id", cell.recon.match.topicID); obj.put(ID, cell.recon.match.topicID);
} else { } else {
obj.put("id", (String) null); obj.put(ID, (String) null);
obj.put("name", cell.value.toString()); obj.put(NAME, cell.value.toString());
obj.put("type", node.type.id); obj.put(TYPE, node.type.id);
obj.put("create", "unless_exists"); obj.put(CREATE, "unless_exists");
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -118,13 +126,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (obj == null) { if (obj == null) {
obj = new JSONObject(); obj = new JSONObject();
try { try {
obj.put("value", cell.value.toString()); obj.put(VALUE, cell.value.toString());
obj.put("type", node.valueType); obj.put(TYPE, node.valueType);
if ("/type/text".equals(node.lang)) { 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -147,13 +155,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (obj == null) { if (obj == null) {
obj = new JSONObject(); obj = new JSONObject();
try { try {
obj.put("value", cell.value.toString()); obj.put(VALUE, cell.value.toString());
JSONObject nsObj = new JSONObject(); JSONObject nsObj = new JSONObject();
nsObj.put("id", node.namespace.id); nsObj.put(ID, node.namespace.id);
obj.put("namespace", nsObj); obj.put("namespace", nsObj);
obj.put("connect", "insert"); obj.put(CONNECT, "insert");
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -174,7 +182,7 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (obj == null) { if (obj == null) {
obj = new JSONObject(); obj = new JSONObject();
try { try {
obj.put("id", node.topic.id); obj.put(ID, node.topic.id);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -195,13 +203,13 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory {
if (obj == null) { if (obj == null) {
obj = new JSONObject(); obj = new JSONObject();
try { try {
obj.put("value", node.value); obj.put(VALUE, node.value);
obj.put("type", node.valueType); obj.put(TYPE, node.valueType);
if ("/type/text".equals(node.lang)) { 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -91,7 +91,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
protected class AnonymousTransposedNode extends TransposedNodeWithChildren { protected class AnonymousTransposedNode extends TransposedNodeWithChildren {
protected AnonymousTransposedNode(AnonymousNode node) { } //protected AnonymousTransposedNode(AnonymousNode node) { }
public String write(String subject, String predicate) { public String write(String subject, String predicate) {
if (children.size() == 0 || subject == null) { if (children.size() == 0 || subject == null) {
@ -249,7 +249,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
FreebaseProperty property, FreebaseProperty property,
AnonymousNode node) { AnonymousNode node) {
WritingTransposedNode tnode = new AnonymousTransposedNode(node); WritingTransposedNode tnode = new AnonymousTransposedNode();
processTransposedNode(tnode, parentNode, property); processTransposedNode(tnode, parentNode, property);

View File

@ -5,35 +5,35 @@ package com.metaweb.gridworks;
*/ */
public class Configurations { public class Configurations {
public static String get(String name) { public static String get(final String name) {
return System.getProperty(name); return System.getProperty(name);
} }
public static String get(String name, String def) { public static String get(final String name, final String def) {
String val = get(name); final String val = get(name);
return (val == null) ? def : val; return (val == null) ? def : val;
} }
public static boolean getBoolean(String name, boolean def) { public static boolean getBoolean(final String name, final boolean def) {
String val = get(name); final String val = get(name);
return (val == null) ? def : Boolean.parseBoolean(val); return (val == null) ? def : Boolean.parseBoolean(val);
} }
public static int getInteger(String name, int def) { public static int getInteger(final String name, final int def) {
String val = get(name); final String val = get(name);
try { try {
return (val == null) ? def : Integer.parseInt(val); return (val == null) ? def : Integer.parseInt(val);
} catch (NumberFormatException e) { } 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) { public static float getFloat(final String name, final float def) {
String val = get(name); final String val = get(name);
try { try {
return (val == null) ? def : Float.parseFloat(val); return (val == null) ? def : Float.parseFloat(val);
} catch (NumberFormatException e) { } 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);
} }
} }

View File

@ -32,7 +32,7 @@ import org.mortbay.log.Log;
import org.mortbay.util.Scanner; import org.mortbay.util.Scanner;
import com.metaweb.util.logging.IndentingLayout; import com.metaweb.util.logging.IndentingLayout;
import com.metaweb.util.signal.SignalHandler; import com.metaweb.util.signal.AbstractSignalHandler;
import com.metaweb.util.threads.ThreadPoolExecutorAdapter; import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
public class Gridworks { public class Gridworks {
@ -298,7 +298,7 @@ class GridworksClient extends JFrame implements ActionListener {
} }
} }
class ShutdownSignalHandler extends SignalHandler { class ShutdownSignalHandler extends AbstractSignalHandler {
private Server _server; private Server _server;

View File

@ -48,7 +48,6 @@ public class IndentingLayout extends Layout {
protected static final int CONTEXT_SIZE = 25; protected static final int CONTEXT_SIZE = 25;
protected static final long MAX_DELTA = 10000; protected static final long MAX_DELTA = 10000;
protected final StringBuffer buf = new StringBuffer(256);
protected Calendar calendar = Calendar.getInstance(); protected Calendar calendar = Calendar.getInstance();
protected long previousTime = 0; protected long previousTime = 0;
protected int indentation = 0; protected int indentation = 0;
@ -67,7 +66,7 @@ public class IndentingLayout extends Layout {
if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) this.indentation--; if ((leader == '<') && (secondLeader == ' ') && (this.indentation > 0)) this.indentation--;
// Reset buf // Reset buf
buf.setLength(0); StringBuffer buf = new StringBuffer(256);
Date date = new Date(); Date date = new Date();
long now = date.getTime(); long now = date.getTime();
@ -134,7 +133,7 @@ public class IndentingLayout extends Layout {
private void pad(StringBuffer buffer, int pads, char padchar) { private void pad(StringBuffer buffer, int pads, char padchar) {
for (int i = 0; i < pads; i++) { for (int i = 0; i < pads; i++) {
buf.append(padchar); buffer.append(padchar);
} }
} }

View File

@ -1,14 +1,12 @@
package com.metaweb.util.signal; package com.metaweb.util.signal;
public abstract class SignalHandler { public abstract class AbstractSignalHandler {
SignalHandlerWrapper _wrapper; public AbstractSignalHandler(final String signalName) {
public SignalHandler(String signalName) {
try { try {
_wrapper = new SignalHandlerWrapper(signalName, this); new SignalHandlerWrapper(signalName, this);
} catch (Throwable e) { } 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);
} }
} }

View File

@ -1,22 +1,25 @@
package com.metaweb.util.signal; package com.metaweb.util.signal;
import sun.misc.Signal;
import sun.misc.SignalHandler;
/* /*
* This class allows our own SignalHandler class to fail more gracefully * 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. * 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; this.handler = handler;
sun.misc.Signal signal = new sun.misc.Signal(signalName); final Signal signal = new Signal(signalName);
existingHandler = sun.misc.Signal.handle(signal, this); 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)) { if (handler.handle(sig.getName()) && (existingHandler != null)) {
existingHandler.handle(sig); existingHandler.handle(sig);
} }