source: josm/trunk/src/org/openstreetmap/josm/gui/io/ChangesetCommentModel.java@ 17356

Last change on this file since 17356 was 16643, checked in by simon04, 4 years ago

see #19334 - https://errorprone.info/bugpattern/StringSplitter

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import java.util.Arrays;
5import java.util.List;
6import java.util.Objects;
7import java.util.stream.Collectors;
8
9import org.openstreetmap.josm.gui.util.ChangeNotifier;
10import 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 */
17public 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}
Note: See TracBrowser for help on using the repository browser.