| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | @SuppressWarnings("WeakerAccess") | |
| 29 | 29 | public class XQueryGenerator { | |
| 30 | 30 | private static final Pattern ANNOTATION_XML_PATTERN = Pattern.compile( "annotation(-xml)?" ); | |
| 31 | + //Qvar map of qvar name to XPaths referenced by each qvar | ||
| 31 | 32 | private Map<String, ArrayList<String>> qvar = new HashMap<>(); | |
| 32 | 33 | private String relativeXPath = ""; | |
| 33 | 34 | private String lengthConstraint = ""; | |
@@ -139,33 +140,37 @@ public String toString() { | |||
| 139 | 140 | if ( mainElement == null ) { | |
| 140 | 141 | return null; | |
| 141 | 142 | } | |
| 142 | - String fixedConstraints = generateConstraints( mainElement, true ); | ||
| 143 | - String qvarConstraintString = ""; | ||
| 143 | + final String fixedConstraints = generateConstraints( mainElement, true ); | ||
| 144 | + final StringBuilder qvarConstraintString = new StringBuilder(); | ||
| 145 | + //Generate qvar constraint string | ||
| 146 | + //This specifies that the same qvars must refer to the same nodes, using the XQuery "=" equality | ||
| 147 | + //This is equality based on: same text, same node names, and same children by the "=" equality | ||
| 144 | 148 | for ( Map.Entry<String, ArrayList<String>> entry : qvar.entrySet() ) { | |
| 145 | - String addString = ""; | ||
| 146 | - boolean newContent = false; | ||
| 149 | + final StringBuilder addString = new StringBuilder(); | ||
| 147 | 150 | if ( entry.getValue().size() > 1 ) { | |
| 148 | - String first = entry.getValue().get( 0 ); | ||
| 149 | - if ( qvarConstraintString.length() > 0 ) { | ||
| 150 | - addString += "\n and "; | ||
| 151 | + final String firstEntry = entry.getValue().get( 0 ); | ||
| 152 | + if ( qvarConstraintString.length() != 0 ) { | ||
| 153 | + addString.append("\n and "); | ||
| 151 | 154 | } | |
| 152 | - String lastSecond = ""; | ||
| 153 | - for ( String second : entry.getValue() ) { | ||
| 154 | - if ( !second.equals( first ) ) { | ||
| 155 | - if ( lastSecond.length() > 0 ) { | ||
| 156 | - addString += " and "; | ||
| 155 | + String lastEntry = ""; | ||
| 156 | + boolean newContent = false; | ||
| 157 | + //begins at second entry | ||
| 158 | + for ( final String currentEntry : entry.getValue() ) { | ||
| 159 | + if ( !currentEntry.equals( firstEntry ) ) { | ||
| 160 | + if ( !lastEntry.isEmpty() ) { | ||
| 161 | + addString.append(" and "); | ||
| 157 | 162 | } | |
| 158 | - addString += "$x" + first + " = $x" + second; | ||
| 159 | - lastSecond = second; | ||
| 163 | + addString.append("$x").append(firstEntry).append(" = $x").append(currentEntry); | ||
| 164 | + lastEntry = currentEntry; | ||
| 160 | 165 | newContent = true; | |
| 161 | 166 | } | |
| 162 | 167 | } | |
| 163 | 168 | if ( newContent ) { | |
| 164 | - qvarConstraintString += addString; | ||
| 169 | + qvarConstraintString.append(addString); | ||
| 165 | 170 | } | |
| 166 | 171 | } | |
| 167 | 172 | } | |
| 168 | - return getString( mainElement, fixedConstraints, qvarConstraintString ); | ||
| 173 | + return getString( mainElement, fixedConstraints, qvarConstraintString.toString() ); | ||
| 169 | 174 | } | |
| 170 | 175 | ||
| 171 | 176 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments