<commit_before>package io.disassemble.asm.util;

import io.disassemble.asm.ClassFactory;
import io.disassemble.asm.ClassField;
import io.disassemble.asm.ClassMethod;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.Printer;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Predicate;

import static org.objectweb.asm.tree.AbstractInsnNode.*;

/**
 * @author <NAME>
 * @since 2/1/16
 */
public class Assembly implements Opcodes {

    /**
     * Creates a predicate that matches any of the given opcodes.
     *
     * @param opcodes The opcodes to match.
     * @return A predicate that matches any of the given opcodes.
     */
    public static Predicate<AbstractInsnNode> createOpcodePredicate(int... opcodes) {
        Arrays.sort(opcodes);
        return insn -> (Arrays.binarySearch(opcodes, insn.getOpcode()) >= 0);
    }

    /**
     * Checks how many instructions from the given list match the given predicate.
     *
     * @param list      The list of instructions.
     * @param predicate The predicate to match.
     * @return The amount of instructions from the given list matching the given predicate.
     */
    public static int count(InsnList list, Predicate<AbstractInsnNode> predicate) {
        int count = 0;
        AbstractInsnNode[] instructions = list.toArray();
        for (AbstractInsnNode insn : instructions) {
            if (predicate.test(insn)) {
                count++;
            }
        }
        return count;
    }

    /**
     * Finds the first occurrence of an instruction matching the given predicate.
     *
     * @param list      The list of instructions.
     * @param predicate The predicate to match.
     * @return The first occurrence of an instruction matching the given predicate.
     */
    @SuppressWarnings("unchecked")
    public static <E extends AbstractInsnNode> E findFirst(InsnList list, Predicate<AbstractInsnNode> predicate) {<commit_msg>Add Assembly#findAll<commit_after>package io.disassemble.asm.util;

import io.disassemble.asm.ClassFactory;
import io.disassemble.asm.ClassField;
import io.disassemble.asm.ClassMethod;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.Printer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

import static org.objectweb.asm.tree.AbstractInsnNode.*;

/**
 * @author <NAME>
 * @since 2/1/16
 */
public class Assembly implements Opcodes {

    /**
     * Creates a predicate that matches any of the given opcodes.
     *
     * @param opcodes The opcodes to match.
     * @return A predicate that matches any of the given opcodes.
     */
    public static Predicate<AbstractInsnNode> createOpcodePredicate(int... opcodes) {
        Arrays.sort(opcodes);
        return insn -> (Arrays.binarySearch(opcodes, insn.getOpcode()) >= 0);
    }

    /**
     * Gets a list of instructions matching the given predicate.
     *
     * @param list The list of instructions.
     * @param predicate The predicate to match.
     * @return A list of instructions matching the given predicate.
     */
    @SuppressWarnings("unchecked")
    public static <E extends AbstractInsnNode> List<E> findAll(InsnList list, Predicate<AbstractInsnNode> predicate) {
        List<E> results = new ArrayList<>();
        AbstractInsnNode[] instructions = list.toArray();
        for (AbstractInsnNode insn : instructions) {
            if (predicate.test(insn)) {
                results.add((E) insn);
            }
        }
        return results;
    }

    /**
     * Checks how many instructions from the given list match the given predicate.
     *
     * @param list      The list of instructions.
     * @param predicate The predicate to match.
     * @return The amount of instructions from the given list matching the given predicate.
     */
    public static int count(InsnList list, Predicate<AbstractInsnNode> predicate) {
        return findAll(list, predicate).size();
    }

    /**
     * Finds the first occurrence of an instruction matching the given predicate.
     *
     * @param list      The list of instructions.
     * @param predicate The predicate to match.
     * @return The first occurrence of an instruction matching the given predicate.
     */
    @SuppressWarnings("unchecked")
    public static <E extends AbstractInsnNode> E findFirst(InsnList list, Predicate<AbstractInsnNode> predicate) {
{'fraction_non_alphanumeric': 0.09467713787085515, 'fraction_numerical': 0.002399650959860384, 'mean_word_length': 2.939003436426117, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, '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': '7386180', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1278, 'n_words': 401}