com.dashjoin.jsonata.Utils Maven / Gradle / Ivy
The newest version!
/**
* jsonata-java is the JSONata Java reference port
*
* Copyright Dashjoin GmbH. https://dashjoin.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dashjoin.jsonata;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.dashjoin.jsonata.Jsonata.JFunction;
import com.dashjoin.jsonata.Jsonata.JFunctionCallable;
@SuppressWarnings({"rawtypes"})
public class Utils {
public static boolean isNumeric(Object v) {
if (v instanceof Long) return true;
boolean isNum = false;
if (v instanceof Number) {
double d = ((Number)v).doubleValue();
isNum = !Double.isNaN(d);
if (isNum && !Double.isFinite(d)) {
throw new JException("D1001", 0, v);
}
}
return isNum;
}
public static boolean isArrayOfStrings(Object v) {
boolean result = false;
if (v instanceof Collection) {
for (Object o : ((Collection)v))
if (!(o instanceof String))
return false;
return true;
}
return false;
}
public static boolean isArrayOfNumbers(Object v) {
boolean result = false;
if (v instanceof Collection) {
for (Object o : ((Collection)v))
if (!isNumeric(o))
return false;
return true;
}
return false;
}
public static boolean isFunction(Object o) {
return o instanceof JFunction || o instanceof JFunctionCallable;
}
static Object NONE = new Object();
/**
* Create an empty sequence to contain query results
* @returns {Array} - empty sequence
*/
public static List