// Path: src/com/openxc/openxcdiagnostic/util/MessageAnalyzer.java
// public class MessageAnalyzer {
// 
//     public static boolean isCommand(VehicleMessage msg) {
//         return msg instanceof Command;
//     }
// 
//     public static boolean isDiagnosticRequest(VehicleMessage msg) {
//         return msg instanceof DiagnosticRequest;
//     }
// 
//     public static boolean isDiagnosticResponse(VehicleMessage msg) {
//         return msg instanceof DiagnosticResponse;
//     }
// 
//     public static boolean isCommandResponse(VehicleMessage msg) {
//         return msg instanceof CommandResponse;
//     }
// 
//     public static boolean canBeSent(VehicleMessage msg) {
//         return isDiagnosticRequest(msg) || isCommand(msg);
//     }
// 
//     /**
//      * Determines if the given messages have equal bus, mode, and pid.
//      * 
//      * @param msg1
//      * @param msg2
//      * @return
//      */
//     public static boolean exactMatchExceptId(DiagnosticMessage msg1,
//             DiagnosticMessage msg2) {
//         return msg1.getBusId() == msg2.getBusId()
//                 && msg1.getMode() == msg2.getMode()
//                 && msg1.getPid() == msg2.getPid();
//     }
// 
//     /**
//      * Finds a matching <code>KeyedMessage</code> in <code>arr</code>. Matching
//      * is determined by matcher.matches(KeyedMessage)
//      * 
//      * @param matcher
//      * @param arr
//      * @return
//      */
//     public static VehicleMessage findMatching(ExactKeyMatcher matcher,
//             ArrayList<? extends KeyedMessage> arr) {
// 
//         if (matcher != null) {
//             for (int i = 0; i < arr.size(); i++) {
//                 KeyedMessage request = arr.get(i);
//                 if (matcher.matches(request)) {
//                     return request;
//                 }
//             }
//         }
//         return null;
//     }
// 
// }


import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.openxc.messages.Command;
import com.openxc.messages.DiagnosticRequest;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.util.MessageAnalyzer;
package com.openxc.openxcdiagnostic.diagnostic;




/**
 * 
 * Manager for storing favorite requests and commands.
 * 
 */
public class FavoritesManager {

    private static String TAG = "DiagnosticFavoritesManager";

    private static ArrayList<DiagnosticRequest> sFavoriteRequests;
    private static ArrayList<Command> sFavoriteCommands;
    private static SharedPreferences sPreferences;

    // Don't like having to pass in a context to a static class on init, but
    // advantageous this way so you can access favorites from any class.
    public static void init(DiagnosticActivity context) {
        sPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        sFavoriteRequests = loadFavoriteRequests();
        sFavoriteCommands = loadFavoriteCommands();
    }

    /**
     * Add the given <code>req</code> to favorites. The method will decide
     * whether it should be added as a <code>DiagnosticRequest</code> or a
     * <code>Command</code>.
     * 
     * @param req
     *            The request/command to add.
     */
    public static void add(VehicleMessage req) {
// Path: src/com/openxc/openxcdiagnostic/util/MessageAnalyzer.java
// public class MessageAnalyzer {
// 
//     public static boolean isCommand(VehicleMessage msg) {
//         return msg instanceof Command;
//     }
// 
//     public static boolean isDiagnosticRequest(VehicleMessage msg) {
//         return msg instanceof DiagnosticRequest;
//     }
// 
//     public static boolean isDiagnosticResponse(VehicleMessage msg) {
//         return msg instanceof DiagnosticResponse;
//     }
// 
//     public static boolean isCommandResponse(VehicleMessage msg) {
//         return msg instanceof CommandResponse;
//     }
// 
//     public static boolean canBeSent(VehicleMessage msg) {
//         return isDiagnosticRequest(msg) || isCommand(msg);
//     }
// 
//     /**
//      * Determines if the given messages have equal bus, mode, and pid.
//      * 
//      * @param msg1
//      * @param msg2
//      * @return
//      */
//     public static boolean exactMatchExceptId(DiagnosticMessage msg1,
//             DiagnosticMessage msg2) {
//         return msg1.getBusId() == msg2.getBusId()
//                 && msg1.getMode() == msg2.getMode()
//                 && msg1.getPid() == msg2.getPid();
//     }
// 
//     /**
//      * Finds a matching <code>KeyedMessage</code> in <code>arr</code>. Matching
//      * is determined by matcher.matches(KeyedMessage)
//      * 
//      * @param matcher
//      * @param arr
//      * @return
//      */
//     public static VehicleMessage findMatching(ExactKeyMatcher matcher,
//             ArrayList<? extends KeyedMessage> arr) {
// 
//         if (matcher != null) {
//             for (int i = 0; i < arr.size(); i++) {
//                 KeyedMessage request = arr.get(i);
//                 if (matcher.matches(request)) {
//                     return request;
//                 }
//             }
//         }
//         return null;
//     }
// 
// }


// Path: src/com/openxc/openxcdiagnostic/diagnostic/FavoritesManager.java
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.openxc.messages.Command;
import com.openxc.messages.DiagnosticRequest;
import com.openxc.messages.VehicleMessage;
import com.openxc.openxcdiagnostic.util.MessageAnalyzer;

package com.openxc.openxcdiagnostic.diagnostic;




/**
 * 
 * Manager for storing favorite requests and commands.
 * 
 */
public class FavoritesManager {

    private static String TAG = "DiagnosticFavoritesManager";

    private static ArrayList<DiagnosticRequest> sFavoriteRequests;
    private static ArrayList<Command> sFavoriteCommands;
    private static SharedPreferences sPreferences;

    // Don't like having to pass in a context to a static class on init, but
    // advantageous this way so you can access favorites from any class.
    public static void init(DiagnosticActivity context) {
        sPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        sFavoriteRequests = loadFavoriteRequests();
        sFavoriteCommands = loadFavoriteCommands();
    }

    /**
     * Add the given <code>req</code> to favorites. The method will decide
     * whether it should be added as a <code>DiagnosticRequest</code> or a
     * <code>Command</code>.
     * 
     * @param req
     *            The request/command to add.
     */
    public static void add(VehicleMessage req) {
        if (MessageAnalyzer.isDiagnosticRequest(req)) {