use of com.google.common.base.Function in project google-cloud-java by GoogleCloudPlatform.
the class ITTableSnippets method testInsertParams.
@Test
public void testInsertParams() throws InterruptedException {
InsertAllResponse response = tableSnippets.insertWithParams("row1", "row2");
assertTrue(response.hasErrors());
List<List<FieldValue>> rows = ImmutableList.copyOf(tableSnippets.list().getValues());
while (rows.isEmpty()) {
Thread.sleep(500);
rows = ImmutableList.copyOf(tableSnippets.list().getValues());
}
Set<List<?>> values = FluentIterable.from(rows).transform(new Function<List<FieldValue>, List<?>>() {
@Override
public List<?> apply(List<FieldValue> row) {
return ImmutableList.of(row.get(0).getStringValue(), row.get(1).getBooleanValue());
}
}).toSet();
assertEquals(ImmutableSet.of(ROW2), values);
}
use of com.google.common.base.Function in project google-cloud-java by GoogleCloudPlatform.
the class BlobInfo method toPb.
StorageObject toPb() {
StorageObject storageObject = blobId.toPb();
if (acl != null) {
storageObject.setAcl(Lists.transform(acl, new Function<Acl, ObjectAccessControl>() {
@Override
public ObjectAccessControl apply(Acl acl) {
return acl.toObjectPb();
}
}));
}
if (deleteTime != null) {
storageObject.setTimeDeleted(new DateTime(deleteTime));
}
if (updateTime != null) {
storageObject.setUpdated(new DateTime(updateTime));
}
if (createTime != null) {
storageObject.setTimeCreated(new DateTime(createTime));
}
if (size != null) {
storageObject.setSize(BigInteger.valueOf(size));
}
if (owner != null) {
storageObject.setOwner(new Owner().setEntity(owner.toPb()));
}
if (storageClass != null) {
storageObject.setStorageClass(storageClass.toString());
}
Map<String, String> pbMetadata = metadata;
if (metadata != null && !Data.isNull(metadata)) {
pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size());
for (Map.Entry<String, String> entry : metadata.entrySet()) {
pbMetadata.put(entry.getKey(), firstNonNull(entry.getValue(), Data.<String>nullOf(String.class)));
}
}
if (customerEncryption != null) {
storageObject.setCustomerEncryption(customerEncryption.toPb());
}
storageObject.setMetadata(pbMetadata);
storageObject.setCacheControl(cacheControl);
storageObject.setContentEncoding(contentEncoding);
storageObject.setCrc32c(crc32c);
storageObject.setContentType(contentType);
storageObject.setMd5Hash(md5);
storageObject.setMediaLink(mediaLink);
storageObject.setMetageneration(metageneration);
storageObject.setContentDisposition(contentDisposition);
storageObject.setComponentCount(componentCount);
storageObject.setContentLanguage(contentLanguage);
storageObject.setEtag(etag);
storageObject.setId(generatedId);
storageObject.setSelfLink(selfLink);
return storageObject;
}
use of com.google.common.base.Function in project google-cloud-java by GoogleCloudPlatform.
the class BucketInfo method fromPb.
static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb) {
Builder builder = new BuilderImpl(bucketPb.getName());
if (bucketPb.getId() != null) {
builder.setGeneratedId(bucketPb.getId());
}
if (bucketPb.getEtag() != null) {
builder.setEtag(bucketPb.getEtag());
}
if (bucketPb.getMetageneration() != null) {
builder.setMetageneration(bucketPb.getMetageneration());
}
if (bucketPb.getSelfLink() != null) {
builder.setSelfLink(bucketPb.getSelfLink());
}
if (bucketPb.getTimeCreated() != null) {
builder.setCreateTime(bucketPb.getTimeCreated().getValue());
}
if (bucketPb.getLocation() != null) {
builder.setLocation(bucketPb.getLocation());
}
if (bucketPb.getStorageClass() != null) {
builder.setStorageClass(StorageClass.valueOf(bucketPb.getStorageClass()));
}
if (bucketPb.getCors() != null) {
builder.setCors(transform(bucketPb.getCors(), Cors.FROM_PB_FUNCTION));
}
if (bucketPb.getAcl() != null) {
builder.setAcl(transform(bucketPb.getAcl(), new Function<BucketAccessControl, Acl>() {
@Override
public Acl apply(BucketAccessControl bucketAccessControl) {
return Acl.fromPb(bucketAccessControl);
}
}));
}
if (bucketPb.getDefaultObjectAcl() != null) {
builder.setDefaultAcl(transform(bucketPb.getDefaultObjectAcl(), new Function<ObjectAccessControl, Acl>() {
@Override
public Acl apply(ObjectAccessControl objectAccessControl) {
return Acl.fromPb(objectAccessControl);
}
}));
}
if (bucketPb.getOwner() != null) {
builder.setOwner(Entity.fromPb(bucketPb.getOwner().getEntity()));
}
if (bucketPb.getVersioning() != null) {
builder.setVersioningEnabled(bucketPb.getVersioning().getEnabled());
}
Website website = bucketPb.getWebsite();
if (website != null) {
builder.setIndexPage(website.getMainPageSuffix());
builder.setNotFoundPage(website.getNotFoundPage());
}
if (bucketPb.getLifecycle() != null && bucketPb.getLifecycle().getRule() != null) {
builder.setDeleteRules(transform(bucketPb.getLifecycle().getRule(), new Function<Rule, DeleteRule>() {
@Override
public DeleteRule apply(Rule rule) {
return DeleteRule.fromPb(rule);
}
}));
}
return builder.build();
}
use of com.google.common.base.Function in project google-cloud-java by GoogleCloudPlatform.
the class BucketInfo method toPb.
com.google.api.services.storage.model.Bucket toPb() {
com.google.api.services.storage.model.Bucket bucketPb = new com.google.api.services.storage.model.Bucket();
bucketPb.setId(generatedId);
bucketPb.setName(name);
bucketPb.setEtag(etag);
if (createTime != null) {
bucketPb.setTimeCreated(new DateTime(createTime));
}
if (metageneration != null) {
bucketPb.setMetageneration(metageneration);
}
if (location != null) {
bucketPb.setLocation(location);
}
if (storageClass != null) {
bucketPb.setStorageClass(storageClass.toString());
}
if (cors != null) {
bucketPb.setCors(transform(cors, Cors.TO_PB_FUNCTION));
}
if (acl != null) {
bucketPb.setAcl(transform(acl, new Function<Acl, BucketAccessControl>() {
@Override
public BucketAccessControl apply(Acl acl) {
return acl.toBucketPb();
}
}));
}
if (defaultAcl != null) {
bucketPb.setDefaultObjectAcl(transform(defaultAcl, new Function<Acl, ObjectAccessControl>() {
@Override
public ObjectAccessControl apply(Acl acl) {
return acl.toObjectPb();
}
}));
}
if (owner != null) {
bucketPb.setOwner(new Owner().setEntity(owner.toPb()));
}
bucketPb.setSelfLink(selfLink);
if (versioningEnabled != null) {
bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));
}
if (indexPage != null || notFoundPage != null) {
Website website = new Website();
website.setMainPageSuffix(indexPage);
website.setNotFoundPage(notFoundPage);
bucketPb.setWebsite(website);
}
if (deleteRules != null) {
Lifecycle lifecycle = new Lifecycle();
lifecycle.setRule(transform(deleteRules, new Function<DeleteRule, Rule>() {
@Override
public Rule apply(DeleteRule deleteRule) {
return deleteRule.toPb();
}
}));
bucketPb.setLifecycle(lifecycle);
}
return bucketPb;
}
use of com.google.common.base.Function in project google-cloud-java by GoogleCloudPlatform.
the class MachineType method toPb.
com.google.api.services.compute.model.MachineType toPb() {
com.google.api.services.compute.model.MachineType machineTypePb = new com.google.api.services.compute.model.MachineType();
if (generatedId != null) {
machineTypePb.setId(new BigInteger(generatedId));
}
if (creationTimestamp != null) {
machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
}
machineTypePb.setName(machineTypeId.getType());
machineTypePb.setDescription(description);
machineTypePb.setSelfLink(machineTypeId.getSelfLink());
machineTypePb.setGuestCpus(cpus);
machineTypePb.setMemoryMb(memoryMb);
if (scratchDisksSizeGb != null) {
machineTypePb.setScratchDisks(Lists.transform(scratchDisksSizeGb, new Function<Integer, ScratchDisks>() {
@Override
public ScratchDisks apply(Integer diskSize) {
return new ScratchDisks().setDiskGb(diskSize);
}
}));
}
machineTypePb.setMaximumPersistentDisks(maximumPersistentDisks);
machineTypePb.setMaximumPersistentDisksSizeGb(maximumPersistentDisksSizeGb);
machineTypePb.setZone(machineTypeId.getZoneId().getZone());
if (deprecationStatus != null) {
machineTypePb.setDeprecated(deprecationStatus.toPb());
}
return machineTypePb;
}
Aggregations