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 | import org.openstreetmap.josm.tools.Utils;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * ChangesetCommentModel is an observable model for the changeset comment edited
|
---|
14 | * in the {@link UploadDialog}.
|
---|
15 | * @since 3133
|
---|
16 | */
|
---|
17 | public class ChangesetCommentModel extends ChangeNotifier {
|
---|
18 | private String comment = "";
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Sets the current changeset comment and notifies observers if the comment has changed.
|
---|
22 | *
|
---|
23 | * @param comment the new upload comment. Empty string assumed if null.
|
---|
24 | */
|
---|
25 | public void setComment(String comment) {
|
---|
26 | String oldValue = this.comment;
|
---|
27 | this.comment = comment == null ? "" : comment;
|
---|
28 | if (!Objects.equals(oldValue, this.comment)) {
|
---|
29 | fireStateChanged();
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Replies the current changeset comment in this model.
|
---|
35 | *
|
---|
36 | * @return the current changeset comment in this model.
|
---|
37 | */
|
---|
38 | public String getComment() {
|
---|
39 | return comment == null ? "" : comment;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Extracts the list of hashtags from the comment text.
|
---|
44 | * @return the list of hashtags from the comment text. Can be empty, but not null.
|
---|
45 | * @since 13109
|
---|
46 | */
|
---|
47 | public List<String> findHashTags() {
|
---|
48 | return Arrays.stream(comment.split("\\s", -1))
|
---|
49 | .map(s -> Utils.strip(s, ",;"))
|
---|
50 | .filter(s -> s.matches("#[a-zA-Z][a-zA-Z_\\-0-9]+"))
|
---|
51 | .collect(Collectors.toList());
|
---|
52 | }
|
---|
53 | }
|
---|