1/** 2 ******************************************************************************* 3 * Copyright (C) 2003-2011, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ******************************************************************************* 6 */ 7package com.ibm.icu.dev.test; 8 9import java.util.Calendar; 10import java.util.Date; 11import java.util.GregorianCalendar; 12 13import com.ibm.icu.util.VersionInfo; 14 15public abstract class AbstractTestLog implements TestLog { 16 /** 17 * Returns true if ICU_Version < major.minor. 18 */ 19 static public boolean isICUVersionBefore(int major, int minor) { 20 return isICUVersionBefore(major, minor, 0); 21 } 22 23 /** 24 * Returns true if ICU_Version < major.minor.milli. 25 */ 26 static public boolean isICUVersionBefore(int major, int minor, int milli) { 27 return VersionInfo.ICU_VERSION.compareTo(VersionInfo.getInstance(major, minor, milli)) < 0; 28 } 29 30 /** 31 * Returns true if ICU_Version >= major.minor. 32 */ 33 static public boolean isICUVersionAtLeast(int major, int minor) { 34 return isICUVersionAtLeast(major, minor, 0); 35 } 36 37 /** 38 * Returns true if ICU_Version >= major.minor.milli. 39 */ 40 static public boolean isICUVersionAtLeast(int major, int minor, int milli) { 41 return !isICUVersionBefore(major, minor, milli); 42 } 43 44 /** 45 * Add a message. 46 */ 47 public final void log(String message) { 48 msg(message, LOG, true, false); 49 } 50 51 /** 52 * Add a message and newline. 53 */ 54 public final void logln(String message) { 55 msg(message, LOG, true, true); 56 } 57 58 /** 59 * Report an error. 60 */ 61 public final void err(String message) { 62 msg(message, ERR, true, false); 63 } 64 65 /** 66 * Report an error and newline. 67 */ 68 public final void errln(String message) { 69 msg(message, ERR, true, true); 70 } 71 72 /** 73 * Report a warning (generally missing tests or data). 74 */ 75 public final void warn(String message) { 76 msg(message, WARN, true, false); 77 } 78 79 /** 80 * Report a warning (generally missing tests or data) and newline. 81 */ 82 public final void warnln(String message) { 83 msg(message, WARN, true, true); 84 } 85 86 /** 87 * Vector for logging. Callers can force the logging system to 88 * not increment the error or warning level by passing false for incCount. 89 * 90 * @param message the message to output. 91 * @param level the message level, either LOG, WARN, or ERR. 92 * @param incCount if true, increments the warning or error count 93 * @param newln if true, forces a newline after the message 94 */ 95 public abstract void msg(String message, int level, boolean incCount, boolean newln); 96 97 /** 98 * Not sure if this class is useful. This lets you log without first testing 99 * if logging is enabled. The Delegating log will either silently ignore the 100 * message, if the delegate is null, or forward it to the delegate. 101 */ 102 public static final class DelegatingLog extends AbstractTestLog { 103 private TestLog delegate; 104 105 public DelegatingLog(TestLog delegate) { 106 this.delegate = delegate; 107 } 108 109 public void msg(String message, int level, boolean incCount, boolean newln) { 110 if (delegate != null) { 111 delegate.msg(message, level, incCount, newln); 112 } 113 } 114 } 115 public boolean isDateAtLeast(int year, int month, int day){ 116 Date now = new Date(); 117 Calendar c = new GregorianCalendar(year, month, day); 118 Date dt = c.getTime(); 119 if(now.compareTo(dt)>=0){ 120 return true; 121 } 122 return false; 123 } 124} 125