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

Last change on this file since 13109 was 13109, checked in by Don-vip, 6 years ago

fix #15537 - Support changeset hashtags (hashtags changeset tag, extracted from comment at upload, or set by remote control through new changeset_hashtags parameter)

  • Property svn:eol-style set to native
File size: 1.5 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;
10
11/**
12 * ChangesetCommentModel is an observable model for the changeset comment edited
13 * in the {@link UploadDialog}.
14 * @since 3133
15 */
16public 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}
Note: See TracBrowser for help on using the repository browser.