use of org.finos.legend.pure.runtime.java.shared.hash.HashType in project legend-pure by finos.
the class Hash method execute.
@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException {
// Parameter 0: text
String text = PrimitiveUtilities.getStringValue(Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport));
// Parameter 1: hashType
CoreInstance enumeration = Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport);
String enumName = enumeration.getName();
HashType hashType = HashType.valueOf(enumName);
try {
String hashResult = HashingUtil.hash(text, hashType);
CoreInstance result = this.modelRepository.newStringCoreInstance(hashResult);
return ValueSpecificationBootstrap.wrapValueSpecification(result, true, processorSupport);
} catch (Exception e) {
throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "Error occurred in hashing: " + e.getMessage(), e);
}
}
use of org.finos.legend.pure.runtime.java.shared.hash.HashType in project legend-pure by finos.
the class Pure method hash.
public static String hash(String text, Object hashTypeObject) {
Enum hashTypeEnum = (Enum) hashTypeObject;
HashType hashType = HashType.valueOf(hashTypeEnum._name());
return HashingUtil.hash(text, hashType);
}
Aggregations