<commit_before>// Portions Copyright (c) 2003 Microsoft Corporation.  All rights reserved.

package tlc2.tool;

import tlc2.value.Value;
import tla2sany.semantic.SemanticNode;

public class FingerprintException extends RuntimeException {

  final public Value value;
  final public FingerprintException next;

  private FingerprintException(Throwable initCauseThrowable, Value value, FingerprintException next) {
    initCause(initCauseThrowable);
    this.value = value;
    this.next = next;
  }

  public static FingerprintException getNewHead(Value v, Throwable t){
    FingerprintException fpe = null;
    if(!(t instanceof FingerprintException))
      fpe = FingerprintException.createNewHead(v, t);
    else
      fpe = ((FingerprintException) t).prependNewHead(v);
    return fpe;
  }

  private static FingerprintException createNewHead(Value value, Throwable initCauseThrowable){
    if(value == null || initCauseThrowable == null)
      return null;
    else
      return new FingerprintException(initCauseThrowable, value, null);
  }

  private FingerprintException prependNewHead(Value value){
    if(value == null)
      return null;
    else
      return new FingerprintException(null, value, this);
  }

  public Throwable getRootCause(){
    FingerprintException nextFPE = this;
    while(nextFPE.next != null)
      nextFPE = nextFPE.next;
    return nextFPE.getCause();
  }

  public String getTrace(){
    return getTraceImpl(0, null);
  }

  private String getTraceImpl(final Integer traceIndexLabel, final Integer lastSemanticNodeUid){
    SemanticNode semanticNode = value.getSourceSemanticNode();
    if(semanticNode == null){
      if(next == null)
        return "";
      else
        return next.getTraceImpl(traceIndexLabel, lastSemanticNodeUid);
    }
    else{
      Integer semanticNodeUid = semanticNode.getUid();
      if(semanticNodeUid.equals(lastSemanticNodeUid)){ // same SemanticNode compared to current top of stack
        if(next == null)
          return "";
        else
          return next.getTraceImpl(traceIndexLabel, lastSemanticNodeUid);
      }
      else{ // different SemanticNode compared to current top of stack
        String description = traceIndexLabel + ") " + semanticNode.toString() + "\n";
        if(next == null)
          return description;
        else
          return next.getTraceImpl(traceIndexLabel+1, semanticNodeUid) + description;
      }
    }
  }

}<commit_msg>minor correction in method signature and simplification in method implementation<commit_after>// Portions Copyright (c) 2003 Microsoft Corporation.  All rights reserved.

package tlc2.tool;

import tlc2.value.Value;
import tla2sany.semantic.SemanticNode;

public class FingerprintException extends RuntimeException {

  final public Value value;
  final public FingerprintException next;

  private FingerprintException(Throwable initCauseThrowable, Value value, FingerprintException next) {
    initCause(initCauseThrowable);
    this.value = value;
    this.next = next;
  }

  public static FingerprintException getNewHead(Value v, Throwable t){
    FingerprintException fpe = null;
    if(t instanceof FingerprintException)
      fpe = ((FingerprintException) t).prependNewHead(v);
    else
      fpe = FingerprintException.createNewHead(v, t);
    return fpe;
  }

  private static FingerprintException createNewHead(Value value, Throwable initCauseThrowable){
    if(value == null || initCauseThrowable == null)
      return null;
    else
      return new FingerprintException(initCauseThrowable, value, null);
  }

  private FingerprintException prependNewHead(Value value){
    if(value == null)
      return null;
    else
      return new FingerprintException(null, value, this);
  }

  public Throwable getRootCause(){
    FingerprintException nextFPE = this;
    while(nextFPE.next != null)
      nextFPE = nextFPE.next;
    return nextFPE.getCause();
  }

  public String getTrace(){
    return getTraceImpl(0, null);
  }

  private String getTraceImpl(final int traceIndexLabel, final Integer lastSemanticNodeUid){
    SemanticNode semanticNode = value.getSourceSemanticNode();
    if(semanticNode == null){
      if(next == null)
        return "";
      else
        return next.getTraceImpl(traceIndexLabel, lastSemanticNodeUid);
    }
    else{
      Integer semanticNodeUid = semanticNode.getUid();
      if(semanticNodeUid.equals(lastSemanticNodeUid)){ // same SemanticNode compared to current top of stack
        if(next == null)
          return "";
        else
          return next.getTraceImpl(traceIndexLabel, lastSemanticNodeUid);
      }
      else{ // different SemanticNode compared to current top of stack
        String description = traceIndexLabel + ") " + semanticNode.toString() + "\n";
        if(next == null)
          return description;
        else
          return next.getTraceImpl(traceIndexLabel+1, semanticNodeUid) + description;
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.0840080971659919, 'fraction_numerical': 0.0036437246963562753, 'mean_word_length': 3.4353680430879714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6195378', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1386, 'n_words': 363}