Skip to content

Commit 5544c22

Browse files
committed
Helpers are now cloneable.
1 parent 7df18b3 commit 5544c22

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/main/java/com/github/ygimenez/model/helper/BaseHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @param <Helper> A class that extends {@link BaseHelper}.
2525
* @param <T> The type of collection used to store pages.
2626
*/
27-
public abstract class BaseHelper<Helper extends BaseHelper<Helper, T>, T> {
27+
public abstract class BaseHelper<Helper extends BaseHelper<Helper, T>, T> implements Cloneable {
2828
private final Class<Helper> subClass;
2929

3030
private final T content;
@@ -182,4 +182,12 @@ public <Out extends MessageRequest<Out>> Out apply(Out action) {
182182
* @return Whether it needs to be updated or not.
183183
*/
184184
public abstract boolean shouldUpdate(Message msg);
185+
186+
/**
187+
* Create a new helper with the same parameters as this one. The new content will be a shallow copy of the original.
188+
*
189+
* @return A clone of this helper.
190+
*/
191+
@Override
192+
public abstract Helper clone();
185193
}

src/main/java/com/github/ygimenez/model/helper/ButtonizeHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,9 @@ public boolean shouldUpdate(Message msg) {
214214

215215
return !checks.test(ids);
216216
}
217+
218+
@Override
219+
public ButtonizeHelper clone() {
220+
return new ButtonizeHelper(new LinkedHashMap<>(getContent()), isUsingButtons());
221+
}
217222
}

src/main/java/com/github/ygimenez/model/helper/CategorizeHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,9 @@ public boolean shouldUpdate(Message msg) {
201201

202202
return !checks.test(ids);
203203
}
204+
205+
@Override
206+
public CategorizeHelper clone() {
207+
return new CategorizeHelper(new LinkedHashMap<>(getContent()), isUsingButtons());
208+
}
204209
}

src/main/java/com/github/ygimenez/model/helper/LazyPaginateHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ public boolean shouldUpdate(Message msg) {
141141

142142
return !checks.test(emotes);
143143
}
144+
145+
@Override
146+
public LazyPaginateHelper clone() {
147+
return new LazyPaginateHelper(pageLoader, cache ? new ArrayList<>(getContent()) : null, isUsingButtons());
148+
}
144149
}

src/main/java/com/github/ygimenez/model/helper/PaginateHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,9 @@ public boolean shouldUpdate(Message msg) {
169169

170170
return !checks.test(emotes);
171171
}
172+
173+
@Override
174+
public PaginateHelper clone() {
175+
return new PaginateHelper(new ArrayList<>(getContent()), isUsingButtons());
176+
}
172177
}

0 commit comments

Comments
 (0)