content: package me.tongfei.progressbar;
  
  /*-
   * #%L
   * TongFei ProgressBar
   * %%
   * Copyright (C) 2014 - 2018 Tongfei Chen
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * #L%
   */
  
  
  import org.joda.time.LocalDateTime;
  
  /**
   * Encapsulates the internal states of a progress bar.
   * @author Tongfei Chen
   * @since 0.5.0
   */
  class ProgressState {
  
      String task;
  
      boolean indefinite = false;
  
      long current = 0;
      long max = 0;
  
      LocalDateTime startTime = null;
  
      String extraMessage = "";
  
      ProgressState(String task, long initialMax) {
          this.task = task;
          this.max = initialMax;
          if (initialMax < 0) indefinite = true;
      }
  
      synchronized void setAsDefinite() {
          indefinite = false;
      }
  
      synchronized void setAsIndefinite() {
          indefinite = true;
      }
  
      synchronized void maxHint(long n) {
          max = n;
      }
  
      synchronized void stepBy(long n) {
          current += n;
          if (current > max) max = current;
      }
  
      synchronized void stepTo(long n) {
          current = n;
          if (current > max) max = current;
      }
  
      synchronized void setExtraMessage(String msg) {
          extraMessage = msg;
      }
  
      String getTask() {
          return task;
      }
  
      synchronized String getExtraMessage() {
          return extraMessage;
      }
  
      synchronized long getCurrent() {
          return current;
      }
  
      synchronized long getMax() {
          return max;
      }
  
  }
  