public Builder mergeFrom(com.google.type.Money other) { if (other == com.google.type.Money.getDefaultInstance()) return this; if (!other.getCurrencyCode().isEmpty()) { currencyCode_ = other.currencyCode_; onChanged(); } if (other.getUnits() != 0L) { setUnits(other.getUnits()); } if (other.getNanos() != 0) { setNanos(other.getNanos()); } onChanged(); return this; }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public com.google.type.Money buildPartial() { com.google.type.Money result = new com.google.type.Money(this); result.currencyCode_ = currencyCode_; result.units_ = units_; result.nanos_ = nanos_; onBuilt(); return result; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.type.Money)) { return super.equals(obj); } com.google.type.Money other = (com.google.type.Money) obj; boolean result = true; result = result && getCurrencyCode() .equals(other.getCurrencyCode()); result = result && (getUnits() == other.getUnits()); result = result && (getNanos() == other.getNanos()); return result; }
/** * <pre> * The 3-letter currency code defined in ISO 4217. * </pre> * * <code>string currency_code = 1;</code> */ public Builder clearCurrencyCode() { currencyCode_ = getDefaultInstance().getCurrencyCode(); onChanged(); return this; } /**
public int compareTo(Money other) { return Double.compare(units/Math.pow(10, precision), other.getUnits()/Math.pow(10, other.getPrecision())); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + CURRENCY_CODE_FIELD_NUMBER; hash = (53 * hash) + getCurrencyCode().hashCode(); hash = (37 * hash) + UNITS_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getUnits()); hash = (37 * hash) + NANOS_FIELD_NUMBER; hash = (53 * hash) + getNanos(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!getCurrencyCodeBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, currencyCode_); } if (units_ != 0L) { output.writeInt64(2, units_); } if (nanos_ != 0) { output.writeInt32(3, nanos_); } }
public com.google.type.Money getDefaultInstanceForType() { return com.google.type.Money.getDefaultInstance(); }
public com.google.type.Money build() { com.google.type.Money result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getCurrencyCodeBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, currencyCode_); } if (units_ != 0L) { size += com.google.protobuf.CodedOutputStream .computeInt64Size(2, units_); } if (nanos_ != 0) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(3, nanos_); } memoizedSize = size; return size; }
@Override public Void answer(InvocationOnMock invocation) { Color color = invocation.getArgument(0); StreamObserver<Money> observer = invocation.getArgument(1); observer.onNext( Money.newBuilder() .setCurrencyCode("USD") .setUnits((long) (color.getRed() * 255)) .build()); observer.onCompleted(); return null; } })
private Money getMoney(String currencyCode) { return Money.newBuilder().setCurrencyCode(currencyCode).build(); }
private static Money convert(Color color) { Money result = Money.newBuilder().setCurrencyCode("USD").setUnits((long) (color.getRed() * 255)).build(); return result; }
@Test public void testBlockingServerStreaming() throws Exception { Color request = Color.newBuilder().setRed(0.5f).build(); ServerStream<Money> response = streamingCallable.call(request); List<Money> responseData = Lists.newArrayList(response); Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build(); Truth.assertThat(responseData).containsExactly(expected); }
@Test public void testClientStreaming() throws Exception { ClientStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createClientStreamingCallable( GrpcCallSettings.create(METHOD_CLIENT_STREAMING_RECOGNIZE), null, clientContext); CountDownLatch latch = new CountDownLatch(1); MoneyObserver moneyObserver = new MoneyObserver(latch); Color request = Color.newBuilder().setRed(0.5f).build(); ApiStreamObserver<Color> requestObserver = streamingCallable.clientStreamingCall(moneyObserver); requestObserver.onNext(request); requestObserver.onCompleted(); latch.await(20, TimeUnit.SECONDS); assertThat(moneyObserver.error).isNull(); Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build(); assertThat(moneyObserver.response).isEqualTo(expected); assertThat(moneyObserver.completed).isTrue(); }
@Test public void testBidiStreaming() throws Exception { BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable( GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE), null, clientContext); CountDownLatch latch = new CountDownLatch(1); GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch); Color request = Color.newBuilder().setRed(0.5f).build(); ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver); stream.send(request); stream.closeSend(); latch.await(20, TimeUnit.SECONDS); assertThat(moneyObserver.error).isNull(); Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build(); assertThat(moneyObserver.response).isEqualTo(expected); assertThat(moneyObserver.completed).isTrue(); }
@Test public void testResponseTransformer() { ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setResponse(Any.pack(inputMoney)).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }
@Test public void testMetadataTransformer() { MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }
@Test public void testResponseTransformer_exception() { thrown.expect(UnavailableException.class); ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class); Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build(); Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.value()).build(); OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create( Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build()); Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney); }