<commit_before>package com.github.pfichtner.ardulink.core.proto.api;

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

public final class MessageIdHolders {

	private MessageIdHolders() {
		super();
	}

	public static class MessageIdHolderInvocationHandler implements
			InvocationHandler {

		private static final Method messageIdHolderGetIdMethod = getMessageIdHolderGetIdMethod();

		private final Object delegate;
		private final long messageId;

		private static Method getMessageIdHolderGetIdMethod() {
			try {
				return MessageIdHolder.class.getMethod("getId");
			} catch (SecurityException e) {
				throw new RuntimeException(e);
			} catch (NoSuchMethodException e) {
				throw new RuntimeException(e);
			}
		}

		public MessageIdHolderInvocationHandler(Object delegate, long messageId) {
			this.delegate = delegate;
			this.messageId = messageId;
		}

		@Override
		public Object invoke(Object proxy, Method method, Object[] args)
				throws Throwable {
			return messageIdHolderGetIdMethod.equals(method) ? messageId
					: method.invoke(delegate, args);
		}

	}

	@SuppressWarnings("unchecked")
	public static <T> T proxy(T delegateTo, long messageId) {
		return (T) Proxy.newProxyInstance(
				delegateTo.getClass().getClassLoader(),
				insertInto(Class.class, MessageIdHolder.class, delegateTo
						.getClass().getInterfaces()),
				new MessageIdHolderInvocationHandler(delegateTo, messageId));
	}

	private static <T> T[] insertInto(Class<T> type, T toAdd, T[] src) {
		T[] newArray = newArray(type, src.length + 1);
		newArray[0] = toAdd;
		System.arraycopy(src, 0, newArray, 1, src.length);
		return newArray;
	}

	@SuppressWarnings("unchecked")
	private static <T> T[] newArray(Class<T> type, int length) {
		return (T[]) Array.newInstance(type, length);
	}

}<commit_msg>javadoc<commit_after>package com.github.pfichtner.ardulink.core.proto.api;

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

public final class MessageIdHolders {

	private MessageIdHolders() {
		super();
	}

	public static class MessageIdHolderInvocationHandler implements
			InvocationHandler {

		private static final Method messageIdHolderGetIdMethod = getMessageIdHolderGetIdMethod();

		private final Object delegate;
		private final long messageId;

		private static Method getMessageIdHolderGetIdMethod() {
			try {
				return MessageIdHolder.class.getMethod("getId");
			} catch (SecurityException e) {
				throw new RuntimeException(e);
			} catch (NoSuchMethodException e) {
				throw new RuntimeException(e);
			}
		}

		public MessageIdHolderInvocationHandler(Object delegate, long messageId) {
			this.delegate = delegate;
			this.messageId = messageId;
		}

		@Override
		public Object invoke(Object proxy, Method method, Object[] args)
				throws Throwable {
			return messageIdHolderGetIdMethod.equals(method) ? messageId
					: method.invoke(delegate, args);
		}

	}

	/**
	 * Creates a dynamic proxy that implements MessageIdHolder automatically.
	 * Calls to {@link MessageIdHolder#getId()} will return the passed
	 * <code>messageId</code>. All other calls are forwarded to the passed
	 * <code>delegateTo</code>.
	 * 
	 * @param delegateTo
	 *            the instance to delegate all calls except
	 *            {@link MessageIdHolder#getId()}
	 * @param messageId
	 *            the messageId to return when {@link MessageIdHolder#getId()}
	 *            is called
	 * @return dynamic proxy implementing {@link MessageIdHolder}
	 */
	@SuppressWarnings("unchecked")
	public static <T> T proxy(T delegateTo, long messageId) {
		return (T) Proxy.newProxyInstance(
				delegateTo.getClass().getClassLoader(),
				insertInto(Class.class, MessageIdHolder.class, delegateTo
						.getClass().getInterfaces()),
				new MessageIdHolderInvocationHandler(delegateTo, messageId));
	}

	private static <T> T[] insertInto(Class<T> type, T toAdd, T[] src) {
		T[] newArray = newArray(type, src.length + 1);
		newArray[0] = toAdd;
		System.arraycopy(src, 0, newArray, 1, src.length);
		return newArray;
	}

	@SuppressWarnings("unchecked")
	private static <T> T[] newArray(Class<T> type, int length) {
		return (T[]) Array.newInstance(type, length);
	}

}
{'fraction_non_alphanumeric': 0.10589318600368323, 'fraction_numerical': 0.001841620626151013, 'mean_word_length': 4.417705735660848, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5329171', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1276, 'n_words': 330}