001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.kernel.identifiers;
017
018import com.google.common.base.Converter;
019
020/**
021 * An {@link IdentifierConverter} accepts and returns identifiers, translating
022 * them in some type-specific manner. The typical use of this
023 * contract is for translating between internal and external identifiers.
024 *
025 * @author ajs6f
026 * @since Mar 26, 2014
027 * @param <B> the type to and from which we are translating
028 */
029public abstract class IdentifierConverter<A, B> extends Converter<A, B> {
030
031    /**
032     * Check if the given resource is in the domain of this converter
033     * @param resource the given resource
034     * @return boolean value of the check
035     */
036    public boolean inDomain(final A resource) {
037        return convert(resource) != null;
038    }
039
040    /**
041     * Convert a plain string to a resource appropriate to this converter
042     * @param resource the plain string resource
043     * @return the resource appropriate to this converter
044     */
045    abstract public A toDomain(final String resource);
046
047    /**
048     * Convert the given resource into a plain string representation of the conversion to the resource
049     * @param resource the given resource
050     * @return a plain string representation of the conversion to the resource
051     */
052    abstract public String asString(final A resource);
053}