Class Formats


  • public class Formats
    extends java.lang.Object
    Helper methods for formatting
    Since:
    0.2.0
    Author:
    Alexandre Carvalho, Andre Bertolace
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.math.BigInteger NEAR_NOMINATION
      Number of indivisible units in one NEAR.
      static int NEAR_NOMINATION_EXP
      Exponent for calculating how many indivisible units are there in one NEAR.
    • Constructor Summary

      Constructors 
      Constructor Description
      Formats()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanupAmount​(java.lang.String amount)
      Removes commas from the input
      static java.lang.String formatNearAmount​(java.lang.String balance, java.lang.Integer fracDigits)
      Convert account balance value from internal indivisible units to NEAR.
      static java.lang.String formatWithCommas​(java.lang.String value)
      Returns a human-readable value with commas
      static java.lang.String padEnd​(java.lang.String input, int maxLength, char fillChar)
      Pads an input string from its end with a char until it reaches a max length
      static java.lang.String padStart​(java.lang.String input, int maxLength, char fillChar)
      Pads an input string from its start with a char until it reaches a max length
      static java.lang.String parseNearAmount​(java.lang.String amount)
      Convert human-readable NEAR amount to internal indivisible units.
      static java.lang.String trimLeadingZeroes​(java.lang.String value)
      Removes leading zeroes from an input
      static java.lang.String trimTrailingZeroes​(java.lang.String value)
      Removes .000… from an input
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NEAR_NOMINATION_EXP

        public static int NEAR_NOMINATION_EXP
        Exponent for calculating how many indivisible units are there in one NEAR. See NEAR_NOMINATION.
      • NEAR_NOMINATION

        public static java.math.BigInteger NEAR_NOMINATION
        Number of indivisible units in one NEAR. Derived from NEAR_NOMINATION_EXP.
    • Constructor Detail

      • Formats

        public Formats()
    • Method Detail

      • formatNearAmount

        public static java.lang.String formatNearAmount​(java.lang.String balance,
                                                        java.lang.Integer fracDigits)
        Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined by NEAR_NOMINATION. Effectively this divides given amount by NEAR_NOMINATION.
        Parameters:
        balance - decimal string representing balance in smallest non-divisible NEAR units (as specified by NEAR_NOMINATION)
        fracDigits - number of fractional digits to preserve in formatted string. Balance is rounded to match given number of digits.
        Returns:
        Value in Ⓝ
      • parseNearAmount

        public static java.lang.String parseNearAmount​(java.lang.String amount)
        Convert human-readable NEAR amount to internal indivisible units. Effectively this multiplies given amount by NEAR_NOMINATION.
        Parameters:
        amount - decimal string (potentially fractional) denominated in NEAR.
        Returns:
        The parsed yoctoⓃ amount or null if no amount was passed in
      • padStart

        public static java.lang.String padStart​(java.lang.String input,
                                                int maxLength,
                                                char fillChar)
        Pads an input string from its start with a char until it reaches a max length
        Parameters:
        input - the input string
        maxLength - the max length to reach
        fillChar - the char to fill
        Returns:
        the padded string
      • padEnd

        public static java.lang.String padEnd​(java.lang.String input,
                                              int maxLength,
                                              char fillChar)
        Pads an input string from its end with a char until it reaches a max length
        Parameters:
        input - the input string
        maxLength - the max length to reach
        fillChar - the char to fill
        Returns:
        the padded string
      • cleanupAmount

        public static java.lang.String cleanupAmount​(java.lang.String amount)
        Removes commas from the input
        Parameters:
        amount - A value or amount that may contain commas
        Returns:
        string The cleaned value
      • trimTrailingZeroes

        public static java.lang.String trimTrailingZeroes​(java.lang.String value)
        Removes .000… from an input
        Parameters:
        value - A value that may contain trailing zeroes in the decimals place
        Returns:
        string The value without the trailing zeros
      • trimLeadingZeroes

        public static java.lang.String trimLeadingZeroes​(java.lang.String value)
        Removes leading zeroes from an input
        Parameters:
        value - A value that may contain leading zeroes
        Returns:
        string The value without the leading zeroes
      • formatWithCommas

        public static java.lang.String formatWithCommas​(java.lang.String value)
        Returns a human-readable value with commas
        Parameters:
        value - A value that may not contain commas
        Returns:
        string A value with commas