[Minor] extracted ModelStatistics
This commit is contained in:
parent
16db0e357e
commit
d36267f640
|
@ -0,0 +1,50 @@
|
||||||
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import static ch.eitchnet.utils.helper.StringHelper.NULL;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
|
||||||
|
|
||||||
|
public class ModelStatistics {
|
||||||
|
|
||||||
|
public Date startTime;
|
||||||
|
public long durationNanos;
|
||||||
|
public long nrOfResources;
|
||||||
|
public long nrOfOrders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nrOfOrders
|
||||||
|
*/
|
||||||
|
public long getNrOfOrders() {
|
||||||
|
return this.nrOfOrders;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nrOfResources
|
||||||
|
*/
|
||||||
|
public long getNrOfResources() {
|
||||||
|
return this.nrOfResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNrOfElements() {
|
||||||
|
return this.nrOfOrders + this.nrOfResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(getClass().getSimpleName() + " [startTime=");
|
||||||
|
builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance()
|
||||||
|
.formatDate(this.startTime));
|
||||||
|
builder.append(", durationNanos=");
|
||||||
|
builder.append(StringHelper.formatNanoDuration(this.durationNanos));
|
||||||
|
builder.append(", nrOfResources=");
|
||||||
|
builder.append(this.nrOfResources);
|
||||||
|
builder.append(", nrOfOrders=");
|
||||||
|
builder.append(this.nrOfOrders);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,13 +15,12 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.xml;
|
package li.strolch.model.xml;
|
||||||
|
|
||||||
import static ch.eitchnet.utils.helper.StringHelper.NULL;
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.GroupedParameterizedElement;
|
import li.strolch.model.GroupedParameterizedElement;
|
||||||
|
import li.strolch.model.ModelStatistics;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.ParameterBag;
|
import li.strolch.model.ParameterBag;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
@ -53,20 +52,20 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(XmlModelSaxReader.class);
|
protected static final Logger logger = LoggerFactory.getLogger(XmlModelSaxReader.class);
|
||||||
|
|
||||||
protected StrolchElementListener listener;
|
protected StrolchElementListener listener;
|
||||||
protected XmlModelStatistics statistics;
|
protected ModelStatistics statistics;
|
||||||
|
|
||||||
private GroupedParameterizedElement parameterizedElement;
|
private GroupedParameterizedElement parameterizedElement;
|
||||||
private ParameterBag pBag;
|
private ParameterBag pBag;
|
||||||
|
|
||||||
public XmlModelSaxReader(StrolchElementListener listener) {
|
public XmlModelSaxReader(StrolchElementListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.statistics = new XmlModelStatistics();
|
this.statistics = new ModelStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the statistics
|
* @return the statistics
|
||||||
*/
|
*/
|
||||||
public XmlModelStatistics getStatistics() {
|
public ModelStatistics getStatistics() {
|
||||||
return this.statistics;
|
return this.statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,46 +197,4 @@ public class XmlModelSaxReader extends DefaultHandler {
|
||||||
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
throw new IllegalArgumentException(MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class XmlModelStatistics {
|
|
||||||
|
|
||||||
public Date startTime;
|
|
||||||
public long durationNanos;
|
|
||||||
public int nrOfResources;
|
|
||||||
public int nrOfOrders;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the nrOfOrders
|
|
||||||
*/
|
|
||||||
public int getNrOfOrders() {
|
|
||||||
return this.nrOfOrders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the nrOfResources
|
|
||||||
*/
|
|
||||||
public int getNrOfResources() {
|
|
||||||
return this.nrOfResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getNrOfElements() {
|
|
||||||
return this.nrOfOrders + this.nrOfResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("XmlModelStatistics [startTime=");
|
|
||||||
builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance()
|
|
||||||
.formatDate(this.startTime));
|
|
||||||
builder.append(", durationNanos=");
|
|
||||||
builder.append(StringHelper.formatNanoDuration(this.durationNanos));
|
|
||||||
builder.append(", nrOfResources=");
|
|
||||||
builder.append(this.nrOfResources);
|
|
||||||
builder.append(", nrOfOrders=");
|
|
||||||
builder.append(this.nrOfOrders);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import li.strolch.model.xml.StrolchElementListener;
|
import li.strolch.model.xml.StrolchElementListener;
|
||||||
import li.strolch.model.xml.XmlModelSaxReader.XmlModelStatistics;
|
|
||||||
import li.strolch.model.xml.XmlModelSaxFileReader;
|
import li.strolch.model.xml.XmlModelSaxFileReader;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -64,7 +63,7 @@ public class XmlModelDefaultHandlerTest {
|
||||||
assertEquals(3, resourceMap.size());
|
assertEquals(3, resourceMap.size());
|
||||||
assertEquals(3, orderMap.size());
|
assertEquals(3, orderMap.size());
|
||||||
|
|
||||||
XmlModelStatistics statistics = handler.getStatistics();
|
ModelStatistics statistics = handler.getStatistics();
|
||||||
logger.info("Parsing took " + StringHelper.formatNanoDuration(statistics.durationNanos));
|
logger.info("Parsing took " + StringHelper.formatNanoDuration(statistics.durationNanos));
|
||||||
assertEquals(3, statistics.nrOfOrders);
|
assertEquals(3, statistics.nrOfOrders);
|
||||||
assertEquals(3, statistics.nrOfResources);
|
assertEquals(3, statistics.nrOfResources);
|
||||||
|
|
Loading…
Reference in New Issue