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

com.vladsch.flexmark.util.format.FormattedCounter Maven / Gradle / Ivy

The newest version!
package com.vladsch.flexmark.util.format;

import com.vladsch.flexmark.util.misc.Utils;

public class FormattedCounter {
  private final NumberFormat numberFormat;
  private final Boolean isLowercase;
  private final String delimiter;
  private int count;

  public FormattedCounter(NumberFormat format, Boolean lowercase, String delimiter) {
    numberFormat = format;
    isLowercase = lowercase;
    this.delimiter = delimiter;
    reset();
  }

  public void reset() {
    count = 0;
  }

  public int getCount() {
    return count;
  }

  public int nextCount() {
    return ++count;
  }

  public String getFormatted(boolean withDelimiter) {
    String s = NumberFormat.getFormat(numberFormat, Utils.minLimit(count, 1));
    String o = isLowercase == null ? s : isLowercase ? s.toLowerCase() : s.toUpperCase();
    return withDelimiter && delimiter != null && !delimiter.isEmpty() ? o + delimiter : o;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy