List of usage examples for org.joda.time Period getValues
public int[] getValues()
From source file:com.metamx.druid.PeriodGranularity.java
License:Open Source License
private static boolean isCompoundPeriod(Period period) { int[] values = period.getValues(); boolean single = false; for (int v : values) { if (v > 0) { if (single) return true; single = true;//from w w w.j av a 2s.com } } return false; }
From source file:ee.ut.soras.test_ajavt.KiiruseTestiTulemus.java
License:Open Source License
private String convertToOtherFields(double timeInMills) { Period p = new Period((long) timeInMills, PeriodType.millis()); p = p.normalizedStandard();/*from w ww .j av a2s . c om*/ DurationFieldType[] fieldTypes = p.getFieldTypes(); int[] values = p.getValues(); if (values.length == fieldTypes.length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { if (values[i] != 0) { sb.append(values[i] + " " + fieldTypes[i].getName() + " "); } } return sb.toString(); } return p.toString(); }
From source file:io.druid.java.util.common.granularity.GranularityType.java
License:Apache License
/** * Note: This is only an estimate based on the values in period. * This will not work for complicated periods that represent say 1 year 1 day *///from w ww. ja v a 2 s. c om public static GranularityType fromPeriod(Period period) { int[] vals = period.getValues(); int index = -1; for (int i = 0; i < vals.length; i++) { if (vals[i] != 0) { if (index < 0) { index = i; } else { throw new IAE("Granularity is not supported. [%s]", period); } } } switch (index) { case 0: return GranularityType.YEAR; case 1: if (vals[index] == 3) { return GranularityType.QUARTER; } else if (vals[index] == 1) { return GranularityType.MONTH; } break; case 2: return GranularityType.WEEK; case 3: return GranularityType.DAY; case 4: if (vals[index] == 6) { return GranularityType.SIX_HOUR; } else if (vals[index] == 1) { return GranularityType.HOUR; } break; case 5: if (vals[index] == 30) { return GranularityType.THIRTY_MINUTE; } else if (vals[index] == 15) { return GranularityType.FIFTEEN_MINUTE; } else if (vals[index] == 10) { return GranularityType.TEN_MINUTE; } else if (vals[index] == 5) { return GranularityType.FIVE_MINUTE; } else if (vals[index] == 1) { return GranularityType.MINUTE; } break; case 6: return GranularityType.SECOND; default: break; } throw new IAE("Granularity is not supported. [%s]", period); }
From source file:io.druid.java.util.common.granularity.PeriodGranularity.java
License:Apache License
private static boolean isCompoundPeriod(Period period) { int[] values = period.getValues(); boolean single = false; for (int v : values) { if (v > 0) { if (single) { return true; }//from w ww .ja v a 2 s . c o m single = true; } } return false; }
From source file:net.tourbook.tour.photo.TourPhotoLinkView.java
License:Open Source License
/** * column: duration time//from www . j ava2 s . co m */ private void defineColumn_Time_TourDurationTime() { final ColumnDefinition colDef = TableColumnFactory.TIME_TOUR_DURATION_TIME.createColumn(_columnManager, _pc); colDef.setIsDefaultColumn(); colDef.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final TourPhotoLink link = (TourPhotoLink) cell.getElement(); final Period period = link.tourPeriod; int periodSum = 0; for (final int value : period.getValues()) { periodSum += value; } if (periodSum == 0) { // < 1 h cell.setText(Messages.Photos_AndTours_Label_DurationLess1Hour); } else { // > 1 h cell.setText(period.toString(_durationFormatter)); } setBgColor(cell, link); } }); }
From source file:org.kalypso.commons.time.PeriodUtils.java
License:Open Source License
private static int countNonZeroFields(final Period period) { int fieldCount = 0; final int[] values = period.getValues(); for (final int value : values) { if (value != 0) fieldCount++;// ww w . j ava2 s .c o m } return fieldCount; }
From source file:org.kalypso.ogc.sensor.metadata.MetadataHelper.java
License:Open Source License
public static void setTimestep(final MetadataList mdl, final Period timestep) { final int[] values = timestep.getValues(); int fieldCount = 0; for (final int value : values) { if (value != 0) fieldCount++;/*from w w w . ja va 2 s. c om*/ } if (fieldCount > 1) throw new IllegalArgumentException(Messages.getString("MetadataHelper_2") + timestep); //$NON-NLS-1$ int amount = -1; int calendarField = -1; if (timestep.getDays() != 0) { amount = timestep.getDays(); calendarField = Calendar.DAY_OF_MONTH; } else if (timestep.getHours() != 0) { amount = timestep.getHours(); calendarField = Calendar.HOUR_OF_DAY; } else if (timestep.getMillis() != 0) { amount = timestep.getMillis(); calendarField = Calendar.MILLISECOND; } else if (timestep.getMinutes() != 0) { amount = timestep.getMinutes(); calendarField = Calendar.MINUTE; } else if (timestep.getMonths() != 0) { amount = timestep.getMonths(); calendarField = Calendar.MONTH; } else if (timestep.getSeconds() != 0) { amount = timestep.getSeconds(); calendarField = Calendar.SECOND; } else if (timestep.getWeeks() != 0) { amount = timestep.getWeeks(); calendarField = Calendar.WEEK_OF_YEAR; } else if (timestep.getYears() != 0) { amount = timestep.getYears(); calendarField = Calendar.YEAR; } if (amount == -1) throw new IllegalArgumentException(Messages.getString("MetadataHelper_3")); //$NON-NLS-1$ setTimestep(mdl, calendarField, amount); return; }