001package systems.dmx.core.model;
002
003import java.util.ArrayList;
004import java.util.List;
005
006
007
008public enum IndexMode {
009
010    OFF, KEY, FULLTEXT, FULLTEXT_KEY;
011
012    // ------------------------------------------------------------------------------------------------------- Constants
013
014    private static final String INDEX_MODES_NAMESPACE = "dmx.core.";
015
016    // -------------------------------------------------------------------------------------------------- Public Methods
017
018    public static List<IndexMode> fromTopics(List<? extends RelatedTopicModel> topics) {
019        List<IndexMode> indexModes = new ArrayList();
020        for (TopicModel topic : topics) {
021            indexModes.add(fromUri(topic.getUri()));
022        }
023        return indexModes;
024    }
025
026    public static IndexMode fromUri(String uri) {
027        if (!uri.startsWith(INDEX_MODES_NAMESPACE)) {
028            throw new RuntimeException("\"" + uri + "\" is not a valid index mode URI");
029        }
030        String name = uri.substring(INDEX_MODES_NAMESPACE.length()).toUpperCase();
031        return IndexMode.valueOf(name);
032    }
033
034    public String toUri() {
035        return INDEX_MODES_NAMESPACE + name().toLowerCase();
036    }
037}