001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014
015package ch.qos.logback.classic.boolex;
016
017import org.slf4j.Marker;
018
019import java.util.List;
020
021/**
022 * A helper class to be used in conjunction with {@link ch.qos.logback.classic.boolex.JaninoEventEvaluator}
023 *
024 * @since 1.5.4
025 */
026public class MarkerList {
027
028    List<Marker> markers;
029
030    public MarkerList(List<Marker> markers) {
031        this.markers = markers;
032    }
033
034    /**
035     * Check whether this list contains a given marker.
036     *
037     * @param markerName
038     * @return
039     */
040    public boolean contains(String markerName) {
041        if(markerName == null || markerName.trim().length() == 0)
042            return false;
043
044        if(markers == null || markers.isEmpty())
045            return false;
046
047        final boolean result = markers.stream().anyMatch( m -> m.contains(markerName));
048        return  result;
049    }
050
051    /**
052     * Return the first marker on the list, can be null.
053     *
054     *
055     * @return the first marker on the list, can be null
056     */
057    public Marker getFirstMarker() {
058        if(markers == null || markers.isEmpty()) {
059            return null;
060        } else {
061            return markers.get(0);
062        }
063    }
064}