Class ServiceType

java.lang.Object
proseccoCoding.TLN.model.ServiceType

public class ServiceType extends Object
This class represents a type of service with his name and code. It implements the Singleton pattern customized to be used for not one but all known service types. To retrieve the instance only the type code is needed and, if the code is known, automatically his complete name is associated with it. In case of unrecognized type code this class uses the code as name, adding "(complete name not found)". In both cases the fact that the object would be a singleton is granted.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
    Code of this service type
    private static HashMap<String,ServiceType>
    HashMap used to contain all possible instances of ServiceType objects
    private String
    Name of this service type
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    ServiceType(String code, String name)
    Private constructor for a ServiceType object
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Equals method that compares service types only by code
    Getter for type code
    getInstance(String typeCode)
    Returns the instance associated with the given typeCode, if not present in all types the instance will be added
    Getter for type name
    int
    Hash Code generated only from the code attribute
    static void
    Initializes and fills "instances" with all the known service types
    static ArrayList<javafx.util.Pair<String,String>>
    Returns the list of Pairs that represents all the known service types

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • instances

      private static HashMap<String,ServiceType> instances
      HashMap used to contain all possible instances of ServiceType objects
    • code

      private String code
      Code of this service type
    • name

      private String name
      Name of this service type
  • Constructor Details

    • ServiceType

      private ServiceType(String code, String name)
      Private constructor for a ServiceType object
      Parameters:
      code - the code of the service type
      name - The name of the service type
      Throws:
      IllegalArgumentException - if one of the parameters is null
  • Method Details

    • getInstance

      public static ServiceType getInstance(String typeCode)
      Returns the instance associated with the given typeCode, if not present in all types the instance will be added
      Parameters:
      typeCode - The code of the type to get the instance
      Returns:
      the Singleton instance of ServiceType associated with typeCode
      Throws:
      IllegalArgumentException - if the code is null
    • init

      public static void init()
      Initializes and fills "instances" with all the known service types
    • getName

      public String getName()
      Getter for type name
      Returns:
      The type name string
    • getCode

      public String getCode()
      Getter for type code
      Returns:
      The type code string
    • printServiceTypes

      public static ArrayList<javafx.util.Pair<String,String>> printServiceTypes()
      Returns the list of Pairs that represents all the known service types
      Returns:
      An ArrayList of Pairs containing as Key the type code, and as value the type name
    • hashCode

      public int hashCode()
      Hash Code generated only from the code attribute
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Equals method that compares service types only by code
      Overrides:
      equals in class Object
      Parameters:
      obj - object to compare to this