Package proseccoCoding.TLN.model
Class ServiceType
java.lang.Object
proseccoCoding.TLN.model.ServiceType
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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ServiceType
(String code, String name) Private constructor for a ServiceType object -
Method Summary
Modifier and TypeMethodDescriptionboolean
Equals method that compares service types only by codegetCode()
Getter for type codestatic ServiceType
getInstance
(String typeCode) Returns the instance associated with the given typeCode, if not present in all types the instance will be addedgetName()
Getter for type nameint
hashCode()
Hash Code generated only from the code attributestatic void
init()
Initializes and fills "instances" with all the known service typesReturns the list of Pairs that represents all the known service types
-
Field Details
-
instances
HashMap used to contain all possible instances of ServiceType objects -
code
Code of this service type -
name
Name of this service type
-
-
Constructor Details
-
ServiceType
Private constructor for a ServiceType object- Parameters:
code
- the code of the service typename
- The name of the service type- Throws:
IllegalArgumentException
- if one of the parameters is null
-
-
Method Details
-
getInstance
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
Getter for type name- Returns:
- The type name string
-
getCode
Getter for type code- Returns:
- The type code 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 -
equals
Equals method that compares service types only by code
-