All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.security.fences.util.LazyString Maven / Gradle / Ivy

There is a newer version: 1.9-beta
Show newest version
package com.google.security.fences.util;

import com.google.common.base.Preconditions;

/**
 * A CharSequence that lazily computes a string which can be useful when a
 * debug log message might be unbounded in length.
 */
public abstract class LazyString implements CharSequence {
  private String s;

  public int length() {
    return toString().length();
  }

  public char charAt(int index) {
    return toString().charAt(index);
  }

  public CharSequence subSequence(int start, int end) {
    return toString().substring(start, end);
  }

  @Override
  public final String toString() {
    if (s == null) {
      s = Preconditions.checkNotNull(makeString());
    }
    return s;
  }

  protected abstract String makeString();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy