001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.io; 003 004import java.util.Arrays; 005import java.util.List; 006import java.util.Objects; 007import java.util.stream.Collectors; 008 009import org.openstreetmap.josm.gui.util.ChangeNotifier; 010 011/** 012 * ChangesetCommentModel is an observable model for the changeset comment edited 013 * in the {@link UploadDialog}. 014 * @since 3133 015 */ 016public class ChangesetCommentModel extends ChangeNotifier { 017 private String comment = ""; 018 019 /** 020 * Sets the current changeset comment and notifies observers if the comment has changed. 021 * 022 * @param comment the new upload comment. Empty string assumed if null. 023 */ 024 public void setComment(String comment) { 025 String oldValue = this.comment; 026 this.comment = comment == null ? "" : comment; 027 if (!Objects.equals(oldValue, this.comment)) { 028 fireStateChanged(); 029 } 030 } 031 032 /** 033 * Replies the current changeset comment in this model. 034 * 035 * @return the current changeset comment in this model. 036 */ 037 public String getComment() { 038 return comment == null ? "" : comment; 039 } 040 041 /** 042 * Extracts the list of hashtags from the comment text. 043 * @return the list of hashtags from the comment text. Can be empty, but not null. 044 * @since 13109 045 */ 046 public List<String> findHashTags() { 047 return Arrays.stream(comment.split("\\s")).filter(s -> s.length() >= 2 && s.charAt(0) == '#').collect(Collectors.toList()); 048 } 049}