<commit_before>/*
 * Created on 24-Oct-2004
 * 
 * (c) 2003-2004 ThoughtWorks Ltd
 *
 * See license.txt for license details
 */
package com.thoughtworks.jbehave.core.minimock;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;


/**
 * Syntactic sugar for MiniMock
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class MiniMockSugar {
    public Constraint eq(final Object expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return arg == null ? expectedArg == null : arg.equals(expectedArg);
            }
            public String toString() {
                return "eq(" + expectedArg + ")";
            }
        };
    }
    
    public Constraint eq(float expectedArg) {
        return eq(new Float(expectedArg));
    }
    
    public Constraint eq(double expectedArg) {
        return eq(new Double(expectedArg));
    }
    
    public Constraint eq(int expectedArg) {
        return eq(new Integer(expectedArg));
    }
    
    public Constraint eq(long expectedArg) {
        return eq(new Long(expectedArg));
    }
    
    public Constraint eq(char expectedArg) {
        return eq(new Character(expectedArg));
    }
    
    public Constraint eq(short expectedArg) {
        return eq(new Short(expectedArg));
    }
    
    public Constraint eq(byte expectedArg) {
        return eq(new Byte(expectedArg));
    }
    
    public Constraint eq(boolean expectedArg) {
        return eq(expectedArg ? Boolean.TRUE : Boolean.FALSE);
    }
    
    // some useful constraints

    public Constraint same(final Object expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return expectedArg == arg;
            }
            public String toString() {
                return "same(" + expectedArg + ")";
            }
        };
    }

    public Constraint anything() {
        return new Constraint() {
            public boolean matches(Object arg) {
                return true;
            }
            public String toString() {
                return "anything";
            }
        };
    }

    public Constraint instanceOf(final Class type) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return type.isInstance(arg);
            }
            public String toString() {
                return "instance of " + type.getName();
            }
        };
    }
    
    // boolean constraints - and, or, not
    
    public Constraint and(final Constraint a, final Constraint b) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return a.matches(arg) && b.matches(arg);
            }
            public String toString() {
                return a + " and " + b;
            }
        };
    }
    
    public Constraint both(final Constraint a, final Constraint b) {
        return and(a, b);
    }
    
    public Constraint or(final Constraint a, final Constraint b) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return a.matches(arg) || b.matches(arg);
            }
            public String toString() {
                return a + " or " + b;
            }
        };
    }
    
    public Constraint either(final Constraint a, final Constraint b) {
        return either(a, b);
    }
    
    public Constraint not(final Constraint c) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return !c.matches(arg);
            }
            public String toString() {
                return "not " + c;
            }
        };
    }
    
    // some handy invocation handlers for setting up expectations
    
    public InvocationHandler returnValue(final Object result) {
        return new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) {
                return result;
            }
        };
    }
    
    public InvocationHandler throwException(final Throwable cause) {
        return new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw cause;
            }
        };
    }
    
    // yawn - box all the primitive types
    
    public InvocationHandler returnValue(byte result) {
        return returnValue(new Byte(result));
    }
    public InvocationHandler returnValue(char result) {
        return returnValue(new Character(result));
    }
    public InvocationHandler returnValue(short result) {
        return returnValue(new Short(result));
    }
    public InvocationHandler returnValue(int result) {
        return returnValue(new Integer(result));
    }
    public InvocationHandler returnValue(long result) {
        return returnValue(new Long(result));
    }
    public InvocationHandler returnValue(float result) {
        return returnValue(new Float(result));
    }
    public InvocationHandler returnValue(double result) {
        return returnValue(new Double(result));
    }
    public InvocationHandler returnValue(boolean result) {
        return returnValue(result ? Boolean.TRUE : Boolean.FALSE);
    }
}
<commit_msg>remove some overloaded eq methods<commit_after>/*
 * Created on 24-Oct-2004
 * 
 * (c) 2003-2004 ThoughtWorks Ltd
 *
 * See license.txt for license details
 */
package com.thoughtworks.jbehave.core.minimock;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;


/**
 * Syntactic sugar for MiniMock
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class MiniMockSugar {
    public Constraint eq(final Object expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return arg == null ? expectedArg == null : arg.equals(expectedArg);
            }
            public String toString() {
                return "eq(" + expectedArg + ")";
            }
        };
    }
     
   
    public Constraint eq(final double expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                Number n = (Number)arg;
                return n.doubleValue() == expectedArg;
            }          
        };
    }
      
    public Constraint eq(final long expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                Number n = (Number)arg;
                return n.longValue() == expectedArg;
            }          
        };
    }
    
    public Constraint eq(char expectedArg) {
        return eq(new Character(expectedArg));
    }
     
    
    public Constraint eq(boolean expectedArg) {
        return eq(expectedArg ? Boolean.TRUE : Boolean.FALSE);
    }
    
    // some useful constraints

    public Constraint same(final Object expectedArg) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return expectedArg == arg;
            }
            public String toString() {
                return "same(" + expectedArg + ")";
            }
        };
    }

    public Constraint anything() {
        return new Constraint() {
            public boolean matches(Object arg) {
                return true;
            }
            public String toString() {
                return "anything";
            }
        };
    }

    public Constraint instanceOf(final Class type) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return type.isInstance(arg);
            }
            public String toString() {
                return "instance of " + type.getName();
            }
        };
    }
    
    // boolean constraints - and, or, not
    
    public Constraint and(final Constraint a, final Constraint b) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return a.matches(arg) && b.matches(arg);
            }
            public String toString() {
                return a + " and " + b;
            }
        };
    }
    
    public Constraint both(final Constraint a, final Constraint b) {
        return and(a, b);
    }
    
    public Constraint or(final Constraint a, final Constraint b) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return a.matches(arg) || b.matches(arg);
            }
            public String toString() {
                return a + " or " + b;
            }
        };
    }
    
    public Constraint either(final Constraint a, final Constraint b) {
        return either(a, b);
    }
    
    public Constraint not(final Constraint c) {
        return new Constraint() {
            public boolean matches(Object arg) {
                return !c.matches(arg);
            }
            public String toString() {
                return "not " + c;
            }
        };
    }
    
    // some handy invocation handlers for setting up expectations
    
    public InvocationHandler returnValue(final Object result) {
        return new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) {
                return result;
            }
        };
    }
    
    public InvocationHandler throwException(final Throwable cause) {
        return new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw cause;
            }
        };
    }
    
    // yawn - box all the primitive types
    
    public InvocationHandler returnValue(byte result) {
        return returnValue(new Byte(result));
    }
    public InvocationHandler returnValue(char result) {
        return returnValue(new Character(result));
    }
    public InvocationHandler returnValue(short result) {
        return returnValue(new Short(result));
    }
    public InvocationHandler returnValue(int result) {
        return returnValue(new Integer(result));
    }
    public InvocationHandler returnValue(long result) {
        return returnValue(new Long(result));
    }
    public InvocationHandler returnValue(float result) {
        return returnValue(new Float(result));
    }
    public InvocationHandler returnValue(double result) {
        return returnValue(new Double(result));
    }
    public InvocationHandler returnValue(boolean result) {
        return returnValue(result ? Boolean.TRUE : Boolean.FALSE);
    }
}

{'fraction_non_alphanumeric': 0.08582669960655137, 'fraction_numerical': 0.0025619910330313845, 'mean_word_length': 1.6362759286058852, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7061283', 'n_tokens_mistral': 2782, 'n_tokens_neox': 2654, 'n_words': 754}