Record Class Durata
java.lang.Object
java.lang.Record
it.unimi.di.prog2.temisvolti.playfy.Durata
Record (immutabile) che rappresenta una durata (non negativa).
Le istanze possono essere costruite a partire dalla durata espressa in secondi, oppure tramite un metodo di fabbricazione che accetta stringhe del formato HH:MM:SS.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The field for thesecondi
record component. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.int
secondi()
Returns the value of thesecondi
record component.Restituisce una nuova durata pari alla somma di questa durata con l'argomento.Restituisce una nuova durata pari alla differenza tra questa durata con l'argomento.private static int
Metodo di utilità che effettua la conversione da una componente della stringa HH:MM:SS al valore numerico corrispondete.toString()
Returns a string representation of this record class.(package private) static Durata
Fabbrica una durata data una stringa del formato HH:MM:SS, MM:SS o SS.
-
Field Details
-
secondi
private final int secondiThe field for thesecondi
record component.
-
-
Constructor Details
-
Durata
public Durata(int secondi) Costruisce una durata.- Parameters:
secondi
- la durata espressa in secondin.- Throws:
IllegalArgumentException
- se la durata è negativa.
-
-
Method Details
-
toHMS
Metodo di utilità che effettua la conversione da una componente della stringa HH:MM:SS al valore numerico corrispondete.Questo metodo può essere usato per convertire una delle parti ottenute dividendo la stringa HH:MM:SS ove occorre il carattere :, il parametro
bounded
consente di specificare se il massimo valore accettabile sia 60 (per le componenti MM e SS) o non se c'è limite (per la componente HH).- Parameters:
componente
- la componente dell'orario.bounded
- se il il valore numerico della componente dev'essere minore di 60.- Returns:
- il valore numerico della componente.
- Throws:
NullPointerException
- se la componente ènull
.IllegalArgumentException
- se la componente è vuota, se non può essere converita in un intero, se il suo valore non è compreso tra 0 (compreso) e il bound specificato (escluso).
-
valueOf
Fabbrica una durata data una stringa del formato HH:MM:SS, MM:SS o SS.- Parameters:
durata
- la durata nel formato specificato.- Returns:
- una
Durata
. - Throws:
NullPointerException
- se la durata ènull
.IllegalArgumentException
- se la stringa è nulla, o non è nel formato specificato.
-
somma
Restituisce una nuova durata pari alla somma di questa durata con l'argomento.- Parameters:
altra
- la durata da sommare a questa.- Returns:
- la somma delle durate.
- Throws:
NullPointerException
- se la durata ènull
.
-
sottrai
Restituisce una nuova durata pari alla differenza tra questa durata con l'argomento.- Parameters:
altra
- la durata da sottrarre da questa.- Returns:
- la differenza delle durate.
- Throws:
NullPointerException
- se la durata ènull
.IllegalArgumentException
- se l'altra durata è maggiore di questa.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
secondi
public int secondi()Returns the value of thesecondi
record component.- Returns:
- the value of the
secondi
record component
-