Skip to content

Commit

Permalink
[refactor] alter code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiao.he committed Nov 9, 2019
1 parent 569f2a2 commit e2e640b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lunar/src/main/java/com/github/heqiao2010/lunar/LunarCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.util.GregorianCalendar;

/**
* 中国农历
* Created by heqiao on 2019/3/31.
* Chinese Calendar
* Created by joel on 2019/3/31.
*
* @author joel
*/
public final class LunarCalendar implements Serializable {
// ------------------------ 常量定义 --------------------------------

/**
* 支持的最小年份
*/
Expand Down Expand Up @@ -42,9 +44,9 @@ public final class LunarCalendar implements Serializable {
/**
* 农历日期名
*/
private static final String[] LunarDayName = {"初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一",
"十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "廿十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九",
"卅十"};
private static final String[] LunarDayName = {"初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九",
"初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "廿十", "廿一", "廿二", "廿三", "廿四",
"廿五", "廿六", "廿七", "廿八", "廿九", "卅十"};
/**
* 农历信息.<br>
* 每个数组的第一个数表示该年闰月月份,为0表示不闰月<br>
Expand Down Expand Up @@ -353,10 +355,14 @@ public final class LunarCalendar implements Serializable {
{0, 208, 310, 408, 508, 606, 705, 804, 902, 1002, 1031, 1130, 1230}, //2149
{6, 129, 227, 329, 427, 527, 625, 724, 822, 921, 1020, 1119, 1219, 1318}, //2150
};

/**
* serialVersionUID
*/
private static final long serialVersionUID = 7241031233810655166L;

// ------------------------ 成员变量 --------------------------------

// 农历年,和公历是一样的
private int lyear;
// 农历月,范围1-12
Expand All @@ -370,6 +376,8 @@ public final class LunarCalendar implements Serializable {
// 公历日期,公历月份范围:0-11
private GregorianCalendar solar = new GregorianCalendar();

// ------------------------ 构造方法 --------------------------------

/**
* 默认构造
*/
Expand Down Expand Up @@ -398,6 +406,8 @@ public LunarCalendar(Calendar calendar) {
computeBySolarDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
}

// ------------------------ 静态方法 --------------------------------

/**
* 计算两个农历日期之差
*
Expand Down Expand Up @@ -540,6 +550,8 @@ public static char getAnimalYearName(int y) {
return LunarAnimailName[(y - 4) % 12];
}

// ------------------------ 成员方法 --------------------------------

/**
* 日期增加,和<code>GregorianCalendar.add</code>类似
*
Expand Down Expand Up @@ -625,8 +637,6 @@ public String getFullLunarName() {
return this.toString() + " " + getTraditionalYearName(this.lyear) + " " + getAnimalYearName(this.lyear);
}

//// ----------- private methods -------------

/**
* 一个简单的二分查找,返回查找到的元素坐标,用于查找农历二维数组信息
*
Expand Down Expand Up @@ -796,8 +806,8 @@ private void computeBySolarDate(final int solarYear, final int solarMonth, final
this.getSolar().set(Calendar.DATE, solarDate);
}

// ------------------------ getter and sette --------------------------------

// getter and setter
public int getLyear() {
return lyear;
}
Expand Down Expand Up @@ -890,4 +900,3 @@ public void setMessage(String message) {

}
}

0 comments on commit e2e640b

Please sign in to comment.