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
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
033    private final LocalMetadataRequest request;
034
035    private File file;
036
037    private boolean stale;
038
039    /**
040     * Creates a new result for the specified request.
041     *
042     * @param request The local metadata request, must not be {@code null}.
043     */
044    public LocalMetadataResult( LocalMetadataRequest request )
045    {
046        this.request = requireNonNull( request, "local metadata request cannot be null" );
047    }
048
049    /**
050     * Gets the request corresponding to this result.
051     *
052     * @return The corresponding request, never {@code null}.
053     */
054    public LocalMetadataRequest getRequest()
055    {
056        return request;
057    }
058
059    /**
060     * Gets the file to the requested metadata if the metadata is available in the local repository.
061     * 
062     * @return The file to the requested metadata or {@code null}.
063     */
064    public File getFile()
065    {
066        return file;
067    }
068
069    /**
070     * Sets the file to requested metadata.
071     * 
072     * @param file The metadata file, may be {@code null}.
073     * @return This result for chaining, never {@code null}.
074     */
075    public LocalMetadataResult setFile( File file )
076    {
077        this.file = file;
078        return this;
079    }
080
081    /**
082     * This value indicates whether the metadata is stale and should be updated.
083     * 
084     * @return {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
085     */
086    public boolean isStale()
087    {
088        return stale;
089    }
090
091    /**
092     * Sets whether the metadata is stale.
093     * 
094     * @param stale {@code true} if the metadata is stale and should be updated, {@code false} otherwise.
095     * @return This result for chaining, never {@code null}.
096     */
097    public LocalMetadataResult setStale( boolean stale )
098    {
099        this.stale = stale;
100        return this;
101    }
102
103    @Override
104    public String toString()
105    {
106        return request.toString() + "(" + getFile() + ")";
107    }
108
109}