Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Started mechanism to determine whether attributes are alone or beside other attributes.

AuthorDave Jarvis <email>
Date2015-03-10 22:52:01 GMT-0700
Commitf35c0e5fd29c4d233223485c315ca507574c0c14
Parentb8daf7b
source/java/com/whitemagicsoftware/rxm/tree/TransformationTree.java
sb.append( start( tree ) );
- for( Tree<T> branch : tree.getLeaves() ) {
+ for( Tree<T> branch : tree.getBranches() ) {
sb.append( System.lineSeparator() );
source/java/com/whitemagicsoftware/rxm/tree/Tree.java
/** Child trees of this tree, possibly empty. */
- private List<Tree<T>> leaves = new ArrayList<Tree<T>>();
+ private List<Tree<T>> branches = new ArrayList<Tree<T>>();
/**
- * Constructs a new tree, ready to have leaves added.
+ * Constructs a new tree, ready to have branches added.
*
* @param payload The data associated with this tree leaf (must not
* be null).
*/
public Tree( T payload ) {
setPayload( payload );
}
/**
- * Adds the given tree to the list of this tree's leaves. This will also
+ * Adds the given tree to the list of this tree's branches. This will also
* set the parent of the given tree to this tree instance.
*
- * @param tree The tree to append to the list of leaves.
+ * @param tree The tree to append to the list of branches.
* @return The tree that was added (i.e., the tree parameter).
*/
public Tree<T> addLeaf( Tree<T> tree ) {
- getLeaves().add( tree );
+ getBranches().add( tree );
tree.setParent( this );
return tree;
/**
- * Returns the list of leaves for this tree.
+ * Answers whether the given payload equals the payload in this tree
+ * instance.
*
- * @return A non-null, but possibly empty, list of leaves.
+ * @param payload The payload to compare against.
+ *
+ * @return true The payload is the same.
*/
- public List<Tree<T>> getLeaves() {
- return this.leaves;
+ public boolean hasPayload( T payload ) {
+ return getPayload().equals( payload );
+ }
+
+ /**
+ * Returns the list of branches for this tree.
+ *
+ * @return A non-null, but possibly empty, list of branches.
+ */
+ public List<Tree<T>> getBranches() {
+ return this.branches;
+ }
+
+ /**
+ * Returns the location of the payload in the list of branches (sub-trees).
+ * The index returned is 0-based.
+ *
+ * @return -1 if the payload doesn't exist.
+ */
+ private int indexOf( T payload ) {
+ int index = 0;
+
+ // TODO: Get consecutive attribute map contexts
+ /*
+ for( Tree<T> branch : getBranches() ) {
+ System.out.println( ((com.whitemagicsoftware.rxm.tree.Payload)branch.getPayload()).getParserRuleContext().getClass() );
+ }
+ */
+
+ for( Tree<T> branch : getBranches() ) {
+ if( branch.hasPayload( payload ) ) {
+ return index;
+ }
+
+ // While the payload hasn't been found...
+ index++;
+ }
+
+ // No payload found.
+ return -1;
+ }
+
+ /**
+ * Answers whether the given payload has any siblings before it.
+ *
+ * @param payload The payload to find in the branches (sub-trees).
+ *
+ * @return true At least one antecedent payload exists in the branches.
+ */
+ public boolean hasPrecedingPayload( T payload ) {
+ return indexOf( payload ) > 0;
+ }
+
+ /**
+ * Answers whether the given payload has any siblings after it.
+ *
+ * @param payload The payload to find in the branches (sub-trees).
+ *
+ * @return true At least one subsequent payload exists in the branches.
+ */
+ public boolean hasFollowingPayload( T payload ) {
+ int index = indexOf( payload );
+
+ return index > -1 && index < getBranches().size();
}
}
source/java/com/whitemagicsoftware/rxm/tree/xml/AttributeMapContext.java
@Override
public Token getStart() {
+ if( hasPrecedingPayload() ) {
+ System.out.printf( "%s . %s\n", getColumnName() , getAttributeName() );
+ }
+
return new Token(
String.format( ",%s",
startAttributes(
getTableName(),
getColumnName(),
getAttributeName()
)
)
);
+ }
+
+ /**
+ * Closes the XMLATTRIBUTES expression, should no more attributes be
+ * forthcoming.
+ *
+ * @return ")" or the empty string.
+ */
+ @Override
+ public Token getStop() {
+ System.out.println( "STOP: " + hasFollowingPayload() );
+ return new Token( hasFollowingPayload() ? "" : ")" );
}
private Payload getTreePayload() {
return getTree().getPayload();
- }
-
- /**
- * @return true There are more attributes to be found.
- */
- private boolean hasSiblings() {
- return false;
}
}
source/java/com/whitemagicsoftware/rxm/tree/xml/PayloadParserRuleContext.java
*/
public abstract class PayloadParserRuleContext extends ParserRuleContext {
- private ParserRuleContext payload;
- private Tree<Payload> tree;
+ private Payload initPayload;;
/**
* Constructs a wrapper class that provides the ParserRuleContext and
* tree for the *Context classes.
*
- * @param payload The data that contains the ParserRuleContext and the
+ * @param initPayload The data that contains the ParserRuleContext and the
* abstract syntax tree.
*/
- protected PayloadParserRuleContext( Payload payload ) {
- this.payload = payload.getParserRuleContext();
- this.tree = payload.getTree();
+ protected PayloadParserRuleContext( Payload initPayload ) {
+ this.initPayload = initPayload;
}
/**
- * Returns the current payload.
+ * Opens the current transformation expression. Subclasses must override
+ * this to provide the correct opening SQL/XML expression. It could be
+ * made abstract, but is a useful convenience method.
*
- * @return The payload containing tokens parsed from the input <b>rxm</b>
- * document.
+ * @return "("
*/
- protected ParserRuleContext getParserRuleContext() {
- return this.payload;
+ @Override
+ public Token getStart() {
+ return new Token( "(" );
+ }
+
+ /**
+ * Closes the current transformation expression. Subclasses may override
+ * this to provide a custom closing SQL/XML expression.
+ *
+ * @return ")"
+ */
+ @Override
+ public Token getStop() {
+ return new Token( ")" );
}
return result;
+ }
+
+ /**
+ * Returns the current payload.
+ *
+ * @return The payload containing tokens parsed from the input <b>rxm</b>
+ * document.
+ */
+ protected ParserRuleContext getParserRuleContext() {
+ return getInitPayload().getParserRuleContext();
}
*/
protected Tree<Payload> getTree() {
- return this.tree;
+ return getInitPayload().getTree();
}
/**
- * Opens the current transformation expression. Subclasses must override
- * this to provide the correct opening SQL/XML expression. It could be
- * made abstract, but is a useful convenience method.
+ * Returns the payload used to associate the parser rule context with
+ * a tree.
*
- * @return "("
+ * @return The payload containing a parser rule context and tree.
*/
- @Override
- public Token getStart() {
- return new Token( "(" );
+ private Payload getInitPayload() {
+ return this.initPayload;
}
/**
- * Closes the current transformation expression. Subclasses may override
- * this to provide a custom closing SQL/XML expression.
+ * Answers whether the current payload has an antecedent sibling.
*
- * @return ")"
+ * @return true This payload has a preceding sibling.
*/
- @Override
- public Token getStop() {
- return new Token( ")" );
+ public boolean hasPrecedingPayload() {
+ return getTree().hasPrecedingPayload( getInitPayload() );
+ }
+
+ /**
+ * Answers whether the current payload has an antecedent sibling.
+ *
+ * @return true This payload has a following sibling.
+ */
+ public boolean hasFollowingPayload() {
+ return getTree().hasFollowingPayload( getInitPayload() );
}
}
test/people.rxm
root > people,
person > person,
+.id > @id,
.birthday > @born,
.first_name > first,
Delta143 lines added, 42 lines removed, 101-line increase