<commit_before>package net.lacolaco.smileessence.entity;

import net.lacolaco.smileessence.util.UIObservable;
import twitter4j.*;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

public abstract class EntitySupport extends UIObservable {
    private List<String> mentions;
    private List<String> hashtags;
    private List<String> mediaUrls;
    private List<String> urlsExpanded;
    private List<String> symbols;

    protected void updateEntities(twitter4j.EntitySupport status) {
        mentions = extractMentions(status.getUserMentionEntities());
        hashtags = extractHashtags(status.getHashtagEntities());
        mediaUrls = extractMediaUrls(status.getExtendedMediaEntities().length > 0 ? status.getExtendedMediaEntities() : status.getMediaEntities());
        urlsExpanded = extractExpandedUrls(status.getURLEntities());
        symbols = extractSymbols(status.getSymbolEntities());
    }

    public List<String> getMentions() {
        return mentions;
    }

    public List<String> getHashtags() {
        return hashtags;
    }

    public List<String> getMediaUrls() {
        return mediaUrls;
    }

    public List<String> getUrlsExpanded() {
        return urlsExpanded;
    }

    public List<String> getSymbols() {
        return symbols;
    }

    private List<String> extractMentions(UserMentionEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (UserMentionEntity entity : entities) {
                names.add(entity.getScreenName());
            }
        }
        return names;
    }

    private List<String> extractSymbols(SymbolEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (SymbolEntity entity : entities) {
                names.add(entity.getText());
            }
        }
        return names;
    }

    private List<String> extractExpandedUrls(URLEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (URLEntity entity : entities) {
                names.add(entity.getExpandedURL());
            }
        }
        return names;
    }

    private List<String> extractMediaUrls(MediaEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (MediaEntity entity : entities) {
                names.add(entity.getMediaURLHttps());
            }
        }
        return names;
    }

    private List<String> extractHashtags(HashtagEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (HashtagEntity entity : entities) {
                names.add(entity.getText());
            }
        }
        return names;
    }

    public String extractText(twitter4j.Status status, boolean expand) {
        return extractText(status, status.getText(), expand);
    }

    public String extractText(twitter4j.DirectMessage status, boolean expand) {
        return extractText(status, status.getText(), expand);
    }

    private String extractText(twitter4j.EntitySupport status, String text, boolean expand) {
        SortedSet<twitter4j.URLEntity> set = new TreeSet<>((a, b) -> a.getStart() - b.getStart());
        if (status.getURLEntities() != null) {
            for (URLEntity entity : status.getURLEntities()) {
                set.add(entity);
            }
        }
        if (status.getExtendedMediaEntities() != null) {
            for (URLEntity entity : status.getExtendedMediaEntities()) {
                set.add(entity);
            }
        } else if (status.getMediaEntities() != null) {
            for (URLEntity entity : status.getMediaEntities()) {
                set.add(entity);
            }<commit_msg>EntitySupport: Collections.addAll をつかう<commit_after>package net.lacolaco.smileessence.entity;

import net.lacolaco.smileessence.util.UIObservable;
import twitter4j.*;

import java.util.*;

public abstract class EntitySupport extends UIObservable {
    private List<String> mentions;
    private List<String> hashtags;
    private List<String> mediaUrls;
    private List<String> urlsExpanded;
    private List<String> symbols;

    protected void updateEntities(twitter4j.EntitySupport status) {
        mentions = extractMentions(status.getUserMentionEntities());
        hashtags = extractHashtags(status.getHashtagEntities());
        mediaUrls = extractMediaUrls(status.getExtendedMediaEntities().length > 0 ? status.getExtendedMediaEntities() : status.getMediaEntities());
        urlsExpanded = extractExpandedUrls(status.getURLEntities());
        symbols = extractSymbols(status.getSymbolEntities());
    }

    public List<String> getMentions() {
        return mentions;
    }

    public List<String> getHashtags() {
        return hashtags;
    }

    public List<String> getMediaUrls() {
        return mediaUrls;
    }

    public List<String> getUrlsExpanded() {
        return urlsExpanded;
    }

    public List<String> getSymbols() {
        return symbols;
    }

    private List<String> extractMentions(UserMentionEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (UserMentionEntity entity : entities) {
                names.add(entity.getScreenName());
            }
        }
        return names;
    }

    private List<String> extractSymbols(SymbolEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (SymbolEntity entity : entities) {
                names.add(entity.getText());
            }
        }
        return names;
    }

    private List<String> extractExpandedUrls(URLEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (URLEntity entity : entities) {
                names.add(entity.getExpandedURL());
            }
        }
        return names;
    }

    private List<String> extractMediaUrls(MediaEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (MediaEntity entity : entities) {
                names.add(entity.getMediaURLHttps());
            }
        }
        return names;
    }

    private List<String> extractHashtags(HashtagEntity[] entities) {
        List<String> names = new ArrayList<>();
        if (entities != null) {
            for (HashtagEntity entity : entities) {
                names.add(entity.getText());
            }
        }
        return names;
    }

    public String extractText(twitter4j.Status status, boolean expand) {
        return extractText(status, status.getText(), expand);
    }

    public String extractText(twitter4j.DirectMessage status, boolean expand) {
        return extractText(status, status.getText(), expand);
    }

    private String extractText(twitter4j.EntitySupport status, String text, boolean expand) {
        SortedSet<twitter4j.URLEntity> set = new TreeSet<>((a, b) -> a.getStart() - b.getStart());
        if (status.getURLEntities() != null) {
            Collections.addAll(set, status.getURLEntities());
        }
        if (status.getExtendedMediaEntities() != null) {
            Collections.addAll(set, status.getExtendedMediaEntities());
        } else if (status.getMediaEntities() != null) {
            Collections.addAll(set, status.getMediaEntities());
{'fraction_non_alphanumeric': 0.10954157782515991, 'fraction_numerical': 0.0018656716417910447, 'mean_word_length': 2.4842154131847725, 'pattern_counts': {'":': 0, '<': 57, '<?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': '3437093', 'n_tokens_mistral': 2089, 'n_tokens_neox': 2064, 'n_words': 441}