mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Add billing plans so different plans can be compared. Performance enhancements to charge calculations.
This commit is contained in:
@@ -955,4 +955,48 @@ public class CollectionUtils {
|
||||
return 0;
|
||||
return _arr.length;
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(float[] _floats) {
|
||||
if ((_floats == null) || (_floats.length == 0))
|
||||
return null;
|
||||
ByteBuffer bb = ByteBuffer.allocate(_floats.length * 4);
|
||||
for (float f : _floats) {
|
||||
bb.putFloat(f);
|
||||
}
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
public static float[] toFloatArray(byte[] _bytes) {
|
||||
if ((_bytes == null) || (_bytes.length == 0))
|
||||
return null;
|
||||
int offset = 0;
|
||||
float[] floats = new float[_bytes.length/4];
|
||||
ByteBuffer bb = ByteBuffer.wrap(_bytes);
|
||||
while (bb.hasRemaining()) {
|
||||
floats[offset++] = bb.getFloat();
|
||||
}
|
||||
return floats;
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(double[] _doubles) {
|
||||
if ((_doubles == null) || (_doubles.length == 0))
|
||||
return null;
|
||||
ByteBuffer bb = ByteBuffer.allocate(_doubles.length * 8);
|
||||
for (double d : _doubles) {
|
||||
bb.putDouble(d);
|
||||
}
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
public static double[] toDoubleArray(byte[] _bytes) {
|
||||
if ((_bytes == null) || (_bytes.length == 0))
|
||||
return null;
|
||||
int offset = 0;
|
||||
double[] doubles = new double[_bytes.length/8];
|
||||
ByteBuffer bb = ByteBuffer.wrap(_bytes);
|
||||
while (bb.hasRemaining()) {
|
||||
doubles[offset++] = bb.getDouble();
|
||||
}
|
||||
return doubles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.lanternsoftware.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
@@ -224,6 +226,11 @@ public abstract class DateUtils {
|
||||
return String.format("%d years", iYears);
|
||||
}
|
||||
|
||||
public static int getDaysBetween(Date _start, Date _end, TimeZone _tz) {
|
||||
ZoneId tz = _tz.toZoneId();
|
||||
return (int)ChronoUnit.DAYS.between(_start.toInstant().atZone(tz).toLocalDate(), _end.toInstant().atZone(tz).toLocalDate());
|
||||
}
|
||||
|
||||
public static int getMonthsBetween(Date _dtStart, Date _dtEnd) {
|
||||
Calendar calStart = getGMTCalendar(_dtStart.getTime());
|
||||
Calendar calEnd = getGMTCalendar(_dtEnd.getTime());
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.lanternsoftware.util.mutable;
|
||||
|
||||
public class MutableDouble {
|
||||
private double value;
|
||||
|
||||
public MutableDouble() {
|
||||
}
|
||||
|
||||
public MutableDouble(double _value) {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(double _value) {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
public void add(double _value) {
|
||||
value += _value;
|
||||
}
|
||||
|
||||
public void subtract(double _value) {
|
||||
value -= _value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user