/** 最初の日付の文字列解析。 */ @Test public void parse_zero() { Date date = Date.valueOf("00010101", Date.Format.SIMPLE); assertThat(date.getYear(), is(1)); assertThat(date.getMonth(), is(1)); assertThat(date.getDay(), is(1)); }
/** 単純な文字列解析。 */ @Test public void parse() { Date date = Date.valueOf("12340102", Date.Format.SIMPLE); assertThat(date.getYear(), is(1234)); assertThat(date.getMonth(), is(1)); assertThat(date.getDay(), is(2)); }
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView("systeminfo"); mav.addObject("sysprops", new TreeMap<String, String>((Map) System.getProperties())); mav.addObject("sysenv", new TreeMap<String, String>((Map) System.getenv())); mav.addObject("systime", new Date()); //Calculate app uptime duration Date appStartTime = (Date) getServletContext().getAttribute("appStartTime"); long durationMillis = new Date().getTime() - appStartTime.getTime(); String duration = DurationFormatUtils.formatDurationWords(durationMillis, true, false); mav.addObject("appUptime", duration); //Calculate system resources. Runtime runtime = Runtime.getRuntime(); long totalMem = runtime.totalMemory() / MB; long freeMem = runtime.freeMemory() / MB; long avaCPU = runtime.availableProcessors(); mav.addObject("sysres", "CPU: " + avaCPU + ", MemoryUsed: " + (totalMem - freeMem) + "M/" + totalMem + "M"); if(applicationProperties== null){ applicationProperties = new Properties(); } mav.addObject("applicationProps", applicationProperties); return mav; }
/** * Schedule a task for repeated fixed-rate execution after a specific time has been reached. * * @param task the task to schedule. * @param when time of first execution. * @param period amount of time in milliseconds between subsequent executions. * @throws IllegalArgumentException if {@code when.getTime() < 0} or {@code period < 0}. * @throws IllegalStateException if the {@code Timer} has been canceled, or if the task has been * scheduled or canceled. */ public void scheduleAtFixedRate(TimerTask task, Date when, long period) { if (period <= 0 || when.getTime() < 0) { throw new IllegalArgumentException(); } long delay = when.getTime() - System.currentTimeMillis(); scheduleImpl(task, delay, period, true); }
/* int returnValue <- 0 String year1 <- getYear() String year2 <- anotherDate.getYear() if(year1.compareTo(year2) > 0) returnValue <- 1 else if(year1.compareTo(year2) < 0) returnValue <- -1 else if(year1.compareTo(year2) == 0) String month1 <- getMonth() String month2 <- anotherDate.getMonth() if(month1.compareTo(month2) > 0) returnValue <- 1 else if(month1.compareTo(month20 < 0) returnValue <- -1 else if(month1.compareTo(month2) == 0) String day1 <- getDay() String day2 <- anotherDate.getDay() if(day1.compareTo(day2) > 0) returnValue <- 1 else if(day1.compareTo(day2) < 0) returnValue <- -1 else if(day1.compareTo(day2) == 0) returnValue <- 0 return returnValue */ public int compareTo(Date anotherDate) { int returnValue = 0; String year1 = getYear(); String year2 = anotherDate.getYear(); if (year1.compareTo(year2) > 0) { returnValue = 1; } else if (year1.compareTo(year2) < 0) { returnValue = -1; } else if (year1.compareTo(year2) == 0) { String month1 = getMonth(); String month2 = anotherDate.getMonth(); if (month1.compareTo(month2) > 0) { returnValue = 1; } else if (month1.compareTo(month2) < 0) { returnValue = -1; } else if (month1.compareTo(month2) == 0) { String day1 = getDay(); String day2 = anotherDate.getDay(); if (day1.compareTo(day2) > 0) { returnValue = 1; } else if (day1.compareTo(day2) < 0) { returnValue = -1; } else if (day1.compareTo(day2) == 0) { returnValue = 0; } } } return returnValue; }
/** * Schedule a task for single execution. If {@code when} is less than the current time, it will be * scheduled to be executed as soon as possible. * * @param task the task to schedule. * @param when time of execution. * @throws IllegalArgumentException if {@code when.getTime() < 0}. * @throws IllegalStateException if the {@code Timer} has been canceled, or if the task has been * scheduled or canceled. */ public void schedule(TimerTask task, Date when) { if (when.getTime() < 0) { throw new IllegalArgumentException(); } long delay = when.getTime() - System.currentTimeMillis(); scheduleImpl(task, delay < 0 ? 0 : delay, -1, false); }
/* 136: */ /* 137: */ public final DateTime date_time() /* 138: */ throws ParseException /* 139: */ { /* 140:142 */ switch (this.jj_ntk == -1 ? jj_ntk() : this.jj_ntk) /* 141: */ { /* 142: */ case 4: /* 143: */ case 5: /* 144: */ case 6: /* 145: */ case 7: /* 146: */ case 8: /* 147: */ case 9: /* 148: */ case 10: /* 149:150 */ day_of_week(); /* 150:151 */ jj_consume_token(3); /* 151:152 */ break; /* 152: */ default: /* 153:154 */ this.jj_la1[1] = this.jj_gen; /* 154: */ } /* 155:157 */ Date d = date(); /* 156:158 */ Time t = time(); /* 157:159 */ return new DateTime( d.getYear(), d.getMonth(), d.getDay(), t.getHour(), t.getMinute(), t.getSecond(), t.getZone()); /* 158: */ }
/** parses standard date string. */ @Test public void parse_standard() { Date date = Date.valueOf("1234-01-02", Date.Format.STANDARD); assertThat(date.getYear(), is(1234)); assertThat(date.getMonth(), is(1)); assertThat(date.getDay(), is(2)); }
/** 大きな日付の文字列解析。 */ @Test public void parse_big() { Date date = Date.valueOf("29991231", Date.Format.SIMPLE); assertThat(date.getYear(), is(2999)); assertThat(date.getMonth(), is(12)); assertThat(date.getDay(), is(31)); }
/** optionの解析。 */ @Test public void parse_option() { StringOption option = new StringOption("20100615"); Date date = Date.valueOf(option, Date.Format.SIMPLE); assertThat(date.getYear(), is(2010)); assertThat(date.getMonth(), is(6)); assertThat(date.getDay(), is(15)); }
public String getInfo() { return destination + ", " + getPrice() + "PLN,\n\tfrom " + start.getInfo() + " to " + end.getInfo(); }
public void draw() { int i; System.out.printf("ID:%d,Date:%d/%d/%d", ID, day.getYear(), day.getMonth(), day.getDate()); System.out.println(); System.out.print("Number:"); for (i = 0; i < 6; i++) { System.out.printf("%d ", num[i]); } System.out.println(); }
// convert to String in universal time format (HH:MM:SS) public String toUniversalString() { return String.format( "%02d/%02d/%04d - %02d:%02d:%02d", date.getMonth(), date.getDay(), date.getYear(), time.getHour(), time.getMinute(), time.getSecond()); }
// default constructor - default date and time public DateAndTime() { date.setMonth(1); date.setDay(1); date.setYear(1900); time.setHour(0); time.setMinute(0); time.setSecond(0); System.out.printf("DateAndTime default constructor : %s\n", this); }
// return DateAndTime string representation public String toString() { return String.format( "%02d/%02d/%04d - %02d:%02d:%02d %s", date.getMonth(), date.getDay(), date.getYear(), ((time.getHour() == 0 || time.getHour() == 12) ? 12 : time.getHour() % 12), time.getMinute(), time.getSecond(), (time.getHour() < 12 ? "AM" : "PM")); }
// constructor with both date and time specified public DateAndTime(int month, int day, int year, int hour, int min, int sec) { date.setMonth(month); date.setDay(day); date.setYear(year); time.setHour(hour); time.setMinute(min); time.setSecond(sec); System.out.printf("DateAndTime time custom values constructor : %s\n", this); }
/** * Get the first date attribute found as a string. If none are found return an empty string. * * @return the date string. */ public String getSortableDate() { for (final GedObject gedObject : getAttributes()) { if (!(gedObject instanceof Date)) { continue; } final Date attr = (Date) gedObject; if (!attr.getDate().isEmpty()) { return attr.getSortDate(); } } return ""; }
@Override public int hashCode() { int result = from.hashCode(); result = 31 * result + to.hashCode(); result = 31 * result + duration.hashCode(); result = 31 * result + holiday.hashCode(); result = 31 * result + (loc != null ? loc.hashCode() : 0); result = 31 * result + shifters.hashCode(); result = 31 * result + selector.hashCode(); result = 31 * result + (customDayOfMonth != null ? customDayOfMonth.hashCode() : 0); result = 31 * result + (customDayOfYear != null ? customDayOfYear.hashCode() : 0); return result; }
@Test public void show() { String question; // = "1、用经济常识知识简要说明重视安全生产的经济意义。"; int answer = 1; int flag = 1; int firstAnswer = 0; Map<String, Double> queryList; Map<Integer, Double> result; // = ss.getResult(question); try { OutputStreamWriter ow = null; for (int i = 0; i < d.getQuestionList().size(); i++) { question = d.getQuestionList().get(i); queryList = ss.getQueryList(question); result = ss.getResult(queryList); answer = d.getAnswerList().get(i); // System.out.println("\n"+question); for (Integer obj : result.keySet()) { if (flag == 1) { firstAnswer = obj.intValue(); if (firstAnswer == answer) { ow = new OutputStreamWriter( new FileOutputStream("D:\\result\\" + (i + 1) + ".txt"), "GB2312"); ow.write("\n" + question + "\n正确\t答案是" + answer + "\n"); // ow.write("\n" + question + ",正确,答案是" + answer+"\n"); System.out.println("\n" + question + "\n正确,答案是" + answer); // break; } else { ow = new OutputStreamWriter( new FileOutputStream("D:\\result\\" + (i + 1) + "w.txt"), "GB2312"); ow.write("\n" + question + "\n不正确\t答案是" + answer + "\n"); // +question); // ow.write("\n" + question + ",不正确,答案是" + answer+"\n");// +question); System.out.println("\n" + question + "\n不正确,答案是" + answer); // +question); } // TODO assertTrue(firstAnswer == answer.intValue()); flag = 0; } /* ow.write(obj + "," + result.get(obj) + "," + ss.getDocument(obj)+"\n");*/ ow.write(obj + "\t" + result.get(obj) + "\t" + ss.getDocument(obj) + "\n"); System.out.println(obj + "\t" + result.get(obj) + "\t" + ss.getDocument(obj)); // break;//System.out.print(obj + " "); } flag = 1; } } catch (IOException e) { e.printStackTrace(); } }
/** Compares two dates and returns -1, 0, or 1 is the date is before, equal or after */ public int compareTo(Date other) { if (this.getYear() < other.getYear()) return -1; else if ((this.getYear() <= other.getYear()) && (this.getIntMonth() < other.getIntMonth())) return -1; else if ((this.getYear() <= other.getYear()) && (this.getIntMonth() <= other.getIntMonth()) && (this.getDay() < other.getDay())) return -1; else if ((this.getYear() == other.getYear()) && (this.getIntMonth() == other.getIntMonth()) && (this.getDay() == other.getDay())) return 0; else return 1; }
public static Timestamp valueOf(String s) { String[] components = s.split(" "); if (components.length != 2) { throw new IllegalArgumentException("Invalid escape format: " + s); } String[] timeComponents = components[1].split("\\."); boolean hasNanos = true; int nanos = 0; if (timeComponents.length == 1) { // Allow timestamps without .fffffffff nanoseconds field hasNanos = false; } else if (timeComponents.length != 2) { throw new IllegalArgumentException("Invalid escape format: " + s); } Date d = Date.valueOf(components[0]); Time t = Time.valueOf(timeComponents[0]); if (hasNanos) { String nanosString = timeComponents[1]; int len = nanosString.length(); assert len > 0; // len must be > 0 if hasNanos is true if (len > 9) { throw new IllegalArgumentException("Invalid escape format: " + s); } // Pad zeros on the right up to a total of 9 digits if (len < 9) { nanosString += "00000000".substring(len - 1); } try { nanos = Integer.valueOf(nanosString); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid escape format: " + s); } } return new Timestamp( d.getYear(), d.getMonth(), d.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), nanos); }
/** Returns a recursively created XML representation of this <code>Meta</code>. */ public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append("<" + xmltag + ">" + newline); if (null != corpus_id) { buffer.append("\t\t\t" + corpus_id.toString()); } if (null != history) { buffer.append("\t\t\t" + history.toString()); } if (null != format) { buffer.append("\t\t\t" + format.toString()); } if (null != name) { buffer.append("\t\t\t" + name.toString()); } if (null != author) { buffer.append("\t\t\t" + author.toString()); } if (null != date) { buffer.append("\t\t\t" + date.toString()); } if (null != description) { buffer.append("\t\t\t" + description.toString()); } buffer.append("\t\t</" + xmltag + ">" + newline); return buffer.toString(); }
/** * Build a {@PListObject} from a string that matches one of the tags defined in {@link Constants}. * * @param tag * @param value can be null if tag equals {@link Constants#TAG_BOOL_FALSE} or {@link * Constants#TAG_BOOL_TRUE}. * @throws Exception * @todo replace with factory for PListObject */ public PListObject buildObject(java.lang.String tag, java.lang.String value) throws Exception { if (null == tag) { throw new Exception("Cannot add a child with a null tag to a PList."); } PListObject ret = null; if (tag.equalsIgnoreCase(Constants.TAG_INTEGER)) { ret = new Integer(); ((Integer) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_STRING)) { ret = new String(); ((String) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_REAL)) { ret = new Real(); ((Real) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_DATE)) { ret = new Date(); ((Date) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_FALSE)) { ret = new False(); } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_TRUE)) { ret = new True(); } else if (tag.equalsIgnoreCase(Constants.TAG_DATA)) { ret = new Data(); ((Data) ret).setValue(value.trim(), true); } else if (tag.equalsIgnoreCase(Constants.TAG_DICT)) { ret = new Dict(); } else if (tag.equalsIgnoreCase(Constants.TAG_PLIST_ARRAY)) { ret = new Array(); } return ret; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DatesFrom datesFrom = (DatesFrom) o; if (!from.equals(datesFrom.from)) return false; return true; }
/** * Updates the alarm settings of the RTC. * * @param now point of time the next alarm will be searched from, if <code>null</code> the current * time will be used */ public static void updateAlarm(Time now) { if (now == null) now = new Time(); else now = new Time(now.year, now.month, now.day, now.dow, now.hour, now.minute + 1, 0); Date wakeup = Date.getNextDate(now); if (wakeup != null) { wakeup.time.second = 0; // not used -> to default value RTC.setAlarm(wakeup.time, RTC.DATED); } else { RTC.setAlarm(null, RTC.OFF); } }
public void test_Date_setDay() { Date date = new Date(2005, 2, 12, 12, 15, 45, 1, 2, 0); assertTrue(date != null); int i = date.setDay(29); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getDay() == 1); i = date.setDay(31); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getDay() == 1); i = date.setDay(15); assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS); assertTrue(date.getDay() == 15); assertTrue(date.getDateAsString().equals("2005-02-15T12:15:45+02:00")); date = null; }
public void test_Date_setYear() { Date date = new Date(2005, 12, 30, 12, 15, 45, 1, 2, 0); assertTrue(date != null); int i = date.setYear(434); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getYear() == 2000); i = date.setYear(12121); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getYear() == 2000); i = date.setYear(2008); assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS); assertTrue(date.getYear() == 2008); assertTrue(date.getDateAsString().equals("2008-12-30T12:15:45+02:00")); date = null; }
public void test_Date_setMinutesOffset() { Date date = new Date(2005, 12, 30, 12, 15, 45, 1, 2, 0); assertTrue(date != null); int i = date.setMinutesOffset(434); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getMinutesOffset() == 0); i = date.setMinutesOffset(60); assertTrue(i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE); assertTrue(date.getMinutesOffset() == 0); i = date.setMinutesOffset(45); assertTrue(i == libsbml.LIBSBML_OPERATION_SUCCESS); assertTrue(date.getMinutesOffset() == 45); assertTrue(date.getDateAsString().equals("2005-12-30T12:15:45+02:45")); date = null; }
public SequencingAnalysis copy() { SequencingAnalysis dst = new SequencingAnalysis(); dst.subject = subject == null ? null : subject.copy(); dst.date = date == null ? null : date.copy(); dst.name = name == null ? null : name.copy(); dst.genome = genome == null ? null : genome.copy(dst); dst.file = new ArrayList<Attachment>(); for (Attachment i : file) dst.file.add(i.copy()); dst.inputLab = new ArrayList<ResourceReference>(); for (ResourceReference i : inputLab) dst.inputLab.add(i.copy()); dst.inputAnalysis = new ArrayList<ResourceReference>(); for (ResourceReference i : inputAnalysis) dst.inputAnalysis.add(i.copy()); return dst; }
/** * Returns a textual representation of the contents of the cell, formatted as a {@link String}. */ public String toString() { switch (type) { case DATE: // date return date.toString(); case DOUBLE: // number return Double.toString(d); case FORMULA: // Formula return formula.toString(); case STRING: // String return "\"" + s + "\""; default: // case EMPTY: return "<empty>"; } }