⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastdateformat.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        public void appendTo(StringBuffer buffer, Calendar calendar) {            buffer.append(mValues[calendar.get(mField)]);        }    }    private static class UnpaddedNumberField implements NumberRule {        private final int mField;        UnpaddedNumberField(int field) {            mField = field;        }        public int estimateLength() {            return 4;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(mField));        }        public final void appendTo(StringBuffer buffer, int value) {            if (value < 10) {                buffer.append((char)(value + '0'));            }            else if (value < 100) {                buffer.append((char)(value / 10 + '0'));                buffer.append((char)(value % 10 + '0'));            }            else {                buffer.append(Integer.toString(value));            }        }    }    private static class UnpaddedMonthField implements NumberRule {        UnpaddedMonthField() {        }        public int estimateLength() {            return 2;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(Calendar.MONTH) + 1);        }        public final void appendTo(StringBuffer buffer, int value) {            if (value < 10) {                buffer.append((char)(value + '0'));            }            else {                buffer.append((char)(value / 10 + '0'));                buffer.append((char)(value % 10 + '0'));            }        }    }    private static class PaddedNumberField implements NumberRule {        private final int mField;        private final int mSize;        PaddedNumberField(int field, int size) {            if (size < 3) {                // Should use UnpaddedNumberField or TwoDigitNumberField.                throw new IllegalArgumentException();            }            mField = field;            mSize = size;        }        public int estimateLength() {            return 4;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(mField));        }        public final void appendTo(StringBuffer buffer, int value) {            if (value < 100) {                for (int i = mSize; --i >= 2; ) {                    buffer.append('0');                }                buffer.append((char)(value / 10 + '0'));                buffer.append((char)(value % 10 + '0'));            }            else {                int digits;                if (value < 1000) {                    digits = 3;                }                else {                    digits = (int)(Math.log(value) / LOG_10) + 1;                }                for (int i = mSize; --i >= digits; ) {                    buffer.append('0');                }                buffer.append(Integer.toString(value));            }        }    }    private static class TwoDigitNumberField implements NumberRule {        private final int mField;        TwoDigitNumberField(int field) {            mField = field;        }        public int estimateLength() {            return 2;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(mField));        }        public final void appendTo(StringBuffer buffer, int value) {            if (value < 100) {                buffer.append((char)(value / 10 + '0'));                buffer.append((char)(value % 10 + '0'));            }            else {                buffer.append(Integer.toString(value));            }        }    }    private static class TwoDigitYearField implements NumberRule {        TwoDigitYearField() {        }        public int estimateLength() {            return 2;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(Calendar.YEAR) % 100);        }        public final void appendTo(StringBuffer buffer, int value) {            buffer.append((char)(value / 10 + '0'));            buffer.append((char)(value % 10 + '0'));        }    }    private static class TwoDigitMonthField implements NumberRule {        TwoDigitMonthField() {        }        public int estimateLength() {            return 2;        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            appendTo(buffer, calendar.get(Calendar.MONTH) + 1);        }        public final void appendTo(StringBuffer buffer, int value) {            buffer.append((char)(value / 10 + '0'));            buffer.append((char)(value % 10 + '0'));        }    }    private static class TwelveHourField implements NumberRule {        private final NumberRule mRule;        TwelveHourField(NumberRule rule) {            mRule = rule;        }        public int estimateLength() {            return mRule.estimateLength();        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            int value = calendar.get(Calendar.HOUR);            if (value == 0) {                value = calendar.getLeastMaximum(Calendar.HOUR) + 1;            }            mRule.appendTo(buffer, value);        }        public void appendTo(StringBuffer buffer, int value) {            mRule.appendTo(buffer, value);        }    }    private static class TwentyFourHourField implements NumberRule {        private final NumberRule mRule;        TwentyFourHourField(NumberRule rule) {            mRule = rule;        }        public int estimateLength() {            return mRule.estimateLength();        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            int value = calendar.get(Calendar.HOUR_OF_DAY);            if (value == 0) {                value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;            }            mRule.appendTo(buffer, value);        }        public void appendTo(StringBuffer buffer, int value) {            mRule.appendTo(buffer, value);        }    }    private static class TimeZoneRule implements Rule {        private final TimeZone mTimeZone;        private final Locale mLocale;        private final int mStyle;        private final String mStandard;        private final String mDaylight;        TimeZoneRule(TimeZone timeZone, Locale locale, int style) {            mTimeZone = timeZone;            mLocale = locale;            mStyle = style;            if (timeZone != null) {                mStandard = getTimeZoneDisplay(timeZone, false, style, locale);                mDaylight = getTimeZoneDisplay(timeZone, true, style, locale);            }            else {                mStandard = null;                mDaylight = null;            }        }        public int estimateLength() {            if (mTimeZone != null) {                return Math.max(mStandard.length(), mDaylight.length());            }            else if (mStyle == TimeZone.SHORT) {                return 4;            }            else {                return 40;            }        }        public void appendTo(StringBuffer buffer, Calendar calendar) {            TimeZone timeZone;            if ((timeZone = mTimeZone) != null) {                if (timeZone.useDaylightTime() &&                    calendar.get(Calendar.DST_OFFSET) != 0) {                    buffer.append(mDaylight);                }                else {                    buffer.append(mStandard);                }            }            else {                timeZone = calendar.getTimeZone();                if (timeZone.useDaylightTime() &&                    calendar.get(Calendar.DST_OFFSET) != 0) {                    buffer.append(getTimeZoneDisplay                                  (timeZone, true, mStyle, mLocale));                }                else {                    buffer.append(getTimeZoneDisplay                                  (timeZone, false, mStyle, mLocale));                }            }        }    }    private static class TimeZoneDisplayKey {        private final TimeZone mTimeZone;        private final int mStyle;        private final Locale mLocale;        TimeZoneDisplayKey(TimeZone timeZone,                           boolean daylight, int style, Locale locale) {            mTimeZone = timeZone;            if (daylight) {                style |= 0x80000000;            }            mStyle = style;            mLocale = locale;        }        public int hashCode() {            return mStyle * 31 + mLocale.hashCode();        }        public boolean equals(Object obj) {            if (this == obj) {                return true;            }            if (obj instanceof TimeZoneDisplayKey) {                TimeZoneDisplayKey other = (TimeZoneDisplayKey)obj;                return                    mTimeZone.equals(other.mTimeZone) &&                    mStyle == other.mStyle &&                    mLocale.equals(other.mLocale);            }            return false;        }    }    private static class Pair implements Comparable, java.io.Serializable {        private final Object mObj1;        private final Object mObj2;        public Pair(Object obj1, Object obj2) {            mObj1 = obj1;            mObj2 = obj2;        }        public int compareTo(Object obj) {            if (this == obj) {                return 0;            }            Pair other = (Pair)obj;            Object a = mObj1;            Object b = other.mObj1;            firstTest: {                if (a == null) {                    if (b != null) {                        return 1;                    }                    // Both a and b are null.                    break firstTest;                }                else {                    if (b == null) {                        return -1;                    }                }                int result = ((Comparable)a).compareTo(b);                if (result != 0) {                    return result;                }            }            a = mObj2;            b = other.mObj2;            if (a == null) {                if (b != null) {                    return 1;                }                // Both a and b are null.                return 0;            }            else {                if (b == null) {                    return -1;                }            }            return ((Comparable)a).compareTo(b);        }        public boolean equals(Object obj) {            if (this == obj) {                return true;            }            if (!(obj instanceof Pair)) {                return false;            }            Pair key = (Pair)obj;            return                (mObj1 == null ?                 key.mObj1 == null : mObj1.equals(key.mObj1)) &&                (mObj2 == null ?                 key.mObj2 == null : mObj2.equals(key.mObj2));        }        public int hashCode() {            return                (mObj1 == null ? 0 : mObj1.hashCode()) +                (mObj2 == null ? 0 : mObj2.hashCode());        }        public String toString() {            return "[" + mObj1 + ':' + mObj2 + ']';        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -