use of com.google.api.ads.admanager.axis.v202111.Targeting in project googleads-java-lib by googleads.
the class GetAllTargetingPresets method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the TargetingPresetService.
TargetingPresetServiceInterface targetingPresetService = adManagerServices.get(session, TargetingPresetServiceInterface.class);
// Create a statement to get all targeting presets.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get targeting presets by statement.
TargetingPresetPage page = targetingPresetService.getTargetingPresetsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (TargetingPreset targetingPreset : page.getResults()) {
System.out.printf("%d) Targeting preset with ID %d and name '%s' was found.%n", i++, targetingPreset.getId(), targetingPreset.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202111.Targeting 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}, and {@link DateTimeValue} for type {@link DateTime}.
* 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.getValues().addAll(values);
return setValue;
} else {
throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
}
}
}
use of com.google.api.ads.admanager.axis.v202111.Targeting 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}, and {@link DateTimeValue} for type {@link DateTime}.
* 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.getValues().addAll(values);
return setValue;
} else {
throw new IllegalArgumentException("Unsupported Value type [" + value.getClass() + "]");
}
}
}
use of com.google.api.ads.admanager.axis.v202111.Targeting 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() + "]");
}
}
}
use of com.google.api.ads.admanager.axis.v202111.Targeting 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() + "]");
}
}
}
Aggregations