Search in sources :

Example 86 with Function

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);
}
Also used : Function(com.google.common.base.Function) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) FieldValue(com.google.cloud.bigquery.FieldValue) InsertAllResponse(com.google.cloud.bigquery.InsertAllResponse) Test(org.junit.Test)

Example 87 with Function

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;
}
Also used : Function(com.google.common.base.Function) Owner(com.google.api.services.storage.model.StorageObject.Owner) StorageObject(com.google.api.services.storage.model.StorageObject) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) DateTime(com.google.api.client.util.DateTime)

Example 88 with Function

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();
}
Also used : Function(com.google.common.base.Function) BucketAccessControl(com.google.api.services.storage.model.BucketAccessControl) Website(com.google.api.services.storage.model.Bucket.Website) ObjectAccessControl(com.google.api.services.storage.model.ObjectAccessControl) Rule(com.google.api.services.storage.model.Bucket.Lifecycle.Rule)

Example 89 with Function

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;
}
Also used : Owner(com.google.api.services.storage.model.Bucket.Owner) Lifecycle(com.google.api.services.storage.model.Bucket.Lifecycle) Website(com.google.api.services.storage.model.Bucket.Website) DateTime(com.google.api.client.util.DateTime) Function(com.google.common.base.Function) Versioning(com.google.api.services.storage.model.Bucket.Versioning)

Example 90 with Function

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;
}
Also used : BigInteger(java.math.BigInteger) Function(com.google.common.base.Function) BigInteger(java.math.BigInteger) ScratchDisks(com.google.api.services.compute.model.MachineType.ScratchDisks)

Aggregations

Function (com.google.common.base.Function)616 List (java.util.List)138 ArrayList (java.util.ArrayList)114 Nullable (javax.annotation.Nullable)103 Map (java.util.Map)97 IOException (java.io.IOException)89 HashMap (java.util.HashMap)78 Test (org.junit.Test)73 ImmutableList (com.google.common.collect.ImmutableList)49 File (java.io.File)46 Set (java.util.Set)46 Collection (java.util.Collection)35 ImmutableMap (com.google.common.collect.ImmutableMap)34 DateTime (org.joda.time.DateTime)33 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)29 HashSet (java.util.HashSet)27 Iterator (java.util.Iterator)27 LinkedList (java.util.LinkedList)26 ExecutionException (java.util.concurrent.ExecutionException)24 Collectors (java.util.stream.Collectors)15