<commit_before>package editor.collection;

import java.awt.datatransfer.DataFlavor;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import editor.collection.deck.CategorySpec;
import editor.database.attributes.CardAttribute;
import editor.database.card.Card;

/**
 * This class represents a collection of cards.  Each card should be represented by a single entry
 * that keeps track of information such as how many copies are in the CardList.  If an implementation
 * of Card list doesn't do this, that should be noted by its documentation.
 * <p>
 * This does not implement {@link Collection}<Card>, {@link List}<Card>, or {@link Set}<Card> because
 * its behavior for add and remove are slightly different than any of them.  For example, if a card is
 * added twice, it should only take up one place in the list (like Set), but when if it is removed once,
 * it should still be part of the CardList (like List).  It doesn't implement {@link Collection}<Card>
 * because Collection is bound by legacy definitions like remove taking an Object and not being generic.
 *
 * @author <NAME>
 */
public interface CardList extends Iterable<Card>
{
    /**
     * This class represents an entry in a {@link CardList} whose actual implementation is dependent on the parent
     * list.  It contains metadata about a card such as count and date added.
     *
     * @author <NAME>
     */
    interface Entry
    {
        /**
         * Get this Entry's card.
         *
         * @return the Card this Entry has data for.
         */
        Card card();

        /**
         * Get the categories this Entry's card belongs to.
         *
         * @return the CategorySpecs in the parent CardList this Entry's Card matches (optional
         * operation)
         * @throws UnsupportedOperationException if this operation is not supported
         */
        Set<CategorySpec> categories() throws UnsupportedOperationException;

        /**
         * Get the number of copies of this Entry's card in the parent {@link CardList}.
         *
         * @return the number of copies in the parent CardList of this Entry's Card (optional operation).
         * @throws UnsupportedOperationException if this operation is not supported
         */
        int count() throws UnsupportedOperationException;

        /**
         * Get the date this Entry's card was added to the parent {@link CardList}.
         *
         * @return the date this Entry's Card was added (optional operation).
         * @throws UnsupportedOperationException if this operation is not supported
         */
        LocalDate dateAdded() throws UnsupportedOperationException;

        /**
         * Get some information about this Entry's Card.
         *
         * @param data type of information to get
         * @return the value of the given information about this Entry's Card.
         */
        default Object get(CardAttribute data)
        {
            return switch (data) {
                case NAME           -> card().unifiedName();
                case LAYOUT         -> card().layout();
                case MANA_COST      -> card().manaCost();
                case CMC            -> card().cmc();
                case COLORS         -> card().colors();
                case COLOR_IDENTITY -> card().colorIdentity();
                case TYPE_LINE      -> card().unifiedTypeLine();
                case EXPANSION      -> card().expansion().toString();
                case RARITY         -> card().rarity();
                case POWER          -> card().power();
                case TOUGHNESS      -> card().toughness();
                case LOYALTY        -> card().loyalty();
                case ARTIST         -> card().artist().get(0);
                case CARD_NUMBER    -> String.join(' ' + Card.FACE_SEPARATOR + ' ', card().number());
                case LEGAL_IN       -> card().legalIn();
                case COUNT          -> count();
                case CATEGORIES     -> categories();
                case DATE_ADDED     -> dateAdded();
                default -> throw new IllegalArgumentException("Unknown data type " + data);
            };
        }
    }

    /**
     * Data flavor representing entries in a deck.  Transfer data will appear as a
     * map of cards onto an integer representing the number of copies to transfer.
     */
    DataFlavor entryFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=\"" + Map.class.getName() + "\"", "Deck Entries");

    /**
     * Add one copy of a Card to this CardList (optional operation).
     *
     * @param card card to add
     * @return true if a copy of the Card was added, and false otherwise.
     * @throws UnsupportedOperationException if this operation is not supported
     */
    boolean add(Card card) throws UnsupportedOperationException;

    /**<commit_msg>Fix entry return value for block and tags<commit_after>package editor.collection;

import java.awt.datatransfer.DataFlavor;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import editor.collection.deck.CategorySpec;
import editor.database.attributes.CardAttribute;
import editor.database.card.Card;

/**
 * This class represents a collection of cards.  Each card should be represented by a single entry
 * that keeps track of information such as how many copies are in the CardList.  If an implementation
 * of Card list doesn't do this, that should be noted by its documentation.
 * <p>
 * This does not implement {@link Collection}<Card>, {@link List}<Card>, or {@link Set}<Card> because
 * its behavior for add and remove are slightly different than any of them.  For example, if a card is
 * added twice, it should only take up one place in the list (like Set), but when if it is removed once,
 * it should still be part of the CardList (like List).  It doesn't implement {@link Collection}<Card>
 * because Collection is bound by legacy definitions like remove taking an Object and not being generic.
 *
 * @author <NAME>
 */
public interface CardList extends Iterable<Card>
{
    /**
     * This class represents an entry in a {@link CardList} whose actual implementation is dependent on the parent
     * list.  It contains metadata about a card such as count and date added.
     *
     * @author <NAME>
     */
    interface Entry
    {
        /**
         * Get this Entry's card.
         *
         * @return the Card this Entry has data for.
         */
        Card card();

        /**
         * Get the categories this Entry's card belongs to.
         *
         * @return the CategorySpecs in the parent CardList this Entry's Card matches (optional
         * operation)
         * @throws UnsupportedOperationException if this operation is not supported
         */
        Set<CategorySpec> categories() throws UnsupportedOperationException;

        /**
         * Get the number of copies of this Entry's card in the parent {@link CardList}.
         *
         * @return the number of copies in the parent CardList of this Entry's Card (optional operation).
         * @throws UnsupportedOperationException if this operation is not supported
         */
        int count() throws UnsupportedOperationException;

        /**
         * Get the date this Entry's card was added to the parent {@link CardList}.
         *
         * @return the date this Entry's Card was added (optional operation).
         * @throws UnsupportedOperationException if this operation is not supported
         */
        LocalDate dateAdded() throws UnsupportedOperationException;

        /**
         * Get some information about this Entry's Card.
         *
         * @param data type of information to get
         * @return the value of the given information about this Entry's Card.
         */
        default Object get(CardAttribute data)
        {
            return switch (data) {
                case NAME           -> card().unifiedName();
                case LAYOUT         -> card().layout();
                case MANA_COST      -> card().manaCost();
                case CMC            -> card().cmc();
                case COLORS         -> card().colors();
                case COLOR_IDENTITY -> card().colorIdentity();
                case TYPE_LINE      -> card().unifiedTypeLine();
                case EXPANSION      -> card().expansion().toString();
                case BLOCK          -> card().expansion().block;
                case RARITY         -> card().rarity();
                case POWER          -> card().power();
                case TOUGHNESS      -> card().toughness();
                case LOYALTY        -> card().loyalty();
                case ARTIST         -> card().artist().get(0);
                case CARD_NUMBER    -> String.join(' ' + Card.FACE_SEPARATOR + ' ', card().number());
                case LEGAL_IN       -> card().legalIn();
                case COUNT          -> count();
                case CATEGORIES     -> categories();
                case DATE_ADDED     -> dateAdded();
                case TAGS           -> {
                    var tags = Card.tags.get(card());
                    if (tags == null)
                        yield "[]";
                    else
                        yield tags.stream().sorted().collect(Collectors.joining(", ", "[", "]"));
                }
                default -> throw new IllegalArgumentException("Unknown data type " + data);
            };
        }
    }

    /**
     * Data flavor representing entries in a deck.  Transfer data will appear as a
     * map of cards onto an integer representing the number of copies to transfer.
     */
    DataFlavor entryFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=\"" + Map.class.getName() + "\"", "Deck Entries");

    /**
     * Add one copy of a Card to this CardList (optional operation).
     *
     * @param card card to add
     * @return true if a copy of the Card was added, and false otherwise.
     * @throws UnsupportedOperationException if this operation is not supported
     */
    boolean add(Card card) throws UnsupportedOperationException;

    /**
{'fraction_non_alphanumeric': 0.09197372179377321, 'fraction_numerical': 0.00019042178425211843, 'mean_word_length': 2.066861313868613, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2757983', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2501, 'n_words': 1006}