Core consists of two parts, which are core
and json
.
The core
contains the inner layer. This is where the essential and fundamental functionality of the app is. It contains two classes and a record, Workout
, User
and Exercise
. It also contains an interface for User
, and the RemoteUserAccess
which is in fxui
.
The Exercise record is a record that contains five properties
- (
String
) name - (
int
) sets - (
int
) repMin - (
int
) repMax - (
int
) weight
The rep-range is split into two integer fields, repMin
and repMax
, rather than making a string containing both.
All fields except from name
are ints, because it is more intuitive than Strings.
Since Exercise
is a record, you can get any of the parameters by calling <nameofexercise>
.<nameofproperty>
The workout class creates a workout that contains a list of exercises, as well as a name and a date. It also has a saved
field.
- (
Date
) date - See when the workout was created - (
String
) name - Given inOverview
to classify - (
boolean
) saved - Tracks if the workout has been saved - (
List<Exercise>
) exercises - The exercises that make up a workout
- addExercise(): Adds an
Exercise
toexercises
- removeExercise(): Removes an
Exercise
fromexercises
- moveExercise(): Moves an
Exercise
based on specific position inexercises
and the direction - getters and setters
The user class represents a user in the application. It has a list of workouts and an index of the current workout.
- (
int
) currentWorkoutIndex - gets the index of the current workout - (
List<Workout>
) workouts - A list of all workouts for the user - (
boolean
) persistence - indicates whether workouts should be loaded or not from a file
- removeWorkout(): Removes a specific
Workout
fromworkouts
based on input - removeCurrentWorkout(): Removes the current
Workout
fromworkouts
- getCurrentWorkoutSaved(): Returns true if the current
Workout
is saved. - getCurrentWorkoutExerciseCount(): Returns the number of exercises in the current
Workout
. - getCurrentWorkoutName(): Returns the
name
fo the current workout. - getCurrentWorkoutExerciseAttribute(): Returns a
String
based on the exercise index, and which attribute to consider. - setCurrentWorkout: Sets the current workout index to be the specified value.
- getWorkoutNames(): Returns all the names of the workouts.
- getWorkoutDates(): Returns all the dates of the workouts.
- addExerciseToCurrentWorkout(): Adds an exercise to the current workout.
- removeExerciseFromCurrentWorkout(): Removes an exercise from the current workout.
- moveExerciseInCurrentWorkout(): Calls
moveExercise
on the current workout to specify what and where to move the exercise - saveCurrentWorkout(): Saves the workout by setting
name
,date
andsaved
of the workout. - deleteUnsavedWorkouts(): Removes the workouts that aren't saved from
workouts
. - getExerciseList(): gets a list of exercise-names based on JSON.
This is an interface that is implemented by User
and RemoteUserAccess
.
The json
folder contains the classes ExerciseListLoader
and WorkoutPersistence
. These classes are used for file-handling and are used to read the required data from json files.
ExerciseListLoader
loads exercises from a JSON file as a list of string and has one static method.
- (
ObjectMapper
) OBJECT_MAPPER - a static objectmapper for reading from a json file.
- loadExerciseListFromJson(): Loads the names of the exercises to a list, and returns a list of strings.
WorkoutPersistence
saves the workout for the current session.
- (
ObjectMapper
) OBJECT_MAPPER - a static objectmapper for reading and writing to a json file. - (
String
) resourcePath - the defined path for where everything should be saved to
- loadWorkoutFromJson(): Returns a list of workouts from the designated file if possible.
- saveWorkoutsToJson(): Saves a list of workouts to the designated file.
The date is to see when the workout was created, the name is given in Overview
to classify, and the list of exercises, are the exercises that shows up in the overview of plans.
Our app has implemented persistence via the library Jackson. This library serializes Java objects to a JSON format, and deserializes JSON back to Java objects. That's why additional deserializers and serializers are unnecessary for the app.
Because we have direct control over when and how the data is saved, the saving is explicit. Take the case where you save a workout. This runs the saveCurrentWorkout() function in User, which activates the persistence. This is the opposite of implicit saving, where data gets saved automatically. The persistence saves a list of workouts, making the document-metaphor work best. This is because you can look at the list of workouts as a document. This document is what gets serialized and deserialized, and makes the persistence simple by having only a list to save to and from.
workoutplanner/core/CORE.md