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.spi.connector.checksum;
020
021import java.util.Collection;
022import java.util.List;
023
024/**
025 * Component performing selection of {@link ChecksumAlgorithmFactory} based on known factory names.
026 * Note: this component is NOT meant to be implemented or extended by client, is exposed ONLY to make clients
027 * able to get {@link ChecksumAlgorithmFactory} instances.
028 *
029 * @noimplement This interface is not intended to be implemented by clients.
030 * @noextend This interface is not intended to be extended by clients.
031 * @since 1.8.0
032 */
033public interface ChecksumAlgorithmFactorySelector {
034    /**
035     * Returns factory for given algorithm name, or throws if algorithm not supported.
036     *
037     * @throws IllegalArgumentException if asked algorithm name is not supported.
038     */
039    ChecksumAlgorithmFactory select(String algorithmName);
040
041    /**
042     * Returns a list of factories in same order as algorithm names are ordered, or throws if any of the
043     * algorithm name is not supported. The returned list has equal count of elements as passed in collection of names,
044     * and if names contains duplicated elements, the returned list of algorithms will have duplicates as well.
045     *
046     * @throws IllegalArgumentException if any asked algorithm name is not supported.
047     * @throws NullPointerException if passed in list of names is {@code null}.
048     * @since 1.9.0
049     */
050    List<ChecksumAlgorithmFactory> selectList(Collection<String> algorithmNames);
051
052    /**
053     * Returns immutable collection of all supported algorithms. This set represents ALL the algorithms supported by
054     * Resolver, and is NOT in any relation to given repository layout used checksums, returned by method {@link
055     * org.eclipse.aether.spi.connector.layout.RepositoryLayout#getChecksumAlgorithmFactories()} (in fact, is super set
056     * of it).
057     */
058    Collection<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories();
059
060    /**
061     * Returns {@code true} if passed in extension matches any known checksum extension. The extension string may
062     * start or contain dot ("."), but does not have to. In former case "ends with" is checked
063     * (i.e. "jar.sha1" -&gt; true; ".sha1" -&gt; true) while in latter equality (i.e. "sha1" -&gt; true).
064     *
065     * @since 1.9.3
066     */
067    boolean isChecksumExtension(String extension);
068}