List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
/** * @param cal/*from ww w . j a va 2 s. c om*/ * @return */ private boolean checkHourList(GregorianCalendar cal) { if (mByHourList.size() > 0) { for (Integer cur : mByHourList) { int curHour = cal.get(Calendar.HOUR_OF_DAY); if (curHour == cur.intValue()) return true; // since the month list is in order, if we hit a HIGHER month, // then we know out current month isn't in the list, and therefore // we should go to this next one if (cur > curHour) { cal.set(Calendar.HOUR_OF_DAY, cur); return false; // must re-start checks } } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.HOUR, mByHourList.get(0)); cal.add(Calendar.DAY_OF_YEAR, 1); return false; // must re-start checks } return true; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private boolean checkMonthList(GregorianCalendar cal) { if (mByMonthList.size() > 0) { for (Integer cur : mByMonthList) { int curMonth = cal.get(Calendar.MONTH) + 1; if (cur == curMonth) return true; // since the month list is in order, if we hit a HIGHER month, // then we know out current month isn't in the list, and therefore // we should go to this next one if (cur > curMonth) { cal.set(Calendar.MONTH, cur - 1); return false; // must re-start checks }/*from w w w. ja v a2 s. c om*/ } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.MONTH, mByMonthList.get(0) - 1); cal.add(Calendar.YEAR, 1); return false; // must re-start checks } return true; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private boolean checkYearDayList(GregorianCalendar cal) { if (mByYearDayList.size() > 0) { for (Integer cur : mByYearDayList) { int curYearDay = cal.get(Calendar.DAY_OF_YEAR); if (cur == curYearDay) return true; // since the YearDay list is in order, if we hit a HIGHER one, // then we know out current one isn't in the list, and therefore // we should go to this one we just found in the list if (cur > curYearDay) { cal.set(Calendar.DAY_OF_YEAR, cur); return false; }// ww w . j a va 2 s . com } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.DAY_OF_YEAR, mByYearDayList.get(0)); cal.add(Calendar.YEAR, 1); return false; } return true; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private boolean checkMonthDayList(GregorianCalendar cal) { if (mByMonthDayList.size() > 0) { for (Integer cur : mByMonthDayList) { int curMonthDay = cal.get(Calendar.DAY_OF_MONTH); if (cur == curMonthDay) return true; // since the list is in order, if we hit a HIGHER one, // then we know out current one isn't in the list, and therefore // we should go to this one we just found in the list if (cur > curMonthDay) { cal.set(Calendar.DAY_OF_MONTH, cur); return false; }//ww w .j a v a 2 s.c o m } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.DAY_OF_MONTH, mByMonthDayList.get(0)); cal.add(Calendar.MONTH, 1); return false; } return true; }
From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java
/** * Returns a GMT string representation (yyyy-MM-dd HH:mm:ss) without time if 0 ((yyyy-MM-dd) from a date * value and an udunits string./*ww w . j ava2s . com*/ * * @param date Date object to convert * * @return a string representation of the date */ public static String getDateAsGMTNoZeroTimeString(Date date) { if (date == null) { return ""; } GregorianCalendar calendar = new GregorianCalendar(GMT_TIMEZONE); calendar.setTime(date); int h = calendar.get(Calendar.HOUR_OF_DAY); int m = calendar.get(Calendar.MINUTE); int s = calendar.get(Calendar.SECOND); String format = DATETIME_FORMAT; if ((h == 0) && (m == 0) && (s == 0)) { format = DATE_FORMAT; } return FastDateFormat.getInstance(format, GMT_TIMEZONE).format(date); }
From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java
private IBinder confirmJob(Intent intent, int flags, int startId) { // A client is binding to the service with bindService() String command = intent.getExtras().getString(DAEMON_COMMAND); //Object obj1=intent.getExtras().getClassLoader(); //confirmDaemonAlive(); if (command != null) { if (command.length() < 3) return null; intent.putExtra(DAEMON_COMMAND, "EXECUTED"); if (command.equalsIgnoreCase(GET_BINDER)) { String sType = intent.getExtras().getString(SERVICE_TYPE); if (sType != null && sType.equalsIgnoreCase(URGENT)) { serverHeartBit = 10 * 1000; urgentMailBox.clear();//w ww .jav a 2 s . c o m } return new UrgentMailBinder(); } sendCommand(command); return null; } command = intent.getExtras().getString(ALARM_DONE); if (command == null) return null; PowerManager.WakeLock wlR = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KEEP_THREAD_ALIVE"); wlR.acquire(); switch (command) { case ALARM_BIT: //mDaemon.hasCommand=true; //mDaemon.interrupt(); confirmDaemonAlive(); //startServerHearBeatAlarm(); break; case ALARM_1BOOT: String param = intent.getExtras().getString(ALARM_1BOOT); long on_time = Long.parseLong(param); sendCommand("M5-" + new DecimalFormat("00").format(on_time / 60000)); //startOneBootAlarm(); break; case ALARM_NBOOT: Log.i("ALARM_SET", "got recurring start intent"); GregorianCalendar gToday = new GregorianCalendar( TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en))); if (gToday.get(Calendar.HOUR_OF_DAY) >= 7 && gToday.get(Calendar.HOUR_OF_DAY) < 19) break; String params = intent.getExtras().getString(ALARM_NBOOT); int idx = params.indexOf("-"); long last4 = Long.parseLong(params.substring(0, idx)); sendCommand("M5-" + new DecimalFormat("00").format(last4 / 60000)); long off_time = Long.parseLong(params.substring(idx + 1)); setRecurringBootAlarm(last4, off_time); break; case ALARM_HOUR: //if (heartBitIntent==null) startServerHearBeatAlarm(); if (oneBootIntent == null) startOneBootAlarm(); if (recurringBootIntent == null) startRecurringBootAlarm(); //reStartScheduleAlarms(); startHourlyCheckAlarm(); break; default: break; } wlR.release(); return null;//mBinder; }
From source file:processing.app.debug.Compiler.java
private PreferencesMap createBuildPreferences(String _buildPath, String _primaryClassName) throws RunnerException { if (BaseNoGui.getBoardPreferences() == null) { RunnerException re = new RunnerException( _("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace();// w w w . j a v a 2s. c o m throw re; } // Check if the board needs a platform from another package TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform corePlatform = null; PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences(); String core = boardPreferences.get("build.core", "arduino"); if (core.contains(":")) { String[] split = core.split(":"); core = split[1]; corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); if (corePlatform == null) { RunnerException re = new RunnerException( I18n.format(_("Selected board depends on '{0}' core (not installed)."), split[0])); re.hideStackTrace(); throw re; } } // Merge all the global preference configuration in order of priority PreferencesMap buildPref = new PreferencesMap(); buildPref.putAll(PreferencesData.getMap()); if (corePlatform != null) { buildPref.putAll(corePlatform.getPreferences()); } buildPref.putAll(targetPlatform.getPreferences()); buildPref.putAll(BaseNoGui.getBoardPreferences()); for (String k : buildPref.keySet()) { if (buildPref.get(k) == null) { buildPref.put(k, ""); } } buildPref.put("build.path", _buildPath); buildPref.put("build.project_name", _primaryClassName); buildPref.put("build.arch", targetPlatform.getId().toUpperCase()); // Platform.txt should define its own compiler.path. For // compatibility with earlier 1.5 versions, we define a (ugly, // avr-specific) default for it, but this should be removed at some // point. if (!buildPref.containsKey("compiler.path")) { System.err.println(_( "Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.")); buildPref.put("compiler.path", BaseNoGui.getAvrBasePath()); } TargetPlatform referencePlatform = null; if (corePlatform != null) { referencePlatform = corePlatform; } else { referencePlatform = targetPlatform; } buildPref.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath()); // Core folder File coreFolder = new File(referencePlatform.getFolder(), "cores"); coreFolder = new File(coreFolder, core); buildPref.put("build.core", core); buildPref.put("build.core.path", coreFolder.getAbsolutePath()); // System Folder File systemFolder = referencePlatform.getFolder(); systemFolder = new File(systemFolder, "system"); buildPref.put("build.system.path", systemFolder.getAbsolutePath()); // Variant Folder String variant = buildPref.get("build.variant"); if (variant != null) { TargetPlatform t; if (!variant.contains(":")) { t = targetPlatform; } else { String[] split = variant.split(":", 2); t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); variant = split[1]; } File variantFolder = new File(t.getFolder(), "variants"); variantFolder = new File(variantFolder, variant); buildPref.put("build.variant.path", variantFolder.getAbsolutePath()); } else { buildPref.put("build.variant.path", ""); } ContributedPlatform installedPlatform = BaseNoGui.indexer .getInstalled(referencePlatform.getContainerPackage().getId(), referencePlatform.getId()); if (installedPlatform != null) { List<ContributedTool> tools = installedPlatform.getResolvedTools(); BaseNoGui.createToolPreferences(tools, false); } // Build Time GregorianCalendar cal = new GregorianCalendar(); long current = new Date().getTime() / 1000; long timezone = cal.get(Calendar.ZONE_OFFSET) / 1000; long daylight = cal.get(Calendar.DST_OFFSET) / 1000; buildPref.put("extra.time.utc", Long.toString(current)); buildPref.put("extra.time.local", Long.toString(current + timezone + daylight)); buildPref.put("extra.time.zone", Long.toString(timezone)); buildPref.put("extra.time.dst", Long.toString(daylight)); List<Map.Entry<String, String>> unsetPrefs = buildPref.entrySet().stream() .filter(entry -> Constants.PREF_REMOVE_PLACEHOLDER.equals(entry.getValue())) .collect(Collectors.toList()); buildPref.entrySet().stream().filter(entry -> { return unsetPrefs.stream().filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())) .count() > 0; }).forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), "")); return buildPref; }
From source file:processing.app.debug.OldCompiler.java
private PreferencesMap createBuildPreferences(String _buildPath, String _primaryClassName) throws RunnerException { if (BaseNoGui.getBoardPreferences() == null) { RunnerException re = new RunnerException( tr("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace();//from www . java2 s. c o m throw re; } // Check if the board needs a platform from another package TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform corePlatform = null; PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences(); String core = boardPreferences.get("build.core", "arduino"); if (core.contains(":")) { String[] split = core.split(":"); core = split[1]; corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); if (corePlatform == null) { RunnerException re = new RunnerException( I18n.format(tr("Selected board depends on '{0}' core (not installed)."), split[0])); re.hideStackTrace(); throw re; } } // Merge all the global preference configuration in order of priority PreferencesMap buildPref = new PreferencesMap(); buildPref.putAll(PreferencesData.getMap()); if (corePlatform != null) { buildPref.putAll(corePlatform.getPreferences()); } buildPref.putAll(targetPlatform.getPreferences()); buildPref.putAll(BaseNoGui.getBoardPreferences()); for (String k : buildPref.keySet()) { if (buildPref.get(k) == null) { buildPref.put(k, ""); } } buildPref.put("build.path", _buildPath); buildPref.put("build.project_name", _primaryClassName); buildPref.put("build.arch", targetPlatform.getId().toUpperCase()); // Platform.txt should define its own compiler.path. For // compatibility with earlier 1.5 versions, we define a (ugly, // avr-specific) default for it, but this should be removed at some // point. if (!buildPref.containsKey("compiler.path")) { System.err.println(tr( "Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.")); buildPref.put("compiler.path", BaseNoGui.getAvrBasePath()); } TargetPlatform referencePlatform = null; if (corePlatform != null) { referencePlatform = corePlatform; } else { referencePlatform = targetPlatform; } buildPref.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath()); // Core folder File coreFolder = new File(referencePlatform.getFolder(), "cores"); coreFolder = new File(coreFolder, core); buildPref.put("build.core", core); buildPref.put("build.core.path", coreFolder.getAbsolutePath()); // System Folder File systemFolder = referencePlatform.getFolder(); systemFolder = new File(systemFolder, "system"); buildPref.put("build.system.path", systemFolder.getAbsolutePath()); // Variant Folder String variant = buildPref.get("build.variant"); if (variant != null) { TargetPlatform t; if (!variant.contains(":")) { t = targetPlatform; } else { String[] split = variant.split(":", 2); t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); variant = split[1]; } File variantFolder = new File(t.getFolder(), "variants"); variantFolder = new File(variantFolder, variant); buildPref.put("build.variant.path", variantFolder.getAbsolutePath()); } else { buildPref.put("build.variant.path", ""); } ContributedPlatform installedPlatform = BaseNoGui.indexer .getInstalled(referencePlatform.getContainerPackage().getId(), referencePlatform.getId()); if (installedPlatform != null) { List<ContributedTool> tools = installedPlatform.getResolvedTools(); BaseNoGui.createToolPreferences(tools, false); } // Build Time GregorianCalendar cal = new GregorianCalendar(); long current = new Date().getTime() / 1000; long timezone = cal.get(Calendar.ZONE_OFFSET) / 1000; long daylight = cal.get(Calendar.DST_OFFSET) / 1000; buildPref.put("extra.time.utc", Long.toString(current)); buildPref.put("extra.time.local", Long.toString(current + timezone + daylight)); buildPref.put("extra.time.zone", Long.toString(timezone)); buildPref.put("extra.time.dst", Long.toString(daylight)); List<Map.Entry<String, String>> unsetPrefs = buildPref.entrySet().stream() .filter(entry -> Constants.PREF_REMOVE_PLACEHOLDER.equals(entry.getValue())) .collect(Collectors.toList()); buildPref.entrySet().stream() .filter(entry -> unsetPrefs.stream() .filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())).count() > 0) .forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), "")); new LoadVIDPIDSpecificPreferences().load(buildPref); return buildPref; }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on Weight , date start and resource * @param start/* w w w . j a va 2s. c o m*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID()); double dailyCapacity = rosource.getDailyCapacity().doubleValue(); double utilization = rosource.getPercentUtilization().doubleValue(); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
/** * This version is for HOURLY/DAILY frequencies: it does NOT check the ordinal at all, * it only verifies that the day-of-the-week matches * * @param cal/*from w w w.j a va2s . c om*/ * @return */ private boolean checkDayList(GregorianCalendar cal) { assert (mFreq != Frequency.MONTHLY && mFreq != Frequency.YEARLY && mFreq != Frequency.WEEKLY); if (mByDayList.size() > 0) { for (ZWeekDayNum listCur : mByDayList) { int curDayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if (listCur.mDay.getCalendarDay() == curDayOfWeek) return true; // since the DayOfWeek list is in week-order, if we hit a HIGHER one, // then we know out current one isn't in the list, and therefore // we should go to this one we just found in the list if (listCur.mDay.getCalendarDay() > curDayOfWeek) { cal.set(Calendar.DAY_OF_WEEK, listCur.mDay.getCalendarDay()); return false; } } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.DAY_OF_WEEK, mByDayList.get(0).mDay.getCalendarDay()); cal.add(Calendar.WEEK_OF_YEAR, 1); return false; } return true; }