    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 * http://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.commons.compress.archivers.tar;
    020
    021import java.util.Objects;
    022
    023/**
    024 * This class represents struct sparse in a Tar archive.
    025 * <p>
    026 * Whereas, "struct sparse" is:
    027 * <pre>
    028 * struct sparse {
    029 * char offset[12];   // offset 0
    030 * char numbytes[12]; // offset 12
    031 * };
    032 * </pre>
    033 * @since 1.20
    034 */
    035public final class TarArchiveStructSparse {
    036    private final long offset;
    037    private final long numbytes;
    038
    039    public TarArchiveStructSparse(final long offset, final long numbytes) {
    040        if (offset < 0) {
    041            throw new IllegalArgumentException("offset must not be negative");
    042        }
    043        if (numbytes < 0) {
    044            throw new IllegalArgumentException("numbytes must not be negative");
    045        }
    046        this.offset = offset;
    047        this.numbytes = numbytes;
    048    }
    049
    050    @Override
    051    public boolean equals(final Object o) {
    052        if (this == o) {
    053            return true;
    054        }
    055        if (o == null || getClass() != o.getClass()) {
    056            return false;
    057        }
    058        final TarArchiveStructSparse that = (TarArchiveStructSparse) o;
    059        return offset == that.offset &&
    060                numbytes == that.numbytes;
    061    }
    062
    063    public long getNumbytes() {
    064        return numbytes;
    065    }
    066
    067    public long getOffset() {
    068        return offset;
    069    }
    070
    071    @Override
    072    public int hashCode() {
    073        return Objects.hash(offset, numbytes);
    074    }
    075
    076    @Override
    077    public String toString() {
    078        return "TarArchiveStructSparse{" +
    079                "offset=" + offset +
    080                ", numbytes=" + numbytes +
    081                '}';
    082    }
    083}