<commit_before>package collinear;

import java.util.*;

public class BruteCollinearPoints {
    private Point[] points;
    private LineSegment[] lineSegments;
    private int numberOfSegments;

    public BruteCollinearPoints(Point[] points) {
        if (checkForCornerCases(points)) return;

        List<Point> pointList = identifyUniquePoints(points);

        this.points = new Point[pointList.size()];
        for (int i = 0; i < pointList.size(); i++) {
            this.points[i] = pointList.get(i);
        }
        Arrays.sort(this.points);

        lineSegments = new LineSegment[this.points.length];

        double slope01, slope02, slope03 = -1;
        Point prevJ = this.points[0], prevK = prevJ, prevL = prevK;

        for (int i = 0; i < this.points.length; i++) {
            for (int j = 0 + i; j < this.points.length; j++) {
                for (int k = 0 + j; k < this.points.length; k++) {
                    for (int l = 0 + k; l < this.points.length; l++) {
                        if(i < j
                                && i < k && i < l
                                                 && j < k && j < l
                                                                   && k < l) {
                            if (prevJ.compareTo(this.points[j]) != 0
                                    && prevK.compareTo(this.points[k]) != 0
                                    && prevL.compareTo(this.points[l]) != 0) {
                                slope01 = this.points[i].slopeTo(this.points[j]);
                                slope02 = this.points[i].slopeTo(this.points[k]);
                                if(slope01 == slope02)
                                    slope03 = this.points[i].slopeTo(this.points[l]);
                                if (slope01 == slope02 && slope02 == slope03 && slope01 == slope03) {
                                    if (numberOfSegments < this.points.length) {
                                        lineSegments[numberOfSegments++]
                                                = new LineSegment(this.points[i], this.points[l]);
                                        prevJ = this.points[j];
                                        prevK = this.points[k];
                                        prevL = this.points[l];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } // finds all line segments containing 4 points

    private List<Point> identifyUniquePoints(Point[] points) {
        List<Point> pointList = new ArrayList<>();
        for (int i = 0; i < points.length - 1; i++) {
            if (points[i].compareTo(points[i + 1]) != 0) {
                pointList.add(points[i]);
            }
        }
        if (points[points.length - 1].compareTo(points[0]) != 0) {
            pointList.add(points[points.length - 1]);
        }
        return pointList;
    }

    private boolean checkForCornerCases(Point[] points) {
        if (points == null || points.length == 0) {
            throw new NullPointerException("there are no points");
        }
        if (points.length > 0) {
            for (int i = 0; i < points.length; i++) {
                if (points[i] == null) {
                    throw new NullPointerException("one of the points is null");
                }
            }
        }
        if (points.length > 1) {
            Set<Point> pointSet = new TreeSet<>();
            for (int i = 0; i < points.length; i++) {
                pointSet.add(points[i]);
            }
            if (pointSet.size() != points.length) {
                throw new IllegalArgumentException("there is a duplicate");
            }
        }
        if (points.length == 1) {
            return true;
        }
        return false;
    }

    public LineSegment[] segments() {
        LineSegment[] copyOfLineSegments = new LineSegment[numberOfSegments];
        System.arraycopy(lineSegments, 0, copyOfLineSegments, 0, numberOfSegments);
        return copyOfLineSegments;
    } // the line segments

    public int numberOfSegments() {
        return numberOfSegments;
    } // the number of line segments
}<commit_msg>added tree set for checking on duplicate points<commit_after>package collinear;

import java.util.*;

public class BruteCollinearPoints {
    private Point[] points;
    private LineSegment[] lineSegments;
    private int numberOfSegments;

    public BruteCollinearPoints(Point[] points) {
        if (points == null || points.length == 0) {
            throw new NullPointerException("there are no points");
        }
        if (points.length > 0) {
            for (int i = 0; i < points.length; i++) {
                if (points[i] == null) {
                    throw new NullPointerException("one of the points is null");
                }
            }
        }
        Set<Point> pointSet = new TreeSet<>();
        if (points.length > 1) {
            for (int i = 0; i < points.length; i++) {
                pointSet.add(points[i]);
            }
            if (pointSet.size() != points.length) {
                throw new IllegalArgumentException("there is a duplicate");
            }
        }
        if (points.length == 1) {
            return;
        }
        pointSet.toArray();
        List<Point> pointList = new ArrayList<>(pointSet);
        this.points = new Point[pointList.size()];
        for (int i = 0; i < pointList.size(); i++) {
            this.points[i] = pointList.get(i);
        }
        Arrays.sort(this.points);

        lineSegments = new LineSegment[this.points.length];

        double slope01, slope02, slope03 = -1;
        Point prevJ = this.points[0], prevK = prevJ, prevL = prevK;

        for (int i = 0; i < this.points.length; i++) {
            for (int j = 0 + i; j < this.points.length; j++) {
                for (int k = 0 + j; k < this.points.length; k++) {
                    for (int l = 0 + k; l < this.points.length; l++) {
                        if(i < j
                                && i < k && i < l
                                                 && j < k && j < l
                                                                   && k < l) {
                            if (prevJ.compareTo(this.points[j]) != 0
                                    && prevK.compareTo(this.points[k]) != 0
                                    && prevL.compareTo(this.points[l]) != 0) {
                                slope01 = this.points[i].slopeTo(this.points[j]);
                                slope02 = this.points[i].slopeTo(this.points[k]);
                                if(slope01 == slope02)
                                    slope03 = this.points[i].slopeTo(this.points[l]);
                                if (slope01 == slope02
                                        && slope02 == slope03
                                        && slope01 == slope03) {
                                    if (numberOfSegments < this.points.length) {
                                        lineSegments[numberOfSegments++]
                                                = new LineSegment(this.points[i],
                                                this.points[l]);
                                        prevJ = this.points[j];
                                        prevK = this.points[k];
                                        prevL = this.points[l];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } // finds all line segments containing 4 points

    public LineSegment[] segments() {
        LineSegment[] copyOfLineSegments = new LineSegment[numberOfSegments];
        System.arraycopy(lineSegments, 0, copyOfLineSegments, 0, numberOfSegments);
        return copyOfLineSegments;
    } // the line segments

    public int numberOfSegments() {
        return numberOfSegments;
    } // the number of line segments
}
{'fraction_non_alphanumeric': 0.1113717742931226, 'fraction_numerical': 0.012594147425608099, 'mean_word_length': 1.1502521900716751, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4733582', 'n_tokens_mistral': 2129, 'n_tokens_neox': 1998, 'n_words': 492}