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.eclipse.aether.repository;
020
021import java.io.File;
022
023import static java.util.Objects.requireNonNull;
024
025/**
026 * A result from the local repository about the existence of metadata.
027 *
028 * @see LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession, LocalMetadataRequest)
029 */
030public final class LocalMetadataResult {
031
032    private final LocalMetadataRequest request;
033
034    private File file;
035
036    private boolean stale;
037
038    /**
039     * Creates a new result for the specified request.
040     *
041     * @param request The local metadata request, must not be {@code null}.
042     */
043    public LocalMetadataResult(LocalMetadataRequest request) {
044        this.request = requireNonNull(request, "local metadata request cannot be null");
045    }
046
047    /**
048     * Gets the request corresponding to this result.
049     *
050     * @return The corresponding request, never {@code null}.
051     */
052    public LocalMetadataRequest getRequest() {
053        return request;
054    }
055
056    /**
057     * Gets the file to the requested metadata if the metadata is available in the local repository.
058     *
059     * @return The file to the requested metadata or {@code null}.
060     */
061    public File getFile() {
062        return file;
063    }
064
065    /**
066     * Sets the file to requested metadata.
067     *
068     * @param file The metadata file, may be {@code null}.
069     * @return This result for chaining, never {@code null}.
070     */
071    public LocalMetadataResult setFile(File file) {
072        this.file = file;
073        return this;
074    }
075
076    /**
077     * This value indicates whether the metadata is stale and should be updated.
078     *
079     * @return {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
080     */
081    public boolean isStale() {
082        return stale;
083    }
084
085    /**
086     * Sets whether the metadata is stale.
087     *
088     * @param stale {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
089     * @return This result for chaining, never {@code null}.
090     */
091    public LocalMetadataResult setStale(boolean stale) {
092        this.stale = stale;
093        return this;
094    }
095
096    @Override
097    public String toString() {
098        return request.toString() + "(" + getFile() + ")";
099    }
100}