<commit_before>/*
 * Created on 03-May-2004
 *
 * (c) 2003-2005 ThoughtWorks
 *
 * See license.txt for license details
 */
package com.thoughtworks.proxy.toys.decorate;

import com.thoughtworks.proxy.ProxyFactory;
import com.thoughtworks.proxy.factory.StandardProxyFactory;


// TODO: use the AOP alliance API

/**
 * Toy factory to create proxies decorating an object in an AOP style.
 * <p>
 * An InvocationDecorator is used for the additional functionality. It is called before the original method is called,
 * after the original method was called, after the original method has thrown an exceptionor when an exception occurs,
 * calling the method of the decorated object.
 * </p>
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <NAME>
 * @author J&ouml;<NAME>
 * @see com.thoughtworks.proxy.toys.decorate
 * @since 0.1
 */
public class Decorating<T> {
    
    private Object delegate;
    private Class<T>[] types;
    private InvocationDecorator decorator;

    private Decorating(final Class<T>... types) {
        this.types = types;
    }

    public static <T> Decorating<T> decoratable(final Class<T> type) {
        return new Decorating<T>(type);
    }

    public static <T> Decorating<T> decoratable(final Class<T>[] types) {
        return new Decorating<T>(types);
    }

    public Decorating<T> with(Object delegate, InvocationDecorator decorator) {
        this.delegate = delegate;
        this.decorator = decorator;
        return this;
    }

    public T build() {
        return (T) new StandardProxyFactory().createProxy(types, new DecoratingInvoker(delegate, decorator));
    }

    public T build(final ProxyFactory proxyFactory) {
        return (T) proxyFactory.createProxy(types, new DecoratingInvoker(delegate, decorator));
    }
}<commit_msg>use varargs on decorate toy<commit_after>/*
 * Created on 03-May-2004
 *
 * (c) 2003-2005 ThoughtWorks
 *
 * See license.txt for license details
 */
package com.thoughtworks.proxy.toys.decorate;

import com.thoughtworks.proxy.ProxyFactory;
import com.thoughtworks.proxy.factory.StandardProxyFactory;


// TODO: use the AOP alliance API

/**
 * Toy factory to create proxies decorating an object in an AOP style.
 * <p>
 * An InvocationDecorator is used for the additional functionality. It is called before the original method is called,
 * after the original method was called, after the original method has thrown an exceptionor when an exception occurs,
 * calling the method of the decorated object.
 * </p>
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <NAME>&oslash;y
 * @author J&ouml;<NAME>
 * @see com.thoughtworks.proxy.toys.decorate
 * @since 0.1
 */
public class Decorating<T> {
    
    private Object delegate;
    private Class<T>[] types;
    private InvocationDecorator decorator;

    private Decorating(final Class<T>... types) {
        this.types = types;
    }

    public static <T> Decorating<T> decoratable(final Class<T>... types) {
        return new Decorating<T>(types);
    }

    public Decorating<T> with(Object delegate, InvocationDecorator decorator) {
        this.delegate = delegate;
        this.decorator = decorator;
        return this;
    }

    public T build() {
        return (T) new StandardProxyFactory().createProxy(types, new DecoratingInvoker(delegate, decorator));
    }

    public T build(final ProxyFactory proxyFactory) {
        return (T) proxyFactory.createProxy(types, new DecoratingInvoker(delegate, decorator));
    }
}
{'fraction_non_alphanumeric': 0.10607798165137615, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 3.5252918287937742, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '1893275', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1026, 'n_words': 318}