package ca.ubc.ece.salt.sdjsb.analysis.prediction;

import java.util.Map;

import ca.ubc.ece.salt.sdjsb.analysis.learning.apis.Keyword;
import ca.ubc.ece.salt.sdjsb.analysis.learning.apis.TopLevelAPI;

/**
 * Abstract class to model a Predictor
 */
public abstract class Predictor {
	/** The top level API where API's are looked for */
	protected TopLevelAPI api;

	protected Map<Keyword, Integer> insertedKeywords;
	protected Map<Keyword, Integer> removedKeywords;
	protected Map<Keyword, Integer> updatedKeywords;
	protected Map<Keyword, Integer> unchangedKeywords;

	public Predictor(TopLevelAPI api, Map<Keyword, Integer> insertedKeywords, Map<Keyword, Integer> removedKeywords,
			Map<Keyword, Integer> updatedKeywords, Map<Keyword, Integer> unchangedKeywords) {
		this.api = api;
		this.insertedKeywords = insertedKeywords;
		this.removedKeywords = removedKeywords;
		this.updatedKeywords = updatedKeywords;
		this.unchangedKeywords = unchangedKeywords;

		// TODO: Look on input for PACKAGEs keywords. Those are the packages
		// there were actually imported on the file and will serve as a filter
		// on our predictions
	}

	public abstract PredictionResults predictKeyword(Keyword keyword);
}

@@ -62,19 +62,67 @@
 va.util.
-Map
+HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0Aimpor
@@ -177,16 +177,89 @@
 eyword;%0A
+import ca.ubc.ece.salt.sdjsb.analysis.learning.apis.Keyword.KeywordType;%0A
 import c
@@ -683,16 +683,195 @@
 words;%0A%0A
+%09/**%0A%09 * The %22required name%22 of packages that were actually imported on the file%0A%09 * and will serve as a filter on our predictions%0A%09 */%0A%09protected Set%3CString%3E requiredAPIsNames;%0A%0A
 %09public 
@@ -1261,15 +1261,14 @@
 %0A%09%09/
-/ TODO:
+*%0A%09%09 *
  Loo
@@ -1304,199 +1304,901 @@
 rds.
- Those are the packages%0A%09%09// there were actually imported on the file and will serve as a filter%0A%09%09// on our predictions%0A%09%7D%0A%0A%09public abstract PredictionResults predictKeyword(Keyword keyword);
+%0A%09%09 */%0A%0A%09%09requiredAPIsNames = lookupRequiredAPIs(insertedKeywords, unchangedKeywords);%0A%09%7D%0A%0A%09public abstract PredictionResults predictKeyword(Keyword keyword);%0A%0A%09/**%0A%09 * Internal method to look for KeywordType.PACKAGE keywords on the input%0A%09 */%0A%09protected Set%3CString%3E lookupRequiredAPIs(Map%3CKeyword, Integer%3E... keywordsMaps) %7B%0A%09%09Set%3CString%3E outputSet = new HashSet%3C%3E();%0A%0A%09%09/*%0A%09%09 * we assume %22global%22 is always imported%0A%09%09 */%0A%09%09outputSet.add(%22global%22);%0A%0A%09%09/*%0A%09%09 * If no input is given, just return empty list%0A%09%09 */%0A%09%09if (keywordsMaps.length == 0)%0A%09%09%09return outputSet;%0A%0A%09%09for (Map%3CKeyword, Integer%3E keywordsMap : keywordsMaps) %7B%0A%09%09%09/*%0A%09%09%09 * If null map is given, skip it%0A%09%09%09 */%0A%09%09%09if (keywordsMap == null)%0A%09%09%09%09continue;%0A%0A%09%09%09for (Keyword keyword : keywordsMap.keySet()) %7B%0A%09%09%09%09if (keyword.type.equals(KeywordType.PACKAGE))%0A%09%09%09%09%09outputSet.add(keyword.api.getName());%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return outputSet;%0A%09%7D
 %0A%7D%0A

Store on Predictor the list of "required packages"