Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. package net.byteflux.core.library;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Base64;
  5. import java.util.Collection;
  6. import java.util.Collections;
  7. import java.util.LinkedList;
  8. import java.util.List;
  9. import static java.util.Objects.requireNonNull;
  10.  
  11. public class Library {
  12. private final Collection<String> urls;
  13. private final String groupId;
  14. private final String artifactId;
  15. private final String version;
  16. private final String classifier;
  17. private final byte[] checksum;
  18. private final Collection<Relocation> relocations;
  19.  
  20. public Library(Collection<String> urls,
  21. String groupId,
  22. String artifactId,
  23. String version,
  24. String classifier,
  25. byte[] checksum,
  26. Collection<Relocation> relocations) {
  27.  
  28. this.urls = urls != null ? Collections.unmodifiableList(new LinkedList<>(urls)) : Collections.emptyList();
  29. this.groupId = requireNonNull(groupId, "groupId");
  30. this.artifactId = requireNonNull(artifactId, "artifactId");
  31. this.version = requireNonNull(version, "version");
  32. this.classifier = classifier;
  33. this.checksum = requireNonNull(checksum, "checksum");
  34. this.relocations = relocations != null ? Collections.unmodifiableList(new LinkedList<>(relocations)) : null;
  35. }
  36.  
  37. public Collection<String> getUrls() {
  38. return urls;
  39. }
  40.  
  41. public String getGroupId() {
  42. return groupId;
  43. }
  44.  
  45. public String getArtifactId() {
  46. return artifactId;
  47. }
  48.  
  49. public String getVersion() {
  50. return version;
  51. }
  52.  
  53. public String getClassifier() {
  54. return classifier;
  55. }
  56.  
  57. public byte[] getChecksum() {
  58. return checksum;
  59. }
  60.  
  61. public Collection<Relocation> getRelocations() {
  62. return relocations;
  63. }
  64.  
  65. public boolean hasRelocations() {
  66. return !relocations.isEmpty();
  67. }
  68.  
  69. @Override
  70. public String toString() {
  71. return "Library{" +
  72. "groupId='" + groupId + '\'' +
  73. ", artifactId='" + artifactId + '\'' +
  74. ", version='" + version + '\'' +
  75. ", classifier='" + classifier + '\'' +
  76. '}';
  77. }
  78.  
  79. public static Builder builder() {
  80. return new Builder();
  81. }
  82.  
  83. public static class Builder {
  84. private final List<String> urls = new ArrayList<>();
  85. private String groupId;
  86. private String artifactId;
  87. private String version;
  88. private String classifier;
  89. private byte[] checksum;
  90. private final List<Relocation> relocations = new ArrayList<>();
  91.  
  92. private Builder() {}
  93.  
  94. public Builder url(String url) {
  95. urls.add(requireNonNull(url, "url").toLowerCase());
  96. return this;
  97. }
  98.  
  99. public Builder groupId(String groupId) {
  100. this.groupId = requireNonNull(groupId, "groupId");
  101. return this;
  102. }
  103.  
  104. public Builder artifactId(String artifactId) {
  105. this.artifactId = requireNonNull(artifactId, "artifactId");
  106. return this;
  107. }
  108.  
  109. public Builder version(String version) {
  110. this.version = requireNonNull(version, "version");
  111. return this;
  112. }
  113.  
  114. public Builder classifier(String classifier) {
  115. this.classifier = classifier;
  116. return this;
  117. }
  118.  
  119. public Builder checksum(byte[] checksum) {
  120. this.checksum = requireNonNull(checksum, "checksum");
  121. return this;
  122. }
  123.  
  124. public Builder checksum(String checksum) {
  125. this.checksum = Base64.getDecoder().decode(requireNonNull(checksum, "checksum"));
  126. return this;
  127. }
  128.  
  129. public Builder relocate(Relocation relocation) {
  130. relocations.add(requireNonNull(relocation, "relocation"));
  131. return this;
  132. }
  133.  
  134. public Builder relocate(String pattern, String relocatedPattern) {
  135. return relocate(new Relocation(pattern, relocatedPattern));
  136. }
  137.  
  138. public Library build() {
  139. return new Library(urls, groupId, artifactId, version, classifier, checksum, relocations);
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement