001package org.hl7.fhir.validation.instance; 002 003import org.hl7.fhir.r5.elementmodel.Element; 004 005public class PercentageTracker { 006 007 private int total; 008 private int last; 009 private int current; 010 private boolean log; 011 private String url; 012 013 private static int instance; 014 015 public PercentageTracker(int total, String fhirType, String url, boolean log) { 016 this.total = total; 017 instance++; 018 last = 0; 019 this.log = log; 020 this.url = url; 021 if (log) { 022 System.out.print("Validate "+fhirType+" against "+url); 023 } 024 } 025 026 public void done() { 027 if (log) { 028 System.out.println("|"); 029 } 030 } 031 032 public String getUrl() { 033 return url; 034 } 035 036 public void seeElement(Element e) { 037 if (e.getInstanceId() != instance) { 038 e.setInstanceId(instance); 039 current++; 040 int pct = total == 0 ? 0: (current*100) / total; 041 if (pct > last + 2) { 042 while (last + 2 < pct) { 043 if (log) { 044 System.out.print("."); 045 } 046 last = last + 2; 047 if (last % 20 == 0) { 048 if (log) { 049 System.out.print(""+last); 050 } 051 } 052 } 053 } 054 } 055 } 056 057}