Portfolio Code | Clement Colmerauer
Repositories
Site
Software engineering : Airport library
Code
Commits
Branches
Tags
Search
Tree:
12cfefd
Branches
Tags
master
Software engineering : Airport library
src
flights
identifier
FlightId.java
Initial commit
ClementColmerauer
commited
12cfefd
at 2024-10-20 09:50:50
FlightId.java
Blame
History
Raw
package com.uca.flights; import com.uca.data_validation.IdentifierValidator; /** * Represent a flight identifier, the prefix of the company plus an integer on 4 digits * @Author Cesano Ugo, Colmerauer Clément * */ public class FlightId implements Comparable<FlightId> //Pas besoinde clone car non modifiable { /**Flight id value*/ final private String value; /** * Constructor * @param value the flight id value * @throws IllegalArgumentException on null or empty parameter */ FlightId(String value) { if(!IdentifierValidator.isFlightIdValid(value)) { throw new IllegalArgumentException("Invalid flight id."); } this.value = value; } /** * Getter * @return flight id value */ public String getValue() { return this.value; } /** * Redefinition of toString * @return the value of the flight id */ @Override public String toString() { return this.value; } /** * Redefinition of compareTo * @param other the FlightId to compare to * @return 0 if other has the same value, 1 else * @throws IllegalArgumentException on null parameter */ @Override public int compareTo(FlightId other) { if(other == null) { throw new IllegalArgumentException("FlightId can't be null."); } if(this.value == other.getValue()) { return 0; } return 1; } /** * Redefinition of equals * @param other the FlightId to compare to * @return true if other has the same value, false else * @throws IllegalArgumentException on null or not FlightId parameter */ @Override public boolean equals(Object other) { if(other == null) { throw new IllegalArgumentException("FlightId can't be null."); } if(!(other instanceof FlightId)) { throw new IllegalArgumentException("Must be compared with flight id."); } FlightId f = (FlightId)other; return compareTo(f) == 0; } /** * Redefinition of hashCode * @return the hashcode */ @Override public int hashCode() { return this.value == null ? 0 : this.value.length(); } }