001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2021, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.model;
015
016import java.util.Objects;
017
018public class NamedComponentModel extends ComponentModel implements INamedModel {
019
020    private static final long serialVersionUID = -6388316680413871442L;
021    String name;
022
023    @Override
024    protected NamedComponentModel makeNewInstance() {
025        return new NamedComponentModel();
026    }
027    
028    @Override
029    protected void mirror(Model that) {
030        NamedComponentModel actual = (NamedComponentModel) that;
031        super.mirror(actual);
032        this.name = actual.name;
033    }
034    
035    public String getName() {
036        return name;
037    }
038
039    public void setName(String name) {
040        this.name = name;
041    }
042
043    @Override
044    public String toString() {
045        return "NamedComponentModel [name=" + name + ", className=" + className + ", tag=" + tag + ", bodyText="
046                + bodyText + "]";
047    }
048
049    @Override
050    public int hashCode() {
051        final int prime = 31;
052        int result = super.hashCode();
053        result = prime * result + Objects.hash(name);
054        return result;
055    }
056
057    @Override
058    public boolean equals(Object obj) {
059        if (this == obj)
060            return true;
061        if (!super.equals(obj))
062            return false;
063        if (getClass() != obj.getClass())
064            return false;
065        NamedComponentModel other = (NamedComponentModel) obj;
066        return Objects.equals(name, other.name);
067    }
068
069    
070}