Skip to content

Commit

Permalink
Add BigDecimal getters for prices and deprecate double getters
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-signal committed Aug 11, 2023
1 parent c95ba8a commit 415acda
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 17 deletions.
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/InboundCallPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.twilio.converter.Promoter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
Expand Down Expand Up @@ -41,8 +42,8 @@ public static Type forValue(final String value) {
}
}

private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;
private final Type type;

/**
Expand All @@ -53,19 +54,57 @@ public static Type forValue(final String value) {
* @param type type of phone number
*/
@JsonCreator
public InboundCallPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice,
public InboundCallPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice,
@JsonProperty("number_type") final Type type) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
this.type = type;
}

/**
* Returns the retail price per minute to receive a call to this phone number type. The value returned by this
* method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to receive a call to this phone number type
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to receive a call to this phone number type.
*
* @return the retail price per minute to receive a call to this phone number type
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to receive a call
* to this phone number type. The value returned by this method is represented as a {@code double}, which may result
* in loss of precision.
*
* @return the current price per minute to receive a call to this phone number type
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to receive a call
* to this phone number type.
*
* @return the current price per minute to receive a call to this phone number type
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
45 changes: 41 additions & 4 deletions src/main/java/com/twilio/type/InboundSmsPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.twilio.converter.Promoter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
Expand Down Expand Up @@ -42,8 +43,8 @@ public static Type forValue(final String value) {
}
}

private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;
private final Type type;

/**
Expand All @@ -54,19 +55,55 @@ public static Type forValue(final String value) {
* @param type type of phone number
*/
@JsonCreator
public InboundSmsPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice,
public InboundSmsPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice,
@JsonProperty("number_type") final Type type) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
this.type = type;
}

/**
* Returns the retail price to receive a message. The value returned by this method is represented as a
* {@code double}, which may result in loss of precision.
*
* @return the retail price to receive a message
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price to receive a message.
*
* @return the retail price to receive a message
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price (which accounts for any volume or custom price discounts) to receive a message. The
* value returned by this method is represented as a {@code double}, which may result in loss of precision.
*
* @return the current price to receive a message
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price (which accounts for any volume or custom price discounts) to receive a message.
*
* @return the current price to receive a message
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/OutboundCallPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,65 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class OutboundCallPrice {
private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;

@JsonCreator
public OutboundCallPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice) {
public OutboundCallPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
}

/**
* Returns the retail price per minute to make a call from this phone number type. The value returned by this
* method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to make a call from this phone number type
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to make a call from this phone number type.
*
* @return the retail price per minute to make a call from this phone number type
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call
* from this phone number type. The value returned by this method is represented as a {@code double}, which may
* result in loss of precision.
*
* @return the current price per minute to make a call from this phone number type
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call
* from this phone number type.
*
* @return the current price per minute to make a call from this phone number type
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/OutboundPrefixPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

Expand All @@ -22,8 +23,8 @@ public class OutboundPrefixPrice {

private final List<String> prefixes;
private final String friendlyName;
private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;

/**
* Initialize an OutboundPrefixPrice.
Expand All @@ -36,8 +37,8 @@ public class OutboundPrefixPrice {
@JsonCreator
public OutboundPrefixPrice(@JsonProperty("prefixes") final List<String> prefixes,
@JsonProperty("friendly_name") final String friendlyName,
@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice) {
@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice) {
this.prefixes = prefixes;
this.friendlyName = friendlyName;
this.basePrice = basePrice;
Expand All @@ -52,11 +53,49 @@ public String getFriendlyName() {
return friendlyName;
}

/**
* Returns the retail price per minute to make a call to numbers matching this prefix list. The value returned by
* this method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to make a call to numbers matching this prefix list
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to make a call to numbers matching this prefix list.
*
* @return the retail price per minute to make a call to numbers matching this prefix list
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call to
* numbers matching this prefix list. The value returned by this method is represented as a {@code double}, which
* may result in loss of precision.
*
* @return the current price per minute to make a call to numbers matching this prefix list
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call to
* numbers matching this prefix list.
*
* @return the current price per minute to make a call to numbers matching this prefix list
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/twilio/type/InboundCallPriceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.math.BigDecimal;

/**
* Test class for {@link InboundCallPrice}.
Expand All @@ -21,6 +22,8 @@ public void testFromJson() throws IOException {
InboundCallPrice icp = fromJson(json, InboundCallPrice.class);
Assert.assertEquals(1.00, icp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, icp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), icp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), icp.getCurrentPriceDecimal());
Assert.assertEquals(InboundCallPrice.Type.MOBILE, icp.getType());
}

Expand All @@ -35,6 +38,8 @@ public void testFromJsonTollFree() throws IOException {
InboundCallPrice icp = fromJson(json, InboundCallPrice.class);
Assert.assertEquals(1.00, icp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, icp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), icp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), icp.getCurrentPriceDecimal());
Assert.assertEquals(InboundCallPrice.Type.TOLLFREE, icp.getType());
}

Expand All @@ -50,6 +55,8 @@ public void testFromJsonExtraField() throws IOException {
InboundCallPrice icp = fromJson(json, InboundCallPrice.class);
Assert.assertEquals(1.00, icp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, icp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), icp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), icp.getCurrentPriceDecimal());
Assert.assertEquals(InboundCallPrice.Type.TOLLFREE, icp.getType());
}
}
5 changes: 5 additions & 0 deletions src/test/java/com/twilio/type/InboundSmsPriceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.math.BigDecimal;

/**
* Test class for {@link InboundSmsPrice}.
Expand All @@ -21,6 +22,8 @@ public void testFromJson() throws IOException {
InboundSmsPrice icp = fromJson(json, InboundSmsPrice.class);
Assert.assertEquals(1.00, icp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, icp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), icp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), icp.getCurrentPriceDecimal());
Assert.assertEquals(InboundSmsPrice.Type.MOBILE, icp.getType());
}

Expand All @@ -35,6 +38,8 @@ public void testFromJsonTollFree() throws IOException {
InboundSmsPrice icp = fromJson(json, InboundSmsPrice.class);
Assert.assertEquals(1.00, icp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, icp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), icp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), icp.getCurrentPriceDecimal());
Assert.assertEquals(InboundSmsPrice.Type.TOLLFREE, icp.getType());
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/twilio/type/OutboundCallPriceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.math.BigDecimal;

/**
* Test class for {@link OutboundCallPrice}.
Expand All @@ -20,5 +21,7 @@ public void testFromJson() throws IOException {
OutboundCallPrice ocp = fromJson(json, OutboundCallPrice.class);
Assert.assertEquals(1.00, ocp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, ocp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), ocp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), ocp.getCurrentPriceDecimal());
}
}
4 changes: 4 additions & 0 deletions src/test/java/com/twilio/type/OutboundPrefixPriceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;

/**
Expand All @@ -28,5 +29,8 @@ public void testFromJson() throws IOException {
Assert.assertEquals("name", opp.getFriendlyName());
Assert.assertEquals(1.00, opp.getBasePrice(), 0.00);
Assert.assertEquals(2.00, opp.getCurrentPrice(), 0.00);
Assert.assertEquals(new BigDecimal("1.00"), opp.getBasePriceDecimal());
Assert.assertEquals(new BigDecimal("2.00"), opp.getCurrentPriceDecimal());

}
}
Loading

0 comments on commit 415acda

Please sign in to comment.