Class Conventions

java.lang.Object
overit.geocall.util.Conventions
All Implemented Interfaces:
Serializable

public class Conventions extends Object implements Serializable
The class implements the object used to set and retrieve the correct values for the data formats that depends on the cultural conventions used in the application.
See Also:
  • Field Details

    • CODING

      public static final Conventions CODING
      A thread-safe Conventions object, with the standard CODING_FORMAT
    • CODING_FORMAT

      public static final String CODING_FORMAT
      Defines the standard coding format
      See Also:
    • _sdfParse

      protected transient SimpleDateFormat _sdfParse
    • _sdfFormat

      protected transient SimpleDateFormat _sdfFormat
    • _strSdfParse

      protected String _strSdfParse
    • _strSdfFormat

      protected String _strSdfFormat
    • _fdw

      protected String _fdw
    • timeHourSystem

      protected String timeHourSystem
    • _decimalFormat

      protected transient DecimalFormat _decimalFormat
    • _decimalFormatSymbols

      protected transient DecimalFormatSymbols _decimalFormatSymbols
    • _format

      protected String _format
    • _minusSymbol

      protected char _minusSymbol
    • _groupingSeparator

      protected char _groupingSeparator
    • _groupingSize

      protected int _groupingSize
    • _decimalSeparator

      protected char _decimalSeparator
    • _decimalSize

      protected int _decimalSize
    • _percentSymbol

      protected char _percentSymbol
    • _exponentString

      protected String _exponentString
    • _currencyDecimalFormat

      protected transient DecimalFormat _currencyDecimalFormat
    • _currencyDecimalFormatSymbols

      protected transient DecimalFormatSymbols _currencyDecimalFormatSymbols
    • _currencyFormat

      protected String _currencyFormat
    • _currencyMinusSymbol

      protected char _currencyMinusSymbol
    • _currencyGroupingSeparator

      protected char _currencyGroupingSeparator
    • _currencyGroupingSize

      protected int _currencyGroupingSize
    • _currencyDecimalSeparator

      protected char _currencyDecimalSeparator
    • _currencyDecimalSize

      protected int _currencyDecimalSize
    • _currencyString

      protected String _currencyString
    • displayUnitsMap

      protected ConcurrentHashMap<Measure,MeasureWrapper> displayUnitsMap
    • teacherDuty

      protected TeacherDuty teacherDuty
  • Constructor Details

    • Conventions

      public Conventions()
      Empty constructor, creates a thread-safe object
    • Conventions

      public Conventions(Teacher t)
      Creates an instance of Conventions in which the variables will be initialized eventually using the dictionary provided by the Teacher, passed as parameter, or with the default values set by the Lang
      Parameters:
      t - The Teacher used to retrieve the variable's values
    • Conventions

      public Conventions(Conventions c)
      Copy Constructor
      Parameters:
      c - An instance of Conventions
  • Method Details

    • getSdfParse

      public String getSdfParse()
      Returns the string that represents the format used by this instance of Conventions for the parsing of Dates (read a string and obtain a Date).
      Returns:
      A string that represents the SimpleDateFormat used for the parsing of the Dates
    • getSdfFormat

      public String getSdfFormat()
      Returns the string that represents the format used by this instance of Conventions for the format of Dates (read a Date and obtain a String).
      Returns:
      A string that represents the SimpleDateFormat used for the reading of the Dates
    • getFdw

      public String getFdw()
      Returns the string that represents which is the day considered as first day of the week
      Returns:
      "s" for sunday, "m" for monday
    • getTimeHourSystem

      public String getTimeHourSystem()
      Returns the string that represents which hour system will be used; 24h or 12h
      Returns:
      "24" for 24h time format, or "12" for 24h time format
    • getFormat

      public String getFormat()
      Returns the string that represents the DecimalFormat used by this instance of Conventions for the format of numbers
      Returns:
      A string that represents the DecimalFormat
    • getMinusSymbol

      public char getMinusSymbol()
      Returns the char that represents the minus symbol for the DecimalFormat of this instance of Conventions
      Returns:
      A char that represents the minus symbol
    • getGroupingSeparator

      public char getGroupingSeparator()
      Returns the char that represents the thousands separator for the DecimalFormat of this instance of Conventions
      Returns:
      A char that represents the thousands separator
    • getGroupingSize

      public int getGroupingSize()
      Returns the number of the thousands grouping size for the DecimalFormat of this instance of Conventions
      Returns:
      The size of the thousands grouping
    • getDecimalSeparator

      public char getDecimalSeparator()
      Returns the char that represents the decimal separator for the DecimalFormat of this instance of Conventions
      Returns:
      A char that represents the decimal separator
    • getDecimalSize

      public int getDecimalSize()
      Returns the number of decimal digits (precision) for the DecimalFormat of this instance of Conventions
      Returns:
      The number of decimal digits allowed
    • getPercentSymbol

      public char getPercentSymbol()
      Returns the char that represents the symbol used for the percentual numbers by the DecimalFormat of this instance of Conventions
      Returns:
      The char that represents the symbol used to indicate the percentual numbers
    • getExponentString

      public String getExponentString()
      Returns the string that represents the exponent symbol used by the DecimalFormat of this instance of Conventions
      Returns:
      The string that represents the exponents
    • getCurrencyFormat

      public String getCurrencyFormat()
      Returns the string that represents the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      A string that represents the DecimalFormat used for currencies
    • getCurrencyMinusSymbol

      public char getCurrencyMinusSymbol()
      Returns the char that represents the minus symbol for the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      A char that represents the minus symbol for currencies
    • getCurrencyGroupingSeparator

      public char getCurrencyGroupingSeparator()
      Returns the char that represents the thousands separator for the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      A char that represents the thousands separator for currencies
    • getCurrencyGroupingSize

      public int getCurrencyGroupingSize()
      Returns the number of the thousands grouping size for the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      The size of the thousands grouping for currencies
    • getCurrencyDecimalSeparator

      public char getCurrencyDecimalSeparator()
      Returns the char that represents the decimal separator for the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      A char that represents the decimal separator for currencies
    • getCurrencyDecimalSize

      public int getCurrencyDecimalSize()
      Returns the number of decimal digits (precision) for the DecimalFormat used by this instance of Conventions to represents the currencies values
      Returns:
      The number of decimal digits allowed for the currencies
    • getCurrencyString

      public String getCurrencyString()
      Returns the string that represents the currency symbol for the DecimalFormat used by thi instance of Conventions to represents the currencies values
      Returns:
      The currency symbol string
    • getDisplayUnit

      public MeasureWrapper getDisplayUnit(Measure displayUnit)
      Retrieves the correct MeasureWrapper associated (by the user's language preferences) to the displayUnit passed as parameter.
      For example, if in the user's language preferences it's set that the kilometers must be shown as miles ( with $MEASURE_km=mi,2), so if the display unit passed as parameter represent the kilometers it will be returned the MeasureWrapper object that represent the miles unit of measurement and its output decimal precision.
      Parameters:
      displayUnit - The Measure from wich retrieve the right display unit of measurement set for the specific language.
      Returns:
      Retrieves the correct MeasureWrapper of measurement associated (by the language user's preferences) to the displayUnit passed as parameter.
    • setSdf

      public void setSdf(String sdfParse, String sdfFormat)
      Sets the SimpleDateFormat string for String parsing and Date formatting
      Parameters:
      sdfParse - String used as format to parse a String into a Date. If this param is null, the variable _strSdfParse is not set.
      sdfFormat - String used as format to format a Date into a String. If this param is null, the variable _strSdfFormat is not set.
    • setTimeHourSystem

      public void setTimeHourSystem(String timeHourSystem)
      Set the hour system used to display the time.
      Parameters:
      timeHourSystem - Possible values are:
      • "24" for 24h format
      • "12" for 12h format
    • setDecimalFormat

      public void setDecimalFormat(String format)
      Sets the string used to define the DecimalFormat used by this instance of Conventions
      Parameters:
      format - The string used to define the DecimaFormat
    • setDecimalFormat

      public void setDecimalFormat(String format, Character minusSymbol, Character groupingSymbol, Integer groupingSize, Character decimalSymbol, Integer decimalSize, Character percentSymbol, String exponent)
      Sets the DecimalFormat and all the corresponding symbols
      Parameters:
      format - A string that represents the DecimalFormat; if null the format will be not set
      minusSymbol - A Character that represents the minus symbol; if null the symbol will be not set
      groupingSymbol - A Character that represents the thousands separator; if null the separator will be not set
      groupingSize - The size of the thousands grouping; if null the size will be not set
      decimalSymbol - A Character that represents the decimal separator; if null the separator will be not set
      decimalSize - The number of decimal digits allowed; if null the number will be not set
      percentSymbol - The char that represents the symbol used to indicate the percentual numbers; if null the symbol will be not set
      exponent - The string that represents the exponents; if null the exponent will be not set
    • setCurrencyFormat

      public void setCurrencyFormat(String format)
      Sets the string used to define the DecimalFormat used by this instance of Conventions to represents the currency values
      Parameters:
      format - The string used to define the DecimaFormat for the currencies
    • setCurrencyFormat

      public void setCurrencyFormat(String format, Character minusSymbol, Character groupingSymbol, Integer groupingSize, Character decimalSymbol, Integer decimalSize, String currency)
      Sets the DecimalFormat for the currencies and all the corresponding symbols
      Parameters:
      format - A string that represents the DecimalFormat for the currencies; if null the format will be not set
      minusSymbol - A Character that represents the minus symbol for currencies; if null the symbol will be not set
      groupingSymbol - A Character that represents the thousands separator for currencies; if null the separator will be not set
      groupingSize - The size of the thousands grouping for currencies; if null the size will be not set
      decimalSymbol - A Character that represents the decimal separator for currencies; if null the symbol will be not set
      decimalSize - The number of decimal digits allowed for the currencies; if null the number will be not set
      currency - The currency symbol string; if null the symbol will be not set
    • setupDecimalFormat

      public void setupDecimalFormat(String symbols)
      Sets the symbols for the DecimalFormat used by this instance of Conventions
      Parameters:
      symbols - A string of symbols, written according to the following order:
      - the first character shall be used as a symbol for identifying negative numbers
      - the second character shall be used as a group separator for the whole part. If this character is followed by a number, then this number points out the size of the group (forcing the datum defined in the DecimalFormat). To avoid using a group separator, the 0 digit can be entered or the figure can be left out.
      - a character that will be used as a group separator for the fraction part. If this character is followed by a whole number, then this number points out the minimum number of decimal figures (forcing the datum defined in the DecimalFormat). By omitting the figure, we intend to avoid forcing a minimum number of decimal figures.
      - a character that will be used as a symbol for identifying percentage numbers
      - a string to be used as an exponent. The string must be reported in single quotes.
    • setupCurrencyFormat

      public void setupCurrencyFormat(String symbols)
      Sets the symbols for the DecimalFormat used for currencies
      Parameters:
      symbols - A string of symbols, written according to the following order:
      - a character that will be used as a symbol for identifying negative numbers
      - a character that will be used as a group separator for the whole part. If this character is followed by a whole number, then this number points out the size of the group (forcing the datum defined in the DecimalFormat). To avoid using a group separator, the 0 digit can be entered or the figure can be left out.
      - a character that will be used as a group separator for the fraction part. If the character is followed by a whole number, then this number points out the number of decimal figures required in the number (forcing the datum defined in the DecimalFormat). By omitting the figure, we intend to avoid forcing the number of decimal figures.
      - a string to be used as a currency symbol. The possible string must be reported in single quotes. The currency symbol will only be entered if the format requires it
    • string2Decimal

      public BigDecimal string2Decimal(String s) throws ParseException
      Converts the string passed as parameter into a BigDecimal number, using the current correct DecimalFormat of the instance
      Parameters:
      s - The string to convert
      Returns:
      The BigDecimal that corresponds to the string
      Throws:
      ParseException - If an error occurs during the parsing of the string, a ParseException will be raised
    • decimal2String

      public String decimal2String(BigDecimal d)
      Converts the BigDecimal passed as parameter into a string, using the current correct DecimalFormat of the instance
      Parameters:
      d - The number to convert
      Returns:
      The string that corresponds to the number
    • string2Date

      public Date string2Date(String s) throws ParseException
      Converts the string passed as parameter into a Date, using the current correct SimpleDateFormat of the instance
      Parameters:
      s - The string to convert; it is possible to use "now" to obtain a new Date()
      Returns:
      The Date that corresponds to the string
      Throws:
      ParseException - If an error occurs during the parsing of the string, a ParseException will be raised
    • string2LocalDateTime

      public LocalDateTime string2LocalDateTime(String dateString) throws DateTimeParseException
      Converts a string representation of a date and time to a LocalDateTime object.

      If the input string is "now", the method returns the current date and time. Otherwise, it attempts to parse the string using the ISO date-time format (yyyy-MM-ddTHH:mm:ss). If the parsing fails with a DateTimeParseException, the method attempts to parse the string using an alternative date-time format without the 'T' separator.

      Parameters:
      dateString - the string representation of the date and time. This can be "now" to get the current date and time.
      Returns:
      the corresponding LocalDateTime object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid LocalDateTime.
    • string2LocalDate

      public LocalDate string2LocalDate(String dateString) throws DateTimeParseException
      Converts a string representation of a date to a LocalDate object.

      If the input string is "now", the method returns the current date. Otherwise, it attempts to parse the string using the ISO local date format (yyyy-MM-dd).

      Parameters:
      dateString - the string representation of the date. This can be "now" to get the current date.
      Returns:
      the corresponding LocalDate object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid LocalDate.
    • string2LocalTime

      public LocalTime string2LocalTime(String timeString) throws DateTimeParseException
      Converts a string representation of a time to a LocalTime object.

      If the input string is "now", the method returns the current time. Otherwise, it attempts to parse the string using the ISO time format (HH:mm:ss).

      Parameters:
      timeString - the string representation of the time. This can be "now" to get the current time.
      Returns:
      the corresponding LocalTime object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid LocalTime.
    • date2String

      public String date2String(Date d)
      Converts the Date passed as parameter into a string, using the current correct SimpleDateFormat of the instance
      Parameters:
      d - The Date to convert
      Returns:
      The string that corresponds to the Date
    • string2Currency

      public Euro string2Currency(String s)
      Converts the string passed as parameter into a Euro object, using the current correct DecimalFormat for currencies of the instance
      Parameters:
      s - The string to convert
      Returns:
      The Euro that corresponds to the string
    • currency2String

      public String currency2String(Euro e)
      Converts the Euro object passed as parameter into a string, using the current correct DecimalFormat for currencies of the instance
      Parameters:
      e - The Euro object to convert
      Returns:
      The string that corresponds to the Euro
    • string2ZonedDateTime

      public ZonedDateTime string2ZonedDateTime(@NotNull @NotNull String dateString) throws DateTimeParseException
      Converts a string representation of a date to a ZonedDateTime object.

      If the input string is now, the method returns the current date. Otherwise, it attempts to parse the string using the ISO zoned date time format (yyyy-MM-ddTHH:mm:ssXXX).

      Parameters:
      dateString - the string representation of the date. This can be now to get the current date.
      Returns:
      the corresponding ZonedDateTime object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid ZonedDateTime.
    • string2OffsetDateTime

      public OffsetDateTime string2OffsetDateTime(@NotNull @NotNull String dateString) throws DateTimeParseException
      Converts a string representation of a date to a OffsetDateTime object.

      If the input string is now, the method returns the current date. Otherwise, it attempts to parse the string using the ISO zoned date time format (yyyy-MM-ddTHH:mm:ssXXX).

      Parameters:
      dateString - the string representation of the date. This can be now to get the current date.
      Returns:
      the corresponding OffsetDateTime object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid OffsetDateTime.
    • string2OffsetTime

      public OffsetTime string2OffsetTime(String timeString) throws DateTimeParseException
      Converts a string representation of a time to a OffsetTime object.

      If the input string is "now", the method returns the current time. Otherwise, it attempts to parse the string using the ISO time format (HH:mm:ss).

      Parameters:
      timeString - the string representation of the time. This can be "now" to get the current time.
      Returns:
      the corresponding OffsetTime object.
      Throws:
      DateTimeParseException - if the string cannot be parsed into a valid OffsetTime.