io.deephaven.engine.table.impl.select.FormulaUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.select;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
public class FormulaUtil {
public static List getFormulaTokens(String formula, Collection names) {
List result = new ArrayList();
for (String name : names) {
int lastIndex = 0;
while ((lastIndex = formula.indexOf(name, lastIndex)) != -1) {
if (lastIndex > 0 && (Character.isLetter(formula.charAt(lastIndex - 1))
|| formula.charAt(lastIndex - 1) == '_')) {
lastIndex++;
continue;
}
int nextChar = lastIndex + name.length();
if (nextChar < formula.length() && (Character.isLetter(formula.charAt(nextChar))
|| formula.charAt(nextChar) == '_' || Character.isDigit(formula.charAt(nextChar)))) {
lastIndex++;
continue;
}
result.add(name);
break;
}
}
return result;
}
public static String replaceFormulaTokens(String formula, String sourceToken, String destToken) {
int lastIndex = 0;
while (lastIndex < formula.length() && (lastIndex = formula.indexOf(sourceToken, lastIndex)) != -1) {
if (lastIndex > 0
&& (Character.isLetter(formula.charAt(lastIndex - 1)) || formula.charAt(lastIndex - 1) == '_')) {
lastIndex++;
continue;
}
int nextChar = lastIndex + sourceToken.length();
if (nextChar < formula.length() && (Character.isLetter(formula.charAt(nextChar))
|| formula.charAt(nextChar) == '_' || Character.isDigit(formula.charAt(nextChar)))) {
lastIndex++;
continue;
}
formula = formula.substring(0, lastIndex) + destToken + formula.substring(lastIndex + sourceToken.length());
lastIndex += destToken.length();
}
return formula;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy