|
1 | | -<!-- Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
2 | | - Licensed under the Universal Permissive License v 1.0 as shown at |
3 | | - http://oss.oracle.com/licenses/upl.--> |
| 1 | +// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at |
| 3 | +// http://oss.oracle.com/licenses/upl. |
4 | 4 |
|
5 | 5 | package com.examples.pof; |
6 | 6 |
|
|
10 | 10 |
|
11 | 11 | import com.tangosol.util.Base; |
12 | 12 |
|
13 | | -import java.io.IOException; |
14 | | - |
15 | 13 | import java.util.Date; |
16 | 14 |
|
17 | 15 | /** |
18 | | - * * @author Sanjay Mantoor * |
19 | 16 | * POF serialization implementation for coherence cache |
20 | 17 | */ |
21 | 18 | public class Contact implements PortableObject { |
22 | 19 |
|
23 | | - private String m_sFirstName; |
24 | | - private String m_sLastName; |
25 | | - |
26 | | - public Contact() { |
27 | | - |
28 | | - } |
29 | | - |
30 | | - public Contact(String firstName, String lastName) { |
31 | | - m_sFirstName = firstName; |
32 | | - m_sLastName = lastName; |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * * Return the first name. * * @return the first name |
37 | | - */ |
38 | | - public String getFirstName() { |
39 | | - return m_sFirstName; |
40 | | - } |
41 | | - |
42 | | - /** |
43 | | - * * Set the first name. * * @param sFirstName the first name |
44 | | - */ |
45 | | - public void setFirstName(String sFirstName) { |
46 | | - m_sFirstName = sFirstName; |
47 | | - } |
48 | | - |
49 | | - /** |
50 | | - * * Return the last name. * * @return the last name |
51 | | - */ |
52 | | - public String getLastName() { |
53 | | - return m_sLastName; |
54 | | - } |
55 | | - |
56 | | - /** |
57 | | - * * Set the last name. * * @param sLastName the last name |
58 | | - */ |
59 | | - public void setLastName(String sLastName) { |
60 | | - m_sLastName = sLastName; |
61 | | - } |
62 | | - |
63 | | - /** |
64 | | - * * {@inheritDoc} |
65 | | - */ |
66 | | - public void readExternal(PofReader reader) throws IOException { |
67 | | - m_sFirstName = reader.readString(FIRSTNAME); |
68 | | - m_sLastName = reader.readString(LASTNAME); |
69 | | - } |
70 | | - |
71 | | - /** |
72 | | - * * {@inheritDoc} |
73 | | - */ |
74 | | - public void writeExternal(PofWriter writer) throws IOException { |
75 | | - writer.writeString(FIRSTNAME, m_sFirstName); |
76 | | - writer.writeString(LASTNAME, m_sLastName); |
77 | | - } |
78 | | - |
79 | | - /** |
80 | | - * * {@inheritDoc} |
81 | | - */ |
82 | | - public String toString() { |
83 | | - StringBuilder sb = new StringBuilder(getFirstName()).append(" ").append(getLastName()); |
84 | | - return sb.toString(); |
85 | | - } |
86 | | - |
87 | | - /** |
88 | | - * * Returns the hashCode of this {@link Contact}. * * @return the hashCode |
89 | | - * of this {@link Contact} |
90 | | - */ |
91 | | - @Override |
92 | | - public int hashCode() { |
93 | | - final int prime = 31; |
94 | | - int result = 1; |
95 | | - result = prime * result + ((m_sFirstName == null) ? 0 : m_sFirstName.hashCode()); |
96 | | - result = prime * result + ((m_sLastName == null) ? 0 : m_sLastName.hashCode()); |
97 | | - return result; |
98 | | - } |
99 | | - |
100 | | - /** |
101 | | - * * Compares this {@link Contact} with another. * * @param obj |
102 | | - * {@link Contact} to compare to * * @return if the contacts are equal |
103 | | - */ |
104 | | - @Override |
105 | | - public boolean equals(Object obj) { |
106 | | - if (this == obj) { |
107 | | - return true; |
108 | | - } |
109 | | - |
110 | | - if (obj == null) { |
111 | | - return false; |
112 | | - } |
113 | | - |
114 | | - Contact that = (Contact) obj; |
115 | | - |
116 | | - return Base.equals(that.getFirstName(), getFirstName()) && Base.equals(that.getLastName(), getLastName()); |
117 | | - } |
118 | | - |
119 | | - /** |
120 | | - * * The POF index for the FirstName property. |
121 | | - */ |
122 | | - public static final int FIRSTNAME = 0; |
123 | | - |
124 | | - /** |
125 | | - * * The POF index for the LastName property. |
126 | | - */ |
127 | | - public static final int LASTNAME = 1; |
128 | | - |
| 20 | + // The POF index for the FirstName property. |
| 21 | + public static final int FIRSTNAME = 0; |
| 22 | + |
| 23 | + // The POF index for the LastName property. |
| 24 | + public static final int LASTNAME = 1; |
| 25 | + |
| 26 | + private String m_sFirstName; |
| 27 | + private String m_sLastName; |
| 28 | + |
| 29 | + public Contact() { |
| 30 | + } |
| 31 | + |
| 32 | + public Contact(String firstName, String lastName) { |
| 33 | + m_sFirstName = firstName; |
| 34 | + m_sLastName = lastName; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Return the first name. |
| 39 | + */ |
| 40 | + public String getFirstName() { |
| 41 | + return m_sFirstName; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Set the first name. |
| 46 | + * @param sFirstName the first name |
| 47 | + */ |
| 48 | + public void setFirstName(String sFirstName) { |
| 49 | + m_sFirstName = sFirstName; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Return the last name. |
| 54 | + */ |
| 55 | + public String getLastName() { |
| 56 | + return m_sLastName; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Set the last name |
| 61 | + * @param sLastName the last name |
| 62 | + */ |
| 63 | + public void setLastName(String sLastName) { |
| 64 | + m_sLastName = sLastName; |
| 65 | + } |
| 66 | + |
| 67 | + public void readExternal(PofReader reader) throws IOException { |
| 68 | + m_sFirstName = reader.readString(FIRSTNAME); |
| 69 | + m_sLastName = reader.readString(LASTNAME); |
| 70 | + } |
| 71 | + |
| 72 | + public void writeExternal(PofWriter writer) throws IOException { |
| 73 | + writer.writeString(FIRSTNAME, m_sFirstName); |
| 74 | + writer.writeString(LASTNAME, m_sLastName); |
| 75 | + } |
| 76 | + |
| 77 | + public String toString() { |
| 78 | + StringBuilder sb = new StringBuilder(getFirstName()).append(" ").append(getLastName()); |
| 79 | + return sb.toString(); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns the hashCode of the Contact |
| 84 | + */ |
| 85 | + @Override |
| 86 | + public int hashCode() { |
| 87 | + final int prime = 31; |
| 88 | + int result = 1; |
| 89 | + |
| 90 | + result = prime * result + ((m_sFirstName == null) ? 0 : m_sFirstName.hashCode()); |
| 91 | + result = prime * result + ((m_sLastName == null) ? 0 : m_sLastName.hashCode()); |
| 92 | + return result; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Compares this Contact with another |
| 97 | + * @param obj |
| 98 | + */ |
| 99 | + @Override |
| 100 | + public boolean equals(Object obj) { |
| 101 | + if (this == obj) { |
| 102 | + return true; |
| 103 | + } |
| 104 | + if (obj == null) { |
| 105 | + return false; |
| 106 | + } |
| 107 | + Contact that = (Contact) obj; |
| 108 | + return Base.equals(that.getFirstName(), getFirstName()) && Base.equals(that.getLastName(), getLastName()); |
| 109 | + } |
129 | 110 | } |
0 commit comments