    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 * </p>
    028 * <pre>
    029 * struct sparse {
    030 * char offset[12];   // offset 0
    031 * char numbytes[12]; // offset 12
    032 * };
    033 * </pre>
    034 *
    035 * @since 1.20
    036 */
    037public final class TarArchiveStructSparse {
    038    private final long offset;
    039    private final long numbytes;
    040
    041    public TarArchiveStructSparse(final long offset, final long numbytes) {
    042        if (offset < 0) {
    043            throw new IllegalArgumentException("offset must not be negative");
    044        }
    045        if (numbytes < 0) {
    046            throw new IllegalArgumentException("numbytes must not be negative");
    047        }
    048        this.offset = offset;
    049        this.numbytes = numbytes;
    050    }
    051
    052    @Override
    053    public boolean equals(final Object o) {
    054        if (this == o) {
    055            return true;
    056        }
    057        if (o == null || getClass() != o.getClass()) {
    058            return false;
    059        }
    060        final TarArchiveStructSparse that = (TarArchiveStructSparse) o;
    061        return offset == that.offset && numbytes == that.numbytes;
    062    }
    063
    064    public long getNumbytes() {
    065        return numbytes;
    066    }
    067
    068    public long getOffset() {
    069        return offset;
    070    }
    071
    072    @Override
    073    public int hashCode() {
    074        return Objects.hash(offset, numbytes);
    075    }
    076
    077    @Override
    078    public String toString() {
    079        return "TarArchiveStructSparse{" + "offset=" + offset + ", numbytes=" + numbytes + '}';
    080    }
    081}