001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.needle.coherence;
018:
019: import java.io.DataInput;
020: import java.io.DataOutput;
021: import java.io.IOException;
022:
023: import com.tangosol.io.ExternalizableLite;
024:
025: /**
026: * @author kimchy
027: */
028: public class FileBucketKey implements FileKey, ExternalizableLite {
029:
030: private String indexName;
031:
032: private String fileName;
033:
034: private long bucketIndex;
035:
036: // just here for serialization
037: public FileBucketKey() {
038: }
039:
040: public FileBucketKey(String indexName, String fileName,
041: long bucketIndex) {
042: this .indexName = indexName;
043: this .fileName = fileName;
044: this .bucketIndex = bucketIndex;
045: }
046:
047: public String getIndexName() {
048: return indexName;
049: }
050:
051: public String getFileName() {
052: return fileName;
053: }
054:
055: public long getBucketIndex() {
056: return bucketIndex;
057: }
058:
059: public byte getType() {
060: return FILE_BUCKET;
061: }
062:
063: public boolean equals(Object o) {
064: if (this == o)
065: return true;
066: if (((FileKey) o).getType() != getType())
067: return false;
068:
069: FileBucketKey that = (FileBucketKey) o;
070:
071: if (bucketIndex != that.bucketIndex)
072: return false;
073: if (!fileName.equals(that.fileName))
074: return false;
075: if (!indexName.equals(that.indexName))
076: return false;
077:
078: return true;
079: }
080:
081: public int hashCode() {
082: int result = getType();
083: result = 31 * result + indexName.hashCode();
084: result = 31 * result + fileName.hashCode();
085: result = 31 * result
086: + (int) (bucketIndex ^ (bucketIndex >>> 32));
087: return result;
088: }
089:
090: public void readExternal(DataInput in) throws IOException {
091: indexName = in.readUTF();
092: fileName = in.readUTF();
093: bucketIndex = in.readLong();
094: }
095:
096: public void writeExternal(DataOutput out) throws IOException {
097: out.writeUTF(indexName);
098: out.writeUTF(fileName);
099: out.writeLong(bucketIndex);
100: }
101:
102: public String toString() {
103: StringBuilder sb = new StringBuilder();
104: sb.append("fileBucketKey: indexName[").append(indexName)
105: .append("]");
106: sb.append(" fileName[").append(fileName).append("]");
107: sb.append(" bucketIndex[").append(bucketIndex).append("]");
108: return sb.toString();
109: }
110: }
|