// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java
// public class Response {
//     private String            mRawResponse   = null;            // The raw ELM327 response as string
//     private List<String> mResponseLines = null;            // Each array element represents a line
//     private List<ResponseFilter> mResponseFilters = null;  // Response filters
// 
//     /**
//      * Constructor
//      */
//     Response() {
//     }
// 
//     /**
//      * Sets the raw ELM327 response string
//      * @param rawResponse
//      */
//     public void setRawResponse(String rawResponse) {
//         mRawResponse = rawResponse;
//     }
// 
//     /**
//      * Adds a response filter to be executed when processing the response
//      * @param responseFilter A ResponseFilter object
//      * @return Current response object
//      */
//     public Response addResponseFilter(ResponseFilter responseFilter) {
//         if(mResponseFilters == null) {
//             mResponseFilters = new ArrayList<>();
//         }
//         mResponseFilters.add(responseFilter);
//         return this;
//     }
// 
//     /**
//      * Processes the current Response object.
//      */
//     public void process() {
//         if (mResponseLines == null) {
//             final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n");
//             mResponseLines = new ArrayList<>(Arrays.asList(lines));
//         }
// 
//         // Execute response filters (if any)
//         if(mResponseFilters != null) {
//             for(ResponseFilter filter: mResponseFilters) {
//                 filter.onResponseReceived(this);
//             }
//         }
//     }
// 
//     public List<String> getLines() {
//         return mResponseLines;
//     }
// 
//     public String rawResponse() {
//         return mRawResponse;
//     }
// 
//     public int get(int byteIndex) {
//         return get(0, byteIndex);
//     }
// 
//     public int get(int lineIndex, int byteIndex) {
//         final String line = mResponseLines.get(lineIndex);
//         final int start = byteIndex * 2;
//         return HexToInteger(line.substring(start, start + 2));
//     }
// 
//     public static int HexToInteger(String hex) {
//         return Integer.parseInt(hex, 16);
//     }
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java
// public interface ResponseFilter {
//     /**
//      *
//      * @param response
//      */
//     void onResponseReceived(Response response);
// }


import org.hexpresso.elm327.commands.Response;
import org.hexpresso.elm327.commands.ResponseFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

package org.hexpresso.elm327.commands.filters;



/**
 * Created by Pierre-Etienne Messier <pierre.etienne.messier@gmail.com> on 2015-10-25.
 */
public class RegularExpressionResponseFilter implements ResponseFilter {
    private Pattern mPattern = null;

    public RegularExpressionResponseFilter(String regularExpression) {
        mPattern = Pattern.compile(regularExpression);
    }

    public RegularExpressionResponseFilter(Pattern pattern) {
        mPattern = pattern;
    }

    @Override

// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java
// public class Response {
//     private String            mRawResponse   = null;            // The raw ELM327 response as string
//     private List<String> mResponseLines = null;            // Each array element represents a line
//     private List<ResponseFilter> mResponseFilters = null;  // Response filters
// 
//     /**
//      * Constructor
//      */
//     Response() {
//     }
// 
//     /**
//      * Sets the raw ELM327 response string
//      * @param rawResponse
//      */
//     public void setRawResponse(String rawResponse) {
//         mRawResponse = rawResponse;
//     }
// 
//     /**
//      * Adds a response filter to be executed when processing the response
//      * @param responseFilter A ResponseFilter object
//      * @return Current response object
//      */
//     public Response addResponseFilter(ResponseFilter responseFilter) {
//         if(mResponseFilters == null) {
//             mResponseFilters = new ArrayList<>();
//         }
//         mResponseFilters.add(responseFilter);
//         return this;
//     }
// 
//     /**
//      * Processes the current Response object.
//      */
//     public void process() {
//         if (mResponseLines == null) {
//             final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n");
//             mResponseLines = new ArrayList<>(Arrays.asList(lines));
//         }
// 
//         // Execute response filters (if any)
//         if(mResponseFilters != null) {
//             for(ResponseFilter filter: mResponseFilters) {
//                 filter.onResponseReceived(this);
//             }
//         }
//     }
// 
//     public List<String> getLines() {
//         return mResponseLines;
//     }
// 
//     public String rawResponse() {
//         return mRawResponse;
//     }
// 
//     public int get(int byteIndex) {
//         return get(0, byteIndex);
//     }
// 
//     public int get(int lineIndex, int byteIndex) {
//         final String line = mResponseLines.get(lineIndex);
//         final int start = byteIndex * 2;
//         return HexToInteger(line.substring(start, start + 2));
//     }
// 
//     public static int HexToInteger(String hex) {
//         return Integer.parseInt(hex, 16);
//     }
// }
// 
// Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java
// public interface ResponseFilter {
//     /**
//      *
//      * @param response
//      */
//     void onResponseReceived(Response response);
// }


// Path: app/src/main/java/org/hexpresso/elm327/commands/filters/RegularExpressionResponseFilter.java
import org.hexpresso.elm327.commands.Response;
import org.hexpresso.elm327.commands.ResponseFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

package org.hexpresso.elm327.commands.filters;



/**
 * Created by Pierre-Etienne Messier <pierre.etienne.messier@gmail.com> on 2015-10-25.
 */
public class RegularExpressionResponseFilter implements ResponseFilter {
    private Pattern mPattern = null;

    public RegularExpressionResponseFilter(String regularExpression) {
        mPattern = Pattern.compile(regularExpression);
    }

    public RegularExpressionResponseFilter(Pattern pattern) {
        mPattern = pattern;
    }

    @Override

    public void onResponseReceived(Response response) {
