Added getStringKey() method for when it is difficult to generate integer keys that don't collide

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2515 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2012-07-19 00:25:41 +00:00
parent 5dffd249de
commit 4cfb921082
5 changed files with 20 additions and 9 deletions

View File

@ -70,8 +70,8 @@ public class GuidBasedReconConfig extends StrictReconConfig {
String guid; String guid;
@Override @Override
public int getKey() { public String getStringKey() {
return guid.hashCode(); return guid;
} }
} }

View File

@ -70,8 +70,8 @@ public class IdBasedReconConfig extends StrictReconConfig {
String id; String id;
@Override @Override
public int getKey() { public String getStringKey() {
return id.hashCode(); return id;
} }
} }

View File

@ -81,8 +81,8 @@ public class KeyBasedReconConfig extends StrictReconConfig {
String key; String key;
@Override @Override
public int getKey() { public String getStringKey() {
return key.hashCode(); return key;
} }
} }

View File

@ -34,5 +34,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.model.recon; package com.google.refine.model.recon;
abstract public class ReconJob { abstract public class ReconJob {
abstract public int getKey(); public int getKey() {
return this.hashCode();
}
/**
* This method is added because sometimes it's hard to generate integer keys that
* are not prone to collision. If a ReconJob class cannot guarantee no collision of
* integer keys, then that class should override this new method.
*/
public String getStringKey() {
return Integer.toString(getKey());
}
} }

View File

@ -252,7 +252,7 @@ public class ReconOperation extends EngineDependentOperation {
e2.printStackTrace(); e2.printStackTrace();
} }
Map<Integer, JobGroup> jobKeyToGroup = new HashMap<Integer, JobGroup>(); Map<String, JobGroup> jobKeyToGroup = new HashMap<String, JobGroup>();
for (ReconEntry entry : _entries) { for (ReconEntry entry : _entries) {
ReconJob job = _reconConfig.createJob( ReconJob job = _reconConfig.createJob(
@ -263,7 +263,7 @@ public class ReconOperation extends EngineDependentOperation {
entry.cell entry.cell
); );
int key = job.getKey(); String key = job.getStringKey();
JobGroup group = jobKeyToGroup.get(key); JobGroup group = jobKeyToGroup.get(key);
if (group == null) { if (group == null) {
group = new JobGroup(job); group = new JobGroup(job);