BrightSide Workbench Full Report + Source Code
Cards.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.marker.construct;
20 
21 import org.turro.elephant.context.IConstructor;
22 import org.turro.string.IntToWords;
23 
28 public class Cards {
29 
30  public Cards start() {
31  current++;
32  if(isNewRow()) {
33  Markers.cards().cssClass(rowColumns()).start().render(constructor);
34  }
35  return this;
36  }
37 
38  public Cards end() {
39  if(isRowEnd()) {
40  Markers.cards().end().render(constructor);
41  }
42  return this;
43  }
44 
45  /* Columns */
46 
47  public Cards columns(int columns) {
48  this.columns = columns;
49  return this;
50  }
51 
52  public Cards decideColumns(int... choice) {
53  int maxDiff = 0;
54  for(int chosen : choice) {
55  int max = chosen % count;
56  if(max > maxDiff) {
57  maxDiff = max;
58  columns = chosen;
59  }
60  }
61  return this;
62  }
63 
64  private boolean isNewRow() {
65  return current % columns == 1;
66  }
67 
68  private boolean isRowEnd() {
69  return (current % columns) == 0 ||
70  (count == current);
71  }
72 
73  private String rowColumns() {
74  int remaining = count - (current - 1);
75  return IntToWords.convert(remaining < columns ? remaining : columns);
76  }
77 
78  /* Factory */
79 
80  public static Cards getFor(IConstructor constructor, int count) {
81  return new Cards(constructor, count);
82  }
83 
84  private final IConstructor constructor;
85  private final int count;
86 
87  private int columns, current;
88 
89  private Cards(IConstructor constructor, int count) {
90  this.constructor = constructor;
91  this.count = count;
92  current = 0;
93  columns = 3;
94  }
95 
96 }
Cards columns(int columns)
Definition: Cards.java:47
Cards decideColumns(int... choice)
Definition: Cards.java:52
static Cards getFor(IConstructor constructor, int count)
Definition: Cards.java:80