use of ucar.ma2.Range in project imageio-ext by geosolutions-it.
the class NetCDFUtilities method getAttributesAsString.
/**
* Return the value of a NetCDF {@code Attribute} instance as a
* {@code String}. The {@code isUnsigned} parameter allow to handle byte
* attributes as unsigned, in order to represent values in the range
* [0,255].
*/
public static String getAttributesAsString(Attribute attr, final boolean isUnsigned) {
String[] values = null;
if (attr != null) {
final int nValues = attr.getLength();
values = new String[nValues];
final DataType datatype = attr.getDataType();
// TODO: Improve the unsigned management
if (datatype == DataType.BYTE) {
if (isUnsigned)
for (int i = 0; i < nValues; i++) {
byte val = attr.getNumericValue(i).byteValue();
int myByte = (0x000000FF & ((int) val));
short anUnsignedByte = (short) myByte;
values[i] = Short.toString(anUnsignedByte);
}
else {
for (int i = 0; i < nValues; i++) {
byte val = attr.getNumericValue(i).byteValue();
values[i] = Byte.toString(val);
}
}
} else if (datatype == DataType.SHORT) {
for (int i = 0; i < nValues; i++) {
short val = attr.getNumericValue(i).shortValue();
values[i] = Short.toString(val);
}
} else if (datatype == DataType.INT) {
for (int i = 0; i < nValues; i++) {
int val = attr.getNumericValue(i).intValue();
values[i] = Integer.toString(val);
}
} else if (datatype == DataType.LONG) {
for (int i = 0; i < nValues; i++) {
long val = attr.getNumericValue(i).longValue();
values[i] = Long.toString(val);
}
} else if (datatype == DataType.DOUBLE) {
for (int i = 0; i < nValues; i++) {
double val = attr.getNumericValue(i).doubleValue();
values[i] = Double.toString(val);
}
} else if (datatype == DataType.FLOAT) {
for (int i = 0; i < nValues; i++) {
float val = attr.getNumericValue(i).floatValue();
values[i] = Float.toString(val);
}
} else if (datatype == DataType.STRING) {
for (int i = 0; i < nValues; i++) {
values[i] = attr.getStringValue(i);
}
} else {
if (LOGGER.isLoggable(Level.WARNING))
LOGGER.warning("Unhandled Attribute datatype " + attr.getDataType().getClassType().toString());
}
}
String value = "";
if (values != null) {
StringBuffer sb = new StringBuffer();
int j = 0;
for (; j < values.length - 1; j++) {
sb.append(values[j]).append(",");
}
sb.append(values[j]);
value = sb.toString();
}
return value;
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testDenseWindow.
@Test
public void testDenseWindow() {
for (String text : new String[] { "from 2 hours ago to 30 minutes ago", "starting from 2 hours until 30 minutes", "starting from 2 hours ago until 30 minutes ago", "starting from 30 minutes ago until 2 hours ago", "from 30 minutes ago to 2 hours ago " }) {
Window w = WindowProcessor.process(text);
/*
A dense window starting 2 hour ago and continuing until 30 minutes ago
*/
Date now = new Date();
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(1, intervals.size());
assertTimeEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
assertTimeEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
}
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testRepeatWithConflictingExclusionInclusion.
@Test
public void testRepeatWithConflictingExclusionInclusion() {
Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago including saturdays excluding weekends");
Date now = new Date();
// avoid DST impacts if near Midnight
now.setHours(6);
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(0, intervals.size());
}
use of ucar.ma2.Range in project metron by apache.
the class WindowProcessorTest method testDateDaySpecifier.
@Test
public void testDateDaySpecifier() throws ParseException {
for (String text : new String[] { "30 minute window every 24 hours from 14 days ago including date:20171225:yyyyMMdd", "30 minute window every 24 hours from 14 days ago including date:2017-12-25:yyyy-MM-dd", "30 minute window every 24 hours from 14 days ago including date:2017/12/25" }) {
Window w = WindowProcessor.process(text);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Date now = sdf.parse("2017/12/26 12:00");
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(1, intervals.size());
Date includedDate = new Date(intervals.get(0).getMinimum());
SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
assertEquals("20171225", equalityFormat.format(includedDate));
}
{
Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago excluding date:2017/12/25");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Date now = sdf.parse("2017/12/26 12:00");
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(13, intervals.size());
}
{
Window w = WindowProcessor.process("30 minute window every 24 hours from 14 days ago including date:2017/12/25, date:2017/12/24");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Date now = sdf.parse("2017/12/26 12:00");
List<Range<Long>> intervals = w.toIntervals(now.getTime());
assertEquals(2, intervals.size());
{
Date includedDate = new Date(intervals.get(0).getMinimum());
SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
assertEquals("20171224", equalityFormat.format(includedDate));
}
{
Date includedDate = new Date(intervals.get(1).getMinimum());
SimpleDateFormat equalityFormat = new SimpleDateFormat("yyyyMMdd");
assertEquals("20171225", equalityFormat.format(includedDate));
}
}
}
use of ucar.ma2.Range in project sirix by sirixdb.
the class AbstractSunburstGUI method style.
/**
* Style menu.
*/
protected void style() {
final Group ctrl = mControlP5.addGroup("menu", 15, 25, 35);
ctrl.setColorLabel(mParent.color(255));
ctrl.setColorBackground(mParent.color(100));
ctrl.close();
mParent.colorMode(PConstants.RGB, 255, 255, 255);
final int backgroundColor = 0x99ffffff;
int i = 0;
for (final Slider slider : mSliders) {
slider.setGroup(ctrl);
slider.setId(i);
final Label label = slider.getCaptionLabel();
label.toUpperCase(true);
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 0, 1, 3);
style.marginTop = -4;
style.marginLeft = 0;
style.marginRight = -14;
slider.plugTo(mControl);
i++;
}
i = 0;
for (final Range range : mRanges) {
range.setGroup(ctrl);
range.setId(i);
final Label label = range.getCaptionLabel();
label.toUpperCase(true);
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 0, 1, 3);
style.marginTop = -4;
range.plugTo(mControl);
i++;
}
i = 0;
for (final Toggle toggle : mToggles) {
toggle.setGroup(ctrl);
toggle.setId(i);
final Label label = toggle.getCaptionLabel();
label.setColor(mParent.color(0));
label.setColorBackground(backgroundColor);
final ControllerStyle style = label.getStyle();
style.padding(4, 3, 1, 3);
style.marginTop = -19;
style.marginLeft = 18;
style.marginRight = 5;
toggle.plugTo(mControl);
i++;
}
mParent.colorMode(PConstants.HSB, 360, 100, 100);
mParent.textLeading(14);
mParent.textAlign(PConstants.LEFT, PConstants.TOP);
mParent.cursor(PConstants.CROSS);
}
Aggregations