001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.kaha.impl.data;
018
019import org.apache.activemq.kaha.StoreLocation;
020
021/**
022 * A a wrapper for a data in the store
023 * 
024 * 
025 */
026public final class DataItem implements Item, StoreLocation {
027
028    private int file = (int)POSITION_NOT_SET;
029    private long offset = POSITION_NOT_SET;
030    private int size;
031
032    public DataItem() {
033    }
034
035    DataItem(DataItem item) {
036        this.file = item.file;
037        this.offset = item.offset;
038        this.size = item.size;
039    }
040
041    boolean isValid() {
042        return file != POSITION_NOT_SET;
043    }
044
045    /**
046     * @return
047     * @see org.apache.activemq.kaha.StoreLocation#getSize()
048     */
049    public int getSize() {
050        return size;
051    }
052
053    /**
054     * @param size The size to set.
055     */
056    public void setSize(int size) {
057        this.size = size;
058    }
059
060    /**
061     * @return
062     * @see org.apache.activemq.kaha.StoreLocation#getOffset()
063     */
064    public long getOffset() {
065        return offset;
066    }
067
068    /**
069     * @param offset The offset to set.
070     */
071    public void setOffset(long offset) {
072        this.offset = offset;
073    }
074
075    /**
076     * @return
077     * @see org.apache.activemq.kaha.StoreLocation#getFile()
078     */
079    public int getFile() {
080        return file;
081    }
082
083    /**
084     * @param file The file to set.
085     */
086    public void setFile(int file) {
087        this.file = file;
088    }
089
090    /**
091     * @return a pretty print
092     */
093    public String toString() {
094        String result = "offset = " + offset + ", file = " + file + ", size = " + size;
095        return result;
096    }
097
098    public DataItem copy() {
099        return new DataItem(this);
100    }
101}