// Path: src/org/forecat/shared/utils/SubIdProvider.java
// public class SubIdProvider {
// 
// 	public static class Pair {
// 		private final String l;
// 		private final SourceSegment r;
// 
// 		public Pair(String l, SourceSegment r) {
// 			this.l = l;
// 			this.r = r;
// 		}
// 	}
// 
// 	static ArrayList<Pair> subids = new ArrayList<Pair>();
// 	public static boolean isWorking = false;
// 
// 	public static void addElement(String s, SourceSegment ss) {
// 		if (isWorking)
// 			subids.add(new Pair(s, ss));
// 	}
// 
// 	public static int getSubId(String s, SourceSegment ss) {
// 		if (isWorking) {
// 			return subids.indexOf(new Pair(s, ss));
// 		}
// 		return 0;
// 	}
// 
// 	public static void clear() {
// 		subids.clear();
// 	}
// }


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeSet;
import org.forecat.shared.translation.SourceSegment;
import org.forecat.shared.utils.SubIdProvider;
import org.forecat.shared.utils.UtilsShared;
import com.google.gwt.user.client.rpc.IsSerializable;
package org.forecat.shared.suggestions;




public class SuggestionsBasic extends SuggestionsShared implements IsSerializable, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1267521779646327709L;

	@Override
	public List<SuggestionsOutput> obtainSuggestions(SuggestionsInput input,
			Map<String, List<SourceSegment>> segmentPairs, Map<String, Integer> segmentCounts) {

		// SuggestionsOutput includes a compareTo method.
		SortedSet<SuggestionsOutput> preoutput = new TreeSet<SuggestionsOutput>();
		int closerPositionWords, closerDifference, closerPositionChars, i;

		Iterator<Entry<String, List<SourceSegment>>> it = segmentPairs.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<String, List<SourceSegment>> e = it.next();

			// Search for the closest source segment that could have generated this suggestion
			closerPositionWords = -1;
			closerDifference = 0;
			closerPositionChars = 0;
			String originText = "";
			String closerId = "";
			for (SourceSegment ss : segmentPairs.get(e.getKey())) {
				if (closerPositionWords == -1) {
					closerPositionWords = ss.getPosition();
					closerDifference = Math.abs(ss.getPosition() - input.getPosition());
// Path: src/org/forecat/shared/utils/SubIdProvider.java
// public class SubIdProvider {
// 
// 	public static class Pair {
// 		private final String l;
// 		private final SourceSegment r;
// 
// 		public Pair(String l, SourceSegment r) {
// 			this.l = l;
// 			this.r = r;
// 		}
// 	}
// 
// 	static ArrayList<Pair> subids = new ArrayList<Pair>();
// 	public static boolean isWorking = false;
// 
// 	public static void addElement(String s, SourceSegment ss) {
// 		if (isWorking)
// 			subids.add(new Pair(s, ss));
// 	}
// 
// 	public static int getSubId(String s, SourceSegment ss) {
// 		if (isWorking) {
// 			return subids.indexOf(new Pair(s, ss));
// 		}
// 		return 0;
// 	}
// 
// 	public static void clear() {
// 		subids.clear();
// 	}
// }


// Path: src/org/forecat/shared/suggestions/SuggestionsBasic.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeSet;
import org.forecat.shared.translation.SourceSegment;
import org.forecat.shared.utils.SubIdProvider;
import org.forecat.shared.utils.UtilsShared;
import com.google.gwt.user.client.rpc.IsSerializable;

package org.forecat.shared.suggestions;




public class SuggestionsBasic extends SuggestionsShared implements IsSerializable, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1267521779646327709L;

	@Override
	public List<SuggestionsOutput> obtainSuggestions(SuggestionsInput input,
			Map<String, List<SourceSegment>> segmentPairs, Map<String, Integer> segmentCounts) {

		// SuggestionsOutput includes a compareTo method.
		SortedSet<SuggestionsOutput> preoutput = new TreeSet<SuggestionsOutput>();
		int closerPositionWords, closerDifference, closerPositionChars, i;

		Iterator<Entry<String, List<SourceSegment>>> it = segmentPairs.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<String, List<SourceSegment>> e = it.next();

			// Search for the closest source segment that could have generated this suggestion
			closerPositionWords = -1;
			closerDifference = 0;
			closerPositionChars = 0;
			String originText = "";
			String closerId = "";
			for (SourceSegment ss : segmentPairs.get(e.getKey())) {
				if (closerPositionWords == -1) {
					closerPositionWords = ss.getPosition();
					closerDifference = Math.abs(ss.getPosition() - input.getPosition());
					closerId = ss.getId() + "." + SubIdProvider.getSubId(e.getKey(), ss);