View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package mockit;
7   
8   /**
9    * The Class ClassWithObjectOverrides.
10   */
11  public final class ClassWithObjectOverrides implements Cloneable {
12  
13      /** The text. */
14      private final StringBuilder text;
15  
16      /**
17       * Instantiates a new class with object overrides.
18       *
19       * @param text
20       *            the text
21       */
22      public ClassWithObjectOverrides(String text) {
23          this.text = new StringBuilder(text);
24      }
25  
26      @Override
27      public boolean equals(Object o) {
28          return o instanceof ClassWithObjectOverrides && text.equals(((ClassWithObjectOverrides) o).text);
29      }
30  
31      @Override
32      public int hashCode() {
33          return text.hashCode();
34      }
35  
36      @Override
37      public String toString() {
38          return text.toString();
39      }
40  
41      @SuppressWarnings("FinalizeDeclaration")
42      @Override
43      protected void finalize() throws Throwable {
44          super.finalize();
45          text.setLength(0);
46      }
47  
48      @Override
49      public ClassWithObjectOverrides clone() {
50          ClassWithObjectOverrides theClone = null;
51          try {
52              theClone = (ClassWithObjectOverrides) super.clone();
53          } catch (CloneNotSupportedException ignore) {
54          }
55          return theClone;
56      }
57  
58      /**
59       * Gets the int value.
60       *
61       * @return the int value
62       */
63      int getIntValue() {
64          return -1;
65      }
66  
67      /**
68       * Do something.
69       */
70      void doSomething() {
71          throw new RuntimeException();
72      }
73  
74      /**
75       * Do something.
76       *
77       * @param arg
78       *            the arg
79       *
80       * @return the int
81       */
82      int doSomething(Object arg) {
83          return arg.hashCode();
84      }
85  }