package org.openhab.test.habclient.command;

import android.content.Context;

import org.openhab.domain.IOpenHABWidgetControl;
import org.openhab.domain.IPopularNameProvider;
import org.openhab.domain.model.OpenHABWidget;
import org.openhab.domain.util.IRegularExpression;
import org.openhab.habclient.ApplicationMode;
import org.openhab.habclient.IRoomProvider;
import org.openhab.domain.OpenHABWidgetProvider;
import org.openhab.habclient.Room;
import org.openhab.habclient.command.CommandAnalyzer;
import org.openhab.habclient.command.CommandPhraseMatchResult;
import org.openhab.domain.command.WidgetPhraseMatchResult;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Created by Tony Alpskog in 2014.
 */
@Singleton
public class CommandAnalyzerWrapper extends CommandAnalyzer {
    @Inject
    public CommandAnalyzerWrapper(IRoomProvider roomProvider,
                                  OpenHABWidgetProvider openHABWidgetProvider, Context context,
                                  IOpenHABWidgetControl widgetControl,
                                  IRegularExpression regularExpression,
                                  IPopularNameProvider popularNameProvider) {
        super(roomProvider, openHABWidgetProvider, context, widgetControl, regularExpression, popularNameProvider);
    }

    public List<Room> getRoomsFromPhrases(ArrayList<String> speechResult, ApplicationMode applicationMode) {
        return super.getRoomsFromPhrases(speechResult, applicationMode);
    }

    public List<OpenHABWidget> getListOfWidgetsFromListOfRooms(List<Room> listOfRooms) {
        return super.getListOfWidgetsFromListOfRooms(listOfRooms);
    }

//    public List<OpenHABWidget> getUnitsFromPhrases(List<String> commandPhrases, List<Room> listOfRooms) {
//        return super.getUnitsFromPhrases(commandPhrases, listOfRooms);
//    }

    public List<OpenHABWidget> getUnitsFromPhrases(List<String> commandPhrases, List<Room> listOfRooms) {
        return super.getUnitsFromPhrases2(commandPhrases);
//        List<OpenHABWidget> resultList = new ArrayList<OpenHABWidget>();
//
//        // Fill the list view with the strings the recognizer thought it
//        // could have heard
//        List<OpenHABWidget> widgetList = new ArrayList<OpenHABWidget>();// getListOfWidgetsFromListOfRooms(listOfRooms);
////        if(widgetList.size() == 0) {
//            widgetList = habApplication.getOpenHABWidgetProvider2().getWidgetList((Set<OpenHABWidgetType>) null);
////        }
//        //Create widget name Map
//        Iterator<OpenHABWidget> iterator = widgetList.iterator();
//        Map<String, OpenHABWidget> widgetNameMap = new HashMap<String, OpenHABWidget>();
//        while (iterator.hasNext()) {
//            OpenHABWidget nextWidget = iterator.next();
//            widgetNameMap.put(/*nextWidget.hasItem()? nextWidget.getItem().getName() : */getPopularNameFromWidgetLabel(nextWidget.getLabel()).toUpperCase(), nextWidget);
//        }
//
//        //Look for match
//        for(String match : commandPhrases.toArray(new String[0])) {
////            OpenHABWidget foundWidget = widgetNameMap.get(match.toUpperCase());
////            resultList.add(foundWidget);
//            for(String unitName : widgetNameMap.keySet().toArray(new String[0])) {
//                if (match.toUpperCase().contains(unitName)) {
//                    //Got a unit match.
//                    OpenHABWidget foundWidget = widgetNameMap.get(unitName);
//                    resultList.add(foundWidget);
//                    Log.d(habApplication.getLogTag(), "Found unit in command phrase <" + foundWidget.getLabel() + ">");
//                }
//            }
//        }
//
//        return resultList;
    }

//    public List<OpenHABWidget> getUnitsFromPhrases(HABApplication habApplication, List<String> commandPhrases) {
//        List<OpenHABWidget> resultList = new ArrayList<OpenHABWidget>();
//
//        // Fill the list view with the strings the recognizer thought it
//        // could have heard
//        List<OpenHABWidget> widgetList = getListOfWidgetsFromListOfRooms(listOfRooms);
//        if(widgetList.size() == 0) {
//            widgetList = habApplication.getOpenHABWidgetProvider2().getWidgetList((Set<OpenHABWidgetType>) null);
//        }
//        //Create widget name Map
//        Iterator<OpenHABWidget> iterator = widgetList.iterator();
//        Map<String, OpenHABWidget> widgetNameMap = new HashMap<String, OpenHABWidget>();
//        while (iterator.hasNext()) {
//            OpenHABWidget nextWidget = iterator.next();
//            widgetNameMap.put(/*nextWidget.hasItem()? nextWidget.getItem().getName() : */getPopularNameFromWidgetLabel(nextWidget.getLabel()).toUpperCase(), nextWidget);
//        }
//
//        //Look for match
//        for(String match : commandPhrases.toArray(new String[0])) {
////            OpenHABWidget foundWidget = widgetNameMap.get(match.toUpperCase());
////            resultList.add(foundWidget);
//            for(String unitName : widgetNameMap.keySet().toArray(new String[0])) {
//                if (match.toUpperCase().contains(unitName)) {
//                    //Got a unit match.
//                    OpenHABWidget foundWidget = widgetNameMap.get(unitName);
//                    resultList.add(foundWidget);
//                    Log.d(habApplication.getLogTag(), "Found unit in command phrase <" + foundWidget.getLabel() + ">");
//                }
//            }
//        }
//
//        return resultList;
//    }

    @Override
    public Map<CommandPhraseMatchResult, WidgetPhraseMatchResult> getHighestWidgetsFromCommandMatchResult(List<CommandPhraseMatchResult> listOfCommandResult) {
        return super.getHighestWidgetsFromCommandMatchResult(listOfCommandResult);
    }

    @Override
    public String getRegExMatch(String source, Pattern pattern) {
        return super.getRegExMatch(source, pattern);
    }
}

@@ -1770,3857 +1770,173 @@
  %7D%0A%0A
-//    public List%3COpenHABWidget%3E getUnitsFromPhrases(List%3CString%3E commandPhrases, List%3CRoom%3E listOfRooms) %7B%0A//        return super.getUnitsFromPhrases(commandPhrases, listOfRooms);%0A//    %7D%0A%0A    public List%3COpenHABWidget%3E getUnitsFromPhrases(List%3CString%3E commandPhrases, List%3CRoom%3E listOfRooms) %7B%0A        return super.getUnitsFromPhrases2(commandPhrases);%0A//        List%3COpenHABWidget%3E resultList = new ArrayList%3COpenHABWidget%3E();%0A//%0A//        // Fill the list view with the strings the recognizer thought it%0A//        // could have heard%0A//        List%3COpenHABWidget%3E widgetList = new ArrayList%3COpenHABWidget%3E();// getListOfWidgetsFromListOfRooms(listOfRooms);%0A////        if(widgetList.size() == 0) %7B%0A//            widgetList = habApplication.getOpenHABWidgetProvider2().getWidgetList((Set%3COpenHABWidgetType%3E) null);%0A////        %7D%0A//        //Create widget name Map%0A//        Iterator%3COpenHABWidget%3E iterator = widgetList.iterator();%0A//        Map%3CString, OpenHABWidget%3E widgetNameMap = new HashMap%3CString, OpenHABWidget%3E();%0A//        while (iterator.hasNext()) %7B%0A//            OpenHABWidget nextWidget = iterator.next();%0A//            widgetNameMap.put(/*nextWidget.hasItem()? nextWidget.getItem().getName() : */getPopularNameFromWidgetLabel(nextWidget.getLabel()).toUpperCase(), nextWidget);%0A//        %7D%0A//%0A//        //Look for match%0A//        for(String match : commandPhrases.toArray(new String%5B0%5D)) %7B%0A////            OpenHABWidget foundWidget = widgetNameMap.get(match.toUpperCase());%0A////            resultList.add(foundWidget);%0A//            for(String unitName : widgetNameMap.keySet().toArray(new String%5B0%5D)) %7B%0A//                if (match.toUpperCase().contains(unitName)) %7B%0A//                    //Got a unit match.%0A//                    OpenHABWidget foundWidget = widgetNameMap.get(unitName);%0A//                    resultList.add(foundWidget);%0A//                    Log.d(habApplication.getLogTag(), %22Found unit in command phrase %3C%22 + foundWidget.getLabel() + %22%3E%22);%0A//                %7D%0A//            %7D%0A//        %7D%0A//%0A//        return resultList;%0A    %7D%0A%0A//    public List%3COpenHABWidget%3E getUnitsFromPhrases(HABApplication habApplication, List%3CString%3E commandPhrases) %7B%0A//        List%3COpenHABWidget%3E resultList = new ArrayList%3COpenHABWidget%3E();%0A//%0A//        // Fill the list view with the strings the recognizer thought it%0A//        // could have heard%0A//        List%3COpenHABWidget%3E widgetList = getListOfWidgetsFromListOfRooms(listOfRooms);%0A//        if(widgetList.size() == 0) %7B%0A//            widgetList = habApplication.getOpenHABWidgetProvider2().getWidgetList((Set%3COpenHABWidgetType%3E) null);%0A//        %7D%0A//        //Create widget name Map%0A//        Iterator%3COpenHABWidget%3E iterator = widgetList.iterator();%0A//        Map%3CString, OpenHABWidget%3E widgetNameMap = new HashMap%3CString, OpenHABWidget%3E();%0A//        while (iterator.hasNext()) %7B%0A//            OpenHABWidget nextWidget = iterator.next();%0A//            widgetNameMap.put(/*nextWidget.hasItem()? nextWidget.getItem().getName() : */getPopularNameFromWidgetLabel(nextWidget.getLabel()).toUpperCase(), nextWidget);%0A//        %7D%0A//%0A//        //Look for match%0A//        for(String match : commandPhrases.toArray(new String%5B0%5D)) %7B%0A////            OpenHABWidget foundWidget = widgetNameMap.get(match.toUpperCase());%0A////            resultList.add(foundWidget);%0A//            for(String unitName : widgetNameMap.keySet().toArray(new String%5B0%5D)) %7B%0A//                if (match.toUpperCase().contains(unitName)) %7B%0A//                    //Got a unit match.%0A//                    OpenHABWidget foundWidget = widgetNameMap.get(unitName);%0A//                    resultList.add(foundWidget);%0A//                    Log.d(habApplication.getLogTag(), %22Found unit in command phrase %3C%22 + foundWidget.getLabel() + %22%3E%22);%0A//                %7D%0A//            %7D%0A//        %7D%0A//%0A//        return resultList;%0A//
+    public List%3COpenHABWidget%3E getUnitsFromPhrases(List%3CString%3E commandPhrases, List%3CRoom%3E listOfRooms) %7B%0A        return super.getUnitsFromPhrases2(commandPhrases);%0A
     

Remove commented out code