-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add util method for joining 2 sets * Add error if any of the mandatory tags is missing
- Loading branch information
Showing
11 changed files
with
147 additions
and
11 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/com/github/nianna/karedi/problem/MandatoryTagMissingProblem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.nianna.karedi.problem; | ||
|
||
import com.github.nianna.karedi.I18N; | ||
import com.github.nianna.karedi.song.tag.TagKey; | ||
|
||
public class MandatoryTagMissingProblem extends TagProblem { | ||
|
||
public MandatoryTagMissingProblem(TagKey key) { | ||
super(Severity.ERROR, I18N.get("problem.tag.mandatory_missing.title", key), key); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/github/nianna/karedi/song/tag/FormatSpecificationMandatoryTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.nianna.karedi.song.tag; | ||
|
||
import com.github.nianna.karedi.util.CollectionsUtils; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
class FormatSpecificationMandatoryTags { | ||
|
||
private static final Set<TagKey> COMMON_MANDATORY_KEYS = Set.of( | ||
TagKey.ARTIST, | ||
TagKey.TITLE, | ||
TagKey.BPM, | ||
TagKey.MP3 | ||
); | ||
|
||
private static final Set<TagKey> V_1_0_0_MANDATORY_KEYS = CollectionsUtils.join( | ||
COMMON_MANDATORY_KEYS, Set.of(TagKey.VERSION) | ||
); | ||
|
||
private static final Set<TagKey> V_1_1_0_MANDATORY_KEYS = CollectionsUtils.join( | ||
V_1_0_0_MANDATORY_KEYS, | ||
Set.of(TagKey.AUDIO) | ||
); | ||
|
||
private static final Map<FormatSpecification, Set<TagKey>> MANDATORY_KEYS = Map.of( | ||
FormatSpecification.V_1_0_0, V_1_0_0_MANDATORY_KEYS, | ||
FormatSpecification.V_1_1_0, V_1_1_0_MANDATORY_KEYS | ||
); | ||
|
||
|
||
private FormatSpecificationMandatoryTags() { | ||
|
||
} | ||
|
||
public static Set<TagKey> forFormat(FormatSpecification formatSpecification) { | ||
return Optional.ofNullable(formatSpecification) | ||
.map(MANDATORY_KEYS::get) | ||
.orElse(COMMON_MANDATORY_KEYS); | ||
} | ||
|
||
|
||
} |
4 changes: 2 additions & 2 deletions
4
src/main/java/com/github/nianna/karedi/song/tag/FormatSpecificationMultiValuedTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/github/nianna/karedi/util/CollectionsUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.nianna.karedi.util; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public final class CollectionsUtils { | ||
|
||
private CollectionsUtils() { | ||
|
||
} | ||
|
||
public static <T> Set<T> join(Set<T> first, Set<T> second) { | ||
return Stream.of(first, second) | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/com/github/nianna/karedi/song/tag/FormatSpecificationMandatoryTagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.nianna.karedi.song.tag; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FormatSpecificationMandatoryTagsTest { | ||
|
||
@Test | ||
void shouldReturnMandatoryKeysForNullFormat() { | ||
Set<TagKey> result = FormatSpecificationMandatoryTags.forFormat(null); | ||
assertEquals(4, result.size()); | ||
assertTrue(result.containsAll(Set.of(TagKey.ARTIST, TagKey.TITLE, TagKey.BPM, TagKey.MP3))); | ||
} | ||
|
||
@Test | ||
void shouldReturnMandatoryKeysForV1_0_0Format() { | ||
Set<TagKey> result = FormatSpecificationMandatoryTags.forFormat(FormatSpecification.V_1_0_0); | ||
assertEquals(5, result.size()); | ||
assertTrue(result.containsAll(Set.of(TagKey.ARTIST, TagKey.TITLE, TagKey.BPM, TagKey.MP3, TagKey.VERSION))); | ||
} | ||
|
||
@Test | ||
void shouldReturnMandatoryKeysForV1_1_0Format() { | ||
Set<TagKey> result = FormatSpecificationMandatoryTags.forFormat(FormatSpecification.V_1_1_0); | ||
assertEquals(6, result.size()); | ||
assertTrue(result.containsAll(Set.of(TagKey.ARTIST, TagKey.TITLE, TagKey.BPM, TagKey.MP3, TagKey.VERSION, | ||
TagKey.AUDIO))); | ||
} | ||
|
||
} |