<commit_before>package org.neo4j.util;

import java.lang.reflect.Constructor;

import org.neo4j.api.core.NeoService;
import org.neo4j.api.core.Node;
import org.neo4j.api.core.Transaction;

/**
 * Wraps a {@link Node}, also overriding {@link #equals(Object)} and
 * {@link #hashCode()} to make it more useful.
 * @author mattias
 */
public abstract class NodeWrapperImpl implements NodeWrapper
{
	private NeoService neo;
	private Node node;
	
	/**
	 * Utility method for instantiating a new node wrapper instance, using
	 * the class' constructor which takes a {@link Node}.
	 * @param <T> the resulting instance's class type.
	 * @param instanceClass the resulting instance's class type.
	 * @param node the node to wrap, the node returned from
	 * {@link #getUnderlyingNode()}.
	 * @return the new instance wrapping the node.
	 */
	public static <T extends NodeWrapper> T newInstance(
		Class<T> instanceClass, NeoService neo, Node node )
	{
		try
		{
			Constructor<T> constructor =
				instanceClass.getConstructor( NeoService.class, Node.class );
			T result = constructor.newInstance( neo, node );
			return result;
		}
		catch ( RuntimeException e )
		{
			throw e;
		}
		catch ( Exception e )
		{
			throw new RuntimeException( e );
		}
	}
	
	public static <T extends NodeWrapper> T newInstance(
		Class<T> instanceClass, NeoService neo, long nodeId )
	{
		Transaction tx = neo.beginTx();
		try
		{
			Node node = neo.getNodeById( nodeId );<commit_msg>Made node/neo fields final and updated javadoc<commit_after>package org.neo4j.util;

import java.lang.reflect.Constructor;

import org.neo4j.api.core.NeoService;
import org.neo4j.api.core.Node;
import org.neo4j.api.core.Transaction;

/**
 * Wraps a {@link Node}, also overriding {@link #equals(Object)} and
 * {@link #hashCode()} to make it more useful.
 * @author mattias
 */
public abstract class NodeWrapperImpl implements NodeWrapper
{
	private final NeoService neo;
	private final Node node;
	
	/**
	 * Utility method for instantiating a new node wrapper instance, using
	 * the class' constructor which takes a {@link Node}.
	 * @param <T> the resulting instance's class type.
	 * @param instanceClass the resulting instance's class type.
     * @param neo the {@link NeoService} used with the node.
	 * @param node the node to wrap, the node returned from
	 * {@link #getUnderlyingNode()}.
	 * @return the new instance wrapping the node.
	 */
	public static <T extends NodeWrapper> T newInstance(
		Class<T> instanceClass, NeoService neo, Node node )
	{
		try
		{
			Constructor<T> constructor =
				instanceClass.getConstructor( NeoService.class, Node.class );
			T result = constructor.newInstance( neo, node );
			return result;
		}
		catch ( RuntimeException e )
		{
			throw e;
		}
		catch ( Exception e )
		{
			throw new RuntimeException( e );
		}
	}
	
    /**
     * Utility method for instantiating a new node wrapper instance, using
     * the class' constructor which takes a {@link Node}.
     * @param <T> the resulting instance's class type.
     * @param instanceClass the resulting instance's class type.
     * @param neo the {@link NeoService} used with the node.
     * @param nodeId the id of the node to wrap, the node returned from
     * {@link #getUnderlyingNode()}.
     * @return the new instance wrapping the node (with the given id).
     */
	public static <T extends NodeWrapper> T newInstance(
		Class<T> instanceClass, NeoService neo, long nodeId )
	{
		Transaction tx = neo.beginTx();
		try
		{
			Node node = neo.getNodeById( nodeId );
{'fraction_non_alphanumeric': 0.1007357102433503, 'fraction_numerical': 0.0022637238256932655, 'mean_word_length': 3.5790155440414506, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '2488597', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1023, 'n_words': 384}