-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…tion Pattern registration
- Loading branch information
Showing
110 changed files
with
1,983 additions
and
327 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
plugins { | ||
id("refinedarchitect.base") | ||
} | ||
|
||
refinedarchitect { | ||
testing() | ||
mutationTesting() | ||
javadoc() | ||
publishing { | ||
maven = true | ||
} | ||
} | ||
|
||
base { | ||
archivesName.set("refinedstorage-autocrafting-api") | ||
} | ||
|
||
dependencies { | ||
api(libs.apiguardian) | ||
api(project(":refinedstorage-resource-api")) | ||
api(project(":refinedstorage-core-api")) | ||
api(project(":refinedstorage-storage-api")) | ||
api(project(":refinedstorage-query-parser")) | ||
implementation(libs.slf4j.api) | ||
testImplementation(libs.junit.api) | ||
testImplementation(libs.junit.params) | ||
testImplementation(libs.assertj) | ||
testImplementation(libs.mockito) | ||
testRuntimeOnly(libs.junit.engine) | ||
testRuntimeOnly(libs.slf4j.impl) | ||
} |
12 changes: 12 additions & 0 deletions
12
...tocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/Pattern.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.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.Set; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.6") | ||
public interface Pattern { | ||
Set<ResourceKey> getOutputResources(); | ||
} |
16 changes: 16 additions & 0 deletions
16
...-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepository.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,16 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.Set; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8") | ||
public interface PatternRepository { | ||
void add(Pattern pattern); | ||
|
||
void remove(Pattern pattern); | ||
|
||
Set<ResourceKey> getOutputs(); | ||
} |
34 changes: 34 additions & 0 deletions
34
.../src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImpl.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,34 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class PatternRepositoryImpl implements PatternRepository { | ||
private final Set<Pattern> patterns = new HashSet<>(); | ||
private final Set<ResourceKey> outputs = new HashSet<>(); | ||
|
||
@Override | ||
public void add(final Pattern pattern) { | ||
patterns.add(pattern); | ||
outputs.addAll(pattern.getOutputResources()); | ||
} | ||
|
||
@Override | ||
public void remove(final Pattern pattern) { | ||
patterns.remove(pattern); | ||
for (final ResourceKey output : pattern.getOutputResources()) { | ||
final boolean noOtherPatternHasThisOutput = patterns.stream() | ||
.noneMatch(otherPattern -> otherPattern.getOutputResources().contains(output)); | ||
if (noOtherPatternHasThisOutput) { | ||
outputs.remove(output); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Set<ResourceKey> getOutputs() { | ||
return outputs; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...fting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@FieldsAndMethodsAreNonnullByDefault | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
9 changes: 9 additions & 0 deletions
9
...ting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/FakeResources.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,9 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
public enum FakeResources implements ResourceKey { | ||
A, | ||
B, | ||
C | ||
} |
95 changes: 95 additions & 0 deletions
95
.../test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImplTest.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,95 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PatternRepositoryImplTest { | ||
private PatternRepositoryImpl sut; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
sut = new PatternRepositoryImpl(); | ||
} | ||
|
||
@Test | ||
void testDefaultState() { | ||
// Assert | ||
assertThat(sut.getOutputs()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldAddPattern() { | ||
// Act | ||
sut.add(new SimplePattern(FakeResources.A)); | ||
|
||
// Assert | ||
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.A); | ||
} | ||
|
||
@Test | ||
void shouldAddMultiplePatterns() { | ||
// Act | ||
sut.add(new SimplePattern(FakeResources.A)); | ||
sut.add(new SimplePattern(FakeResources.B)); | ||
|
||
// Assert | ||
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( | ||
FakeResources.A, | ||
FakeResources.B | ||
); | ||
} | ||
|
||
@Test | ||
void shouldRemovePattern() { | ||
// Arrange | ||
final SimplePattern a = new SimplePattern(FakeResources.A); | ||
final SimplePattern b = new SimplePattern(FakeResources.B); | ||
|
||
sut.add(a); | ||
sut.add(b); | ||
|
||
// Act | ||
sut.remove(a); | ||
|
||
// Assert | ||
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.B); | ||
} | ||
|
||
@Test | ||
void shouldRemoveMultiplePatterns() { | ||
// Arrange | ||
final SimplePattern a = new SimplePattern(FakeResources.A); | ||
final SimplePattern b = new SimplePattern(FakeResources.B); | ||
|
||
sut.add(a); | ||
sut.add(b); | ||
|
||
// Act | ||
sut.remove(a); | ||
sut.remove(b); | ||
|
||
// Assert | ||
assertThat(sut.getOutputs()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldRemovePatternButNotRemoveOutputIfAnotherPatternStillHasThatOutput() { | ||
// Arrange | ||
final SimplePattern a = new SimplePattern(FakeResources.A); | ||
final SimplePattern b = new SimplePattern(FakeResources.B, FakeResources.A); | ||
|
||
sut.add(a); | ||
sut.add(b); | ||
|
||
// Act | ||
sut.remove(a); | ||
|
||
// Assert | ||
assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( | ||
FakeResources.A, | ||
FakeResources.B | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/SimplePattern.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,18 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.Set; | ||
|
||
public class SimplePattern implements Pattern { | ||
private final Set<ResourceKey> outputs; | ||
|
||
public SimplePattern(final ResourceKey... outputs) { | ||
this.outputs = Set.of(outputs); | ||
} | ||
|
||
@Override | ||
public Set<ResourceKey> getOutputResources() { | ||
return outputs; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...fting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@FieldsAndMethodsAreNonnullByDefault | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
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
2 changes: 1 addition & 1 deletion
2
...common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.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
2 changes: 1 addition & 1 deletion
2
...n-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.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
7 changes: 0 additions & 7 deletions
7
...mon-api/src/main/java/com/refinedmods/refinedstorage/common/api/autocrafting/Pattern.java
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...main/java/com/refinedmods/refinedstorage/common/api/autocrafting/PatternProviderItem.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
Oops, something went wrong.