The collection must store objects of the Worker class, the description of which is given below.
- The class whose collection of instances the program manages must implement sorting by default.
- All class field requirements (specified as comments) must be met.
- For storage, you must use a collection of type java.util.LinkedList.
- When the application starts, the collection should automatically populate with the values from the file.
- The filename must be passed to the program with: command line argument.
- The data must be stored in a file in xml format.
- Reading data from a file must be implemented using the java.util.Scanner class.
- Writing data to a file must be implemented using the java.io.FileOutputStream class.
- All classes in a program must be documented in javadoc format.
- The program should work correctly with incorrect data (user input errors, lack of file access rights, etc.).
- help : show help for available commands
- info : print information about the collection to standard output (type, initialization date, number of elements, etc.)
- show : print to standard output all elements of the collection in string representation
- add {element} : add a new element to the collection
- update id {element} : update the value of the collection element whose id is equal to the given one
- remove_by_id id : remove an element from the collection by its id
- clear : clear the collection
- save : save the collection to a file
- execute_script file_name : read and execute script from specified file. The script contains commands in the same form in which they are entered by the user in interactive mode. exit : exit the program (without saving to a file)
- add_if_max {element} : add a new element to the collection if its value is greater than the value of the largest element in this collection
- add_if_min {element} : add a new element to the collection if its value is less than the smallest element in this collection
- remove_greater {element} : remove from the collection all elements greater than the given one
- remove_all_by_position position : remove from the collection all elements whose position field value is equivalent to the given one
- remove_any_by_salary salary : Remove one element from the collection whose salary field value is equivalent to the given one
- print_descending : Print the elements of a collection in descending order
- All command arguments that are standard data types (primitive types, wrapper classes, String, date storage classes) must be entered on the same line as the command name.
- All composite data types (objects of classes stored in a collection) must be entered one field per line.
- When entering composite data types, the user should be shown a prompt containing the name of the field (for example, "Enter date of birth:")
- If the field is an enum, then the name of one of its constants is entered (in this case, the list of constants must be previously displayed).
- In case of incorrect user input (a string is entered that is not the name of a constant in the enum; a string is entered instead of a number; the entered number is not within the specified limits, etc.) an error message should be displayed and the field should be asked to repeat.
- To enter null values, use an empty string.
- Fields with the comment "The value of this field should be generated automatically" should not be entered manually by the user when adding.
Additional task (DONE): write a java object <-> xml file parser.
public class Worker {
private Long id; //Поле не может быть null, Значение поля должно быть больше 0, Значение этого поля должно быть уникальным, Значение этого поля должно генерироваться автоматически
private String name; //Поле не может быть null, Строка не может быть пустой
private Coordinates coordinates; //Поле не может быть null
private java.time.LocalDate creationDate; //Поле не может быть null, Значение этого поля должно генерироваться автоматически
rivate long salary; //Значение поля должно быть больше 0
private java.time.ZonedDateTime startDate; //Поле не может быть null
private java.util.Date endDate; //Поле может быть null
private Position position; //Поле не может быть null
private Organization organization; //Поле не может быть null
}
public class Coordinates {
private float x; //Значение поля должно быть больше -690
private int y; //Значение поля должно быть больше -247
}
public class Organization {
private int annualTurnover; //Значение поля должно быть больше 0
private OrganizationType type; //Поле не может быть null
private Address officialAddress; //Поле не может быть null
}
public class Address {
private String zipCode; //Длина строки должна быть не меньше 6, Поле не может быть null
private Location town; //Поле не может быть null
}
public class Location {
private Double x; //Поле не может быть null
private int y;
private String name; //Длина строки не должна быть больше 429, Поле может быть null
}
public enum Position {
MANAGER,
HUMAN_RESOURCES,
BAKER,
COOK,
CLEANER;
}
public enum OrganizationType {
COMMERCIAL,
PUBLIC,
GOVERNMENT,
TRUST,
OPEN_JOINT_STOCK_COMPANY;
}