Search in sources :

Example 51 with SetValue

use of com.google.api.ads.admanager.axis.v202105.SetValue 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()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) Value(com.google.api.ads.admanager.jaxws.v202202.Value) Date(com.google.api.ads.admanager.jaxws.v202202.Date) Test(org.junit.Test)

Example 52 with SetValue

use of com.google.api.ads.admanager.axis.v202105.SetValue 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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) Value(com.google.api.ads.admanager.jaxws.v202202.Value) Test(org.junit.Test)

Example 53 with SetValue

use of com.google.api.ads.admanager.axis.v202105.SetValue in project googleads-java-lib by googleads.

the class PqlTest method testCreateValue_commaTextSet.

@Test
public void testCreateValue_commaTextSet() {
    Set<String> textSet = new LinkedHashSet<String>();
    textSet.add("value1");
    textSet.add("comma \",\" separated");
    Value value1 = ((SetValue) Pql.createValue(textSet)).getValues().get(0);
    Value value2 = ((SetValue) Pql.createValue(textSet)).getValues().get(1);
    assertEquals("value1", ((TextValue) value1).getValue());
    assertEquals("comma \",\" separated", ((TextValue) value2).getValue());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) Value(com.google.api.ads.admanager.jaxws.v202202.Value) Test(org.junit.Test)

Example 54 with SetValue

use of com.google.api.ads.admanager.axis.v202105.SetValue in project googleads-java-lib by googleads.

the class PqlTest method testCreateValue_dateTimeSet.

@Test
public void testCreateValue_dateTimeSet() {
    Set<DateTime> dateTimeSet = new LinkedHashSet<DateTime>();
    dateTimeSet.add(dateTime1);
    Value value1 = ((SetValue) Pql.createValue(dateTimeSet)).getValues().get(0);
    assertEquals("2012-12-02T12:45:00+08:00", DateTimes.toStringWithTimeZone(((DateTimeValue) value1).getValue()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) TextValue(com.google.api.ads.admanager.jaxws.v202202.TextValue) BooleanValue(com.google.api.ads.admanager.jaxws.v202202.BooleanValue) DateTimeValue(com.google.api.ads.admanager.jaxws.v202202.DateTimeValue) NumberValue(com.google.api.ads.admanager.jaxws.v202202.NumberValue) TargetingValue(com.google.api.ads.admanager.jaxws.v202202.TargetingValue) SetValue(com.google.api.ads.admanager.jaxws.v202202.SetValue) DateValue(com.google.api.ads.admanager.jaxws.v202202.DateValue) Value(com.google.api.ads.admanager.jaxws.v202202.Value) DateTime(com.google.api.ads.admanager.jaxws.v202202.DateTime) Test(org.junit.Test)

Example 55 with SetValue

use of com.google.api.ads.admanager.axis.v202105.SetValue in project googleads-java-lib by googleads.

the class Pql method createValue.

/**
 * Creates a {@link Value} from the value i.e. a {@link TextValue} for a value of type {@code
 * String}, {@link BooleanValue} for type {@code Boolean}, {@link NumberValue} for type {@code
 * Double}, {@code Long}, or {@code Integer}, {@link DateTimeValue} for type {@link DateTime}, and
 * {@link DateValue} for type {@link Date}. If the value is a {@code Value}, the value is
 * returned. If the value is {@code null}, an empty {@link TextValue} is returned.
 *
 * @param value the value to convert
 * @return the constructed value of the appropriate type
 * @throws IllegalArgumentException if value cannot be converted
 */
public static Value createValue(Object value) {
    if (value instanceof Value) {
        return (Value) value;
    } else if (value == null) {
        return new TextValue();
    } else {
        if (value instanceof Boolean) {
            BooleanValue booleanValue = new BooleanValue();
            booleanValue.setValue((Boolean) value);
            return booleanValue;
        } else if (value instanceof Double || value instanceof Long || value instanceof Integer) {
            NumberValue numberValue = new NumberValue();
            numberValue.setValue(value.toString());
            return numberValue;
        } else if (value instanceof String) {
            TextValue textValue = new TextValue();
            textValue.setValue((String) value);
            return textValue;
        } else if (value instanceof DateTime) {
            DateTimeValue dateTimeValue = new DateTimeValue();
            dateTimeValue.setValue((DateTime) value);
            return dateTimeValue;
        } else if (value instanceof Date) {
            DateValue dateValue = new DateValue();
            dateValue.setValue((Date) value);
            return dateValue;
        } else if (value instanceof Targeting) {
            TargetingValue targetingValue = new TargetingValue();
            targetingValue.setValue((Targeting) value);
            return targetingValue;
        } else if (value instanceof Set<?>) {
            SetValue setValue = new SetValue();
            Set<Value> values = new LinkedHashSet<Value>();
            for (Object entry : (Set<?>) value) {
                validateSetValueEntryForSet(createValue(entry), values);
                values.add(createValue(entry));
            }
            setValue.setValues(values.toArray(new Value[] {}));
            return setValue;
        } else {
            throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
        }
    }
}
Also used : ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DateTimeValue(com.google.api.ads.admanager.axis.v202108.DateTimeValue) Targeting(com.google.api.ads.admanager.axis.v202108.Targeting) DateTime(com.google.api.ads.admanager.axis.v202108.DateTime) Date(com.google.api.ads.admanager.axis.v202108.Date) NumberValue(com.google.api.ads.admanager.axis.v202108.NumberValue) TextValue(com.google.api.ads.admanager.axis.v202108.TextValue) DateValue(com.google.api.ads.admanager.axis.v202108.DateValue) BooleanValue(com.google.api.ads.admanager.axis.v202108.BooleanValue) DateValue(com.google.api.ads.admanager.axis.v202108.DateValue) TargetingValue(com.google.api.ads.admanager.axis.v202108.TargetingValue) DateTimeValue(com.google.api.ads.admanager.axis.v202108.DateTimeValue) BooleanValue(com.google.api.ads.admanager.axis.v202108.BooleanValue) TextValue(com.google.api.ads.admanager.axis.v202108.TextValue) Value(com.google.api.ads.admanager.axis.v202108.Value) SetValue(com.google.api.ads.admanager.axis.v202108.SetValue) NumberValue(com.google.api.ads.admanager.axis.v202108.NumberValue) TargetingValue(com.google.api.ads.admanager.axis.v202108.TargetingValue) SetValue(com.google.api.ads.admanager.axis.v202108.SetValue)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)56 Test (org.junit.Test)40 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)8 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)8 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)8 NumberValue (com.google.api.ads.admanager.axis.v202105.NumberValue)8 SetValue (com.google.api.ads.admanager.axis.v202105.SetValue)8 TargetingValue (com.google.api.ads.admanager.axis.v202105.TargetingValue)8 TextValue (com.google.api.ads.admanager.axis.v202105.TextValue)8 BooleanValue (com.google.api.ads.admanager.axis.v202111.BooleanValue)8 DateTimeValue (com.google.api.ads.admanager.axis.v202111.DateTimeValue)8 DateValue (com.google.api.ads.admanager.axis.v202111.DateValue)8 BooleanValue (com.google.api.ads.admanager.axis.v202108.BooleanValue)6 DateTimeValue (com.google.api.ads.admanager.axis.v202108.DateTimeValue)6 DateValue (com.google.api.ads.admanager.axis.v202108.DateValue)6 NumberValue (com.google.api.ads.admanager.axis.v202108.NumberValue)6 SetValue (com.google.api.ads.admanager.axis.v202108.SetValue)6 TargetingValue (com.google.api.ads.admanager.axis.v202108.TargetingValue)6 TextValue (com.google.api.ads.admanager.axis.v202108.TextValue)6 BooleanValue (com.google.api.ads.admanager.jaxws.v202202.BooleanValue)6