View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.core.impl;
18  
19  import java.io.Serializable;
20  
21  /**
22   * Class and package data used with a {@link StackTraceElement} in a {@link ExtendedStackTraceElement}.
23   */
24  public final class ExtendedClassInfo implements Serializable {
25  
26      private static final long serialVersionUID = 1L;
27  
28      private final boolean exact;
29  
30      private final String location;
31  
32      private final String version;
33  
34      /**
35       * Constructs a new instance.
36       * 
37       * @param exact
38       * @param location
39       * @param version
40       */
41      public ExtendedClassInfo(final boolean exact, final String location, final String version) {
42          super();
43          this.exact = exact;
44          this.location = location;
45          this.version = version;
46      }
47  
48      @Override
49      public boolean equals(final Object obj) {
50          if (this == obj) {
51              return true;
52          }
53          if (obj == null) {
54              return false;
55          }
56          if (!(obj instanceof ExtendedClassInfo)) {
57              return false;
58          }
59          final ExtendedClassInfo other = (ExtendedClassInfo) obj;
60          if (this.exact != other.exact) {
61              return false;
62          }
63          if (this.location == null) {
64              if (other.location != null) {
65                  return false;
66              }
67          } else if (!this.location.equals(other.location)) {
68              return false;
69          }
70          if (this.version == null) {
71              if (other.version != null) {
72                  return false;
73              }
74          } else if (!this.version.equals(other.version)) {
75              return false;
76          }
77          return true;
78      }
79  
80      public boolean getExact() {
81          return this.exact;
82      }
83  
84      public String getLocation() {
85          return this.location;
86      }
87  
88      public String getVersion() {
89          return this.version;
90      }
91  
92      @Override
93      public int hashCode() {
94          final int prime = 31;
95          int result = 1;
96          result = prime * result + (this.exact ? 1231 : 1237);
97          result = prime * result + ((this.location == null) ? 0 : this.location.hashCode());
98          result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
99          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 }