List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:org.thelq.pircbotx.commands.NewYearsCommand.java
License:Open Source License
public void start() throws InterruptedException { DateTime nextNewYears;/*w w w . j a v a 2s .co m*/ while ((nextNewYears = getNextNewYears()) != null) { waitingNewYear = nextNewYears; Alarm newYearAlarm = new Alarm(nextNewYears) { protected Logger log = LoggerFactory.getLogger(getClass()); protected boolean started = false; @Override public List<Integer> getNotifySeconds(long totalSeconds) { List<Integer> notifySeconds = Lists.newArrayList(); notifySeconds.add(5 * 60); notifySeconds.add(2 * 60); notifySeconds.add(60); notifySeconds.add(30); notifySeconds.add(10); notifySeconds.add(5); notifySeconds.add(3); notifySeconds.add(2); notifySeconds.add(1); return notifySeconds; } @Override public void onStart(long secondsTillNotify) { log.debug("Initialized NYE countdown for " + getShortNames(NEW_YEAR_ZONES.get(waitingNewYear))); } @Override public void onNotifyBefore(long secondsToWait) { log.debug("Waiting " + secondsToWait + " seconds for next notify"); } @Override public void onNotify(long secondsRemain) { if (!started) { sendMessage("NEW YEARS EVE COUNTDOWN STARTING!!! " + getExtendedNames(NEW_YEAR_ZONES.get(waitingNewYear))); started = true; } //Theme the countdown if (secondsRemain > 9) sendMessage(FORMATTER_REMAIN.print(new Period(1000 * secondsRemain)) + "till NYE for " + getShortNames(NEW_YEAR_ZONES.get(alarmDate))); else if (secondsRemain <= 9 && secondsRemain > 3) sendMessage(secondsRemain + " seconds"); else if (secondsRemain == 3) sendMessage("3!"); else if (secondsRemain == 2) sendMessage("2!!"); else if (secondsRemain == 1) sendMessage("1!!!"); } @Override public void onEnd() { sendMessage("Happy New Year!!!! Welcome to " + NEW_YEAR + " " + getShortNames(NEW_YEAR_ZONES.get(waitingNewYear)) + " | Drift: " + calcDrift()); } protected void sendMessage(String message) { //Send to all connected, non-blacklisted channels for (PircBotX curBot : Main.MANAGER.getBots()) for (Channel curChannel : curBot.getUserChannelDao().getAllChannels()) { if (blacklistedChannels.contains(curChannel)) continue; sendMessageNow(curBot, curChannel, message); } } }; newYearAlarm.countdown(); } }
From source file:org.trakhound.www.trakhound.DeviceDetails.java
License:Open Source License
private void updateStatus(DeviceStatus status) { if (status.statusInfo == null) status.statusInfo = new StatusInfo(); if (status.statusInfo.deviceStatus != null) { String deviceStatus = status.statusInfo.deviceStatus; // Current Status Indicator View banner = findViewById(R.id.DeviceStatusIndicator); if (banner != null) { if (deviceStatus.equals("Alert")) { banner.setBackgroundColor(getResources().getColor(R.color.statusRed)); } else if (deviceStatus.equals("Idle")) { banner.setBackgroundColor(getResources().getColor(R.color.statusOrange)); } else { banner.setBackgroundColor(getResources().getColor(R.color.statusGreen)); }// w w w . j a v a 2s .c o m } // Current Status Text TextView txt = (TextView) findViewById(R.id.DeviceStatusText); if (txt != null) txt.setText(deviceStatus); // Current Status Timer Period period = new Period(status.statusInfo.deviceStatusTimer * 1000); String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds()); txt = (TextView) findViewById(R.id.DeviceStatusTime); if (txt != null) txt.setText(statusPeriod); } else clearStatus(); }
From source file:org.trakhound.www.trakhound.DeviceDetails.java
License:Open Source License
private void updateDevicePercentages(DeviceStatus status) { // Percentages if (status.timersInfo != null && status.timersInfo.total > 0) { TimersInfo info = status.timersInfo; double active = (info.active / info.total) * 100; double idle = (info.idle / info.total) * 100; double alert = (info.alert / info.total) * 100; // Progress Bars // Active ProgressBar pb = (ProgressBar) findViewById(R.id.ActiveProgressBar); if (pb != null) pb.setProgress((int) Math.round(active)); // Idle//from w w w . ja v a 2 s . com pb = (ProgressBar) findViewById(R.id.IdleProgressBar); if (pb != null) pb.setProgress((int) Math.round(idle)); // Alert pb = (ProgressBar) findViewById(R.id.AlertProgressBar); if (pb != null) pb.setProgress((int) Math.round(alert)); // Percentage TextViews // Active TextView txt = (TextView) findViewById(R.id.ActivePercentage); if (txt != null) txt.setText(String.format("%.0f%%", active)); // Idle txt = (TextView) findViewById(R.id.IdlePercentage); if (txt != null) txt.setText(String.format("%.0f%%", idle)); // Alert txt = (TextView) findViewById(R.id.AlertPercentage); if (txt != null) txt.setText(String.format("%.0f%%", alert)); // Time Elapsed TextViews // Active Integer seconds = Integer.valueOf((int) Math.round(info.active)); Period period = new Period(seconds * 1000); String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds()); txt = (TextView) findViewById(R.id.ActiveTime); if (txt != null) txt.setText(statusPeriod); // Idle seconds = Integer.valueOf((int) Math.round(info.idle)); period = new Period(seconds * 1000); statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds()); txt = (TextView) findViewById(R.id.IdleTime); if (txt != null) txt.setText(statusPeriod); // Alert seconds = Integer.valueOf((int) Math.round(info.alert)); period = new Period(seconds * 1000); statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds()); txt = (TextView) findViewById(R.id.AlertTime); if (txt != null) txt.setText(statusPeriod); } else clearDevicePercentages(); }
From source file:org.trakhound.www.trakhound.device_list.ListAdapter.java
License:Open Source License
private void setProductionStatus(ViewHolder holder, StatusInfo info) { if (info != null && info.deviceStatus != null) { if (holder.ProductionStatus != null) holder.ProductionStatus.setText(info.deviceStatus); if (holder.ProductionStatusTimer != null && info.deviceStatusTimer != null) { Period period = new Period(info.deviceStatusTimer * 1000); String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds()); holder.ProductionStatusTimer.setText(statusPeriod); }//w w w .ja va 2 s . com } }
From source file:org.xwiki.contrib.ratelimiter.internal.DefaultRateLimiterServiceConfiguration.java
License:Open Source License
@Override public String getFormattedMailInterval() { Period period = new Period(getMailInterval()); PeriodFormatter formatter = PeriodFormat.wordBased(getLocale()); return formatter.print(period); }
From source file:org.xwiki.contrib.ratelimiter.script.RateLimiterScriptService.java
License:Open Source License
/** * Return as a human readable formatted string the time to wait before a given amount can be consumed by the * current user on the current wiki.//from w ww.ja v a 2 s . c o m * * @param amount the amount that should be consumable. * @param locale the locale used to format the result. * @return the time to wait as a formatted string. */ public String getFormattedWaitingTime(long amount, Locale locale) { Period period = new Period(getWaitingTime(amount, TimeUnit.MILLISECONDS)); PeriodFormatter formatter = PeriodFormat.wordBased(locale); return formatter.print(period); }
From source file:org.xwiki.contrib.ratelimiter.script.RateLimiterScriptService.java
License:Open Source License
/** * Return as a human readable formatted string the time to wait before a given amount can be consumed by the * current user on the current wiki.// w w w. ja v a 2s .co m * * @param consumer the entity consuming. * @param consumed the entity being consumed. * @param amount the amount that should be consumable. * @param locale the locale used to format the result. * @return the time to wait as a formatted string. */ public String getFormattedWaitingTime(Object consumer, Object consumed, long amount, Locale locale) { if (contextualAuthorizationManager.hasAccess(Right.PROGRAM)) { Period period = new Period(getWaitingTime(consumer, consumed, amount, TimeUnit.MILLISECONDS)); PeriodFormatter formatter = PeriodFormat.wordBased(locale); return formatter.print(period); } return null; }
From source file:propel.core.utils.ConversionUtils.java
License:Open Source License
private static Object changeTypeFromNumber(Object value, Class<?> targetType) { Number number = (Number) value; // dispatch to appropriate constructor method if (targetType.equals(Byte.class)) return new Byte(number.byteValue()); if (targetType.equals(Boolean.class)) return number.longValue() == 0 ? new Boolean(false) : new Boolean(true); if (targetType.equals(Short.class)) return new Short(number.shortValue()); if (targetType.equals(Integer.class)) return new Integer(number.intValue()); if (targetType.equals(Long.class)) return new Long(number.longValue()); if (targetType.equals(Float.class)) return new Float(number.floatValue()); if (targetType.equals(Double.class)) return new Double(number.doubleValue()); if (targetType.equals(Character.class)) return new Character((char) number.shortValue()); if (targetType.equals(byte.class)) return number.byteValue(); if (targetType.equals(boolean.class)) return number.longValue() == 0 ? false : true; if (targetType.equals(char.class)) return (char) number.shortValue(); if (targetType.equals(short.class)) return number.shortValue(); if (targetType.equals(int.class)) return number.intValue(); if (targetType.equals(long.class)) return number.longValue(); if (targetType.equals(float.class)) return number.floatValue(); if (targetType.equals(double.class)) return number.doubleValue(); if (targetType.equals(LocalDateTime.class)) return new LocalDateTime(number.longValue()); if (targetType.equals(DateTime.class)) return new DateTime(number.longValue()); if (targetType.equals(BigDecimal.class)) return new BigDecimal(number.toString()); if (targetType.equals(Duration.class)) return new Duration(number.longValue()); if (targetType.equals(Period.class)) return new Period(number.longValue()); if (targetType.equals(Int128.class)) return new Int128(number.toString()); if (targetType.equals(UnsignedByte.class)) return new UnsignedByte((short) (number.byteValue() & 0xFF)); if (targetType.equals(UnsignedShort.class)) return new UnsignedShort((int) (number.shortValue() & 0xFFFF)); if (targetType.equals(UnsignedInteger.class)) return new UnsignedInteger((long) (number.intValue() & 0xFFFFFFFF)); if (targetType.equals(UnsignedLong.class)) { // perform similar operation as above to get rid of the negative values long ln = new BigInteger(number.toString()).longValue(); return new UnsignedLong(new BigInteger("0" + toBinary(ln))); }// w w w . j a v a 2 s .c o m if (targetType.equals(SignedByte.class)) return new SignedByte(number.byteValue()); if (targetType.equals(BigInteger.class)) return new BigInteger(number.toString()); if (targetType.equals(propel.core.userTypes.BigInteger.class)) { propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger(); bi.setCurrentValue(number.toString()); return bi; } throw new IllegalArgumentException("The provided Number could not be converted to type '" + targetType.getSimpleName() + "': " + value); }
From source file:propel.core.utils.ConversionUtils.java
License:Open Source License
private static Object changeTypeFromCharacter(Object value, Class<?> targetType) { char ch = ((Character) value).charValue(); // dispatch to appropriate construction method if (targetType.equals(Byte.class)) return new Byte((byte) ch); if (targetType.equals(Boolean.class)) return ch == 0 ? new Boolean(false) : new Boolean(true); if (targetType.equals(Short.class)) return new Short((short) ch); if (targetType.equals(Integer.class)) return new Integer(ch); if (targetType.equals(Long.class)) return new Long(ch); if (targetType.equals(Float.class)) return new Float(ch); if (targetType.equals(Double.class)) return new Double(ch); if (targetType.equals(byte.class)) return (byte) ch; if (targetType.equals(boolean.class)) return ch == 0 ? false : true; if (targetType.equals(char.class)) return ch; if (targetType.equals(short.class)) return (short) ch; if (targetType.equals(int.class)) return (int) ch; if (targetType.equals(long.class)) return (long) ch; if (targetType.equals(float.class)) return (float) ch; if (targetType.equals(double.class)) return (double) ch; if (targetType.equals(LocalDateTime.class)) return new LocalDateTime((long) ch); if (targetType.equals(DateTime.class)) return new DateTime((long) ch); if (targetType.equals(BigDecimal.class)) return new BigDecimal(ch); if (targetType.equals(Duration.class)) return new Duration((long) ch); if (targetType.equals(Period.class)) return new Period((long) ch); if (targetType.equals(Int128.class)) return new Int128(Integer.valueOf(ch).toString()); if (targetType.equals(UnsignedByte.class)) return new UnsignedByte((byte) ch); if (targetType.equals(UnsignedShort.class)) return new UnsignedShort(ch); if (targetType.equals(UnsignedInteger.class)) return new UnsignedInteger(ch); if (targetType.equals(UnsignedLong.class)) return new UnsignedLong(new Integer(ch).toString()); if (targetType.equals(SignedByte.class)) return new SignedByte((byte) ch); if (targetType.equals(BigInteger.class)) return new BigInteger(Integer.valueOf(ch).toString()); if (targetType.equals(propel.core.userTypes.BigInteger.class)) { propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger(); bi.setCurrentValue(Integer.valueOf(ch).toString()); return bi; }/* www. j av a 2s . c o m*/ throw new IllegalArgumentException("The provided Character could not be converted to type '" + targetType.getSimpleName() + "': " + value); }
From source file:propel.core.utils.ConversionUtils.java
License:Open Source License
private static Object changeTypeFromBoolean(Object value, Class<?> targetType) { boolean bool = ((Boolean) value).booleanValue(); // dispatch to appropriate construction method if (targetType.equals(Byte.class)) return bool ? new Byte((byte) 1) : new Byte((byte) 0); if (targetType.equals(Character.class)) return bool ? new Character((char) 0) : new Character((char) 1); if (targetType.equals(Short.class)) return bool ? new Short((short) 1) : new Short((short) 0); if (targetType.equals(Integer.class)) return bool ? new Integer(1) : new Integer(0); if (targetType.equals(Long.class)) return bool ? new Long(1) : new Long(0); if (targetType.equals(Float.class)) return bool ? new Float(1) : new Float(0); if (targetType.equals(Double.class)) return bool ? new Double(1) : new Double(0); if (targetType.equals(byte.class)) return bool ? (byte) 1 : (byte) 0; if (targetType.equals(boolean.class)) return bool; if (targetType.equals(char.class)) return bool ? (char) 1 : (char) 0; if (targetType.equals(short.class)) return bool ? (short) 1 : (short) 0; if (targetType.equals(int.class)) return bool ? (int) 1 : (int) 0; if (targetType.equals(long.class)) return bool ? (long) 1 : (long) 0; if (targetType.equals(float.class)) return bool ? (float) 1.0 : (float) 0.0; if (targetType.equals(double.class)) return bool ? (double) 1.0 : (double) 0.0; if (targetType.equals(LocalDateTime.class)) return bool ? new LocalDateTime(1) : new LocalDateTime(0); if (targetType.equals(DateTime.class)) return bool ? new DateTime(1) : new DateTime(0); if (targetType.equals(BigDecimal.class)) return bool ? new BigDecimal(1) : new BigDecimal(0); if (targetType.equals(Duration.class)) return bool ? new Duration(1) : new Duration(0); if (targetType.equals(Period.class)) return bool ? new Period(1) : new Period(0); if (targetType.equals(Int128.class)) return bool ? new Int128("1") : new Int128("0"); if (targetType.equals(UnsignedByte.class)) return bool ? new UnsignedByte((byte) 1) : new UnsignedByte((byte) 0); if (targetType.equals(UnsignedShort.class)) return bool ? new UnsignedShort(1) : new UnsignedShort(0); if (targetType.equals(UnsignedInteger.class)) return bool ? new UnsignedInteger(1) : new UnsignedInteger(0); if (targetType.equals(UnsignedLong.class)) return bool ? new UnsignedLong("1") : new UnsignedLong("0"); if (targetType.equals(SignedByte.class)) return bool ? new SignedByte("1") : new SignedByte("0"); if (targetType.equals(BigInteger.class)) return bool ? new BigInteger("1") : new BigInteger("0"); if (targetType.equals(propel.core.userTypes.BigInteger.class)) { propel.core.userTypes.BigInteger bi = new propel.core.userTypes.BigInteger(); bi.setCurrentValue(bool ? "1" : "0"); return bi; }//from www . ja v a 2s .c o m throw new IllegalArgumentException("The provided Boolean could not be converted to type '" + targetType.getSimpleName() + "': " + value); }