1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | import java.util.Arrays;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Objects;
|
---|
7 | import java.util.stream.Collectors;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.gui.util.ChangeNotifier;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * ChangesetCommentModel is an observable model for the changeset comment edited
|
---|
13 | * in the {@link UploadDialog}.
|
---|
14 | * @since 3133
|
---|
15 | */
|
---|
16 | public class ChangesetCommentModel extends ChangeNotifier {
|
---|
17 | private String comment = "";
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Sets the current changeset comment and notifies observers if the comment has changed.
|
---|
21 | *
|
---|
22 | * @param comment the new upload comment. Empty string assumed if null.
|
---|
23 | */
|
---|
24 | public void setComment(String comment) {
|
---|
25 | String oldValue = this.comment;
|
---|
26 | this.comment = comment == null ? "" : comment;
|
---|
27 | if (!Objects.equals(oldValue, this.comment)) {
|
---|
28 | fireStateChanged();
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Replies the current changeset comment in this model.
|
---|
34 | *
|
---|
35 | * @return the current changeset comment in this model.
|
---|
36 | */
|
---|
37 | public String getComment() {
|
---|
38 | return comment == null ? "" : comment;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Extracts the list of hashtags from the comment text.
|
---|
43 | * @return the list of hashtags from the comment text. Can be empty, but not null.
|
---|
44 | * @since 13109
|
---|
45 | */
|
---|
46 | public List<String> findHashTags() {
|
---|
47 | return Arrays.stream(comment.split("\\s")).filter(s -> s.length() >= 2 && s.charAt(0) == '#').collect(Collectors.toList());
|
---|
48 | }
|
---|
49 | }
|
---|