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

it.unibo.alchemist.model.SupportedIncarnations Maven / Gradle / Ivy

Go to download

Abstract, incarnation independent implementations of the Alchemist's interfaces. Provides support for those who want to write incarnations.

There is a newer version: 35.0.1
Show newest version
/*
 * Copyright (C) 2010-2023, Danilo Pianini and contributors
 * listed, for each module, in the respective subproject's build.gradle.kts file.
 *
 * This file is part of Alchemist, and is distributed under the terms of the
 * GNU General Public License, with a linking exception,
 * as described in the file LICENSE in the Alchemist distribution's top directory.
 */
package it.unibo.alchemist.model;

import it.unibo.alchemist.util.ClassPathScanner;
import org.jooq.lambda.Unchecked;

import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * This enum interfaces the generic components of the graphical interface with
 * the specific incarnation details.
 * 
 */
@SuppressWarnings("unchecked")
public final class SupportedIncarnations {

    private static final Map>> INCARNATIONS;

    static {
        INCARNATIONS = ClassPathScanner.subTypesOf(
            Incarnation.class,
            "it.unibo.alchemist"
        ).stream()
            .map(it -> (Class>) it)
            .collect(Collectors.toMap(c -> preprocess(c.getSimpleName()), Function.identity()));
    }

    private SupportedIncarnations() {
    }

    /**
     * @return The set of incarnations currently available.
     */
    public static Set getAvailableIncarnations() {
        return Collections.unmodifiableSet(INCARNATIONS.keySet());
    }

    /**
     * Fetches an incarnation whose name matches the supplied string.
     * 
     * @param s
     *            the name of the {@link Incarnation}
     * @param 
     *            {@link it.unibo.alchemist.model.Concentration} type
     * @param 

* {@link Position} type * * @return an {@link Optional} containing the incarnation, if one with a * matching name exists */ public static > Optional> get(final String s) { final String cmp = preprocess(s); return Optional.ofNullable(INCARNATIONS.get(cmp)) .map(Unchecked.function(it -> (Incarnation) it.getDeclaredConstructor().newInstance())); } private static String preprocess(final String s) { return s.toLowerCase(Locale.ENGLISH).replace("incarnation", ""); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy