use of com.google.api.ads.admanager.jaxws.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_textSet.
@Test
public void testCreateValue_textSet() {
Set<String> textSet = new LinkedHashSet<String>();
textSet.add("value1");
Value value1 = ((SetValue) Pql.createValue(textSet)).getValues().get(0);
assertEquals("value1", ((TextValue) value1).getValue());
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_dateSet.
@Test
public void testCreateValue_dateSet() {
Set<Date> numberSet = new LinkedHashSet<Date>();
numberSet.add(date1);
Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues().get(0);
assertEquals("2012-12-02", DateTimes.toString(((DateValue) value1).getValue()));
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project googleads-java-lib by googleads.
the class Pql method getApiValue.
/**
* Gets the underlying value of the {@code Value} object that's comparable to what would be
* returned in any other API object (i.e. DateTimeValue will return an API DateTime, not a Joda
* DateTime).
*
* @param value the value to convert
* @return the native value of {@code Value} or {@code null} if the underlying value is null
* @throws IllegalArgumentException if value cannot be converted
*/
public static Object getApiValue(Value value) {
if (value instanceof BooleanValue) {
return ((BooleanValue) value).isValue();
} else if (value instanceof NumberValue) {
if (((NumberValue) value).getValue() == null) {
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) {
List<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() + "]");
}
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_numberSet.
@Test
public void testCreateValue_numberSet() {
Set<Long> numberSet = new LinkedHashSet<Long>();
numberSet.add(1L);
Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues(0);
assertEquals("1", ((NumberValue) value1).getValue());
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_textSet.
@Test
public void testCreateValue_textSet() {
Set<String> textSet = new LinkedHashSet<String>();
textSet.add("value1");
Value value1 = ((SetValue) Pql.createValue(textSet)).getValues(0);
assertEquals("value1", ((TextValue) value1).getValue());
}
Aggregations