@Test public void testGetApiValue() { assertEquals("value1", Pql.getApiValue(textValue1)); assertEquals(false, Pql.getApiValue(booleanValue1)); assertEquals(1L, Pql.getApiValue(numberValue1)); assertEquals(1.02, Pql.getApiValue(numberValue2)); assertEquals(-1L, Pql.getApiValue(numberValue3)); assertEquals(null, Pql.getApiValue(numberValue4)); assertEquals(null, Pql.getApiValue(numberValue5)); assertEquals(dateTime1, Pql.getApiValue(dateTimeValue1)); assertEquals(date1, Pql.getApiValue(dateValue1)); assertEquals(targeting1, Pql.getApiValue(targetingValue1)); assertNull(Pql.getApiValue(new TextValue())); }
public static Object getApiValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof NumberValue) { if (Strings.isNullOrEmpty(((NumberValue) value).getValue())) { return null; } else { try { return NumberFormat.getInstance().parse(((NumberValue) value).getValue()); } catch (ParseException e) { throw new IllegalStateException( "Received invalid number format from API: " + ((NumberValue) value).getValue()); } } } else if (value instanceof TextValue) { return ((TextValue) value).getValue(); } else if (value instanceof DateTimeValue) { return ((DateTimeValue) value).getValue(); } else if (value instanceof DateValue) { return ((DateValue) value).getValue(); } else if (value instanceof TargetingValue) { return ((TargetingValue) value).getValue(); } else if (value instanceof SetValue) { Value[] setValues = ((SetValue) value).getValues(); Set<Object> apiValue = new LinkedHashSet<Object>(); if (setValues != null) { for (Value setValue : setValues) { validateSetValueEntryForSet(getApiValue(setValue), apiValue); apiValue.add(getApiValue(setValue)); } } return apiValue; } else { throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]"); } }
Pql { public static Object getApiValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof NumberValue) { if (Strings.isNullOrEmpty(((NumberValue) value).getValue())) { return null; } else { try { return NumberFormat.getInstance().parse(((NumberValue) value).getValue()); } catch (ParseException e) { throw new IllegalStateException( "Received invalid number format from API: " + ((NumberValue) value).getValue()); } } } else if (value instanceof TextValue) { return ((TextValue) value).getValue(); } else if (value instanceof DateTimeValue) { return ((DateTimeValue) value).getValue(); } else if (value instanceof DateValue) { return ((DateValue) value).getValue(); } else if (value instanceof TargetingValue) { return ((TargetingValue) value).getValue(); } else if (value instanceof SetValue) { Value[] setValues = ((SetValue) value).getValues(); Set<Object> apiValue = new LinkedHashSet<Object>(); if (setValues != null) { for (Value setValue : setValues) { validateSetValueEntryForSet(getApiValue(setValue), apiValue); apiValue.add(getApiValue(setValue)); } } return apiValue; } else { throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]"); } } }
Pql { public static Object getApiValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof NumberValue) { if (Strings.isNullOrEmpty(((NumberValue) value).getValue())) { return null; } else { try { return NumberFormat.getInstance().parse(((NumberValue) value).getValue()); } catch (ParseException e) { throw new IllegalStateException( "Received invalid number format from API: " + ((NumberValue) value).getValue()); } } } else if (value instanceof TextValue) { return ((TextValue) value).getValue(); } else if (value instanceof DateTimeValue) { return ((DateTimeValue) value).getValue(); } else if (value instanceof DateValue) { return ((DateValue) value).getValue(); } else if (value instanceof TargetingValue) { return ((TargetingValue) value).getValue(); } else if (value instanceof SetValue) { Value[] setValues = ((SetValue) value).getValues(); Set<Object> apiValue = new LinkedHashSet<Object>(); if (setValues != null) { for (Value setValue : setValues) { validateSetValueEntryForSet(getApiValue(setValue), apiValue); apiValue.add(getApiValue(setValue)); } } return apiValue; } else { throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]"); } } private  Pql(); }
Pql { public static Object getApiValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof NumberValue) { if (Strings.isNullOrEmpty(((NumberValue) value).getValue())) { return null; } else { try { return NumberFormat.getInstance().parse(((NumberValue) value).getValue()); } catch (ParseException e) { throw new IllegalStateException( "Received invalid number format from API: " + ((NumberValue) value).getValue()); } } } else if (value instanceof TextValue) { return ((TextValue) value).getValue(); } else if (value instanceof DateTimeValue) { return ((DateTimeValue) value).getValue(); } else if (value instanceof DateValue) { return ((DateValue) value).getValue(); } else if (value instanceof TargetingValue) { return ((TargetingValue) value).getValue(); } else if (value instanceof SetValue) { Value[] setValues = ((SetValue) value).getValues(); Set<Object> apiValue = new LinkedHashSet<Object>(); if (setValues != null) { for (Value setValue : setValues) { validateSetValueEntryForSet(getApiValue(setValue), apiValue); apiValue.add(getApiValue(setValue)); } } return apiValue; } else { throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]"); } } private  Pql(); static Value createValue(Object value); static String toString(Value value); static Object getApiValue(Value value); static Object getNativeValue(Value value); static Object getCsvValue(Value value); static List<String[]> resultSetToStringArrayList(ResultSet resultSet); static String resultSetToString(ResultSet resultSet); static List<String> getColumnLabels(ResultSet resultSet); static List<String> getRowStringValues(Row row); static ResultSet combineResultSets(ResultSet first, ResultSet second); }
Pql { public static Object getApiValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof NumberValue) { if (Strings.isNullOrEmpty(((NumberValue) value).getValue())) { return null; } else { try { return NumberFormat.getInstance().parse(((NumberValue) value).getValue()); } catch (ParseException e) { throw new IllegalStateException( "Received invalid number format from API: " + ((NumberValue) value).getValue()); } } } else if (value instanceof TextValue) { return ((TextValue) value).getValue(); } else if (value instanceof DateTimeValue) { return ((DateTimeValue) value).getValue(); } else if (value instanceof DateValue) { return ((DateValue) value).getValue(); } else if (value instanceof TargetingValue) { return ((TargetingValue) value).getValue(); } else if (value instanceof SetValue) { Value[] setValues = ((SetValue) value).getValues(); Set<Object> apiValue = new LinkedHashSet<Object>(); if (setValues != null) { for (Value setValue : setValues) { validateSetValueEntryForSet(getApiValue(setValue), apiValue); apiValue.add(getApiValue(setValue)); } } return apiValue; } else { throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]"); } } private  Pql(); static Value createValue(Object value); static String toString(Value value); static Object getApiValue(Value value); static Object getNativeValue(Value value); static Object getCsvValue(Value value); static List<String[]> resultSetToStringArrayList(ResultSet resultSet); static String resultSetToString(ResultSet resultSet); static List<String> getColumnLabels(ResultSet resultSet); static List<String> getRowStringValues(Row row); static ResultSet combineResultSets(ResultSet first, ResultSet second);  }