Adds monster collections.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.majinnaibu.monstercards.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(tableName = "collections")
|
||||
public class Collection {
|
||||
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public UUID id;
|
||||
|
||||
@NonNull
|
||||
@ColumnInfo(defaultValue = "")
|
||||
public String name;
|
||||
|
||||
@NonNull
|
||||
@ColumnInfo(defaultValue = "")
|
||||
public String description;
|
||||
|
||||
public Collection() {
|
||||
this.id = UUID.randomUUID();
|
||||
this.name = "";
|
||||
this.description = "";
|
||||
}
|
||||
|
||||
public Collection(@NonNull String name, @NonNull String description) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Collection that = (Collection) obj;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(name, that.name) &&
|
||||
Objects.equals(description, that.description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, description);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.majinnaibu.monstercards.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
import androidx.room.Index;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(
|
||||
tableName = "collection_monsters",
|
||||
foreignKeys = {
|
||||
@ForeignKey(
|
||||
entity = Collection.class,
|
||||
parentColumns = "id",
|
||||
childColumns = "collection_id",
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
@ForeignKey(
|
||||
entity = Monster.class,
|
||||
parentColumns = "id",
|
||||
childColumns = "monster_id",
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
},
|
||||
indices = {
|
||||
@Index(value = {"collection_id"}),
|
||||
@Index(value = {"monster_id"})
|
||||
}
|
||||
)
|
||||
public class CollectionMonster {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public long id;
|
||||
|
||||
@NonNull
|
||||
@ColumnInfo(name = "collection_id")
|
||||
public UUID collectionId;
|
||||
|
||||
@NonNull
|
||||
@ColumnInfo(name = "monster_id")
|
||||
public UUID monsterId;
|
||||
|
||||
@ColumnInfo(name = "ordinal", defaultValue = "0")
|
||||
public int ordinal;
|
||||
|
||||
public CollectionMonster() {
|
||||
this.collectionId = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
this.monsterId = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
this.ordinal = 0;
|
||||
}
|
||||
|
||||
public CollectionMonster(@NonNull UUID collectionId, @NonNull UUID monsterId, int ordinal) {
|
||||
this.collectionId = collectionId;
|
||||
this.monsterId = monsterId;
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.majinnaibu.monstercards.models;
|
||||
|
||||
import androidx.room.Embedded;
|
||||
|
||||
public class CollectionWithCount {
|
||||
@Embedded
|
||||
public Collection collection;
|
||||
|
||||
public int monsterCount;
|
||||
|
||||
public CollectionWithCount() {
|
||||
this.collection = new Collection();
|
||||
this.monsterCount = 0;
|
||||
}
|
||||
|
||||
public CollectionWithCount(Collection collection, int monsterCount) {
|
||||
this.collection = collection;
|
||||
this.monsterCount = monsterCount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user