<commit_before>// Modified or written by Lambdascale SRL for inclusion with lambdaj.
// Copyright (c) 2009-2010 <NAME>.
// Licensed under the Apache License, Version 2.0 (the "License")

package ch.lambdaj.function.argument;

/**
 * Registers a sequence of method invocations
 *
 * @author <NAME>
 * @author <NAME>
 */
final class InvocationSequence {
    private static final long serialVersionUID = 1L;

    private final Class<?> rootInvokedClass;
    private String inkvokedPropertyName;
    private Invocation lastInvocation;
    private transient int hashCode;

    InvocationSequence(Class<?> rootInvokedClass) {
        this.rootInvokedClass = rootInvokedClass;
    }

    InvocationSequence(InvocationSequence sequence, Invocation invocation) {
        this(sequence.getRootInvokedClass());
        invocation.previousInvocation = sequence.lastInvocation;
        lastInvocation = invocation;
    }

    Class<?> getRootInvokedClass() {
        return rootInvokedClass;
    }

    String getInkvokedPropertyName() {
        if (inkvokedPropertyName == null) inkvokedPropertyName = calcInkvokedPropertyName();
        return inkvokedPropertyName;
    }

    private String calcInkvokedPropertyName() {
        if (null == lastInvocation) return "";
        StringBuilder sb = new StringBuilder();

        calcInkvokedPropertyName(lastInvocation, lastInvocation.previousInvocation, sb);
        return sb.substring(1);
    }

    private void calcInkvokedPropertyName(Invocation inv, Invocation prevInv, StringBuilder sb) {
        if (prevInv != null) {
            calcInkvokedPropertyName(prevInv, prevInv.previousInvocation, sb);
        }
        sb.append(".").append(inv.getInvokedPropertyName());
    }

    Class<?> getReturnType() {
        return lastInvocation.getReturnType();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object object) {
        return object != null && Invocation.areNullSafeEquals(lastInvocation, ((InvocationSequence)object).lastInvocation);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        if (hashCode != 0) return hashCode;
        hashCode = 13 * rootInvokedClass.hashCode();
        int factor = 17;
        for (Invocation invocation = lastInvocation; invocation != null; invocation = invocation.previousInvocation) {
            hashCode += factor * invocation.hashCode();
            factor += 2;
        }
        return hashCode;
    }

    @SuppressWarnings("unchecked")
    public <T> T invokeOn(Object object) {
        return (T)invokeOn(lastInvocation, object);
    }

    private Object invokeOn(Invocation invocation, Object value) {
        if (invocation.previousInvocation != null) value = invokeOn(invocation.previousInvocation, value);
        return invocation.invokeOn(value);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(100);
        sb.append("[");
        toString(lastInvocation, lastInvocation.previousInvocation, sb, true);
        sb.append("]");
        return sb.toString();
    }

    private void toString(Invocation inv, Invocation prevInv, StringBuilder sb, boolean first) {
        if (prevInv != null) toString(prevInv, prevInv.previousInvocation, sb, false);
        sb.append(inv);
        if (!first) sb.append(", ");
    }
}<commit_msg>fix issue #63<commit_after>// Modified or written by Lambdascale SRL for inclusion with lambdaj.
// Copyright (c) 2009-2010 <NAME>.
// Licensed under the Apache License, Version 2.0 (the "License")

package ch.lambdaj.function.argument;

/**
 * Registers a sequence of method invocations
 *
 * @author <NAME>
 * @author <NAME>
 */
final class InvocationSequence {
    private static final long serialVersionUID = 1L;

    private final Class<?> rootInvokedClass;
    private String inkvokedPropertyName;
    private Invocation lastInvocation;
    private transient int hashCode;

    InvocationSequence(Class<?> rootInvokedClass) {
        this.rootInvokedClass = rootInvokedClass;
    }

    InvocationSequence(InvocationSequence sequence, Invocation invocation) {
        this(sequence.getRootInvokedClass());
        invocation.previousInvocation = sequence.lastInvocation;
        lastInvocation = invocation;
    }

    Class<?> getRootInvokedClass() {
        return rootInvokedClass;
    }

    String getInkvokedPropertyName() {
        if (inkvokedPropertyName == null) inkvokedPropertyName = calcInkvokedPropertyName();
        return inkvokedPropertyName;
    }

    private String calcInkvokedPropertyName() {
        if (null == lastInvocation) return "";
        StringBuilder sb = new StringBuilder();

        calcInkvokedPropertyName(lastInvocation, lastInvocation.previousInvocation, sb);
        return sb.substring(1);
    }

    private void calcInkvokedPropertyName(Invocation inv, Invocation prevInv, StringBuilder sb) {
        if (prevInv != null) {
            calcInkvokedPropertyName(prevInv, prevInv.previousInvocation, sb);
        }
        sb.append(".").append(inv.getInvokedPropertyName());
    }

    Class<?> getReturnType() {
        return lastInvocation.getReturnType();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object object) {
        return object != null && rootInvokedClass == ((InvocationSequence)object).rootInvokedClass
            && Invocation.areNullSafeEquals(lastInvocation, ((InvocationSequence)object).lastInvocation);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        if (hashCode != 0) return hashCode;
        hashCode = 13 * rootInvokedClass.hashCode();
        int factor = 17;
        for (Invocation invocation = lastInvocation; invocation != null; invocation = invocation.previousInvocation) {
            hashCode += factor * invocation.hashCode();
            factor += 2;
        }
        return hashCode;
    }

    @SuppressWarnings("unchecked")
    public <T> T invokeOn(Object object) {
        return (T)invokeOn(lastInvocation, object);
    }

    private Object invokeOn(Invocation invocation, Object value) {
        if (invocation.previousInvocation != null) value = invokeOn(invocation.previousInvocation, value);
        return invocation.invokeOn(value);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(100);
        sb.append("[");
        toString(lastInvocation, lastInvocation.previousInvocation, sb, true);
        sb.append("]");
        return sb.toString();
    }

    private void toString(Invocation inv, Invocation prevInv, StringBuilder sb, boolean first) {
        if (prevInv != null) toString(prevInv, prevInv.previousInvocation, sb, false);
        sb.append(inv);
        if (!first) sb.append(", ");
    }
}
{'fraction_non_alphanumeric': 0.1004566210045662, 'fraction_numerical': 0.006278538812785388, 'mean_word_length': 2.706504494976203, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5451843', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1833, 'n_words': 448}