Commit 67cb69fc authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Merge branch 'api' into jonctApiFront

parents 69e3dffd 7c404a40
Pipeline #23293 failed with stages
in 2 minutes and 33 seconds
......@@ -15,8 +15,8 @@ public class DnDAttr implements Serializable {
/**
* Basic Constructor for create attribute if beautiful value is missing.
* @param nameAttr
* @param value
* @param nameAttr : String represent Name of attribute
* @param value : Integer represent Value of attribute
*/
public DnDAttr(@NonNull String nameAttr, @NonNull Integer value) {
this(nameAttr, value, String.valueOf(value));
......@@ -24,9 +24,9 @@ public class DnDAttr implements Serializable {
/**
* Basic Constructor for create attribute if all arguments are provided.
* @param nameAttr
* @param value
* @param valueUserReadable
* @param nameAttr : String represent Name of attribute
* @param value : Integer represent Value of attribute
* @param valueUserReadable : String represent Value with modifier, ex : "14 (+2)"
*/
public DnDAttr(@NonNull String nameAttr, @NonNull Integer value,
@NonNull String valueUserReadable) {
......@@ -40,6 +40,7 @@ public class DnDAttr implements Serializable {
* @return toString
*/
@Override
@NonNull
public String toString() {
return String.format("%s : %s", nameAttr, valueUserReadable);
}
......@@ -55,7 +56,7 @@ public class DnDAttr implements Serializable {
/**
* For compare Any Object with this attribute.
* @param obj
* @param obj : Object for comparison
* @return equals
*/
@Override
......
......@@ -15,7 +15,7 @@ public class DnDAttrs implements Serializable {
/**
* Basic Constructor for create attributes if all arguments are provided.
* @param attrs
* @param attrs : List of DnDAttr represents all attributes of DnDSheet
*/
public DnDAttrs(@NonNull List<DnDAttr> attrs) {
this.attrs = attrs;
......@@ -26,6 +26,7 @@ public class DnDAttrs implements Serializable {
* @return toString
*/
@Override
@NonNull
public String toString() {
String out = "";
for (DnDAttr attr : attrs)
......@@ -35,9 +36,10 @@ public class DnDAttrs implements Serializable {
/**
* For get specific attribute if is present.
* @param nameAttr
* @param nameAttr : String to represent Attribute to search
* @return attr
*/
@Nullable
public DnDAttr get(@NonNull String nameAttr) {
for (DnDAttr attr : attrs)
if (attr.nameAttr.toLowerCase().equals(nameAttr.toLowerCase()))
......@@ -56,7 +58,7 @@ public class DnDAttrs implements Serializable {
/**
* For compare Any Object with this attributes.
* @param obj
* @param obj : Object for comparison
* @return equals
*/
@Override
......
......@@ -8,30 +8,57 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* DnDClass is a class representing the character’s class with possibly the search parameter to
* retrieve cards of that class only
*/
public class DnDClass implements Serializable, Comparable<DnDClass> {
public String queryArg;
public String name;
/**
* Basic Constructor for create class if queryArg is missing
* @param name : String represent Name of this class
*/
public DnDClass(@NonNull String name) {
this(name, null);
}
/**
* Basic Constructor for create attribute if all arguments are provided.
* @param name : String represent Name of this class
* @param queryArg : String represent the argument to pass to find a record with this class.
*/
public DnDClass(@NonNull String name, @Nullable String queryArg) {
this.name = name;
this.queryArg = queryArg;
}
/**
* For write class.
* @return toString
*/
@Override
@NonNull
public String toString() {
return this.name;
}
/**
* For identify attributes.
* @return hashCode
*/
@Override
public int hashCode() {
return this.name.hashCode();
}
/**
* For compare Any Object with this class.
* @param obj : Object for comparison
* @return equals
*/
@Override
public boolean equals(@Nullable Object obj) {
if (obj != null && obj.getClass() == this.getClass())
......@@ -65,19 +92,26 @@ public class DnDClass implements Serializable, Comparable<DnDClass> {
* For get random class from the API.
* @return class
*/
@NonNull
public static DnDClass getRandomClass() {
return getRandomClass(classes);
}
/**
* For get random class from list provided.
* @param dnDclass
* @param dnDclass : List where we’re going to shoot randomly
* @return class
*/
@NonNull
public static DnDClass getRandomClass(@NonNull List<DnDClass> dnDclass) {
return dnDclass.get(new Random().nextInt(dnDclass.size()));
}
/**
* For compare 2 class
* @param o : Object for comparison
* @return compareToResult
*/
@Override
public int compareTo(DnDClass o) {
return this.name.compareTo(o.name);
......
package fr.iutnantes.miar.dndgenerator.api.dnd;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.Serializable;
......@@ -15,11 +16,11 @@ public class DnDSaves implements Serializable {
/**
* Basic Constructor for create saves if all arguments are provided.
* @param wands
* @param breath
* @param stone
* @param magic
* @param poison
* @param wands : Integer represent resistance to wands
* @param breath : Integer represent resistance to breath
* @param stone : Integer represent resistance to stone
* @param magic : Integer represent resistance to magic
* @param poison : Integer represent resistance to poison
*/
public DnDSaves(@Nullable Integer wands, @Nullable Integer breath, @Nullable Integer stone,
@Nullable Integer magic, @Nullable Integer poison) {
......@@ -35,6 +36,7 @@ public class DnDSaves implements Serializable {
* @return toString
*/
@Override
@NonNull
public String toString() {
String out = "";
String[] labels = new String[]{"wands", "breath", "stone", "magic", "poison"};
......@@ -61,7 +63,7 @@ public class DnDSaves implements Serializable {
/**
* For compare Any Object with this saves.
* @param obj
* @param obj : Object for comparison
* @return equals
*/
@Override
......
......@@ -59,20 +59,20 @@ public class DnDSheet implements Serializable {
public TenorArgs tenorArgs;
/**
* Basic Constructor for create sheet if all arguments are provided.
* @param hp
* @param thac9
* @param ac
* @param appearance
* @param caracterClass
* @param personality
* @param system
* @param languages
* @param equipment
* @param notes
* @param saves
* @param attr
* @param skills
* @param gifObject
* @param hp : Integer represent hp of this character
* @param thac9 : Integer represent thac9 of this character
* @param ac : Integer represent ac of this character
* @param appearance : String represent appearance of this character
* @param caracterClass : DnDClass represent class of this character
* @param personality : String represent personality of this character
* @param system : DnDSystem represent system of this sheet
* @param languages : List of all languages known by this character
* @param equipment : List of all equipment of this character
* @param notes : List of all note concern this character
* @param saves : DnDSaves represent resistances of this character
* @param attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character
* @param gifObject : GIFObject represent a Media associated to this character
*/
public DnDSheet(@Nullable Integer hp, @Nullable Integer thac9, @Nullable Integer ac,
@Nullable String appearance, @NonNull DnDClass caracterClass,
......@@ -99,22 +99,22 @@ public class DnDSheet implements Serializable {
this.tenorArgs = this.gif.tenorArgs;
}
/**
* Basic Constructor for create sheet if all arguments are provided.
* @param hp
* @param thac9
* @param ac
* @param appearance
* @param caracterClass
* @param personality
* @param system
* @param languages
* @param equipment
* @param notes
* @param saves
* @param attr
* @param skills
* @param ctx
* @param tenorArgs
* Basic Constructor for create sheet from Funkaoshi API.
* @param hp : Integer represent hp of this character
* @param thac9 : Integer represent thac9 of this character
* @param ac : Integer represent ac of this character
* @param appearance : String represent appearance of this character
* @param caracterClass : DnDClass represent class of this character
* @param personality : String represent personality of this character
* @param system : DnDSystem represent system of this sheet
* @param languages : List of all languages known by this character
* @param equipment : List of all equipment of this character
* @param notes : List of all note concern this character
* @param saves : DnDSaves represent resistances of this character
* @param attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character
* @param ctx : Context for search media related to this character
* @param tenorArgs : TenorArgs for search media related to this character
*/
private DnDSheet(@Nullable Integer hp, @Nullable Integer thac9, @Nullable Integer ac,
@Nullable String appearance, @NonNull DnDClass caracterClass,
......@@ -128,62 +128,139 @@ public class DnDSheet implements Serializable {
caracterClass, appearance, system), tenorArgs));
}
/**
* For change GIF and update Fav is necessary
* @param ctx : Context for access database
* @param gif : New gif for this character
* @param dbVersion : Version of database
*/
public void changeGIF(@NonNull Context ctx, @NonNull GIFObject gif, int dbVersion) {
this.gif = gif;
if (isFav(ctx, dbVersion))
updateFav(ctx, dbVersion);
}
/**
* For update Fav
* @param ctx : Context for access database
* @param dbVersion : Version of database
* @return favIsUpdated
*/
public boolean updateFav(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).updateGIF(this);
}
/**
* For remove Fav
* @param ctx : Context for access database
* @param dbVersion : Version of database
* @return favIsRemoved
*/
public boolean removeFav(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).removeDnDSheet(this);
}
/**
* For add Fav
* @param ctx : Context for access database
* @param dbVersion : Version of database
* @return favIsAdded
*/
public boolean addFav(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).insertDnDSheet(this);
}
/**
* To find out if he's a fav
* @param ctx : Context for access database
* @param dbVersion : Version of database
* @return isFav
*/
public boolean isFav(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).getDnDSheet(hashCode()) != null;
}
/**
* For get all Favs
* @param ctx : Context for access database
* @param dbVersion : Version of database
* @return allFavs
*/
@NonNull
public static List<DnDSheet> getFavs(@NonNull Context ctx, int dbVersion) {
return new DnDSheetDB(ctx, dbVersion).getAllDnDSheet();
}
/**
* For change GIF and update Fav is necessary (In Default DB)
* @param ctx : Context for access database
* @param gif : New gif for this character
*/
public void changeGIF(@NonNull Context ctx, @NonNull GIFObject gif) {
changeGIF(ctx, gif, DnDSheetDB.DATABASE_VERSION);
}
/**
* For update Fav (In Default DB)
* @param ctx : Context for access database
* @return favIsUpdated
*/
public boolean updateFav(@NonNull Context ctx) {
return updateFav(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* For remove Fav (In Default DB)
* @param ctx : Context for access database
* @return favIsRemoved
*/
public boolean removeFav(@NonNull Context ctx) {
return removeFav(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* For add Fav (In Default DB)
* @param ctx : Context for access database
* @return favIsAdded
*/
public boolean addFav(@NonNull Context ctx) {
return addFav(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* To find out if he's a fav (In default DB)
* @param ctx : Context for access database
* @return isFav
*/
public boolean isFav(@NonNull Context ctx) {
return isFav(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* For get all Favs (In default DB)
* @param ctx : Context for access database
* @return allFavs
*/
@NonNull
public static List<DnDSheet> getFavs(@NonNull Context ctx) {
return getFavs(ctx, DnDSheetDB.DATABASE_VERSION);
}
/**
* For remove all Favs
* @param ctx : Context for access database
* @param dbVersion : Version of database
*/
public static void removeAllFavs(@NonNull Context ctx, int dbVersion) {
new DnDSheetDB(ctx, dbVersion).onClear();
new GIFArtifactDB(ctx, dbVersion).onClear();
new DnDSavesDB(ctx, dbVersion).onClear();
}
/**
* For remove all Favs (In default DB)
* @param ctx : Context for access database
*/
public static void removeAllFavs(@NonNull Context ctx) {
removeAllFavs(ctx, DnDSheetDB.DATABASE_VERSION);
}
......@@ -193,6 +270,7 @@ public class DnDSheet implements Serializable {
* @return toString
*/
@Override
@NonNull
public String toString() {
return String.format(
"DnDSheet of %s with %s", this.caracterClass, this.system
......@@ -222,7 +300,7 @@ public class DnDSheet implements Serializable {
/**
* For compare Any Object with this sheet.
* @param obj
* @param obj : Object for comparison
* @return equals
*/
@Override
......@@ -235,7 +313,7 @@ public class DnDSheet implements Serializable {
/**
* Method for obtaining a list of future character cards.
* @param ctx
* @param ctx : Context for make request for character cards
* @return futures
*/
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx) {
......@@ -243,63 +321,69 @@ public class DnDSheet implements Serializable {
}
/**
* Method for a list of future character cards.
* @param ctx
* Method for obtaining a list of character cards.
* @param ctx : Context for make request for character cards
* @return sheets
*/
@NonNull
public static List<DnDSheet> getRandomsCaracterSheet(@NonNull Context ctx) {
return getRandomsCaracterSheet(ctx, DEFAULT_SIZE_LIST_SHEET);
}
/**
* Method for a list of future character cards.
* @param ctx
* @param nb
* Method for obtaining a list of future character cards.
* @param ctx : Context for make request for character cards
* @param nb : Integer represent number of character cards you want
* @return futures
*/
@NonNull
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx,
int nb) {
return getRandomsFutureCaracterSheet(ctx, nb, DnDSystem.getRandomSystem());
}
/**
* Method for a list of future character cards.
* @param ctx
* @param nb
* Method for obtaining a list of character cards.
* @param ctx : Context for make request for character cards
* @param nb : Integer represent number of character cards you want
* @return sheets
*/
@NonNull
public static List<DnDSheet> getRandomsCaracterSheet(@NonNull Context ctx, int nb) {
return getRandomsCaracterSheet(ctx, nb, DnDSystem.getRandomSystem());
}
/**
* Method for a list of future character cards.
* @param ctx
* @param system
* Method for obtaining a list of future character cards.
* @param ctx : Context for make request for character cards
* @param system : DnDSystem represent from which system will be drawn the card
* @return futures
*/
@NonNull
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx,
@NonNull DnDSystem system) {
return getRandomsFutureCaracterSheet(ctx, DEFAULT_SIZE_LIST_SHEET, system);
}
/**
* Method for a list of future character cards.
* @param ctx
* @param system
* Method for obtaining a list of character cards.
* @param ctx : Context for make request for character cards
* @param system : DnDSystem represent from which system will be drawn the card
* @return sheets
*/
@NonNull
public static List<DnDSheet> getRandomsCaracterSheet(@NonNull Context ctx,
@NonNull DnDSystem system) {
return getRandomsCaracterSheet(ctx, DEFAULT_SIZE_LIST_SHEET, system);
}
/**
* Method for a list of future character cards.
* @param ctx
* @param dnDClass
* Method for obtaining a list of future character cards.
* @param ctx : Context for make request for character cards
* @param dnDClass : DnDClass represent with which class will be drawn the card
* @return futures
*/
@NonNull
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx,
@Nullable DnDClass
dnDClass) {
......@@ -307,22 +391,24 @@ public class DnDSheet implements Serializable {
}
/**
* Method for a list of future character cards.
* @param ctx
* @param dnDClass
* Method for obtaining a list of character cards.
* @param ctx : Context for make request for character cards
* @param dnDClass : DnDClass represent with which class will be drawn the card
* @return sheets
*/
@NonNull
public static List<DnDSheet> getRandomsCaracterSheet(@NonNull Context ctx,
@Nullable DnDClass dnDClass) {
return getRandomsCaracterSheet(ctx, DEFAULT_SIZE_LIST_SHEET, dnDClass);
}
/**
* Method for a list of future character cards.
* @param ctx
* @param tenorArgs
* Method for obtaining a list of future character cards.
* @param ctx : Context for make request for character cards
* @param tenorArgs : TenorArgs represent with which arguments, the media related to card is get
* @return futures
*/
@NonNull
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx,
@NonNull TenorArgs
tenorArgs) {
......@@ -330,23 +416,25 @@ public class DnDSheet implements Serializable {
}
/**
* Method for a list of future character cards.
* @param ctx
* @param tenorArgs
* Method for obtaining a list of character cards.
* @param ctx : Context for make request for character cards
* @param tenorArgs : TenorArgs represent with which arguments, the media related to card is get
* @return sheets
*/
@NonNull
public static List<DnDSheet> getRandomsCaracterSheet(@NonNull Context ctx,
@NonNull TenorArgs tenorArgs) {
return getRandomsCaracterSheet(ctx, DEFAULT_SIZE_LIST_SHEET, tenorArgs);
}
/**
* Method for a list of future character cards.
* @param ctx
* @param nb
* @param tenorArgs
* Method for obtaining a list of future character cards.
* @param ctx : Context for make request for character cards
* @param nb : Integer represent number of character cards you want
* @param tenorArgs : TenorArgs represent with which arguments, the media related to card is get
* @return futures
*/
@NonNull
public static List<Future<DnDSheet>> getRandomsFutureCaracterSheet(@NonNull Context ctx, int nb,
@NonNull TenorArgs
tenorArgs) {
......@@ -354,12 +442,13 @@ public class DnDSheet implements Serializable {
}
/**
* Method for a list of future character cards.
* @param ctx
* @param system
* @param tenorArgs