001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.api.notifications;
021    
022    import com.google.common.collect.Maps;
023    import org.apache.commons.lang.builder.ReflectionToStringBuilder;
024    import org.apache.commons.lang.builder.ToStringStyle;
025    
026    import java.io.Serializable;
027    import java.util.HashMap;
028    
029    /**
030     * @since 2.10
031     */
032    public class Notification implements Serializable {
033    
034      private String type;
035    
036      private HashMap<String, String> fields = Maps.newHashMap(); // NOSONAR false-positive due to serialization : usage of HashMap instead of Map
037    
038      public Notification(String type) {
039        this.type = type;
040      }
041    
042      public String getType() {
043        return type;
044      }
045    
046      public Notification setFieldValue(String field, String value) {
047        fields.put(field, value);
048        return this;
049      }
050    
051      public String getFieldValue(String field) {
052        return fields.get(field);
053      }
054    
055      @Override
056      public boolean equals(Object obj) {
057        if (!(obj instanceof Notification)) {
058          return false;
059        }
060        if (this == obj) {
061          return true;
062        }
063        Notification other = (Notification) obj;
064        return this.type.equals(other.type) && this.fields.equals(other.fields);
065      }
066    
067      @Override
068      public int hashCode() {
069        return type.hashCode() * 31 + fields.hashCode();
070      }
071    
072      @Override
073      public String toString() {
074        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
075      }
076    
077    }