use of com.google.api.ads.admanager.jaxws.v202205.Value in project auto-data-tokenize by GoogleCloudPlatform.
the class RecordUnflattener method unflatten.
/**
* Returns an AVRO record by unflattening the FlatRecord through JSON unflattener.
*/
public GenericRecord unflatten(FlatRecord flatRecord) {
Map<String, Object> jsonValueMap = Maps.newHashMap();
for (Map.Entry<String, Value> entry : flatRecord.getValuesMap().entrySet()) {
var valueProcessor = new ValueProcessor(entry);
jsonValueMap.put(valueProcessor.cleanKey(), valueProcessor.convertedValue());
}
String unflattenedRecordJson = new JsonUnflattener(jsonValueMap).unflatten();
return convertJsonToAvro(schema, unflattenedRecordJson);
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project auto-data-tokenize by GoogleCloudPlatform.
the class ContactsFlatRecordSampleGenerator method buildContactRecords.
public ImmutableList<FlatRecord> buildContactRecords(int count) {
ImmutableList.Builder<FlatRecord> recordListBuilder = ImmutableList.builder();
for (int i = 0; i < count; i++) {
HashMap<String, Value> valuesMap = Maps.newHashMap();
HashMap<String, String> flatKeyMap = Maps.newHashMap();
valuesMap.put("$.name", Value.newBuilder().setStringValue(randomName()).build());
flatKeyMap.put("$.name", "$.name");
final int numbers = new Random().nextInt(10);
for (int n = 0; n < numbers; n++) {
String key = "$.contacts[" + n + "].contact.number";
flatKeyMap.put(key, "$.contacts.contact.number");
valuesMap.put(key, Value.newBuilder().setStringValue(randomPhoneNumber(10)).build());
}
final int emails = new Random().nextInt(5);
for (int n = 0; n < emails; n++) {
String key = "$.emails[" + n + "]";
flatKeyMap.put(key, "$.emails");
valuesMap.put(key, Value.newBuilder().setStringValue(randomName()).build());
}
recordListBuilder.add(flatRecordBuilder().putAllValues(valuesMap).putAllFlatKeySchema(flatKeyMap).build());
}
return recordListBuilder.build();
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.
the class Target method getLowerBound.
/**
* Returns a lower bound of field values that can be used as a starting point to scan the index
* defined by {@code fieldIndex}. Returns {@code null} if no lower bound exists.
*/
@Nullable
public Bound getLowerBound(FieldIndex fieldIndex) {
List<Value> values = new ArrayList<>();
boolean inclusive = true;
// For each segment, retrieve a lower bound if there is a suitable filter or startAt.
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
Value segmentValue = null;
boolean segmentInclusive = true;
// Process all filters to find a value for the current field segment
for (FieldFilter fieldFilter : getFieldFiltersForPath(segment.getFieldPath())) {
Value filterValue = null;
boolean filterInclusive = true;
switch(fieldFilter.getOperator()) {
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
filterValue = Values.getLowerBound(fieldFilter.getValue().getValueTypeCase());
break;
case EQUAL:
case IN:
case GREATER_THAN_OR_EQUAL:
filterValue = fieldFilter.getValue();
break;
case GREATER_THAN:
filterValue = fieldFilter.getValue();
filterInclusive = false;
break;
case NOT_EQUAL:
case NOT_IN:
filterValue = Values.MIN_VALUE;
break;
default:
}
if (max(segmentValue, filterValue) == filterValue) {
segmentValue = filterValue;
segmentInclusive = filterInclusive;
}
}
// if we can narrow the scope.
if (startAt != null) {
for (int i = 0; i < orderBys.size(); ++i) {
OrderBy orderBy = this.orderBys.get(i);
if (orderBy.getField().equals(segment.getFieldPath())) {
Value cursorValue = startAt.getPosition().get(i);
if (max(segmentValue, cursorValue) == cursorValue) {
segmentValue = cursorValue;
segmentInclusive = startAt.isInclusive();
}
break;
}
}
}
if (segmentValue == null) {
// No lower bound exists
return null;
}
values.add(segmentValue);
inclusive &= segmentInclusive;
}
return new Bound(values, inclusive);
}
use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.
the class Target method getUpperBound.
/**
* Returns an upper bound of field values that can be used as an ending point when scanning the
* index defined by {@code fieldIndex}. Returns {@code null} if no upper bound exists.
*/
@Nullable
public Bound getUpperBound(FieldIndex fieldIndex) {
List<Value> values = new ArrayList<>();
boolean inclusive = true;
// For each segment, retrieve an upper bound if there is a suitable filter or endAt.
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
@Nullable Value segmentValue = null;
boolean segmentInclusive = true;
// Process all filters to find a value for the current field segment
for (FieldFilter fieldFilter : getFieldFiltersForPath(segment.getFieldPath())) {
Value filterValue = null;
boolean filterInclusive = true;
switch(fieldFilter.getOperator()) {
case GREATER_THAN_OR_EQUAL:
case GREATER_THAN:
filterValue = Values.getUpperBound(fieldFilter.getValue().getValueTypeCase());
filterInclusive = false;
break;
case EQUAL:
case IN:
case LESS_THAN_OR_EQUAL:
filterValue = fieldFilter.getValue();
break;
case LESS_THAN:
filterValue = fieldFilter.getValue();
filterInclusive = false;
break;
case NOT_EQUAL:
case NOT_IN:
filterValue = Values.MAX_VALUE;
break;
default:
}
if (min(segmentValue, filterValue) == filterValue) {
segmentValue = filterValue;
segmentInclusive = filterInclusive;
}
}
// if we can narrow the scope.
if (endAt != null) {
for (int i = 0; i < orderBys.size(); ++i) {
OrderBy orderBy = this.orderBys.get(i);
if (orderBy.getField().equals(segment.getFieldPath())) {
Value cursorValue = endAt.getPosition().get(i);
if (min(segmentValue, cursorValue) == cursorValue) {
segmentValue = cursorValue;
segmentInclusive = endAt.isInclusive();
}
break;
}
}
}
if (segmentValue == null) {
// No upper bound exists
return null;
}
values.add(segmentValue);
inclusive &= segmentInclusive;
}
return new Bound(values, inclusive);
}
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() + "]");
}
}
Aggregations