@Test public void testListSelectorWithFirstLevelFields() { String selector = Helper.listSelector( FIRST_LEVEL_FIELDS, CONTAINER, REQUIRED_FIELDS, new FieldSelector[] {FIELD3}, "field4"); assertTrue(selector.contains("firstLevel1")); assertTrue(selector.contains("firstLevel2")); assertTrue(selector.contains("nextPageToken")); assertTrue(selector.contains("container(")); assertTrue(selector.contains("field1")); assertTrue(selector.contains("field2")); assertTrue(selector.contains("field3")); assertTrue(selector.contains("field4")); assertTrue(selector.endsWith(")")); assertEquals(76, selector.length()); } }
/** * Returns a composite selector given a number of top level fields as strings, a number of * resource fields and a container name. This method also takes an {@code extraResourceFields} * parameter to specify some extra resource fields as strings. The string selector returned by * this method can be used for field selection in API calls that return a list of resources. * This method is not supposed to be used directly by users. */ public static String listSelector( String[] topLevelFields, String containerName, List<? extends FieldSelector> required, FieldSelector[] others, String... extraResourceFields) { Set<String> topLevelStrings = Sets.newHashSetWithExpectedSize(topLevelFields.length + 1); topLevelStrings.addAll(Lists.asList("nextPageToken", topLevelFields)); return Joiner.on(',').join(topLevelStrings) + "," + containerName + '(' + selector(required, others, extraResourceFields) + ')'; } }
/** * Returns an option to specify the blob's fields to be returned by the RPC call. If this option * is not provided all blob's fields are returned. {@code BlobListOption.fields}) can be used to * specify only the fields of interest. Blob name and bucket are always returned, even if not * specified. */ public static BlobListOption fields(BlobField... fields) { return new BlobListOption( StorageRpc.Option.FIELDS, Helper.listSelector(TOP_LEVEL_FIELDS, "items", BlobField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the instance's fields to be returned by the RPC call. If this * option is not provided, all instance's fields are returned. {@code InstanceOption.fields} * can be used to specify only the fields of interest. {@link Instance#instanceId()} is always * returned, even if not specified. */ public static InstanceOption fields(InstanceField... fields) { return new InstanceOption(ComputeRpc.Option.FIELDS, Helper.selector(InstanceField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the subnetwork's fields to be returned by the RPC call. If this * option is not provided, all subnetwork's fields are returned. {@code SubnetworkOption.fields} * can be used to specify only the fields of interest. {@link Subnetwork#subnetworkId()} is * always returned, even if not specified. */ public static SubnetworkOption fields(SubnetworkField... fields) { return new SubnetworkOption(ComputeRpc.Option.FIELDS, Helper.selector(SubnetworkField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the operation's fields to be returned by the RPC call. If this * option is not provided, all operation's fields are returned. {@code OperationOption.fields} * can be used to specify only the fields of interest. {@link Operation#operationId()} is * always returned, even if not specified. */ public static OperationOption fields(OperationField... fields) { return new OperationOption(ComputeRpc.Option.FIELDS, Helper.selector(OperationField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the zone's fields to be returned by the RPC call. If this option * is not provided, all zone's fields are returned. {@code ZoneOption.fields} can be used to * specify only the fields of interest. {@link Zone#zoneId()} is always returned, even if * not specified. */ public static ZoneOption fields(ZoneField... fields) { return new ZoneOption(ComputeRpc.Option.FIELDS, Helper.selector(ZoneField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the zones's fields to be returned by the RPC call. * * <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can * be used to specify only the fields of interest. Zone ID is always returned, even if not * specified. {@link ZoneField} provides a list of fields that can be used. */ public static ZoneOption fields(ZoneField... fields) { return new ZoneOption(DnsRpc.Option.FIELDS, Helper.selector(ZoneField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the network's fields to be returned by the RPC call. If this * option is not provided, all network's fields are returned. {@code NetworkListOption.fields} * can be used to specify only the fields of interest. {@link Network#networkId()} and * {@link Network#configuration()} are always returned, even if not specified. */ public static NetworkListOption fields(NetworkField... fields) { return new NetworkListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", NetworkField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the image's fields to be returned by the RPC call. If this * option is not provided, all image's fields are returned. {@code ImageOption.fields} can be * used to specify only the fields of interest. {@link Image#imageId()} and * {@link Image#configuration()} are always returned, even if not specified. */ public static ImageOption fields(ImageField... fields) { return new ImageOption(ComputeRpc.Option.FIELDS, Helper.selector(ImageField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the snapshot's fields to be returned by the RPC call. If this * option is not provided, all the snapshot's fields are returned. * {@code SnapshotListOption.fields} can be used to specify only the fields of interest. * {@link Snapshot#snapshotId()} is always returned, even if not specified. */ public static SnapshotListOption fields(SnapshotField... fields) { return new SnapshotListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", SnapshotField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the snapshot's fields to be returned by the RPC call. If this * option is not provided, all the snapshot's fields are returned. {@code SnapshotOption.fields} * can be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always * returned, even if not specified. */ public static SnapshotOption fields(SnapshotField... fields) { return new SnapshotOption(ComputeRpc.Option.FIELDS, Helper.selector(SnapshotField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the address' fields to be returned by the RPC call. If this * option is not provided, all address' fields are returned. {@code AddressListOption.fields} * can be used to specify only the fields of interest. {@link Address#addressId()} is always * returned, even if not specified. */ public static AddressListOption fields(AddressField... fields) { return new AddressListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", AddressField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the machine type's fields to be returned by the RPC call. If * this option is not provided, all machine type's fields are returned. * {@code MachineTypeListOption.fields} can be used to specify only the fields of interest. * {@link MachineType#machineTypeId()} is always returned, even if not specified. */ public static MachineTypeListOption fields(MachineTypeField... fields) { return new MachineTypeListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", MachineTypeField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the disk type's fields to be returned by the RPC call. If this * option is not provided, all disk type's fields are returned. * {@code DiskTypeListOption.fields} can be used to specify only the fields of interest. * {@link DiskType#diskTypeId()} is always returned, even if not specified. */ public static DiskTypeListOption fields(DiskTypeField... fields) { return new DiskTypeListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", DiskTypeField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the region's fields to be returned by the RPC call. If this * option is not provided, all region's fields are returned. {@code RegionListOption.fields} can * be used to specify only the fields of interest. {@link Region#regionId()} is always * returned, even if not specified. */ public static RegionListOption fields(RegionField... fields) { return new RegionListOption(ComputeRpc.Option.FIELDS, Helper.listSelector("items", RegionField.REQUIRED_FIELDS, fields)); } }
/** * Returns an option to specify the zones's fields to be returned by the RPC call. * * <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can * be used to specify only the fields of interest. Zone ID is always returned, even if not * specified. {@link ZoneField} provides a list of fields that can be used. */ public static ZoneListOption fields(ZoneField... fields) { return new ZoneListOption(DnsRpc.Option.FIELDS, Helper.listSelector("managedZones", ZoneField.REQUIRED_FIELDS, fields)); }
/** * Returns an option to specify the job's fields to be returned by the RPC call. If this option * is not provided all job's fields are returned. {@code JobOption.fields()} can be used to * specify only the fields of interest. {@link Job#jobId()} as well as type-specific * configuration (e.g. {@link QueryJobConfiguration#query()} for Query Jobs) are always * returned, even if not specified. */ public static JobOption fields(JobField... fields) { return new JobOption(BigQueryRpc.Option.FIELDS, Helper.selector(JobField.REQUIRED_FIELDS, fields)); } }
/** * Returns a composite selector given a number of resource fields and a container name. The * string selector returned by this method can be used for field selection in API calls that * return a list of resources. This method is not supposed to be used directly by users. */ public static String listSelector(String containerName, List<? extends FieldSelector> required, FieldSelector... others) { return "nextPageToken," + containerName + '(' + selector(required, others) + ')'; }
/** * Returns a composite selector given a number of resource fields. The string selector returned * by this method can be used for field selection in API calls that return a single resource. * This method is not supposed to be used directly by users. */ public static String selector(List<? extends FieldSelector> required, FieldSelector... others) { return selector(required, others, new String[] {}); }