001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.correction; 003 004import java.util.Objects; 005 006/** 007 * Represents a change of a single tag. 008 * Both key and value can be subject of this change. 009 * @since 729 010 */ 011public class TagCorrection implements Correction { 012 013 /** Old key */ 014 public final String oldKey; 015 /** New key */ 016 public final String newKey; 017 /** Old value */ 018 public final String oldValue; 019 /** New value */ 020 public final String newValue; 021 022 /** 023 * Constructs a new {@code TagCorrection}. 024 * @param oldKey old key 025 * @param oldValue old value 026 * @param newKey new key 027 * @param newValue new value 028 */ 029 public TagCorrection(String oldKey, String oldValue, String newKey, String newValue) { 030 this.oldKey = oldKey; 031 this.oldValue = oldValue; 032 this.newKey = newKey; 033 this.newValue = newValue; 034 } 035 036 /** 037 * Determines if the key has changed. 038 * @return {@code true} if the key has changed 039 */ 040 public boolean isKeyChanged() { 041 return !newKey.equals(oldKey); 042 } 043 044 /** 045 * Determines if the value has changed. 046 * @return {@code true} if the value has changed 047 */ 048 public boolean isValueChanged() { 049 return !newValue.equals(oldValue); 050 } 051 052 @Override 053 public boolean equals(Object o) { 054 if (this == o) return true; 055 if (o == null || getClass() != o.getClass()) 056 return false; 057 TagCorrection that = (TagCorrection) o; 058 return Objects.equals(oldKey, that.oldKey) && 059 Objects.equals(newKey, that.newKey) && 060 Objects.equals(oldValue, that.oldValue) && 061 Objects.equals(newValue, that.newValue); 062 } 063 064 @Override 065 public int hashCode() { 066 return Objects.hash(oldKey, newKey, oldValue, newValue); 067 } 068}