Changeset 17712 in josm for trunk/src/org


Ignore:
Timestamp:
2021-04-07T22:34:03+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate Note/NoteComment to Instant

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/notes/Note.java

    r16953 r17712  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.time.Instant;
    67import java.util.ArrayList;
    78import java.util.Comparator;
    8 import java.util.Date;
    99import java.util.List;
    1010import java.util.Objects;
    1111
    1212import org.openstreetmap.josm.data.coor.LatLon;
    13 import org.openstreetmap.josm.tools.date.DateUtils;
    1413
    1514/**
     
    6665    private long id;
    6766    private LatLon latLon;
    68     private Date createdAt;
    69     private Date closedAt;
     67    private Instant createdAt;
     68    private Instant closedAt;
    7069    private State state;
    7170    private List<NoteComment> comments = new ArrayList<>();
     
    107106     * @return Date that this note was submitted
    108107     */
    109     public Date getCreatedAt() {
    110         return DateUtils.cloneDate(createdAt);
     108    public Instant getCreatedAt() {
     109        return createdAt;
    111110    }
    112111
     
    115114     * @param createdAt date at which this note has been created
    116115     */
    117     public void setCreatedAt(Date createdAt) {
    118         this.createdAt = DateUtils.cloneDate(createdAt);
     116    public void setCreatedAt(Instant createdAt) {
     117        this.createdAt = createdAt;
    119118    }
    120119
     
    123122     * @return Date that this note was closed. Null if it is still open.
    124123     */
    125     public Date getClosedAt() {
    126         return DateUtils.cloneDate(closedAt);
     124    public Instant getClosedAt() {
     125        return closedAt;
    127126    }
    128127
     
    131130     * @param closedAt date at which this note has been closed
    132131     */
    133     public void setClosedAt(Date closedAt) {
    134         this.closedAt = DateUtils.cloneDate(closedAt);
     132    public void setClosedAt(Instant closedAt) {
     133        this.closedAt = closedAt;
    135134    }
    136135
     
    191190    public void updateWith(Note note) {
    192191        this.comments = note.comments;
    193         this.createdAt = DateUtils.cloneDate(note.createdAt);
     192        this.createdAt = note.createdAt;
    194193        this.id = note.id;
    195194        this.state = note.state;
  • trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java

    r16953 r17712  
    22package org.openstreetmap.josm.data.notes;
    33
     4import java.time.Instant;
    45import java.util.Comparator;
    5 import java.util.Date;
    66
    77import org.openstreetmap.josm.data.osm.User;
    8 import org.openstreetmap.josm.tools.date.DateUtils;
    98
    109/**
     
    1716    private final String text;
    1817    private final User user;
    19     private final Date commentTimestamp;
     18    private final Instant commentTimestamp;
    2019    private final Action action;
    2120
     
    5049     * @param isNew Whether or not this comment is new and needs to be uploaded
    5150     */
    52     public NoteComment(Date createDate, User user, String commentText, Action action, boolean isNew) {
     51    public NoteComment(Instant createDate, User user, String commentText, Action action, boolean isNew) {
    5352        this.text = commentText;
    5453        this.user = user;
    55         this.commentTimestamp = DateUtils.cloneDate(createDate);
     54        this.commentTimestamp = createDate;
    5655        this.action = action;
    5756        this.isNew = isNew;
     
    7877     * @return The time at which this comment was created
    7978     */
    80     public Date getCommentTimestamp() {
    81         return DateUtils.cloneDate(commentTimestamp);
     79    public Instant getCommentTimestamp() {
     80        return commentTimestamp;
    8281    }
    8382
  • trunk/src/org/openstreetmap/josm/data/osm/NoteData.java

    r16548 r17712  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.time.Instant;
    45import java.util.ArrayList;
    56import java.util.Collection;
    67import java.util.Collections;
    78import java.util.Comparator;
    8 import java.util.Date;
    99import java.util.List;
    1010import java.util.Map;
     
    177177        }
    178178        Note note = new Note(location);
    179         note.setCreatedAt(new Date());
     179        note.setCreatedAt(Instant.now());
    180180        note.setState(State.OPEN);
    181181        note.setId(newNoteId--);
    182         NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.OPENED, true);
     182        NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.OPENED, true);
    183183        note.addComment(comment);
    184184        if (Logging.isDebugEnabled()) {
     
    204204            Logging.debug("Adding comment to note {0}: {1}", note.getId(), text);
    205205        }
    206         NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.COMMENTED, true);
     206        NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.COMMENTED, true);
    207207        note.addComment(comment);
    208208        dataUpdated();
     
    224224            Logging.debug("closing note {0} with comment: {1}", note.getId(), text);
    225225        }
    226         NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.CLOSED, true);
     226        NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.CLOSED, true);
    227227        note.addComment(comment);
    228228        note.setState(State.CLOSED);
    229         note.setClosedAt(new Date());
     229        note.setClosedAt(Instant.now());
    230230        dataUpdated();
    231231    }
     
    244244        }
    245245        Logging.debug("reopening note {0} with comment: {1}", note.getId(), text);
    246         NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.REOPENED, true);
     246        NoteComment comment = new NoteComment(Instant.now(), getCurrentUser(), text, NoteComment.Action.REOPENED, true);
    247247        note.addComment(comment);
    248248        note.setState(State.OPEN);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    r17522 r17712  
    1010import java.awt.event.MouseAdapter;
    1111import java.awt.event.MouseEvent;
    12 import java.text.DateFormat;
     12import java.time.format.DateTimeFormatter;
     13import java.time.format.FormatStyle;
    1314import java.util.ArrayList;
    1415import java.util.Arrays;
     
    232233
    233234        private final DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();
    234         private final DateFormat dateFormat = DateUtils.getDateTimeFormat(DateFormat.MEDIUM, DateFormat.SHORT);
     235        private final DateTimeFormatter dateFormat = DateUtils.getDateTimeFormatter(FormatStyle.MEDIUM, FormatStyle.SHORT);
    235236
    236237        @Override
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r17361 r17712  
    1515import java.io.File;
    1616import java.io.IOException;
    17 import java.text.DateFormat;
     17import java.time.format.FormatStyle;
    1818import java.util.Collection;
    1919import java.util.Collections;
     
    319319                sb.append(userName)
    320320                  .append(" on ")
    321                   .append(DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp()))
     321                  .append(DateUtils.getDateFormatter(FormatStyle.MEDIUM).format(comment.getCommentTimestamp()))
    322322                  .append(":<br>");
    323323                String htmlText = XmlWriter.encode(comment.getText(), true);
  • trunk/src/org/openstreetmap/josm/io/NoteReader.java

    r14436 r17712  
    66import java.io.InputStream;
    77import java.nio.charset.StandardCharsets;
     8import java.time.Instant;
    89import java.util.ArrayList;
    9 import java.util.Date;
    1010import java.util.List;
    1111import java.util.Locale;
     
    6060        private String commentUsername;
    6161        private Action noteAction;
    62         private Date commentCreateDate;
     62        private Instant commentCreateDate;
    6363        private boolean commentIsNew;
    6464        private List<Note> notes;
     
    100100                commentUsername = attrs.getValue("user");
    101101                noteAction = Action.valueOf(attrs.getValue("action").toUpperCase(Locale.ENGLISH));
    102                 commentCreateDate = DateUtils.fromString(attrs.getValue("timestamp"));
     102                commentCreateDate = DateUtils.parseInstant(attrs.getValue("timestamp"));
    103103                commentIsNew = Boolean.parseBoolean(Optional.ofNullable(attrs.getValue("is_new")).orElse("false"));
    104104                break;
     
    143143                break;
    144144            case "date_created":
    145                 thisNote.setCreatedAt(DateUtils.fromString(buffer.toString()));
     145                thisNote.setCreatedAt(DateUtils.parseInstant(buffer.toString()));
    146146                break;
    147147            case "date_closed":
    148                 thisNote.setClosedAt(DateUtils.fromString(buffer.toString()));
     148                thisNote.setClosedAt(DateUtils.parseInstant(buffer.toString()));
    149149                break;
    150150            case "date":
    151                 commentCreateDate = DateUtils.fromString(buffer.toString());
     151                commentCreateDate = DateUtils.parseInstant(buffer.toString());
    152152                break;
    153153            case "user":
     
    205205        } else {
    206206            note.setState(Note.State.CLOSED);
    207             note.setClosedAt(DateUtils.fromString(closedTimeStr));
     207            note.setClosedAt(DateUtils.parseInstant(closedTimeStr));
    208208        }
    209209        String createdAt = attrs.apply("created_at");
    210210        if (createdAt != null) {
    211             note.setCreatedAt(DateUtils.fromString(createdAt));
     211            note.setCreatedAt(DateUtils.parseInstant(createdAt));
    212212        }
    213213        return note;
  • trunk/src/org/openstreetmap/josm/io/NoteWriter.java

    r17333 r17712  
    1313import org.openstreetmap.josm.data.osm.NoteData;
    1414import org.openstreetmap.josm.data.osm.User;
    15 import org.openstreetmap.josm.tools.date.DateUtils;
    1615
    1716/**
     
    5352            out.print("lat=\"" + LatLon.cDdHighPrecisionFormatter.format(ll.lat()) + "\" ");
    5453            out.print("lon=\"" + LatLon.cDdHighPrecisionFormatter.format(ll.lon()) + "\" ");
    55             out.print("created_at=\"" + DateUtils.fromDate(note.getCreatedAt()) + "\" ");
     54            out.print("created_at=\"" + note.getCreatedAt() + "\" ");
    5655            if (note.getClosedAt() != null) {
    57                 out.print("closed_at=\"" + DateUtils.fromDate(note.getClosedAt()) + "\" ");
     56                out.print("closed_at=\"" + note.getClosedAt() + "\" ");
    5857            }
    5958
     
    7271        out.print("    <comment");
    7372        out.print(" action=\"" + comment.getNoteAction() + "\" ");
    74         out.print("timestamp=\"" + DateUtils.fromDate(comment.getCommentTimestamp()) + "\" ");
     73        out.print("timestamp=\"" + comment.getCommentTimestamp() + "\" ");
    7574        if (comment.getUser() != null && !comment.getUser().equals(User.getAnonymous())) {
    7675            out.print("uid=\"" + comment.getUser().getId() + "\" ");
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r17653 r17712  
    77import java.time.DateTimeException;
    88import java.time.Instant;
     9import java.time.ZoneId;
    910import java.time.ZoneOffset;
    1011import java.time.ZonedDateTime;
    1112import java.time.format.DateTimeFormatter;
    1213import java.time.format.DateTimeParseException;
     14import java.time.format.FormatStyle;
    1315import java.util.Date;
    1416import java.util.Locale;
     
    270272
    271273    /**
     274     * Returns the date formatter to be used for current user, based on user preferences.
     275     * @param dateStyle The date style. Ignored if "ISO dates" option is set.
     276     * @return The date format
     277     */
     278    public static DateTimeFormatter getDateFormatter(FormatStyle dateStyle) {
     279        DateTimeFormatter formatter = PROP_ISO_DATES.get()
     280                ? DateTimeFormatter.ISO_LOCAL_DATE
     281                : DateTimeFormatter.ofLocalizedDate(dateStyle);
     282        return formatter.withZone(ZoneId.systemDefault());
     283    }
     284
     285    /**
    272286     * Returns the date format used for GPX waypoints.
    273287     * @return the date format used for GPX waypoints
     
    305319            return DateFormat.getTimeInstance(timeStyle, Locale.getDefault());
    306320        }
     321    }
     322
     323    /**
     324     * Returns the time formatter to be used for current user, based on user preferences.
     325     * @param timeStyle The time style. Ignored if "ISO dates" option is set.
     326     * @return The time format
     327     */
     328    public static DateTimeFormatter getTimeFormatter(FormatStyle timeStyle) {
     329        DateTimeFormatter formatter = PROP_ISO_DATES.get()
     330                ? DateTimeFormatter.ISO_LOCAL_TIME
     331                : DateTimeFormatter.ofLocalizedTime(timeStyle);
     332        return formatter.withZone(ZoneId.systemDefault());
    307333    }
    308334
     
    337363
    338364    /**
     365     * Returns the date/time formatter to be used for current user, based on user preferences.
     366     * @param dateStyle The date style. Ignored if "ISO dates" option is set.
     367     * @param timeStyle The time style. Ignored if "ISO dates" option is set.
     368     * @return The date/time format
     369     */
     370    public static DateTimeFormatter getDateTimeFormatter(FormatStyle dateStyle, FormatStyle timeStyle) {
     371        DateTimeFormatter formatter = PROP_ISO_DATES.get()
     372                ? DateTimeFormatter.ISO_LOCAL_DATE_TIME
     373                : DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle);
     374        return formatter.withZone(ZoneId.systemDefault());
     375    }
     376
     377    /**
    339378     * Formats a date/time to be displayed to current user, based on user preferences.
    340379     * @param datetime The date/time to display. Must not be {@code null}
Note: See TracChangeset for help on using the changeset viewer.