summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2015-06-23 12:01:28 +0900
committerDaiki Ueno <ueno@gnu.org>2015-06-23 12:08:38 +0900
commit685db98ea9c4e3eec76f23fbf3138865020c588d (patch)
treed8ee495c7dd65b0bad969f6e9e3505a9762a88de
parent70bae6274fc09272aaf00d2cbfc02f912d3821fb (diff)
downloadexternal_gettext-685db98ea9c4e3eec76f23fbf3138865020c588d.zip
external_gettext-685db98ea9c4e3eec76f23fbf3138865020c588d.tar.gz
external_gettext-685db98ea9c4e3eec76f23fbf3138865020c588d.tar.bz2
maint: Make Matrix.java more flexible
* gettext-runtime/doc/Admin/Matrix.java (Matrix): Group teams considering the actual table width, instead of using a hard-coded rule.
-rw-r--r--gettext-runtime/doc/Admin/Matrix.java81
-rw-r--r--gettext-runtime/doc/ChangeLog5
2 files changed, 42 insertions, 44 deletions
diff --git a/gettext-runtime/doc/Admin/Matrix.java b/gettext-runtime/doc/Admin/Matrix.java
index 70de834..d16b78b 100644
--- a/gettext-runtime/doc/Admin/Matrix.java
+++ b/gettext-runtime/doc/Admin/Matrix.java
@@ -160,56 +160,49 @@ public class Matrix {
}
}
- // Split into separate tables, to keep 80 column width.
- int ngroups;
- int[][] groups;
- if (true) {
- ngroups = 6;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, (nteams-5)/6 };
- groups[1] = new int[] { (nteams-5)/6, (2*nteams-9)/6 };
- groups[2] = new int[] { (2*nteams-9)/6, (3*nteams-1)/6 };
- groups[3] = new int[] { (3*nteams-1)/6, (4*nteams+2)/6 };
- groups[4] = new int[] { (4*nteams+2)/6, (5*nteams+10)/6 };
- groups[5] = new int[] { (5*nteams+10)/6, nteams };
- } else if (true) {
- ngroups = 5;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, (nteams+4)/5 };
- groups[1] = new int[] { (nteams+4)/5, (2*nteams+8)/5 };
- groups[2] = new int[] { (2*nteams+8)/5, (3*nteams+12)/5 };
- groups[3] = new int[] { (3*nteams+12)/5, (4*nteams+12)/5 };
- groups[4] = new int[] { (4*nteams+12)/5, nteams };
- } else if (true) {
- ngroups = 4;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, nteams/4+1 };
- groups[1] = new int[] { nteams/4+1, (2*nteams)/4+1 };
- groups[2] = new int[] { (2*nteams)/4+1, (3*nteams)/4+1 };
- groups[3] = new int[] { (3*nteams)/4+1, nteams };
- } else if (true) {
- ngroups = 3;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, nteams/3+1 };
- groups[1] = new int[] { nteams/3+1, (2*nteams)/3+1 };
- groups[2] = new int[] { (2*nteams)/3+1, nteams };
- } else if (true) {
- ngroups = 2;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, nteams/2+1 };
- groups[1] = new int[] { nteams/2+1, nteams };
- } else {
- ngroups = 1;
- groups = new int[ngroups][];
- groups[0] = new int[] { 0, nteams };
- }
-
int[] columnwidth = new int[nteams];
for (int t = 0; t < nteams; t++)
columnwidth[t] =
Math.max(teams[t].length(),
Integer.toString(total_per_team[t]).length());
+ // Split into separate tables, to keep 80 column width.
+ int maxwidth = 80 - 21 - 5 - Integer.toString(total).length();
+
+ // First determine how many groups are needed.
+ int ngroups = 0;
+ {
+ int width = 0, last_team = 0;
+ for (int t = 0; t < nteams; t++) {
+ int newwidth = width + columnwidth[t] + 1;
+ if (newwidth > maxwidth) {
+ last_team = t;
+ ngroups++;
+ width = 0;
+ }
+ width += columnwidth[t] + 1;
+ }
+ if (last_team < nteams)
+ ngroups++;
+ }
+
+ // Then initialize the size of each group.
+ int[][] groups = new int[ngroups][];
+ {
+ int width = 0, last_team = 0, index = 0;
+ for (int t = 0; t < nteams; t++) {
+ int newwidth = width + columnwidth[t] + 1;
+ if (newwidth > maxwidth) {
+ groups[index++] = new int[] { last_team, t };
+ last_team = t;
+ width = 0;
+ }
+ width += columnwidth[t] + 1;
+ }
+ if (last_team < nteams)
+ groups[index] = new int[] { last_team, nteams };
+ }
+
stream.println("@example");
for (int group = 0; group < ngroups; group++) {
if (group > 0)
diff --git a/gettext-runtime/doc/ChangeLog b/gettext-runtime/doc/ChangeLog
index 0bffd18..fa180be 100644
--- a/gettext-runtime/doc/ChangeLog
+++ b/gettext-runtime/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-23 Daiki Ueno <ueno@gnu.org>
+
+ * Admin/Matrix.java (Matrix): Group teams considering the actual
+ table width, instead of using a hard-coded rule.
+
2014-12-24 Daiki Ueno <ueno@gnu.org>
* gettext 0.19.4 released.