- removed the 'thirdparty' directory (now the 'gridworks' script will download and install needed tools if they are not present in the system already)

- added 'findbugs' command that uses the findbugs static analyzer to look for problems in the code
- fixed a bunch of issues that findbugs found (a few methods would go a little faster, and a few NPE will be avoided... nothing major but good to have)


git-svn-id: http://google-refine.googlecode.com/svn/trunk@382 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-04-05 07:15:16 +00:00
parent 798b2a36ca
commit 2efbf0031f
33 changed files with 328 additions and 225 deletions

View File

@ -26,7 +26,6 @@
<property name="graphics.dir" value="${basedir}/src/graphics" />
<property name="conf.dir" value="${basedir}/src/conf" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="tools.dir" value="${basedir}/thirdparty" />
<property name="tests.dir" value="${basedir}/tests" />
<property name="server_classes.dir" value="${build.dir}/classes" />
@ -100,7 +99,7 @@
<taskdef
name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler"
classpath="${tools.dir}/jarbundler-2.1.0.jar"
classpath="${jarbundler.dir}/jarbundler-2.1.0.jar"
/>
<mkdir dir="${mac.dir}"/>
@ -138,7 +137,7 @@
<taskdef
name="launch4j"
classname="net.sf.launch4j.ant.Launch4jTask"
classpath="${tools.dir}/launch4j/launch4j.jar:${tools.dir}/launch4j/lib/xstream.jar"
classpath="${launch4j.dir}/launch4j.jar:${launch4j.dir}/lib/xstream.jar"
/>
<launch4j>
<config
@ -224,8 +223,6 @@
<copy file="${basedir}/README.txt" tofile="${linux.dir}/README.txt"/>
<copy file="${basedir}/gridworks" tofile="${linux.dir}/gridworks"/>
<echo file="${linux.dir}/.revision" append="false">${revision}</echo>
<tar longfile="gnu" compression="gzip" destfile="${dist.dir}/gridworks-${version}-${revision}.tar.gz">
<tarfileset dir="${linux.dir}/.." filemode="755">
<include name="${linux.name}/gridworks"/>
@ -237,6 +234,19 @@
</tar>
</target>
<target name="findbugs" depends="build">
<taskdef
name="findbugs"
classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
classpath="${findbugs.dir}/lib/findbugs-ant.jar"
/>
<findbugs jvmargs="-Xmx1024m" home="${findbugs.dir}" output="html" outputFile="${build.dir}/gridworks-findbugs.html" >
<auxClasspath refid="class.path" />
<sourcePath path="${src.dir}" />
<class location="${webapp_classes.dir}" />
</findbugs>
</target>
<target name="clean">
<delete file="${build.dir}/gridworks.jar" />
<delete dir="${server_classes.dir}" />

234
gridworks
View File

@ -4,7 +4,7 @@
# Gridworks Control System #
##########################################################
# -------------- functions ------------------------------------
# -------------- utility functions ----------------------
fail () {
cat <<EOF
@ -50,7 +50,8 @@ and <action> is one of
build ..................... Build Gridworks
run ....................... Run Gridworks
test ...................... Test Gridworks
test ...................... Test Gridworks
findbugs .................. Run Findbugs against Gridworks
mac_dist <version> ........ Make MacOSX binary distribution
windows_dist <version> .... Make Windows binary distribution
@ -66,7 +67,7 @@ EOF
}
add_option() {
OPTS="$OPTS $1"
OPTS="$OPTS $1"
}
load_configs() {
@ -80,45 +81,6 @@ check_macosx() {
error "This action can only run on MacOSX"
fi
}
ant_prepare() {
if [ ! -d $GRIDWORKS_BUILD_DIR ] ; then
mkdir $GRIDWORKS_BUILD_DIR || exit 1
fi
ANT=`which ant`
if [ "$ANT" = "" ] ; then
cd thirdparty
ANT_TAR=`ls | grep apache-ant | grep tar.gz | grep -v svn`
ANT_DIR=`echo $ANT_TAR | sed 's/.tar.gz//'`
if [ ! -d $ANT_DIR ] ; then
tar xzf $ANT_TAR -C . || exit 1
fi
ANT="`pwd`/$ANT_DIR/bin/ant"
cd ..
fi
}
ant() {
ant_prepare
$ANT -f build.xml -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || exit 1
}
dist_prepare() {
if [ ! -d $GRIDWORKS_DIST_DIR ] ; then
mkdir $GRIDWORKS_DIST_DIR || exit 1
fi
}
launch4j_prepare() {
cd thirdparty
LAUNCH4J_TAR=`ls | grep launch4j | grep tar.gz | grep -v svn`
LAUNCH4J_DIR="launch4j"
if [ ! -d "$LAUNCH4J_DIR" ] ; then
tar xzf $LAUNCH4J_TAR || exit 1
fi
cd ..
}
get_version() {
VERSION=$1
@ -135,8 +97,6 @@ get_revision() {
INFO=`svn info`
elif [ -d ".git" ]; then
INFO=`git svn info`
elif [ -f ".revision" ]; then
REVISION=`cat .revision`
else
error "cannot obtain revision, exiting!"
fi
@ -144,6 +104,124 @@ get_revision() {
REVISION=`echo $INFO | sed 's/.*Revision: /r/' | sed 's/ .*//'`
}
get_url_file() {
return `echo $1 | sed 's|.*/||'`
}
download() {
URL=$1
DEST=$2
if [ `which curl` == "" ] && [ `which wget` == "" ]; then
error "We need either 'curl' or 'wget' present in PATH to download external dependencies."
fi
if [ `which curl` != "" ] ; then
curl -o $DEST $URL || exit 1
fi
if [ `which wget` != "" ] ; then
wget -O $DEST $URL || exit 1
fi
}
# ----------------------------------------------------------------------------------------------
build_prepare() {
if [ ! -d $GRIDWORKS_BUILD_DIR ] ; then
mkdir $GRIDWORKS_BUILD_DIR || exit 1
fi
}
dist_prepare() {
if [ ! -d $GRIDWORKS_DIST_DIR ] ; then
mkdir $GRIDWORKS_DIST_DIR || exit 1
fi
}
tools_prepare() {
if [ ! -d $GRIDWORKS_TOOLS_DIR ] ; then
mkdir $GRIDWORKS_TOOLS_DIR || exit 1
fi
}
ant_prepare() {
ANT_URL="http://www.apache.org/dist/ant/binaries/apache-ant-1.8.0-bin.tar.gz"
ANT_FILE=`echo $ANT_URL | sed 's|.*/||'`
ANT_DIR="apache-ant-1.8.0"
ANT=`which ant`
if [ $ANT == "" ] ; then
if [ $ANT_HOME == "" ] ; then
cd $GRIDWORKS_TOOLS_DIR
if [ ! -f $ANT_FILE ] ; then
download $ANT_URL $ANT_FILE
fi
if [ ! -d $ANT_DIR ] ; then
tar xzf $ANT_FILE -C . || exit 1
fi
export ANT_HOME="`pwd`/$ANT_DIR"
cd ..
fi
ANT="$ANT_HOME/bin/ant"
fi
}
launch4j_prepare() {
LAUNCH4J_URL="http://downloads.sourceforge.net/project/launch4j/launch4j-3/3.0.1/launch4j-3.0.1-macosx.tgz"
LAUNCH4J_FILE=`echo $LAUNCH4J_URL | sed 's|.*/||'`
LAUNCH4J_DIR="launch4j"
cd $GRIDWORKS_TOOLS_DIR
if [ ! -f "$LAUNCH4J_FILE" ] ; then
download $LAUNCH4J_URL $LAUNCH4J_FILE
fi
if [ ! -d "$LAUNCH4J_DIR" ] ; then
tar xzf $LAUNCH4J_FILE || exit 1
fi
cd ..
}
jarbundler_prepare() {
JARBUNDLER_URL="http://www.informagen.com/JarBundler/dist/jarbundler.tar.gz"
JARBUNDLER_FILE=`echo $JARBUNDLER_URL | sed 's|.*/||'`
JARBUNDLER_DIR="jarbundler-2.1.0"
cd $GRIDWORKS_TOOLS_DIR
if [ ! -f "$JARBUNDLER_FILE" ] ; then
download $JARBUNDLER_URL $JARBUNDLER_FILE
fi
if [ ! -d "$JARBUNDLER_DIR" ] ; then
tar xzf $JARBUNDLER_FILE || exit 1
fi
cd ..
}
findbugs_prepare() {
FINDBUGS_URL="http://downloads.sourceforge.net/project/findbugs/findbugs/1.3.9/findbugs-1.3.9.tar.gz"
FINDBUGS_FILE=`echo $FINDBUGS_URL | sed 's|.*/||'`
FINDBUGS_DIR="findbugs-1.3.9"
cd $GRIDWORKS_TOOLS_DIR
if [ ! -f "$FINDBUGS_FILE" ] ; then
download $FINDBUGS_URL $FINDBUGS_FILE
fi
if [ ! -d "$FINDBUGS_DIR" ] ; then
tar xzf $FINDBUGS_FILE || exit 1
fi
cd ..
}
# ----------------------------------------------------------------------------------------------
ant() {
ant_prepare
#export ANT_OPTS="-Xmx1024M"
$ANT -f build.xml $ANT_PARAMS -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || exit 1
}
# ----------------------------------------------------------------------------------------------
dist() {
mac_dist $1
windows_dist $1
@ -172,6 +250,7 @@ windows_dist() {
get_version $1
get_revision
ANT_PARAMS="-Dlaunch4j.dir=${GRIDWORKS_TOOLS_DIR}/${LAUNCH4J_DIR}"
ant windows
}
@ -186,9 +265,11 @@ linux_dist() {
mac_dist() {
check_macosx
dist_prepare
jarbundler_prepare
get_version $1
get_revision
ANT_PARAMS="-Djarbundler.dir=${GRIDWORKS_TOOLS_DIR}/${JARBUNDLER_DIR}"
ant mac
mkdir -p "$GRIDWORKS_BUILD_DIR/mac/.background"
@ -276,11 +357,7 @@ run() {
if [ "$GRIDWORKS_DATA_DIR" != "" ] ; then
add_option "-Dgridworks.data_dir=$GRIDWORKS_DATA_DIR"
fi
get_revision
add_option "-Dgridworks.version=$REVISION"
CLASSPATH="$GRIDWORKS_BUILD_DIR/classes:$GRIDWORKS_LIB_DIR/*"
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks"
@ -309,6 +386,13 @@ execute() {
exec $RUN_CMD $*
}
findbugs() {
findbugs_prepare
ANT_PARAMS="-Dfindbugs.dir=${GRIDWORKS_TOOLS_DIR}/${FINDBUGS_DIR}"
ant findbugs
}
# -------------------------- script -----------------------------
# ----- Normalize the current directory -------------------------
@ -336,7 +420,7 @@ if [ ! -z "$JAVA_HOME" ] ; then
else
JAVA=`which java`
if [ -z "$JAVA" ] ; then
if [ "$SYSTEM" = 'Darwin' ] ; then
if [ "$SYSTEM" == 'Darwin' ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
else
error "The 'java' command should be in your path or the 'JAVA_HOME' environment variable should be set"
@ -411,6 +495,10 @@ if [ "$GRIDWORKS_LIB_DIR" == "" ] ; then
GRIDWORKS_LIB_DIR="lib"
fi
if [ "$GRIDWORKS_TOOLS_DIR" == "" ] ; then
GRIDWORKS_TOOLS_DIR="tools"
fi
if [ "$GRIDWORKS_DIST_DIR" == "" ] ; then
GRIDWORKS_DIST_DIR="dist"
fi
@ -418,38 +506,16 @@ fi
# ----- Respond to the action given --------------------------------------------
case "$ACTION" in
build)
ant build;;
clean)
ant clean;;
distclean)
ant distclean;;
test)
test $1;;
run)
run;;
execute)
execute $*;;
mac_dist)
mac_dist $1;;
windows_dist)
windows_dist $1;;
linux_dist)
linux_dist $1;;
dist)
dist $1;;
*)
usage; ;;
build) build_prepare; ant build;;
clean) ant clean;;
distclean) ant distclean;;
test) test $1;;
findbugs) findbugs;;
run) run;;
execute) execute $*;;
mac_dist) mac_dist $1;;
windows_dist) windows_dist $1;;
linux_dist) linux_dist $1;;
dist) dist $1;;
*) usage; ;;
esac

View File

@ -59,7 +59,7 @@ public class GridworksServlet extends HttpServlet {
private static final long serialVersionUID = 2386057901503517403L;
static protected Map<String, Command> _commands = new HashMap<String, Command>();
static final protected Map<String, Command> _commands = new HashMap<String, Command>();
// timer for periodically saving projects
static protected Timer _timer;

View File

@ -43,7 +43,7 @@ public class ProjectManager {
static public ProjectManager singleton;
static public void initialize() {
static public synchronized void initialize() {
if (singleton == null) {
File dir = getProjectLocation();
Gridworks.log("Using workspace directory: " + dir.getAbsolutePath());
@ -325,8 +325,6 @@ public class ProjectManager {
List<SaveRecord> records = new ArrayList<SaveRecord>();
Date now = new Date();
boolean gc = false;
synchronized (this) {
for (long id : _projectsMetadata.keySet()) {
ProjectMetadata metadata = _projectsMetadata.get(id);
@ -347,8 +345,6 @@ public class ProjectManager {
* modified. We can safely remove it from the cache to save some memory.
*/
_projects.remove(id);
gc = true;
}
}
}
@ -384,10 +380,6 @@ public class ProjectManager {
}
}
}
if (gc) {
System.gc();
}
}
public void deleteProject(Project project) {

View File

@ -87,10 +87,10 @@ public class NumericBinIndex {
_min = (Math.floor(_min / _step) * _step);
_max = (Math.ceil(_max / _step) * _step);
int binCount = (int) ((_max - _min) / _step);
double binCount = (_max - _min) / _step;
if (binCount > 100) {
_step *= 2;
binCount = Math.round((1 + binCount) / 2);
binCount = (binCount + 1) / 2;
}
if (_max <= originalMax) {
@ -98,7 +98,7 @@ public class NumericBinIndex {
binCount++;
}
_bins = new int[binCount];
_bins = new int[(int) Math.round(binCount)];
for (double d : allValues) {
int bin = (int) Math.floor((d - _min) / _step);
_bins[bin]++;

View File

@ -1,5 +1,6 @@
package com.metaweb.gridworks.clustering.binning;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -27,7 +28,7 @@ public class BinningClusterer extends Clusterer {
private Keyer _keyer;
static protected Map<String, Keyer> _keyers = new HashMap<String, Keyer>();
static final protected Map<String, Keyer> _keyers = new HashMap<String, Keyer>();
List<Map<String,Integer>> _clusters;
@ -65,19 +66,19 @@ public class BinningClusterer extends Clusterer {
public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) {
Cell cell = row.getCell(_colindex);
if (cell != null && cell.value != null) {
String v = cell.value.toString();
Object v = cell.value;
String s = (v instanceof String) ? ((String) v) : v.toString();
String key = _keyer.key(s,_params);
if (_map.containsKey(key)) {
Map<String,Integer> m = _map.get(key);
if (m.containsKey(v)) {
m.put(v, m.get(v) + 1);
if (m.containsKey(s)) {
m.put(s, m.get(s) + 1);
} else {
m.put(v,1);
m.put(s,1);
}
} else {
Map<String,Integer> m = new TreeMap<String,Integer>();
m.put(v,1);
m.put(s,1);
_map.put(key, m);
}
}
@ -89,7 +90,8 @@ public class BinningClusterer extends Clusterer {
}
}
public class SizeComparator implements Comparator<Map<String,Integer>> {
public static class SizeComparator implements Comparator<Map<String,Integer>>, Serializable {
private static final long serialVersionUID = -1390696157208674054L;
public int compare(Map<String,Integer> o1, Map<String,Integer> o2) {
int s1 = o1.size();
int s2 = o2.size();
@ -109,7 +111,8 @@ public class BinningClusterer extends Clusterer {
}
}
public class EntriesComparator implements Comparator<Entry<String,Integer>> {
public static class EntriesComparator implements Comparator<Entry<String,Integer>>, Serializable {
private static final long serialVersionUID = 2763378036791777964L;
public int compare(Entry<String,Integer> o1, Entry<String,Integer> o2) {
return o2.getValue() - o1.getValue();
}

View File

@ -41,7 +41,7 @@ public class kNNClusterer extends Clusterer {
private Distance _distance;
static protected Map<String, Distance> _distances = new HashMap<String, Distance>();
static final protected Map<String, Distance> _distances = new HashMap<String, Distance>();
List<Set<Serializable>> _clusters;
@ -148,7 +148,8 @@ public class kNNClusterer extends Clusterer {
_clusters = visitor.getClusters();
}
public class ValuesComparator implements Comparator<Entry<Serializable,Integer>> {
public static class ValuesComparator implements Comparator<Entry<Serializable,Integer>>, Serializable {
private static final long serialVersionUID = 204469656070583155L;
public int compare(Entry<Serializable,Integer> o1, Entry<Serializable,Integer> o2) {
return o2.getValue() - o1.getValue();
}

View File

@ -46,7 +46,7 @@ public class AnnotateOneRowCommand extends Command {
}
}
protected class StarOneRowProcess extends QuickHistoryEntryProcess {
protected static class StarOneRowProcess extends QuickHistoryEntryProcess {
final int rowIndex;
final boolean starred;

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
@ -145,7 +146,7 @@ public class CreateProjectCommand extends Command {
}
}
class SafeInputStream extends FilterInputStream {
static class SafeInputStream extends FilterInputStream {
public SafeInputStream(InputStream stream) {
super(stream);
}
@ -191,24 +192,29 @@ public class CreateProjectCommand extends Command {
// behave precisely the same, there is no polymorphic behavior so we have
// to treat each instance explicitly... one of those times you wish you had
// closures
if (is instanceof TarInputStream) {
TarInputStream tis = (TarInputStream) is;
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
if (!te.isDirectory()) {
mapExtension(te.getName(),ext_map);
}
}
} else if (is instanceof ZipInputStream) {
ZipInputStream zis = (ZipInputStream) is;
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (!ze.isDirectory()) {
mapExtension(ze.getName(),ext_map);
try {
if (is instanceof TarInputStream) {
TarInputStream tis = (TarInputStream) is;
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
if (!te.isDirectory()) {
mapExtension(te.getName(),ext_map);
}
}
} else if (is instanceof ZipInputStream) {
ZipInputStream zis = (ZipInputStream) is;
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (!ze.isDirectory()) {
mapExtension(ze.getName(),ext_map);
}
}
}
} finally {
try {
is.close();
} catch (IOException e) {}
}
is.close();
// sort extensions by how often they appear
List<Entry<String,Integer>> values = new ArrayList<Entry<String,Integer>>(ext_map.entrySet());
@ -239,32 +245,37 @@ public class CreateProjectCommand extends Command {
// second pass, load the data for real
is = getStream(fileName, new FileInputStream(file));
SafeInputStream sis = new SafeInputStream(is);
if (is instanceof TarInputStream) {
TarInputStream tis = (TarInputStream) is;
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
if (!te.isDirectory()) {
String name = te.getName();
String ext = getExtension(name)[1];
if (exts.contains(ext)) {
internalImportFile(project, options, name, sis);
}
}
}
} else if (is instanceof ZipInputStream) {
ZipInputStream zis = (ZipInputStream) is;
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (!ze.isDirectory()) {
String name = ze.getName();
String ext = getExtension(name)[1];
if (exts.contains(ext)) {
internalImportFile(project, options, name, sis);
try {
if (is instanceof TarInputStream) {
TarInputStream tis = (TarInputStream) is;
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
if (!te.isDirectory()) {
String name = te.getName();
String ext = getExtension(name)[1];
if (exts.contains(ext)) {
internalImportFile(project, options, name, sis);
}
}
}
} else if (is instanceof ZipInputStream) {
ZipInputStream zis = (ZipInputStream) is;
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (!ze.isDirectory()) {
String name = ze.getName();
String ext = getExtension(name)[1];
if (exts.contains(ext)) {
internalImportFile(project, options, name, sis);
}
}
}
}
} finally {
try {
sis.reallyClose();
} catch (IOException e) {}
}
sis.reallyClose();
} else if (fileName.endsWith(".gz")) {
internalImportFile(project, options, getExtension(fileName)[0], new GZIPInputStream(inputStream));
@ -275,7 +286,9 @@ public class CreateProjectCommand extends Command {
}
}
public class ValuesComparator implements Comparator<Entry<String,Integer>> {
public static class ValuesComparator implements Comparator<Entry<String,Integer>>, Serializable {
private static final long serialVersionUID = 8845863616149837657L;
public int compare(Entry<String,Integer> o1, Entry<String,Integer> o2) {
return o2.getValue() - o1.getValue();
}
@ -308,10 +321,8 @@ public class CreateProjectCommand extends Command {
return new TarInputStream(new GZIPInputStream(is));
} else if (fileName.endsWith(".tar.bz2")) {
return new TarInputStream(new CBZip2InputStream(is));
} else if (fileName.endsWith(".zip")) {
return new ZipInputStream(is);
} else {
return null;
return new ZipInputStream(is);
}
}
@ -328,12 +339,19 @@ public class CreateProjectCommand extends Command {
byte[] buffer = new byte[4 * 1024];
long count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
try {
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
} finally {
try {
output.close();
} catch (IOException e) {}
try {
input.close();
} catch (IOException e) {}
}
output.close();
input.close();
return count;
}

View File

@ -75,7 +75,7 @@ public class EditOneCellCommand extends Command {
}
}
protected class EditOneCellProcess extends QuickHistoryEntryProcess {
protected static class EditOneCellProcess extends QuickHistoryEntryProcess {
final int rowIndex;
final int cellIndex;
final Serializable value;

View File

@ -20,7 +20,9 @@ import com.metaweb.gridworks.exporters.XlsExporter;
import com.metaweb.gridworks.model.Project;
public class ExportRowsCommand extends Command {
static protected Map<String, Exporter> s_formatToExporter = new HashMap<String, Exporter>();
static final protected Map<String, Exporter> s_formatToExporter = new HashMap<String, Exporter>();
static {
s_formatToExporter.put("tripleloader", new TripleloaderExporter());
s_formatToExporter.put("html", new HtmlTableExporter());

View File

@ -3,6 +3,7 @@ package com.metaweb.gridworks.commands.info;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -32,9 +33,9 @@ public class GetAllProjectMetadataCommand extends Command {
writer.key("projects");
writer.object();
Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
for (Long id : m.keySet()) {
writer.key(id.toString());
m.get(id).write(writer, options);
for (Entry<Long,ProjectMetadata> e : m.entrySet()) {
writer.key(e.getKey().toString());
e.getValue().write(writer, options);
}
writer.endObject();

View File

@ -81,14 +81,14 @@ public class ReconJudgeOneCellCommand extends Command {
}
}
protected class JudgeOneCellProcess extends QuickHistoryEntryProcess {
protected static class JudgeOneCellProcess extends QuickHistoryEntryProcess {
final int rowIndex;
final int cellIndex;
final Judgment judgment;
final ReconCandidate match;
Cell newCell;
JudgeOneCellProcess(
Project project,
String briefDescription,

View File

@ -16,7 +16,7 @@ public class Get implements Function {
if (args.length > 1 && args.length <= 3) {
Object v = args[0];
Object from = args[1];
Object to = args.length == 3 ? args[2] : null;
Object to = (args.length == 3) ? args[2] : null;
if (v != null && from != null) {
if (v instanceof HasFields) {
@ -42,8 +42,7 @@ public class Get implements Function {
((Object[]) v)[start] :
ExpressionUtils.toObjectList(v).get(start));
} else {
int end = to != null && to instanceof Number ?
((Number) to).intValue() : length;
int end = (to != null && to instanceof Number) ? ((Number) to).intValue() : length;
if (end < 0) {
end = length + end;
@ -63,7 +62,7 @@ public class Get implements Function {
}
}
} else {
String s = (v instanceof String ? (String) v : v.toString());
String s = (v instanceof String) ? (String) v : v.toString();
int start = ((Number) from).intValue();
if (start < 0) {

View File

@ -15,7 +15,7 @@ public class Slice implements Function {
if (args.length > 1 && args.length <= 3) {
Object v = args[0];
Object from = args[1];
Object to = args.length == 3 ? args[2] : null;
Object to = (args.length == 3) ? args[2] : null;
if (v != null && from != null && from instanceof Number && (to == null || to instanceof Number)) {
if (v.getClass().isArray() || v instanceof List<?>) {
@ -24,8 +24,7 @@ public class Slice implements Function {
ExpressionUtils.toObjectList(v).size();
int start = ((Number) from).intValue();
int end = to != null && to instanceof Number ?
((Number) to).intValue() : length;
int end = (to != null && to instanceof Number) ? ((Number) to).intValue() : length;
if (start < 0) {
start = length + start;
@ -47,7 +46,7 @@ public class Slice implements Function {
return ExpressionUtils.toObjectList(v).subList(start, end);
}
} else {
String s = (v instanceof String ? (String) v : v.toString());
String s = (v instanceof String) ? (String) v : v.toString();
int start = ((Number) from).intValue();
if (start < 0) {

View File

@ -44,6 +44,7 @@ public class ChangeSequence implements Change {
static public Change load(LineNumberReader reader) throws Exception {
String line = reader.readLine();
if (line == null) line = "";
int equal = line.indexOf('=');
assert "count".equals(line.substring(0, equal));

View File

@ -196,10 +196,12 @@ public class Project {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
Row row = Row.load(reader.readLine());
project.rows.add(row);
maxCellCount = Math.max(maxCellCount, row.cells.size());
line = reader.readLine();
if (line != null) {
Row row = Row.load(line);
project.rows.add(row);
maxCellCount = Math.max(maxCellCount, row.cells.size());
}
}
}
}

View File

@ -15,6 +15,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields;
public class Recon implements HasFields, Jsonizable {
static public enum Judgment {
None,
Matched,
@ -41,16 +42,14 @@ public class Recon implements HasFields, Jsonizable {
}
}
static public int Feature_typeMatch = 0;
static public int Feature_nameMatch = 1;
static public int Feature_nameLevenshtein = 2;
static public int Feature_nameWordDistance = 3;
static public int Feature_max = 4;
static final public int Feature_typeMatch = 0;
static final public int Feature_nameMatch = 1;
static final public int Feature_nameLevenshtein = 2;
static final public int Feature_nameWordDistance = 3;
static final public int Feature_max = 4;
static protected Map<String, Integer> s_featureMap;
static final protected Map<String, Integer> s_featureMap = new HashMap<String, Integer>();
static {
s_featureMap = new HashMap<String, Integer>();
s_featureMap.put("typeMatch", Feature_typeMatch);
s_featureMap.put("nameMatch", Feature_nameMatch);
s_featureMap.put("nameLevenshtein", Feature_nameLevenshtein);

View File

@ -4,6 +4,7 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Map.Entry;
import org.json.JSONArray;
import org.json.JSONException;
@ -134,9 +135,9 @@ public class Row implements HasFields, Jsonizable {
if (options.containsKey("extra")) {
Properties extra = (Properties) options.get("extra");
if (extra != null) {
for (Object key : extra.keySet()) {
writer.key((String) key);
writer.value(extra.get(key));
for (Entry<Object,Object> e : extra.entrySet()) {
writer.key((String) e.getKey());
writer.value(e.getValue());
}
}
}
@ -194,7 +195,7 @@ public class Row implements HasFields, Jsonizable {
}
protected class Record implements HasFields {
protected static class Record implements HasFields {
final int _recordRowIndex;
final int _currentRowIndex;
@ -211,7 +212,7 @@ public class Row implements HasFields, Jsonizable {
}
}
protected class RecordCells implements HasFields {
protected static class RecordCells implements HasFields {
final int _recordRowIndex;
protected RecordCells(int recordRowIndex) {
@ -247,8 +248,9 @@ public class Row implements HasFields, Jsonizable {
}
}
protected class CellTuple extends ArrayList<Cell> implements HasFields {
private static final long serialVersionUID = -651032866647686293L;
protected static class CellTuple extends ArrayList<Cell> implements HasFields {
private static final long serialVersionUID = -651032866647686293L;
public Object getField(String name, Properties bindings) {
Object[] r = new Object[this.size()];

View File

@ -94,7 +94,10 @@ public class ColumnAdditionChange extends ColumnChange {
newCells = new ArrayList<CellAtRow>(newCellCount);
for (int i = 0; i < newCellCount; i++) {
newCells.add(CellAtRow.load(line = reader.readLine()));
line = reader.readLine();
if (line != null) {
newCells.add(CellAtRow.load(line));
}
}
}
}

View File

@ -87,7 +87,10 @@ public class ColumnRemovalChange extends ColumnChange {
oldCells = new CellAtRow[oldCellCount];
for (int i = 0; i < oldCellCount; i++) {
oldCells[i] = CellAtRow.load(line = reader.readLine());
line = reader.readLine();
if (line != null) {
oldCells[i] = CellAtRow.load(line);
}
}
}
}

View File

@ -302,7 +302,9 @@ public class DataExtensionChange implements Change {
rowIndices = new ArrayList<Integer>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
rowIndices.add(Integer.parseInt(line));
if (line != null) {
rowIndices.add(Integer.parseInt(line));
}
}
} else if ("columnNameCount".equals(field)) {
int count = Integer.parseInt(value);
@ -310,7 +312,9 @@ public class DataExtensionChange implements Change {
columnNames = new ArrayList<String>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
columnNames.add(line);
if (line != null) {
columnNames.add(line);
}
}
} else if ("columnTypeCount".equals(field)) {
int count = Integer.parseInt(value);
@ -327,6 +331,8 @@ public class DataExtensionChange implements Change {
for (int i = 0; i < count; i++) {
line = reader.readLine();
if (line == null) continue;
int rowCount = Integer.parseInt(line);
Object[][] data = new Object[rowCount][];
@ -358,7 +364,9 @@ public class DataExtensionChange implements Change {
oldRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
oldRows.add(Row.load(line));
if (line != null) {
oldRows.add(Row.load(line));
}
}
} else if ("newRowCount".equals(field)) {
int count = Integer.parseInt(value);
@ -366,7 +374,9 @@ public class DataExtensionChange implements Change {
newRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
newRows.add(Row.load(line));
if (line != null) {
newRows.add(Row.load(line));
}
}
}

View File

@ -67,7 +67,9 @@ public class MassRowChange implements Change {
oldRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
oldRows.add(Row.load(line));
if (line != null) {
oldRows.add(Row.load(line));
}
}
} else if ("newRowCount".equals(field)) {
int count = Integer.parseInt(line.substring(equal + 1));
@ -75,10 +77,11 @@ public class MassRowChange implements Change {
newRows = new ArrayList<Row>(count);
for (int i = 0; i < count; i++) {
line = reader.readLine();
newRows.add(Row.load(line));
if (line != null) {
newRows.add(Row.load(line));
}
}
}
}
MassRowChange change = new MassRowChange(newRows);

View File

@ -265,8 +265,6 @@ public class HeuristicReconConfig extends ReconConfig {
e.printStackTrace();
}
System.gc();
return recons;
}
@ -361,8 +359,6 @@ public class HeuristicReconConfig extends ReconConfig {
recons.add(recon);
}
System.gc();
return recons;
}
@ -441,9 +437,8 @@ public class HeuristicReconConfig extends ReconConfig {
return common / longWords.size();
}
static protected Set<String> s_stopWords;
static final protected Set<String> s_stopWords = new HashSet<String>();
static {
s_stopWords = new HashSet<String>();
s_stopWords.add("the");
s_stopWords.add("a");
s_stopWords.add("and");

View File

@ -64,7 +64,7 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
int cellIndex = column.getCellIndex();
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
if (column == null) {
if (keyColumn == null) {
throw new Exception("No key column named " + _keyColumnName);
}
int keyCellIndex = keyColumn.getCellIndex();

View File

@ -70,7 +70,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
int cellIndex = column.getCellIndex();
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
if (column == null) {
if (keyColumn == null) {
throw new Exception("No key column named " + _keyColumnName);
}
int keyCellIndex = keyColumn.getCellIndex();

View File

@ -10,8 +10,9 @@ import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
public abstract class OperationRegistry {
static public Map<String, Class<? extends AbstractOperation>> s_opNameToClass;
static public Map<Class<? extends AbstractOperation>, String> s_opClassToName;
static final public Map<String, Class<? extends AbstractOperation>> s_opNameToClass = new HashMap<String, Class<? extends AbstractOperation>>();
static final public Map<Class<? extends AbstractOperation>, String> s_opClassToName = new HashMap<Class<? extends AbstractOperation>, String>();
static protected void register(String name, Class<? extends AbstractOperation> klass) {
s_opNameToClass.put(name, klass);
@ -19,9 +20,6 @@ public abstract class OperationRegistry {
}
static {
s_opNameToClass = new HashMap<String, Class<? extends AbstractOperation>>();
s_opClassToName = new HashMap<Class<? extends AbstractOperation>, String>();
register("recon", ReconOperation.class);
register("recon-mark-new-topics", ReconMarkNewTopicsOperation.class);
register("recon-match-best-candidates", ReconMatchBestCandidatesOperation.class);

View File

@ -90,13 +90,8 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
}
protected class AnonymousTransposedNode extends TransposedNodeWithChildren {
AnonymousNode node;
protected AnonymousTransposedNode(
AnonymousNode node
) {
this.node = node;
}
protected AnonymousTransposedNode(AnonymousNode node) { }
public String write(String subject, String predicate) {
if (children.size() == 0 || subject == null) {
@ -116,7 +111,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory
sb.append(", ");
}
sb.append("\"" + properties.get(i).id + "\": ");
sb.append(s instanceof String ? JSONObject.quote(s) : s.toString());
sb.append(JSONObject.quote(s));
}
}
sb.append(" }");

View File

@ -20,7 +20,8 @@ import org.json.JSONObject;
import org.json.JSONTokener;
public class ParsingUtilities {
static public SimpleDateFormat s_sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static final public SimpleDateFormat s_sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static public Properties parseUrlParameters(HttpServletRequest request) {
Properties options = new Properties();

View File

@ -8,7 +8,7 @@ public abstract class SignalHandler {
try {
_wrapper = new SignalHandlerWrapper(signalName, this);
} catch (Throwable e) {
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.");
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.