summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-06-02 19:45:31 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-06-02 21:25:44 -0300
commitf39711c88d027fc3b589a7d1f51b2b54eb2a016c (patch)
tree8a038015ca4426389ce0780dd9b311ab474c679a /base/src/main/java/bjc
parent84bbde06c9d24a1f2422478aa04b0122b3c51c2c (diff)
Add memory component repository
This component repository uses a in-memory map for storage
Diffstat (limited to 'base/src/main/java/bjc')
-rw-r--r--base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java144
-rw-r--r--base/src/main/java/bjc/utils/components/ComponentDescriptionState.java142
-rw-r--r--base/src/main/java/bjc/utils/components/MemoryComponentRepository.java29
3 files changed, 173 insertions, 142 deletions
diff --git a/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
index c720cbf..31ae7d0 100644
--- a/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
+++ b/base/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java
@@ -10,6 +10,14 @@ import static bjc.utils.ioutils.RuleBasedReaderPragmas.buildStringCollapser;
/**
* Read a component description from a file.
*
+ * The file format is based entirely off of pragma statements, and should have
+ * at least one of each of the following statements
+ * <ul>
+ * <li>pragma name &lt;component-name&rt; </li>
+ * <li>pragma author &lt;component-version&rt; </li>
+ * <li>pragma description &lt;component-description&rt;</li>
+ * <li>pragma version &lt;component-version&rt; </li>
+ * </ul>
* @author ben
*/
public class ComponentDescriptionFileParser {
@@ -68,4 +76,140 @@ public class ComponentDescriptionFileParser {
reader.addPragma("version", buildInteger("version", (version, state) -> state.setVersion(version)));
}
+
+ private static final class ComponentDescriptionState {
+ /* Tentative name of this component. */
+ private String name;
+
+ /* Tentative description of this component. */
+ private String description;
+
+ /* Tentative author of this component. */
+ private String author;
+
+ /* Tentative version of this component. */
+ private int version;
+
+ /**
+ * Set the author of this component.
+ *
+ * @param author
+ * The author of this component.
+ */
+ public void setAuthor(final String author) {
+ this.author = author;
+ }
+
+ /**
+ * Set the description of this component.
+ *
+ * @param description
+ * The description of this component.
+ */
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+ /**
+ * Set the name of this component.
+ *
+ * @param name
+ * The name of this component.
+ */
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Set the version of this component.
+ *
+ * @param version
+ * The version of this component.
+ */
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ /**
+ * Convert this state into the description it represents.
+ *
+ * @return The description represented by this state.
+ */
+ public ComponentDescription toDescription() {
+ return new ComponentDescription(name, author, description, version);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+
+ result = prime * result + (author == null ? 0 : author.hashCode());
+ result = prime * result + (description == null ? 0 : description.hashCode());
+ result = prime * result + (name == null ? 0 : name.hashCode());
+ result = prime * result + version;
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+
+ final ComponentDescriptionState other = (ComponentDescriptionState) obj;
+
+ if(author == null) {
+ if(other.author != null) return false;
+ } else if(!author.equals(other.author)) return false;
+
+ if(description == null) {
+ if(other.description != null) return false;
+ } else if(!description.equals(other.description)) return false;
+
+ if(name == null) {
+ if(other.name != null) return false;
+ } else if(!name.equals(other.name)) return false;
+
+ if(version != other.version) return false;
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("ComponentDescriptionState [");
+
+ if(name != null) {
+ builder.append("name=");
+ builder.append(name);
+ builder.append(", ");
+ }
+
+ if(description != null) {
+ builder.append("description=");
+ builder.append(description);
+ builder.append(", ");
+ }
+
+ if(author != null) {
+ builder.append("author=");
+ builder.append(author);
+ builder.append(", ");
+ }
+
+ builder.append("version=");
+ builder.append(version);
+ builder.append("]");
+
+ return builder.toString();
+ }
+ }
}
diff --git a/base/src/main/java/bjc/utils/components/ComponentDescriptionState.java b/base/src/main/java/bjc/utils/components/ComponentDescriptionState.java
deleted file mode 100644
index aea886e..0000000
--- a/base/src/main/java/bjc/utils/components/ComponentDescriptionState.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package bjc.utils.components;
-
-/**
- * Internal state of component description parser.
- *
- * @author ben
- */
-public class ComponentDescriptionState {
- /* Tentative name of this component. */
- private String name;
-
- /* Tentative description of this component. */
- private String description;
-
- /* Tentative author of this component. */
- private String author;
-
- /* Tentative version of this component. */
- private int version;
-
- /**
- * Set the author of this component.
- *
- * @param author
- * The author of this component.
- */
- public void setAuthor(final String author) {
- this.author = author;
- }
-
- /**
- * Set the description of this component.
- *
- * @param description
- * The description of this component.
- */
- public void setDescription(final String description) {
- this.description = description;
- }
-
- /**
- * Set the name of this component.
- *
- * @param name
- * The name of this component.
- */
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Set the version of this component.
- *
- * @param version
- * The version of this component.
- */
- public void setVersion(final int version) {
- this.version = version;
- }
-
- /**
- * Convert this state into the description it represents.
- *
- * @return The description represented by this state.
- */
- public ComponentDescription toDescription() {
- return new ComponentDescription(name, author, description, version);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + (author == null ? 0 : author.hashCode());
- result = prime * result + (description == null ? 0 : description.hashCode());
- result = prime * result + (name == null ? 0 : name.hashCode());
- result = prime * result + version;
-
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(getClass() != obj.getClass()) return false;
-
- final ComponentDescriptionState other = (ComponentDescriptionState) obj;
-
- if(author == null) {
- if(other.author != null) return false;
- } else if(!author.equals(other.author)) return false;
-
- if(description == null) {
- if(other.description != null) return false;
- } else if(!description.equals(other.description)) return false;
-
- if(name == null) {
- if(other.name != null) return false;
- } else if(!name.equals(other.name)) return false;
-
- if(version != other.version) return false;
-
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("ComponentDescriptionState [");
-
- if(name != null) {
- builder.append("name=");
- builder.append(name);
- builder.append(", ");
- }
-
- if(description != null) {
- builder.append("description=");
- builder.append(description);
- builder.append(", ");
- }
-
- if(author != null) {
- builder.append("author=");
- builder.append(author);
- builder.append(", ");
- }
-
- builder.append("version=");
- builder.append(version);
- builder.append("]");
-
- return builder.toString();
- }
-}
diff --git a/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java
new file mode 100644
index 0000000..4246016
--- /dev/null
+++ b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java
@@ -0,0 +1,29 @@
+package bjc.utils.components;
+
+public class MemoryComponentRepository<ComponentType extends IDescribedComponent> implements IComponentRepository<ComponentType> {
+ private final IMap<String, ComponentType> repo;
+
+ private final String source;
+
+ public MemoryComponentRepository(IMap<String, ComponentType> repo) {
+ this(repo, "memory");
+ }
+
+ public MemoryComponentRepository(IMap<String, ComponentType> repo, String source) {
+ this.repo = repo;
+
+ this.source = source;
+ }
+
+ public IMap<String, ComponentType> getAll() {
+ return repo;
+ }
+
+ public ComponentType getByName(String name) {
+ return repo.get();
+ }
+
+ public String getSource() {
+
+ }
+}