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

com.github.alexeylapin.m3u8.parser.PlaylistVariableAttribute Maven / Gradle / Ivy

The newest version!
package com.github.alexeylapin.m3u8.parser;

import com.github.alexeylapin.m3u8.model.PlaylistVariable;
import com.github.alexeylapin.m3u8.model.PlaylistVariable;

import java.util.Map;

/*
 * #EXT-X-DEFINE:
 */
public enum PlaylistVariableAttribute implements Attribute {
    NAME {
        @Override
        public void read(PlaylistVariable.Builder builder, String value) {
            builder.name(value);
        }

        @Override
        public void write(PlaylistVariable value, TextBuilder textBuilder) {
            value.name().ifPresent(v -> textBuilder.addQuoted(name(), v));
        }
    },

    VALUE {
        @Override
        public void read(PlaylistVariable.Builder builder, String value) {
            builder.value(value);
        }

        @Override
        public void write(PlaylistVariable value, TextBuilder textBuilder) {
            value.value().ifPresent(v -> textBuilder.addQuoted(name(), v));
        }
    },

    IMPORT {
        @Override
        public void read(PlaylistVariable.Builder builder, String value) {
            builder.importAttribute(value);
        }

        @Override
        public void write(PlaylistVariable value, TextBuilder textBuilder) {
            value.importAttribute().ifPresent(v -> textBuilder.addQuoted(name(), v));
        }
    };

    final static Map attributeMap = ParserUtils.toMap(values(), Attribute::key);

    static PlaylistVariable parse(String attributes, ParsingMode parsingMode) throws PlaylistParserException {
        PlaylistVariable.Builder builder = PlaylistVariable.builder();
        ParserUtils.readAttributes(attributeMap, attributes, builder, parsingMode);
        return builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy