Implements database, adds profiles
This commit is contained in:
@@ -3,7 +3,6 @@ package ch.gtache.fro;
|
||||
/**
|
||||
* Represents a bird
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Bird {
|
||||
|
||||
/**
|
||||
@@ -12,4 +11,18 @@ public interface Bird {
|
||||
* @return The name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns the family of the bird
|
||||
*
|
||||
* @return The family
|
||||
*/
|
||||
BirdFamily family();
|
||||
|
||||
/**
|
||||
* Returns the migration type of the bird
|
||||
*
|
||||
* @return The migration type
|
||||
*/
|
||||
MigrationType migrationType();
|
||||
}
|
||||
|
||||
15
api/src/main/java/ch/gtache/fro/BirdFamily.java
Normal file
15
api/src/main/java/ch/gtache/fro/BirdFamily.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* Represents a bird family
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface BirdFamily {
|
||||
|
||||
/**
|
||||
* Returns the name of the family
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
7
api/src/main/java/ch/gtache/fro/BirdFamilyProvider.java
Normal file
7
api/src/main/java/ch/gtache/fro/BirdFamilyProvider.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* {@link Provider} of {@link BirdFamily}
|
||||
*/
|
||||
public interface BirdFamilyProvider extends Provider<String, BirdFamily> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* Translates a {@link BirdFamily} to a string
|
||||
*/
|
||||
public interface BirdFamilyTranslator extends Translator<BirdFamily> {
|
||||
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package ch.gtache.fro;
|
||||
/**
|
||||
* {@link Provider} of {@link Bird}
|
||||
*/
|
||||
public interface BirdProvider extends Provider<Bird> {
|
||||
public interface BirdProvider extends Provider<String, Bird> {
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package ch.gtache.fro;
|
||||
/**
|
||||
* {@link Provider} of {@link Fetcher}
|
||||
*/
|
||||
public interface FetcherProvider extends Provider<Fetcher> {
|
||||
public interface FetcherProvider extends Provider<String, Fetcher> {
|
||||
|
||||
}
|
||||
|
||||
13
api/src/main/java/ch/gtache/fro/Initializer.java
Normal file
13
api/src/main/java/ch/gtache/fro/Initializer.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* Interface for initializers
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Initializer {
|
||||
|
||||
/**
|
||||
* Runs the initialization
|
||||
*/
|
||||
void initialize();
|
||||
}
|
||||
15
api/src/main/java/ch/gtache/fro/MigrationType.java
Normal file
15
api/src/main/java/ch/gtache/fro/MigrationType.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* Represents a migration type
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MigrationType {
|
||||
|
||||
/**
|
||||
* Returns the name of the type
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* {@link Provider} of {@link MigrationType}
|
||||
*/
|
||||
public interface MigrationTypeProvider extends Provider<String, MigrationType> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
/**
|
||||
* Translates a {@link MigrationType} to a string
|
||||
*/
|
||||
public interface MigrationTypeTranslator extends Translator<MigrationType> {
|
||||
|
||||
}
|
||||
@@ -6,28 +6,31 @@ import java.util.concurrent.CompletionException;
|
||||
|
||||
/**
|
||||
* Provides objects
|
||||
*
|
||||
* @param <K> The type of key
|
||||
* @param <V> The type of value
|
||||
*/
|
||||
public interface Provider<T> {
|
||||
public interface Provider<K, V> {
|
||||
|
||||
/**
|
||||
* Returns the object with the given name
|
||||
* Returns the object with the given key
|
||||
*
|
||||
* @param name The name of the object
|
||||
* @param key The key of the object
|
||||
* @return The object, or null if not found
|
||||
* @throws ProvisionException If an error occurs
|
||||
*/
|
||||
T getObject(final String name) throws ProvisionException;
|
||||
V getObject(final K key) throws ProvisionException;
|
||||
|
||||
/**
|
||||
* Returns the object with the given name asynchronously
|
||||
* Returns the object with the given key asynchronously
|
||||
*
|
||||
* @param name The name of the object
|
||||
* @param key The key of the object
|
||||
* @return A future containing the object, or null if not found
|
||||
*/
|
||||
default CompletableFuture<T> getObjectAsync(final String name) {
|
||||
default CompletableFuture<V> getObjectAsync(final K key) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getObject(name);
|
||||
return getObject(key);
|
||||
} catch (final ProvisionException e) {
|
||||
throw new CompletionException(e);
|
||||
}
|
||||
@@ -40,14 +43,14 @@ public interface Provider<T> {
|
||||
* @return The list of object
|
||||
* @throws ProvisionException If an error occurs
|
||||
*/
|
||||
Collection<T> getAllObjects() throws ProvisionException;
|
||||
Collection<V> getAllObjects() throws ProvisionException;
|
||||
|
||||
/**
|
||||
* Returns all the object known to this provider asynchronously
|
||||
*
|
||||
* @return A future containing the list of object
|
||||
*/
|
||||
default CompletableFuture<Collection<T>> getAllObjectsAsync() {
|
||||
default CompletableFuture<Collection<V>> getAllObjectsAsync() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getAllObjects();
|
||||
|
||||
38
api/src/main/java/ch/gtache/fro/Translated.java
Normal file
38
api/src/main/java/ch/gtache/fro/Translated.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package ch.gtache.fro;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a translated object
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Translated {
|
||||
|
||||
/**
|
||||
* Returns the translations
|
||||
*
|
||||
* @return The translations
|
||||
*/
|
||||
Map<Locale, String> translations();
|
||||
|
||||
/**
|
||||
* Translates the object using the given locale
|
||||
*
|
||||
* @param locale The locale
|
||||
* @return The translated string
|
||||
*/
|
||||
default String translate(final Locale locale) {
|
||||
return translations().get(locale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates the object using the default locale
|
||||
*
|
||||
* @return The translated string
|
||||
*/
|
||||
default String translate() {
|
||||
return translate(Locale.getDefault());
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public interface Translator<T> {
|
||||
* @throws TranslationException If an error occurs
|
||||
*/
|
||||
default String translate(final T object) throws TranslationException {
|
||||
return translate(object, Locale.getDefault());
|
||||
return translate(object, getDefaultLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +55,14 @@ public interface Translator<T> {
|
||||
* @return A future containing the translated string
|
||||
*/
|
||||
default CompletableFuture<String> translateAsync(final T object) {
|
||||
return translateAsync(object, Locale.getDefault());
|
||||
return translateAsync(object, getDefaultLocale());
|
||||
}
|
||||
|
||||
private static Locale normalizeLocale(final Locale locale) {
|
||||
return Locale.of(locale.getLanguage());
|
||||
}
|
||||
|
||||
private static Locale getDefaultLocale() {
|
||||
return normalizeLocale(Locale.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
import ch.gtache.fro.Bird;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Configuration for a practice run
|
||||
*/
|
||||
public interface GroupedBirdPracticeParameters {
|
||||
|
||||
/**
|
||||
* Returns the profile of the parameters (if any)
|
||||
*
|
||||
* @return The profile
|
||||
*/
|
||||
PracticeProfile profile();
|
||||
|
||||
/**
|
||||
* Returns the bird practice parameters
|
||||
*
|
||||
* @return The parameters
|
||||
*/
|
||||
Collection<BirdPracticeParameters> parameters();
|
||||
|
||||
/**
|
||||
* Returns the bird practice parameters for a specific bird
|
||||
*
|
||||
* @param bird The bird
|
||||
* @return The parameters
|
||||
*/
|
||||
default BirdPracticeParameters parameters(final Bird bird) {
|
||||
return parameters().stream().filter(p -> p.bird().equals(bird)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
import ch.gtache.fro.Provider;
|
||||
|
||||
/**
|
||||
* Manager of {@link GroupedBirdPracticeParameters}s
|
||||
*/
|
||||
public interface GroupedBirdPracticeParametersManager extends Provider<PracticeProfile, GroupedBirdPracticeParameters> {
|
||||
|
||||
/**
|
||||
* Saves the given configuration with the given profile
|
||||
*
|
||||
* @param configuration The configuration
|
||||
* @param profile The profile
|
||||
*/
|
||||
void save(final GroupedBirdPracticeParameters configuration, final PracticeProfile profile);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
import ch.gtache.fro.Bird;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public interface PracticeConfiguration {
|
||||
|
||||
/**
|
||||
* Sets the number of unsuccessful guesses before a question is considered as failed
|
||||
*
|
||||
* @return The number of unsuccessful guesses
|
||||
*/
|
||||
int guessesNumber();
|
||||
|
||||
/**
|
||||
* Sets the number of unsuccessful guesses before a question is considered as failed
|
||||
*
|
||||
* @param guessNumber The number of unsuccessful guesses
|
||||
*/
|
||||
void setGuessesNumber(final int guessNumber);
|
||||
|
||||
/**
|
||||
* Returns the saved question rates
|
||||
*
|
||||
* @return The question rates
|
||||
*/
|
||||
Map<QuestionType, Double> questionRates();
|
||||
|
||||
/**
|
||||
* Sets the question rates
|
||||
*
|
||||
* @param questionRates The question rates
|
||||
*/
|
||||
void setQuestionRates(final Map<QuestionType, Double> questionRates);
|
||||
|
||||
/**
|
||||
* Returns the bird practice parameters
|
||||
*
|
||||
* @return The parameters
|
||||
*/
|
||||
Collection<BirdPracticeParameters> birdPracticeParameters();
|
||||
|
||||
/**
|
||||
* Returns the bird practice parameters for a specific bird
|
||||
*
|
||||
* @param bird The bird
|
||||
* @return The parameters
|
||||
*/
|
||||
BirdPracticeParameters birdPracticeParameters(final Bird bird);
|
||||
|
||||
/**
|
||||
* Sets the bird practice parameters
|
||||
*
|
||||
* @param birdPracticeParameters The parameters
|
||||
*/
|
||||
void setBirdPracticeParameters(final Collection<? extends BirdPracticeParameters> birdPracticeParameters);
|
||||
|
||||
/**
|
||||
* Sets the bird practice parameters for a specific bird
|
||||
*
|
||||
* @param birdPracticeParameters The parameters
|
||||
*/
|
||||
void setBirdPracticeParameters(final BirdPracticeParameters birdPracticeParameters);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
import ch.gtache.fro.Bird;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -10,11 +8,11 @@ import java.util.Map;
|
||||
public interface PracticeParameters {
|
||||
|
||||
/**
|
||||
* Returns the mapping of bird to bird parameters
|
||||
* Returns the bird parameters
|
||||
*
|
||||
* @return The mapping of bird to bird parameters
|
||||
* @return The parameters
|
||||
*/
|
||||
Map<Bird, BirdPracticeParameters> birdParameters();
|
||||
GroupedBirdPracticeParameters birdParameters();
|
||||
|
||||
/**
|
||||
* Returns the number of unsuccessful guesses before a question is considered as failed
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
/**
|
||||
* Represents a profile for a practice session
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PracticeProfile {
|
||||
|
||||
/**
|
||||
* Returns the name of the profile
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package ch.gtache.fro.practice;
|
||||
|
||||
import ch.gtache.fro.Provider;
|
||||
|
||||
/**
|
||||
* {@link Provider} of {@link PracticeProfile}
|
||||
*/
|
||||
public interface PracticeProfileProvider extends Provider<String, PracticeProfile> {
|
||||
}
|
||||
Reference in New Issue
Block a user