Skip to content

Commit

Permalink
#46 Deprecation of has_keys. Tests included.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Mar 27, 2024
1 parent 10688e7 commit 4df5551
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions language/buildNumber.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Mon Mar 25 10:44:26 CDT 2024
buildNumber\\d*=12860
#Wed Mar 27 14:15:30 CDT 2024
buildNumber\\d*=12888
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ protected void doHasKey(Polyad polyad, State state) {
}
// if neither is a scalar, do the next bit,
}
QDLStem result = leftArg.hasKeys(rightArg);
QDLStem result = leftArg.hasKey(rightArg);
polyad.setEvaluated(true);
polyad.setResult(result);
polyad.setResultType(STEM_TYPE);
Expand Down Expand Up @@ -2592,6 +2592,7 @@ protected void doShuffle(Polyad polyad, State state) {
* The result is that each key in arg. is renamed, but the values are not changed.
* If a key is in indices. and does not correspond to one on the left, it is skipped,
* by subsetting rule.
* If a key is indices and the old and new value are the same, it is skipped.
* <br/><br/> Limitations are that it applies to the zeroth axis, modifies arg. and
* the indices. are different than remap.
*
Expand Down
31 changes: 20 additions & 11 deletions language/src/main/java/edu/uiuc/ncsa/qdl/variables/QDLStem.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,9 @@ public QDLStem commonKeys(QDLStem arg2) {
*/
public void renameKeys(QDLStem newKeys, boolean overWriteKeys) {
for (Object oldKey : newKeys.keySet()) {
Object newKey = newKeys.get(oldKey);
if(newKey.equals(oldKey)) continue;
if (containsKey(oldKey)) {
Object newKey = newKeys.get(oldKey);
if (containsKey(newKey)) {
if (overWriteKeys) {
Object oldValue = get(oldKey);
Expand Down Expand Up @@ -853,21 +854,29 @@ public QDLStem includeKeys(QDLStem keyList) {
*/
public QDLStem hasKeys(QDLStem keyList) {
QDLStem result = newInstance();
for(Object k : keySet()){
result.putLongOrString(k, keyList.containsKey(k));
if(!keyList.isList()){
throw new IllegalArgumentException("has keys requires a list");
}
for(Object ndx : keyList.getQDLList().orderedKeys()){
result.put((Long)ndx, containsKey(keyList.get((Long)ndx))); // since we know it's a list
}
/* for (int i = 0; i < keyList.size(); i++) {
// for loop to be sure that everything is done in order.
String index = Integer.toString(i);
if (!keyList.containsKey(index)) {
throw new IllegalArgumentException("the set of supplied keys is not a list");
}
result.put(index, containsKey(keyList.get(index).toString()));
}*/
return result;
}

/**
* Modern successor to the deprecated {@link #hasKeys(QDLStem)}. This returns a left conformable
* stem as it should.
* @param keyList
* @return
*/
public QDLStem hasKey(QDLStem keyList) {
QDLStem result = newInstance();

for(Object k : keySet()){
result.putLongOrString(k, keyList.containsKey(k));
}
return result;
}
/* ********
IndexEntry operations
********* */
Expand Down
3 changes: 2 additions & 1 deletion tests/src/test/java/edu/uiuc/ncsa/qdl/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1154,11 +1154,12 @@ public void testHasKey2() throws Throwable {
* @throws Throwable
*/
public void testHasKeys() throws Throwable {
// Part of https://github.com/ncsa/qdl/issues/46
State state = testUtils.getNewState();
StringBuffer script = new StringBuffer();
addLine(script, "var. := random(5);");
addLine(script, "w. := n(10);");
addLine(script, "z. := has_keys(w., var.);");
addLine(script, "z. := has_keys( var., w.);");
QDLInterpreter interpreter = new QDLInterpreter(null, state);
interpreter.execute(script.toString());
// so the first 5 entries are true, the next 5 are false.
Expand Down

0 comments on commit 4df5551

Please sign in to comment.