]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
maint: Make Matrix.java more flexible
authorDaiki Ueno <ueno@gnu.org>
Tue, 23 Jun 2015 03:01:28 +0000 (12:01 +0900)
committerDaiki Ueno <ueno@gnu.org>
Tue, 23 Jun 2015 03:08:38 +0000 (12:08 +0900)
* gettext-runtime/doc/Admin/Matrix.java (Matrix): Group teams
considering the actual table width, instead of using a hard-coded rule.

gettext-runtime/doc/Admin/Matrix.java
gettext-runtime/doc/ChangeLog

index 70de8345a0ea54fd8ccdc45394dffbf345b199bf..d16b78b1661755f51a4cee1f3613af8f143467f3 100644 (file)
@@ -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)
index 0bffd185acad3b3d69b875a1201f76a17ce82c68..fa180be7d6c546bac1ba1bf08b58bb66a256efe9 100644 (file)
@@ -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.