001package org.eclipse.aether.repository;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import static java.util.Objects.requireNonNull;
024
025import org.eclipse.aether.RepositorySystemSession;
026
027/**
028 * A result from the local repository about the existence of metadata.
029 *
030 * @see LocalRepositoryManager#find(RepositorySystemSession, LocalMetadataRequest)
031 */
032public final class LocalMetadataResult
033{
034
035    private final LocalMetadataRequest request;
036
037    private File file;
038
039    private boolean stale;
040
041    /**
042     * Creates a new result for the specified request.
043     *
044     * @param request The local metadata request, must not be {@code null}.
045     */
046    public LocalMetadataResult( LocalMetadataRequest request )
047    {
048        this.request = requireNonNull( request, "local metadata request cannot be null" );
049    }
050
051    /**
052     * Gets the request corresponding to this result.
053     *
054     * @return The corresponding request, never {@code null}.
055     */
056    public LocalMetadataRequest getRequest()
057    {
058        return request;
059    }
060
061    /**
062     * Gets the file to the requested metadata if the metadata is available in the local repository.
063     * 
064     * @return The file to the requested metadata or {@code null}.
065     */
066    public File getFile()
067    {
068        return file;
069    }
070
071    /**
072     * Sets the file to requested metadata.
073     * 
074     * @param file The metadata file, may be {@code null}.
075     * @return This result for chaining, never {@code null}.
076     */
077    public LocalMetadataResult setFile( File file )
078    {
079        this.file = file;
080        return this;
081    }
082
083    /**
084     * This value indicates whether the metadata is stale and should be updated.
085     * 
086     * @return {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
087     */
088    public boolean isStale()
089    {
090        return stale;
091    }
092
093    /**
094     * Sets whether the metadata is stale.
095     * 
096     * @param stale {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
097     * @return This result for chaining, never {@code null}.
098     */
099    public LocalMetadataResult setStale( boolean stale )
100    {
101        this.stale = stale;
102        return this;
103    }
104
105    @Override
106    public String toString()
107    {
108        return request.toString() + "(" + getFile() + ")";
109    }
110
111}