Skip to content
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true

[*.java]
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*]
trim_trailing_whitespace = true
22 changes: 11 additions & 11 deletions src/main/java/org/z3950/zing/cql/CQLAndNode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.z3950.zing.cql;


/**
* Represents an AND node in a CQL parse-tree.
*
Expand All @@ -9,26 +8,27 @@ public class CQLAndNode extends CQLBooleanNode {
/**
* Creates a new AND node with the specified left- and right-hand
* sides and modifiers.
* @param left the left-hand side of the AND
*
* @param left the left-hand side of the AND
* @param right the right-hand side of the AND
* @param ms the modifiers to apply to this AND
* @param ms the modifiers to apply to this AND
* @see ModifierSet
* @see CQLNode
* @see CQLBoolean
* @see CQLBooleanNode
*/
public CQLAndNode(CQLNode left, CQLNode right, ModifierSet ms) {
super(left, right, ms, CQLBoolean.AND);
}
super(left, right, ms, CQLBoolean.AND);
}

// ### Too much code duplication here with OR and NOT
@Override
byte[] opType1() {
byte[] op = new byte[5];
putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
putLen(2, op, 2);
putTag(CONTEXT, 0, PRIMITIVE, op, 3); // and
putLen(0, op, 4);
return op;
byte[] op = new byte[5];
putTag(CONTEXT, 46, CONSTRUCTED, op, 0); // Operator
putLen(2, op, 2);
putTag(CONTEXT, 0, PRIMITIVE, op, 3); // and
putLen(0, op, 4);
return op;
}
}
16 changes: 8 additions & 8 deletions src/main/java/org/z3950/zing/cql/CQLBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* @author jakub
*/
public enum CQLBoolean {
/** AND is the same as CQL's "and" */
AND,
/** OR is the same as CQL's "or" */
OR,
/** NOT is the same as CQL's "not" */
NOT,
/** PROX is the same as CQL's "prox" */
PROX;
/** AND is the same as CQL's "and" */
AND,
/** OR is the same as CQL's "or" */
OR,
/** NOT is the same as CQL's "not" */
NOT,
/** PROX is the same as CQL's "prox" */
PROX;
}
53 changes: 29 additions & 24 deletions src/main/java/org/z3950/zing/cql/CQLBooleanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public abstract class CQLBooleanNode extends CQLNode {
public CQLBoolean getOperator() {
return operator;
}

private CQLNode left;

/**
* The root of a parse-tree representing the left-hand side.
*
* @return the left operand of this boolean node
*/
public CQLNode getLeftOperand() {
Expand All @@ -28,6 +29,7 @@ public CQLNode getLeftOperand() {

/**
* The root of a parse-tree representing the right-hand side.
*
* @return the right operand of this boolean node
*/
public CQLNode getRightOperand() {
Expand All @@ -38,32 +40,33 @@ public CQLNode getRightOperand() {

/**
* The set of modifiers that are applied to this boolean.
*
* @return a list of Modifier objects, which may be empty.
*/
public List<Modifier> getModifiers() {
return ms.getModifiers();
}

protected CQLBooleanNode(CQLNode left, CQLNode right, ModifierSet ms, CQLBoolean operator) {
this.left = left;
this.right = right;
this.ms = ms;
this.left = left;
this.right = right;
this.ms = ms;
this.operator = operator;
}

@Override
public void traverse(CQLNodeVisitor visitor) {
visitor.onBooleanNodeStart(this);
left.traverse(visitor);
visitor.onBooleanNodeOp(this);
right.traverse(visitor);
visitor.onBooleanNodeEnd(this);
visitor.onBooleanNodeStart(this);
left.traverse(visitor);
visitor.onBooleanNodeOp(this);
right.traverse(visitor);
visitor.onBooleanNodeEnd(this);
}

@Override
void toXCQLInternal(XCQLBuilder b, int level,
List<CQLPrefix> prefixes, List<ModifierSet> sortkeys) {
b.indent(level).append("<triple>\n");
List<CQLPrefix> prefixes, List<ModifierSet> sortkeys) {
b.indent(level).append("<triple>\n");
renderPrefixes(b, level + 1, prefixes);
ms.toXCQLInternal(b, level + 1, "boolean", "value");
b.indent(level + 1).append("<leftOperand>\n");
Expand All @@ -78,35 +81,37 @@ void toXCQLInternal(XCQLBuilder b, int level,

@Override
public String toCQL() {
// ### We don't always need parens around the operands
return ("(" + left.toCQL() + ")" +
" " + ms.toCQL() + " " +
"(" + right.toCQL() + ")");
// ### We don't always need parens around the operands
return ("(" + left.toCQL() + ")" +
" " + ms.toCQL() + " " +
"(" + right.toCQL() + ")");
}

@Override
public String toPQF(Properties config) throws PQFTranslationException {
return ("@" + opPQF() +
" " + left.toPQF(config) +
" " + right.toPQF(config));
return ("@" + opPQF() +
" " + left.toPQF(config) +
" " + right.toPQF(config));
}

// represents the operation for PQF: overridden for CQLProxNode
String opPQF() { return ms.getBase(); }
String opPQF() {
return ms.getBase();
}

@Override
public byte[] toType1BER(Properties config) throws PQFTranslationException {
System.out.println("in CQLBooleanNode.toType1BER(): PQF=" +
toPQF(config));
toPQF(config));
byte[] rpn1 = left.toType1BER(config);
byte[] rpn2 = right.toType1BER(config);
byte[] op = opType1();
byte[] rpnStructure = new byte[rpn1.length+rpn2.length+op.length+4];
// rpnRpnOp
byte[] rpnStructure = new byte[rpn1.length + rpn2.length + op.length + 4];

// rpnRpnOp
int offset = putTag(CONTEXT, 1, CONSTRUCTED, rpnStructure, 0);

rpnStructure[offset++] = (byte)(0x80&0xff); // indefinite length
rpnStructure[offset++] = (byte) (0x80 & 0xff); // indefinite length
System.arraycopy(rpn1, 0, rpnStructure, offset, rpn1.length);
offset += rpn1.length;
System.arraycopy(rpn2, 0, rpnStructure, offset, rpn2.length);
Expand Down
59 changes: 30 additions & 29 deletions src/main/java/org/z3950/zing/cql/CQLDefaultNodeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@

/**
* Query tree visitor with default (no-op) implementation
*
* @author jakub
*/
public class CQLDefaultNodeVisitor implements CQLNodeVisitor {
@Override
public void onSortNode(CQLSortNode node) {
}

@Override
public void onPrefixNode(CQLPrefixNode node) {
}

@Override
public void onBooleanNodeStart(CQLBooleanNode node) {
}

@Override
public void onBooleanNodeOp(CQLBooleanNode node) {
}

@Override
public void onBooleanNodeEnd(CQLBooleanNode node) {
}
@Override
public void onTermNode(CQLTermNode node) {
}

@Override
public void onRelation(CQLRelation relation) {
}

@Override
public void onSortNode(CQLSortNode node) {
}

@Override
public void onPrefixNode(CQLPrefixNode node) {
}

@Override
public void onBooleanNodeStart(CQLBooleanNode node) {
}

@Override
public void onBooleanNodeOp(CQLBooleanNode node) {
}

@Override
public void onBooleanNodeEnd(CQLBooleanNode node) {
}

@Override
public void onTermNode(CQLTermNode node) {
}

@Override
public void onRelation(CQLRelation relation) {
}

}
Loading