All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tectonica.jonix.unify.base.BaseSubjects Maven / Gradle / Ivy

/*
 * Copyright (C) 2012-2024 Zach Melamed
 *
 * Latest version available online at https://github.com/zach-m/jonix
 * Contact me at [email protected]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tectonica.jonix.unify.base;

import com.tectonica.jonix.common.codelist.SubjectSchemeIdentifiers;
import com.tectonica.jonix.unify.base.util.LazyMap;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * A {@link List} containing the multiple instances of ONIX <Subject> that may exist in an ONIX Product
 *
 * @author Zach Melamed
 */
@SuppressWarnings("serial")
public abstract class BaseSubjects extends LazyMap> {
    protected void addKV(Map> map, BaseSubject subject,
                         boolean insertFirst) {
        List items = map.computeIfAbsent(subject.subjectSchemeIdentifier, k -> new ArrayList<>());
        if (insertFirst) {
            items.add(0, subject);
        } else {
            items.add(subject);
        }
    }

    public List findSubjects(SubjectSchemeIdentifiers requestedScheme) {
        List items = get(requestedScheme);
        if (items == null) {
            return Collections.emptyList();
        }
        return items;
    }

    public String getMainBisacCode() {
        return findSubjects(SubjectSchemeIdentifiers.BISAC_Subject_Heading)
            .stream().findFirst().map(s -> s.subjectCode).orElse(null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy