// Path: sense-android-library/src/nl/sense_os/service/constants/SensorData.java
// public static class DataPoint implements BaseColumns {
// 
//     public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
//             + "/vnd.sense_os.data_point";
//     public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
//             + "/vnd.sense_os.data_point";
//     public static final String CONTENT_URI_PATH = "/recent_values";
//     @Deprecated
//     public static final String CONTENT_PERSISTED_URI_PATH = "/persisted_values";
//     public static final String CONTENT_REMOTE_URI_PATH = "/remote_values";
// 
//     /**
//      * The name of the sensor that generated the data point. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String SENSOR_NAME = "sensor_name";
//     /**
//      * Description of the sensor that generated the data point. Can either be the hardware name,
//      * or any other useful description. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String SENSOR_DESCRIPTION = "sensor_description";
//     /**
//      * The data type of the data point. <br>
//      * <br>
//      * TYPE: String
//      * 
//      * @see SenseDataTypes
//      */
//     public static final String DATA_TYPE = "data_type";
//     /**
//      * The human readable display name of the sensor that generated the data point. <br>
//      * <br>
//      * TYPE: String
//      * 
//      * @see SenseDataTypes
//      */
//     public static final String DISPLAY_NAME = "display_name";
//     /**
//      * Time stamp for the data point, in milliseconds. <br>
//      * <br>
//      * TYPE: long
//      */
//     public static final String TIMESTAMP = "timestamp";
//     /**
//      * Data point value. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String VALUE = "value";
//     /**
//      * Transmit state of the data point, signalling whether the point has been sent to
//      * CommonSense already.<br>
//      * <br>
//      * TYPE: integer status code: 0 (not sent), or 1 (sent)
//      */
//     public static final String TRANSMIT_STATE = "transmit_state";
//     /**
//      * Device UUID of the sensor. Use this for sensors that are originated from
//      * "external sensors", or leave <code>null</code> to use the phone as default device.<br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String DEVICE_UUID = "device_uuid";
// 
//     private DataPoint() {
//         // class should not be instantiated
//     }
// }


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import nl.sense_os.service.constants.SensorData.DataPoint;
/**************************************************************************************************
 * Copyright (C) 2010 Sense Observation Systems, Rotterdam, the Netherlands. All rights reserved. *
 *************************************************************************************************/
package nl.sense_os.service.storage;



/**
 * Hacky solution for parsing SQL-like queries on the LocalStorage. Normal ContentProviders will not
 * need this class because they can handle these queries themselves, but our {@link LocalStorage}
 * class does not.
 * 
 * @author Steven Mulder <steven@sense-os.nl>
 * @see LocalStorage
 */
public class ParserUtils {

    @SuppressWarnings("unused")
    private static final String TAG = "ParserUtils";

    private static String fixCompareSigns(String s) {
		String result = s.replaceAll(" = ", "=");
		result = result.replaceAll("= ", "=");
		result = result.replaceAll(" =", "=");
		result = result.replaceAll(" > ", ">");
		result = result.replaceAll("> ", ">");
		result = result.replaceAll(" >", ">");
		result = result.replaceAll(" < ", "<");
		result = result.replaceAll("< ", "<");
		result = result.replaceAll(" <", "<");
		result = result.replaceAll(" != ", "!=");
		result = result.replaceAll("!= ", "!=");
		result = result.replaceAll(" !=", "!=");
		return result;
    }

    public static String getSelectedDeviceUuid(String selection, String[] selectionArgs) {
	String deviceUuid = null;
// Path: sense-android-library/src/nl/sense_os/service/constants/SensorData.java
// public static class DataPoint implements BaseColumns {
// 
//     public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
//             + "/vnd.sense_os.data_point";
//     public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
//             + "/vnd.sense_os.data_point";
//     public static final String CONTENT_URI_PATH = "/recent_values";
//     @Deprecated
//     public static final String CONTENT_PERSISTED_URI_PATH = "/persisted_values";
//     public static final String CONTENT_REMOTE_URI_PATH = "/remote_values";
// 
//     /**
//      * The name of the sensor that generated the data point. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String SENSOR_NAME = "sensor_name";
//     /**
//      * Description of the sensor that generated the data point. Can either be the hardware name,
//      * or any other useful description. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String SENSOR_DESCRIPTION = "sensor_description";
//     /**
//      * The data type of the data point. <br>
//      * <br>
//      * TYPE: String
//      * 
//      * @see SenseDataTypes
//      */
//     public static final String DATA_TYPE = "data_type";
//     /**
//      * The human readable display name of the sensor that generated the data point. <br>
//      * <br>
//      * TYPE: String
//      * 
//      * @see SenseDataTypes
//      */
//     public static final String DISPLAY_NAME = "display_name";
//     /**
//      * Time stamp for the data point, in milliseconds. <br>
//      * <br>
//      * TYPE: long
//      */
//     public static final String TIMESTAMP = "timestamp";
//     /**
//      * Data point value. <br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String VALUE = "value";
//     /**
//      * Transmit state of the data point, signalling whether the point has been sent to
//      * CommonSense already.<br>
//      * <br>
//      * TYPE: integer status code: 0 (not sent), or 1 (sent)
//      */
//     public static final String TRANSMIT_STATE = "transmit_state";
//     /**
//      * Device UUID of the sensor. Use this for sensors that are originated from
//      * "external sensors", or leave <code>null</code> to use the phone as default device.<br>
//      * <br>
//      * TYPE: String
//      */
//     public static final String DEVICE_UUID = "device_uuid";
// 
//     private DataPoint() {
//         // class should not be instantiated
//     }
// }


// Path: sense-android-library/src/nl/sense_os/service/storage/ParserUtils.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import nl.sense_os.service.constants.SensorData.DataPoint;

/**************************************************************************************************
 * Copyright (C) 2010 Sense Observation Systems, Rotterdam, the Netherlands. All rights reserved. *
 *************************************************************************************************/
package nl.sense_os.service.storage;



/**
 * Hacky solution for parsing SQL-like queries on the LocalStorage. Normal ContentProviders will not
 * need this class because they can handle these queries themselves, but our {@link LocalStorage}
 * class does not.
 * 
 * @author Steven Mulder <steven@sense-os.nl>
 * @see LocalStorage
 */
public class ParserUtils {

    @SuppressWarnings("unused")
    private static final String TAG = "ParserUtils";

    private static String fixCompareSigns(String s) {
		String result = s.replaceAll(" = ", "=");
		result = result.replaceAll("= ", "=");
		result = result.replaceAll(" =", "=");
		result = result.replaceAll(" > ", ">");
		result = result.replaceAll("> ", ">");
		result = result.replaceAll(" >", ">");
		result = result.replaceAll(" < ", "<");
		result = result.replaceAll("< ", "<");
		result = result.replaceAll(" <", "<");
		result = result.replaceAll(" != ", "!=");
		result = result.replaceAll("!= ", "!=");
		result = result.replaceAll(" !=", "!=");
		return result;
    }

    public static String getSelectedDeviceUuid(String selection, String[] selectionArgs) {
	String deviceUuid = null;
	if (selection != null && selection.contains(DataPoint.DEVICE_UUID)) {