    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements. See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache license, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License. You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the license for the specific language governing permissions and
    015     * limitations under the license.
    016     */
    017    package org.apache.logging.log4j.core.impl;
    018
    019    import java.io.Serializable;
    020
    021    /**
    022     * Class and package data used with a {@link StackTraceElement} in a {@link ExtendedStackTraceElement}.
    023     */
    024    public final class ExtendedClassInfo implements Serializable {
    025
    026        private static final long serialVersionUID = 1L;
    027
    028        private final boolean exact;
    029
    030        private final String location;
    031
    032        private final String version;
    033
    034        /**
    035         * Constructs a new instance.
    036         *
    037         * @param exact
    038         * @param location
    039         * @param version
    040         */
    041        public ExtendedClassInfo(final boolean exact, final String location, final String version) {
    042            super();
    043            this.exact = exact;
    044            this.location = location;
    045            this.version = version;
    046        }
    047
    048        @Override
    049        public boolean equals(final Object obj) {
    050            if (this == obj) {
    051                return true;
    052            }
    053            if (obj == null) {
    054                return false;
    055            }
    056            if (!(obj instanceof ExtendedClassInfo)) {
    057                return false;
    058            }
    059            final ExtendedClassInfo other = (ExtendedClassInfo) obj;
    060            if (this.exact != other.exact) {
    061                return false;
    062            }
    063            if (this.location == null) {
    064                if (other.location != null) {
    065                    return false;
    066                }
    067            } else if (!this.location.equals(other.location)) {
    068                return false;
    069            }
    070            if (this.version == null) {
    071                if (other.version != null) {
    072                    return false;
    073                }
    074            } else if (!this.version.equals(other.version)) {
    075                return false;
    076            }
    077            return true;
    078        }
    079
    080        public boolean getExact() {
    081            return this.exact;
    082        }
    083
    084        public String getLocation() {
    085            return this.location;
    086        }
    087
    088        public String getVersion() {
    089            return this.version;
    090        }
    091
    092        @Override
    093        public int hashCode() {
    094            final int prime = 31;
    095            int result = 1;
    096            result = prime * result + (this.exact ? 1231 : 1237);
    097            result = prime * result + ((this.location == null) ? 0 : this.location.hashCode());
    098            result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
    099            return result;
    100        }
    101
    102        @Override
    103        public String toString() {
    104            final StringBuilder sb = new StringBuilder();
    105            if (!this.exact) {
    106                sb.append('~');
    107            }
    108            sb.append('[');
    109            sb.append(this.location);
    110            sb.append(':');
    111            sb.append(this.version);
    112            sb.append(']');
    113            return sb.toString();
    114        }
    115
    116    }