From 771810bc0d041c67e782649eb55ce086b45bf3d8 Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Mon, 5 Apr 2010 21:36:27 +0000 Subject: [PATCH] avoid exception if there is only one extension in the whole archive git-svn-id: http://google-refine.googlecode.com/svn/trunk@385 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/edit/CreateProjectCommand.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java index 38a347911..3cc4d577b 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java @@ -228,15 +228,19 @@ public class CreateProjectCommand extends Command { HashSet exts = new HashSet(); // find the extension that is most frequent or those who share the highest frequency value - Entry most_frequent = values.get(0); - Entry second_most_frequent = values.get(1); - if (most_frequent.getValue() > second_most_frequent.getValue()) { // we have a winner - exts.add(most_frequent.getKey()); - } else { // multiple extensions have the same frequency - int winning_frequency = most_frequent.getValue(); - for (Entry e : values) { - if (e.getValue() == winning_frequency) { - exts.add(e.getKey()); + if (values.size() == 1) { + exts.add(values.get(0).getKey()); + } else { + Entry most_frequent = values.get(0); + Entry second_most_frequent = values.get(1); + if (most_frequent.getValue() > second_most_frequent.getValue()) { // we have a winner + exts.add(most_frequent.getKey()); + } else { // multiple extensions have the same frequency + int winning_frequency = most_frequent.getValue(); + for (Entry e : values) { + if (e.getValue() == winning_frequency) { + exts.add(e.getKey()); + } } } }