This repository has been archived by the owner on Oct 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete code generation for model and parser
Still only RSS and only certain fields, but already a big step in the right direction. Closes #13
- Loading branch information
Showing
60 changed files
with
2,345 additions
and
1,017 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
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 @@ | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.rometools.rome2.prototype</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<artifactId>common</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
</project> |
6 changes: 6 additions & 0 deletions
6
throwaway-prototype/common/src/main/java/com/rometools/rome/common/OneOrMany.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,6 @@ | ||
package com.rometools.rome.common; | ||
|
||
public enum OneOrMany { | ||
ONE, | ||
MANY; | ||
} |
21 changes: 21 additions & 0 deletions
21
throwaway-prototype/common/src/main/java/com/rometools/rome/common/parser/IntParser.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,21 @@ | ||
package com.rometools.rome.common.parser; | ||
|
||
import com.rometools.rome.common.value.IntValue; | ||
|
||
public class IntParser implements Parser<IntValue> { | ||
|
||
@Override | ||
public Class<IntValue> getResultClass() { | ||
return IntValue.class; | ||
} | ||
|
||
@Override | ||
public IntValue parse(String input) { | ||
return IntValue.ofNullable(Integer.valueOf(input)); | ||
} | ||
|
||
@Override | ||
public IntValue none() { | ||
return IntValue.none(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
throwaway-prototype/common/src/main/java/com/rometools/rome/common/parser/Parser.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,10 @@ | ||
package com.rometools.rome.common.parser; | ||
|
||
public interface Parser<T> { | ||
|
||
Class<T> getResultClass(); | ||
|
||
T parse(String input); | ||
|
||
T none(); | ||
} |
21 changes: 21 additions & 0 deletions
21
throwaway-prototype/common/src/main/java/com/rometools/rome/common/parser/StringParser.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,21 @@ | ||
package com.rometools.rome.common.parser; | ||
|
||
import com.rometools.rome.common.value.StringValue; | ||
|
||
public class StringParser implements Parser<StringValue> { | ||
|
||
@Override | ||
public Class<StringValue> getResultClass() { | ||
return StringValue.class; | ||
} | ||
|
||
@Override | ||
public StringValue parse(String input) { | ||
return StringValue.ofNullable(input); | ||
} | ||
|
||
@Override | ||
public StringValue none() { | ||
return StringValue.none(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tools/rome/model/value/AbstractValue.java → ...ools/rome/common/value/AbstractValue.java
100644 → 100755
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.rometools.rome.model.value; | ||
package com.rometools.rome.common.value; | ||
|
||
import java.util.Optional; | ||
|
||
|
20 changes: 9 additions & 11 deletions
20
...tools/rome/model/value/DateTimeValue.java → ...ools/rome/common/value/DateTimeValue.java
100644 → 100755
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
32 changes: 32 additions & 0 deletions
32
throwaway-prototype/common/src/main/java/com/rometools/rome/common/value/IntValue.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,32 @@ | ||
package com.rometools.rome.common.value; | ||
|
||
import java.util.Comparator; | ||
import java.util.Objects; | ||
|
||
public class IntValue extends AbstractValue<Integer> implements Comparable<IntValue> { | ||
|
||
private IntValue(Integer value) { | ||
super(value); | ||
} | ||
|
||
public static IntValue of(int value) { | ||
return new IntValue(value); | ||
} | ||
|
||
public static IntValue ofNullable(Integer value) { | ||
return new IntValue(value); | ||
} | ||
|
||
public static IntValue none() { | ||
return ofNullable(null); | ||
} | ||
|
||
public Integer defaultToZero() { | ||
return orElse(0); | ||
} | ||
|
||
@Override | ||
public int compareTo(IntValue other) { | ||
return Objects.compare(this, other, Comparator.comparing(IntValue::asNullable)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
throwaway-prototype/common/src/main/java/com/rometools/rome/common/value/StringValue.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,27 @@ | ||
package com.rometools.rome.common.value; | ||
|
||
public class StringValue extends AbstractValue<String> { | ||
|
||
protected StringValue(String value) { | ||
super(value); | ||
} | ||
|
||
public static StringValue of(String value) { | ||
if (value == null) { | ||
throw new IllegalArgumentException(); | ||
} | ||
return new StringValue(value); | ||
} | ||
|
||
public static StringValue ofNullable(String value) { | ||
return new StringValue(value); | ||
} | ||
|
||
public static StringValue none() { | ||
return ofNullable(null); | ||
} | ||
|
||
public String defaultToEmpty() { | ||
return orElse(""); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
throwaway-prototype/common/src/main/java/com/rometools/rome/common/value/Value.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,20 @@ | ||
package com.rometools.rome.common.value; | ||
|
||
public class Value<T> extends AbstractValue<T> { | ||
|
||
protected Value(T value) { | ||
super(value); | ||
} | ||
|
||
public static <T> Value<T> ofNullable(T value) { | ||
return new Value<>(value); | ||
} | ||
|
||
public static <T> Value<T> none() { | ||
return ofNullable(null); | ||
} | ||
|
||
public T defaultToNull() { | ||
return orElse(null); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
throwaway-prototype/common/src/main/java/com/rometools/rome/common/xml/XmlPath.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,91 @@ | ||
package com.rometools.rome.common.xml; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class XmlPath { | ||
|
||
public static final XmlPath ROOT = new XmlPath(Collections.emptyList(), false); | ||
|
||
private List<String> hierarchy; | ||
private boolean isAttribute; | ||
|
||
public XmlPath(List<String> hierarchy, boolean isAttribute) { | ||
this.hierarchy = hierarchy; | ||
this.isAttribute = isAttribute; | ||
} | ||
|
||
public static XmlPath create(String value) { | ||
List<String> hierarchy = Arrays.asList(value.substring(1).split("/")); | ||
|
||
String name = hierarchy.get(hierarchy.size() - 1); | ||
|
||
boolean isAttribute = false; | ||
|
||
if (name.startsWith("@")) { | ||
hierarchy.set(hierarchy.size() - 1, name.replaceFirst("@", "")); | ||
isAttribute = true; | ||
} | ||
|
||
return new XmlPath(hierarchy, isAttribute); | ||
} | ||
|
||
public boolean isAttribute() { | ||
return isAttribute; | ||
} | ||
|
||
public String getName() { | ||
return hierarchy.get(hierarchy.size() - 1); | ||
} | ||
|
||
private XmlPath child(String name, boolean childIsAttribute) { | ||
if (isAttribute) { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
List<String> newHierarchy = new ArrayList<>(hierarchy); | ||
newHierarchy.add(name); | ||
return new XmlPath(newHierarchy, childIsAttribute); | ||
} | ||
|
||
public XmlPath child(String name) { | ||
return child(name, false); | ||
} | ||
|
||
public XmlPath attribute(String name) { | ||
return child(name, true); | ||
} | ||
|
||
public XmlPath parent() { | ||
return new XmlPath(hierarchy.subList(0, hierarchy.size() - 1), false); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
XmlPath that = (XmlPath) o; | ||
return isAttribute == that.isAttribute && Objects.equals(hierarchy, that.hierarchy); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(hierarchy, isAttribute); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (isAttribute) { | ||
return "/" + String.join("/", hierarchy.subList(0, hierarchy.size() - 1)) + "/@" + getName(); | ||
} else { | ||
return "/" + String.join("/", hierarchy); | ||
} | ||
} | ||
} |
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
Empty file modified
0
throwaway-prototype/core/src/main/java/com/rometools/rome/Config.java
100644 → 100755
Empty file.
6 changes: 0 additions & 6 deletions
6
throwaway-prototype/core/src/main/java/com/rometools/rome/EntityType.java
This file was deleted.
Oops, something went wrong.
Empty file modified
0
throwaway-prototype/core/src/main/java/com/rometools/rome/Format.java
100644 → 100755
Empty file.
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
Empty file modified
0
throwaway-prototype/core/src/main/java/com/rometools/rome/RomeException.java
100644 → 100755
Empty file.
Oops, something went wrong.