public final void setTimeAsArray(String key, Date value) { JsArrayInteger jsArray = JavaScriptObject.createArray().cast(); jsArray.set(0, value.getHours()); jsArray.set(1, value.getMinutes()); jsArray.set(2, value.getSeconds()); set(key, jsArray); };
public final void setDateAsArray(String key, Date value) { JsArrayInteger jsArray = JavaScriptObject.createArray().cast(); jsArray.set(0, value.getYear()); jsArray.set(1, value.getMonth()); jsArray.set(2, value.getDate()); set(key, jsArray); };
// sets all bits to true within the given range private static void set(JsArrayInteger array, int fromIndex, int toIndex) { int first = wordIndex(fromIndex); int last = wordIndex(toIndex); int startBit = bitOffset(fromIndex); int endBit = bitOffset(toIndex); if (first == last) { // set the bits in between first and last maskInWord(array, first, startBit, endBit); } else { // set the bits from fromIndex to the next 32 bit boundary if (startBit != 0) { maskInWord(array, first++, startBit, 32); } // set the bits from the last 32 bit boundary to the toIndex if (endBit != 0) { maskInWord(array, last, 0, endBit); } // // set everything in between // for (int i = first; i < last; i++) { array.set(i, 0xffffffff); } } }
// sets all bits at a certain index to the given value private static void setWord(JsArrayInteger array, int index, int value) { // keep 0s out of the array if (value == 0) { deleteWord(array, index); } else { array.set(index, value); } }
// flips all bits stored at a certain index private static void flipWord(JsArrayInteger array, int index) { int word = getWord(array, index); if (word == 0) { array.set(index, 0xffffffff); } else { word = ~word; setWord(array, index, word); } }
// sets all bits to true at a certain index within the given bit range private static void maskInWord(JsArrayInteger array, int index, int from, int to) { // shifting by 32 is the same as shifting by 0, this check prevents that // from happening in addition to the obvious avoidance of extra work if (from != to) { // adjust "to" so it will shift out those bits to = 32 - to; // create a mask and OR it in int value = getWord(array, index); value |= ((0xffffffff >>> from) << (from + to)) >>> to; array.set(index, value); } };
// flips one bit private static void flip(JsArrayInteger array, int bitIndex) { // calculate index and offset int index = wordIndex(bitIndex); int offset = bitOffset(bitIndex); // figure out if the bit is on or off int word = getWord(array, index); if (((word >>> offset) & 1) == 1) { // if on, turn it off setWord(array, index, word & ~(1 << offset)); } else { // if off, turn it on array.set(index, word | (1 << offset)); } };
@SuppressWarnings("deprecation") public JsJobTrigger getJsJobTrigger() { JsJobTrigger jsJobTrigger = JsJobTrigger.instance(); ScheduleType scheduleType = scheduleEditorWizardPanel.getScheduleType(); Date startDate = scheduleEditorWizardPanel.getStartDate(); String startTime = scheduleEditorWizardPanel.getStartTime(); int startHour = getStartHour(startTime); int startMin = getStartMin(startTime); int startYear = startDate.getYear(); int startMonth = startDate.getMonth(); int startDay = startDate.getDate(); Date startDateTime = new Date(startYear, startMonth, startDay, startHour, startMin); Date endDate = scheduleEditorWizardPanel.getEndDate(); MonthOfYear monthOfYear = scheduleEditor.getRecurrenceEditor().getSelectedMonth(); List<DayOfWeek> daysOfWeek = scheduleEditor.getRecurrenceEditor().getSelectedDaysOfWeek(); Integer dayOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedDayOfMonth(); WeekOfMonth weekOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedWeekOfMonth(); if (isBlockoutDialog) { jsJobTrigger.setBlockDuration(calculateBlockoutDuration()); } else { // blockDuration is only valid for blockouts jsJobTrigger.setBlockDuration(new Long(-1)); } if (scheduleType == ScheduleType.RUN_ONCE) { // Run once types jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$ jsJobTrigger.setRepeatInterval(0); jsJobTrigger.setRepeatCount(0); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); } else if ((scheduleType == ScheduleType.SECONDS) || (scheduleType == ScheduleType.MINUTES) || (scheduleType == ScheduleType.HOURS)) { int repeatInterval = 0; try { // Simple Trigger Types repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval()); } catch (Exception e) { // ignored } jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$ jsJobTrigger.setRepeatInterval(repeatInterval); jsJobTrigger.setRepeatCount(-1); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } else if (scheduleType == ScheduleType.DAILY) { if (scheduleEditor.getRecurrenceEditor().isEveryNDays()) { int repeatInterval = 0; try { // Simple Trigger Types repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval()); } catch (Exception e) { // ignored } jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$ jsJobTrigger.setRepeatInterval(repeatInterval); jsJobTrigger.setRepeatCount(-1); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } else { JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray(); int i = 0; for (DayOfWeek dayOfWeek : daysOfWeek) { jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1); } JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startHour); JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startMin); JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, 0); jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$ jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek); jsJobTrigger.setHourRecurrences(hours); jsJobTrigger.setMinuteRecurrences(minutes); jsJobTrigger.setSecondRecurrences(seconds); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } } else if (scheduleType == ScheduleType.CRON) { // Cron jobs jsJobTrigger.setType("cronJobTrigger"); // $NON-NLS-1$ } else if ((scheduleType == ScheduleType.WEEKLY) && (daysOfWeek.size() > 0)) { JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray(); int i = 0; for (DayOfWeek dayOfWeek : daysOfWeek) { jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1); } JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startHour); JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startMin); JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, 0); jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$ jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek); jsJobTrigger.setHourRecurrences(hours); jsJobTrigger.setMinuteRecurrences(minutes); jsJobTrigger.setSecondRecurrences(seconds); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } else if ((scheduleType == ScheduleType.MONTHLY) || ((scheduleType == ScheduleType.YEARLY) && (monthOfYear != null))) { jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$ if (dayOfMonth != null) { JsArrayInteger jsDaysOfMonth = (JsArrayInteger) JavaScriptObject.createArray(); jsDaysOfMonth.set(0, dayOfMonth); JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startHour); JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startMin); JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, 0); jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$ if (monthOfYear != null) { JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray(); jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1); jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear); } jsJobTrigger.setDayOfMonthRecurrences(jsDaysOfMonth); jsJobTrigger.setHourRecurrences(hours); jsJobTrigger.setMinuteRecurrences(minutes); jsJobTrigger.setSecondRecurrences(seconds); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } else if ((daysOfWeek.size() > 0) && (weekOfMonth != null)) { JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray(); int i = 0; for (DayOfWeek dayOfWeek : daysOfWeek) { jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1); } JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startHour); JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, startMin); JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray(); hours.set(0, 0); jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$ if (monthOfYear != null) { JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray(); jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1); jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear); } jsJobTrigger.setHourRecurrences(hours); jsJobTrigger.setMinuteRecurrences(minutes); jsJobTrigger.setSecondRecurrences(seconds); jsJobTrigger.setQualifiedDayOfWeek(daysOfWeek.get(0).name()); jsJobTrigger.setDayOfWeekQualifier(weekOfMonth.name()); jsJobTrigger.setNativeStartTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime)); if (endDate != null) { jsJobTrigger.setNativeEndTime( DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)); } } } return jsJobTrigger; }
// sets one bit to true private static void set(JsArrayInteger array, int bitIndex) { int index = wordIndex(bitIndex); array.set(index, getWord(array, index) | (1 << (bitOffset(bitIndex)))); }