List of usage examples for org.joda.time Period minutes
public static Period minutes(int minutes)
From source file:org.kalypso.ui.rrm.internal.simulations.worker.TimeseriesMappingRunner.java
License:Open Source License
private IStatus executeMappingElement(final ZmlLink linkedTimeseries, final IXLinkedFeature modelElement) { /* Check if link is valid */ if (!linkedTimeseries.isLinkExisting()) { final String message = String.format(Messages.getString("TimeseriesMappingRunner_2"), //$NON-NLS-1$ modelElement.getName(), linkedTimeseries.getHref()); return new Status(IStatus.WARNING, KalypsoUIRRMPlugin.getID(), message); }// w w w . j av a 2 s . co m try { /* Copy and filter the timeseries */ final IObservation timeseries = linkedTimeseries.loadObservation(); /* Get the unadjusted simulation range. */ final Date simulationStart = m_simulation.getSimulationStart(); final Date simulationEnd = m_simulation.getSimulationEnd(); final DateRange unadjustedSimulationRange = new DateRange(simulationStart, simulationEnd); /* Check, if the range of the timeseries covers the unadjusted simulation range. */ final DateRange timeseriesRange = MetadataHelper.getDateRange(timeseries.getMetadataList()); if (!timeseriesRange.containsInclusive(unadjustedSimulationRange)) throw new SensorException(String.format(Messages.getString("TimeseriesMappingRunner.0"), //$NON-NLS-1$ timeseries.getName(), timeseriesRange.toString(), unadjustedSimulationRange.toString())); /* Apply filter. */ final IObservationFilter filteredTimeseries = createTimeseriesFilter(); filteredTimeseries.initFilter(null, timeseries, null); /* Change model link */ final QName modelLinkProperty = m_mappingType.getModelLinkProperty(); final TimeseriesLinkType newLinkType = new TimeseriesLinkType(); newLinkType.setHref(buildTargetHref(modelElement)); modelElement.setProperty(modelLinkProperty, newLinkType); /* Build request */ final Integer timestepMinutes = m_simulation.getMinutesOfTimestep(); final Period timestep = Period.minutes(timestepMinutes).normalizedStandard(); // TODO: Check if we need timestamp for sea evaporation final DateRange simulationRange = CatchmentModelHelper.getRange(m_simulation, timestep, null); final ObservationRequest request = new ObservationRequest(simulationRange); /* Filter and save to new location */ final ZmlLink zmlLink = new ZmlLink(modelElement, modelLinkProperty); zmlLink.saveObservation(filteredTimeseries, request); return Status.OK_STATUS; } catch (final SensorException | UnsupportedEncodingException | CoreException e) { return new Status(IStatus.WARNING, KalypsoUIRRMPlugin.getID(), Messages.getString("TimeseriesMappingRunner_3"), e); //$NON-NLS-1$ } }
From source file:org.openhab.binding.sonos.internal.SonosZonePlayer.java
License:Open Source License
public boolean snoozeAlarm(int minutes) { if (isAlarmRunning() && isConfigured()) { Service service = device.findService(new UDAServiceId("AVTransport")); Action action = service.getAction("SnoozeAlarm"); ActionInvocation invocation = new ActionInvocation(action); Period snoozePeriod = Period.minutes(minutes); PeriodFormatter pFormatter = new PeriodFormatterBuilder().printZeroAlways().appendHours() .appendSeparator(":").appendMinutes().appendSeparator(":").appendSeconds().toFormatter(); try {/*from ww w . j a va 2 s . c o m*/ invocation.setInput("Duration", pFormatter.print(snoozePeriod)); } catch (InvalidValueException ex) { logger.error("Action Invalid Value Exception {}", ex.getMessage()); } catch (NumberFormatException ex) { logger.error("Action Invalid Value Format Exception {}", ex.getMessage()); } executeActionInvocation(invocation); return true; } else { logger.warn("There is no alarm running on {} ", this); return false; } }
From source file:org.openmrs.module.referencedemodata.ReferenceDemoDataActivator.java
License:Open Source License
private Visit createDemoVisit(Patient patient, List<VisitType> visitTypes, Location location, boolean shortVisit) { LocalDateTime visitStart = LocalDateTime.now().minus(Period.days(randomBetween(0, 365 * 2)).withHours(3)); // past 2 years if (!shortVisit) { visitStart = visitStart.minus(Period.days(ADMISSION_DAYS_MAX + 1)); // just in case the start is today, back it up a few days. }/*from w ww .j av a 2 s . co m*/ Visit visit = new Visit(patient, randomArrayEntry(visitTypes), visitStart.toDate()); visit.setLocation(location); LocalDateTime vitalsTime = visitStart.plus(Period.minutes(randomBetween(1, 60))); visit.addEncounter(createDemoVitalsEncounter(patient, vitalsTime.toDate())); LocalDateTime visitNoteTime = visitStart.plus(Period.minutes(randomBetween(60, 120))); visit.addEncounter(createVisitNote(patient, visitNoteTime.toDate(), location)); if (shortVisit) { LocalDateTime visitEndTime = visitNoteTime.plus(Period.minutes(30)); visit.setStopDatetime(visitEndTime.toDate()); } else { // admit now and discharge a few days later Location admitLocation = Context.getLocationService().getLocation("Inpatient Ward"); visit.addEncounter(createEncounter("Admission", patient, visitNoteTime.toDate(), admitLocation)); LocalDateTime dischargeDateTime = visitNoteTime .plus(Period.days(randomBetween(ADMISSION_DAYS_MIN, ADMISSION_DAYS_MAX))); visit.addEncounter(createEncounter("Discharge", patient, dischargeDateTime.toDate(), admitLocation)); visit.setStopDatetime(dischargeDateTime.toDate()); } return visit; }
From source file:org.openvpms.archetype.rules.util.DateUnits.java
License:Open Source License
/** * Converts a value in the units to a {@code Period}. * * @param value the value//from w w w .j ava 2 s .c om * @return a new period */ public Period toPeriod(int value) { switch (this) { case MINUTES: return Period.minutes(value); case HOURS: return Period.hours(value); case DAYS: return Period.days(value); case WEEKS: return Period.weeks(value); case MONTHS: return Period.months(value); default: return Period.years(value); } }
From source file:rcrr.reversi.Game.java
License:Open Source License
/** * Returns a random game instance./*from www . j a va 2 s.c om*/ * <p> * The parameter {@code numberOfRandomPutDiscMoves} must be non negative and must be * less than sixty. * <p> * In the quite obscure case that the game completes before reaching the number of * requested moves, the method restart from the beginning generating a new case. * * @param numberOfRandomPutDiscMoves the number of random moves to be played * @return a random game instance * @throws IllegalArgumentException when the numberOfRandomPutDiscMoves is out of range */ public static Game randomGame(final long numberOfRandomPutDiscMoves) { if (numberOfRandomPutDiscMoves < 0 || numberOfRandomPutDiscMoves > MAX_PUT_DISC_MOVES) { throw new IllegalArgumentException("Parameter numberOfRandomPutDiscMoves must be non negative," + " and must be less than sixty. Got a value of: " + numberOfRandomPutDiscMoves); } final Game randomGame = initialGame(Actor.valueOf("Black Actor", new RandomStrategy()), Actor.valueOf("White Actor", new RandomStrategy()), Period.minutes(1).toStandardDuration(), new NullPrintStream()); while (MAX_PUT_DISC_MOVES - randomGame.board().countPieces(SquareState.EMPTY) < numberOfRandomPutDiscMoves) { if (randomGame.areThereAvailableMoves()) { randomGame.move(); } else { return randomGame(numberOfRandomPutDiscMoves); } } return randomGame; }
From source file:rcrr.reversi.Reversi.java
License:Open Source License
/** * The main entry point for the Reversi Program. * * @param args an array having two elements: [black's strategy, white's strategy] *//*from ww w. jav a 2s . c o m*/ public static void main(final String[] args) { if (args == null || args.length != 2) { System.out.println("Argument list error: blackStrategy and whiteStrategy must be provided."); usage(); System.exit(ERROR_CODE_1); } Strategy[] s = new Strategy[] { null, null }; for (int i = 0; i < s.length; i++) { Object o = null; try { Class<?> c = Class.forName(args[i]); o = c.newInstance(); } catch (ClassNotFoundException e) { System.out.println("Exception e: " + e); usage(); System.exit(ERROR_CODE_2); } catch (InstantiationException e) { System.out.println("Exception e: " + e); usage(); System.exit(ERROR_CODE_3); } catch (IllegalAccessException e) { System.out.println("Exception e: " + e); usage(); System.exit(ERROR_CODE_4); } try { s[i] = (Strategy) o; } catch (ClassCastException e) { System.out.println("Exception e: " + e); usage(); System.exit(ERROR_CODE_5); } } reversi(s[0], s[1], System.out, Period.minutes(DEFAULT_GAME_DURATION_IN_MINUTES).toStandardDuration()); }
From source file:rcrr.reversi.ui.ReversiUI.java
License:Open Source License
private void newGame() { this.pauseRequested = false; this.move = null; this.resultsReady = new ThreadEvent(); Actor black, white;//from w w w . j a v a 2 s . co m final Actor ai = new Actor.Builder().withName("Iago").withStrategy(new IagoStrategy(searchDepth)).build(); final Actor human = new Actor.Builder().withName("Human").withStrategy(new HumanStrategyUI()).build(); if (humanPlayer == Player.BLACK) { black = human; white = ai; } else { black = ai; white = human; } ; game = Game.initialGame(black, white, Period.minutes(gameDuration).toStandardDuration(), consolePrintStream); }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.threshold.TimeThreshold.java
License:Open Source License
public static TimeThreshold minutes(int minutes) { return new TimeThreshold(Period.minutes(minutes)); }