1 package org.apache.lucene.analysis.tokenattributes;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.Serializable;
22 import org.apache.lucene.index.Payload;
23 import org.apache.lucene.util.AttributeImpl;
26 * The payload of a Token. See also {@link Payload}.
28 public class PayloadAttributeImpl extends AttributeImpl implements PayloadAttribute, Cloneable, Serializable {
29 private Payload payload;
32 * Initialize this attribute with no payload.
34 public PayloadAttributeImpl() {}
37 * Initialize this attribute with the given payload.
39 public PayloadAttributeImpl(Payload payload) {
40 this.payload = payload;
44 * Returns this Token's payload.
46 public Payload getPayload() {
51 * Sets this Token's payload.
53 public void setPayload(Payload payload) {
54 this.payload = payload;
63 public Object clone() {
64 PayloadAttributeImpl clone = (PayloadAttributeImpl) super.clone();
65 if (payload != null) {
66 clone.payload = (Payload) payload.clone();
72 public boolean equals(Object other) {
77 if (other instanceof PayloadAttribute) {
78 PayloadAttributeImpl o = (PayloadAttributeImpl) other;
79 if (o.payload == null || payload == null) {
80 return o.payload == null && payload == null;
83 return o.payload.equals(payload);
90 public int hashCode() {
91 return (payload == null) ? 0 : payload.hashCode();
95 public void copyTo(AttributeImpl target) {
96 PayloadAttribute t = (PayloadAttribute) target;
97 t.setPayload((payload == null) ? null : (Payload) payload.clone());