use of com.google.api.ads.adwords.jaxws.v201809.cm.Predicate in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testPredicatesInBuild.
/**
* Tests the predicate with the IN clause.
*/
@Test
public void testPredicatesInBuild() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.in(CampaignField.Status, CampaignStatus.ENABLED.toString(), CampaignStatus.REMOVED.toString());
Selector selector = builder.build();
assertNotNull(selector.getPredicates());
assertEquals(1, selector.getPredicates().length);
Predicate predicate = selector.getPredicates()[0];
assertEquals("Status", predicate.getField());
assertEquals(PredicateOperator.IN, predicate.getOperator());
assertNotNull(predicate.getValues());
assertEquals(2, predicate.getValues().length);
assertEquals(CampaignStatus.ENABLED.toString(), predicate.getValues()[0]);
assertEquals(CampaignStatus.REMOVED.toString(), predicate.getValues()[1]);
checkUtilitiesState(true);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Predicate in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testUniqueInternalPredicateState.
/**
* Tests that the built selectors don't share internal Predicate state.
*/
@Test
public void testUniqueInternalPredicateState() {
SelectorBuilder builder = new SelectorBuilder();
Selector selectorOne = builder.equals("Id", "test").build();
Selector selectorTwo = builder.build();
Predicate predicateTwo = selectorTwo.getPredicates(0);
predicateTwo.setField("Status");
assertEquals("Id", selectorOne.getPredicates(0).getField());
assertEquals("Status", selectorTwo.getPredicates(0).getField());
checkUtilitiesState(false);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Predicate in project googleads-java-lib by googleads.
the class SelectorBuilderImpl method multipleValuePredicate.
/**
* Adds a predicate for the specified field, property values, and operator.
*/
private SelectorBuilderImpl multipleValuePredicate(String field, String[] propertyValues, PredicateOperator operator) {
if (propertyValues == null) {
return this;
}
Predicate predicate = new Predicate();
predicate.setOperator(operator);
predicate.setField(field);
String[] values = Arrays.copyOf(propertyValues, propertyValues.length);
predicate.setValues(values);
this.predicates.add(predicate);
return this;
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Predicate in project googleads-java-lib by googleads.
the class SelectorBuilderImpl method copyPredicatesSet.
/**
* Copies the whole set of predicates, by creating new instances of each one in the given set.
*
* @return the new set of Predicate objects with different instance for each of the Predicate
*/
private Set<Predicate> copyPredicatesSet() {
Set<Predicate> predicatesCopy = Sets.newLinkedHashSet();
for (Predicate predicate : this.predicates) {
Predicate copyPredicate = new Predicate();
copyPredicate.setField(predicate.getField());
copyPredicate.setOperator(predicate.getOperator());
copyPredicate.setValues(Arrays.copyOf(predicate.getValues(), predicate.getValues().length));
predicatesCopy.add(copyPredicate);
}
return predicatesCopy;
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Predicate in project googleads-java-lib by googleads.
the class SelectorBuilderImpl method build.
@Override
public Selector build() {
Selector selectorCopy = new Selector();
Set<OrderBy> orderingCopy = this.copyOrderingSet();
Set<Predicate> predicatesCopy = this.copyPredicatesSet();
selectorCopy.setFields(this.fields.toArray(new String[this.fields.size()]));
selectorCopy.setOrdering(orderingCopy.toArray(new OrderBy[this.ordering.size()]));
selectorCopy.setPredicates(predicatesCopy.toArray(new Predicate[this.predicates.size()]));
if (this.dateRange != null) {
selectorCopy.setDateRange(new DateRange(this.dateRange.getMin(), this.dateRange.getMax()));
}
if (this.paging != null) {
selectorCopy.setPaging(new Paging(this.paging.getStartIndex(), this.paging.getNumberResults()));
}
return selectorCopy;
}
Aggregations