<commit_before>package org.griphyn.vdl.karajan.lib.swiftscript;

import org.apache.log4j.Logger;
import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.griphyn.vdl.karajan.AssertFailedException;
import org.griphyn.vdl.karajan.lib.SwiftArg;
import org.griphyn.vdl.karajan.lib.VDLFunction;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.type.Types;

/**
    Throw AssertionException if input is false or 0. 
 */
public class Assert extends VDLFunction {

    private static final Logger logger = 
        Logger.getLogger(Assert.class);
    
    static {
        setArguments(Assert.class, new Arg[] { Arg.VARGS });
    }
    
    @Override
    protected Object function(VariableStack stack) 
    throws ExecutionException {
        DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
        String message = "";
        
        for (int i = 0; i < args.length; i++) {
            DSHandle handle = args[i];
            VDLFunction.waitFor(stack, handle);
        }
        
        logger.debug("check: ");
        
        if (args.length == 2)
            if (args[1].getType() == Types.STRING)
                message = args[1].toString();
            else
                throw new ExecutionException
                ("Second argument to assert() must be a String!");
         
        checkAssert(args[0], message);
        
        return null;
    }

    private void checkAssert(DSHandle value, String message) 
    throws ExecutionException
    {
        boolean success = true; 
        if (value.getType() == Types.BOOLEAN) { 
            if (! (Boolean) value.getValue())
                success = false;
        }
        else if (value.getType() == Types.INT) {
            double d = ((Double) value.getValue()).doubleValue();
            if (d == 0.0)
                success = false;
        } 
        else 
            throw new ExecutionException<commit_msg>Corrections<commit_after>package org.griphyn.vdl.karajan.lib.swiftscript;

import org.apache.log4j.Logger;
import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.griphyn.vdl.karajan.AssertFailedException;
import org.griphyn.vdl.karajan.lib.SwiftArg;
import org.griphyn.vdl.karajan.lib.VDLFunction;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.type.Types;

/**
    Throw AssertionException if input is false or 0. 
    Optional second argument is string message printed on failure. 
 */
public class Assert extends VDLFunction {

    private static final Logger logger = 
        Logger.getLogger(Assert.class);
    
    static {
        setArguments(Assert.class, new Arg[] { Arg.VARGS });
    }
    
    @Override
    protected Object function(VariableStack stack) 
    throws ExecutionException {
        DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
        String message = "";
        
        for (int i = 0; i < args.length; i++) {
            DSHandle handle = args[i];
            VDLFunction.waitFor(stack, handle);
        }
        
        if (args.length == 2)
            if (args[1].getType() == Types.STRING)
                message = args[1].toString();
            else
                throw new ExecutionException
                ("Second argument to assert() must be a String!");
         
        checkAssert(args[0], message);
        
        return null;
    }

    private void checkAssert(DSHandle value, String message) 
    throws ExecutionException
    {
        boolean success = true; 
        if (value.getType() == Types.BOOLEAN) { 
            if (! (Boolean) value.getValue())
                success = false;
        }
        else if (value.getType() == Types.INT) {
            double d = ((Double) value.getValue()).doubleValue();
            if (d == 0.0)
                success = false;
        } 
        else 
            throw new ExecutionException
{'fraction_non_alphanumeric': 0.1067193675889328, 'fraction_numerical': 0.004446640316205534, 'mean_word_length': 2.1290571870170014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7656511', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1178, 'n_words': 265}