static BucketDestination fromPb(String destinationPb) { Matcher matcher = PATTERN.matcher(destinationPb); if (!matcher.matches()) { throw new IllegalArgumentException(destinationPb + " is not a valid sink destination"); } return new BucketDestination(matcher.group(1)); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || !(obj instanceof BucketDestination)) { return false; } BucketDestination other = (BucketDestination) obj; return baseEquals(other) && bucket.equals(other.bucket); }
@Override public int hashCode() { return Objects.hash(baseHashCode(), bucket); }
@Override public int hashCode() { return Objects.hash(baseHashCode(), bucket); }
static BucketDestination fromPb(String destinationPb) { Matcher matcher = PATTERN.matcher(destinationPb); if (!matcher.matches()) { throw new IllegalArgumentException(destinationPb + " is not a valid sink destination"); } return new BucketDestination(matcher.group(1)); } }
/** * Creates a {@code BucketDestination} object given the name of the bucket to be used as sink * destination. */ public static BucketDestination of(String bucket) { return new BucketDestination(bucket); }
@SuppressWarnings("unchecked") static <T extends Destination> T fromPb(String destinationPb) { if (BucketDestination.matchesDestination(destinationPb)) { return (T) BucketDestination.fromPb(destinationPb); } else if (DatasetDestination.matchesDestination(destinationPb)) { return (T) DatasetDestination.fromPb(destinationPb); } else if (TopicDestination.matchesDestination(destinationPb)) { return (T) TopicDestination.fromPb(destinationPb); } throw new IllegalArgumentException(destinationPb + " is not a valid sink destination"); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || !(obj instanceof BucketDestination)) { return false; } BucketDestination other = (BucketDestination) obj; return baseEquals(other) && bucket.equals(other.bucket); }
@Override SinkInfo parse(String... args) throws Exception { if (args.length >= 3) { if (args.length > 4) { throw new IllegalArgumentException("Too many arguments."); } String name = args[0]; Destination destination; switch (args[1]) { case "bucket": destination = BucketDestination.of(args[2]); break; case "dataset": destination = DatasetDestination.of(args[2]); break; case "topic": destination = TopicDestination.of(args[2]); break; default: throw new IllegalArgumentException("Second argument must be bucket|dataset|topic."); } SinkInfo.Builder builder = SinkInfo.newBuilder(name, destination); if (args.length == 4) { builder.setFilter(args[3]); } return builder.build(); } throw new IllegalArgumentException("Missing required sink name, destination or filter."); }
@Test public void testToAndFromPbDestination() { BucketDestination bucketDestination = Destination.fromPb(BUCKET_DESTINATION.toPb("other")); assertEquals(Destination.Type.BUCKET, bucketDestination.getType()); assertEquals("bucket", bucketDestination.getBucket()); compareBucketDestination(BUCKET_DESTINATION, bucketDestination); DatasetDestination datasetDestination = Destination.fromPb(DATASET_DESTINATION.toPb("other")); assertEquals(Destination.Type.DATASET, datasetDestination.getType()); assertEquals("project", datasetDestination.getProject()); assertEquals("dataset", datasetDestination.getDataset()); compareDatasetDestination(DATASET_DESTINATION, datasetDestination); TopicDestination topicDestination = Destination.fromPb(TOPIC_DESTINATION.toPb("other")); assertEquals(Destination.Type.TOPIC, topicDestination.getType()); assertEquals("project", topicDestination.getProject()); assertEquals("topic", topicDestination.getTopic()); compareTopicDestination(TOPIC_DESTINATION, topicDestination); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("wrongDestination is not a valid sink destination"); Destination.fromPb("wrongDestination"); }
/** * Creates a {@code BucketDestination} object given the name of the bucket to be used as sink * destination. */ public static BucketDestination of(String bucket) { return new BucketDestination(bucket); }
@SuppressWarnings("unchecked") static <T extends Destination> T fromPb(String destinationPb) { if (BucketDestination.matchesDestination(destinationPb)) { return (T) BucketDestination.fromPb(destinationPb); } else if (DatasetDestination.matchesDestination(destinationPb)) { return (T) DatasetDestination.fromPb(destinationPb); } else if (TopicDestination.matchesDestination(destinationPb)) { return (T) TopicDestination.fromPb(destinationPb); } throw new IllegalArgumentException(destinationPb + " is not a valid sink destination"); } }