Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лаб. 5 Java

.docx
Скачиваний:
3
Добавлен:
31.08.2024
Размер:
51.85 Кб
Скачать

ProductList

package lab_3;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.LinkedList;

import java.util.List;

import java.util.Random;

public class ProductList {

private ArrayList<Product> arrayList;

private LinkedList<Product> linkedList;

private LogProcessor logProcessor;

private long[] timeInformation;

private long[] generalTime;

private long[][] allTime;

//private ArrayList<Long> changeTime;

//private static final int[] COLLECTION_SIZES = {10, 100, 1000, 10000, 100000};

private static int[] COLLECTION_SIZES = {};

private static final double REMOVAL_PERCENTAGE = 0.1;

private static final String LOG_FILE_PREFIX = "log_";

private static final String LOG_FILE_EXTENSION = ".txt";

public ProductList(int[] collection) {

arrayList = new ArrayList<>();

linkedList = new LinkedList<>();

logProcessor = new LogProcessor();

timeInformation = new long[4];

generalTime = new long[8];

allTime = new long[6][8];

COLLECTION_SIZES = collection;

//changeTime = new ArrayList<>();

}

public long[] generateCollection(String collectionType, List<Product> collection, int size) {

String logFileName = LOG_FILE_PREFIX + collectionType + "_" + size + LOG_FILE_EXTENSION;

Random random = new Random();

logProcessor.writeHeadLog(logFileName, getCurrentDateTime(), collectionType);

//System.out.println("Размер:" + size);

long startTime;

//System.out.println("Размер коллекции:" + size);

//System.out.println("Коллекция:" + collection);

int capacity = 10;

long sumAddTotalTime = 0;

long currentTime = 0;

long oldTime = 0;

for (int i = 0; i < size; i++) {

//Product product = collection.get(i);

String randomType = generateRandomString();

Product product = new Product(randomType);

startTime = System.nanoTime();

collection.add(product);

currentTime = getCurrentTimeDifference(startTime);

logProcessor.writeAdd(logFileName, currentTime, i);

//writer.println("add, ID = " + (i + 1) + ", " + currentTime);

//product.load();

sumAddTotalTime += currentTime;

if ((i == 10 || i == 0) && collectionType.equals("ArrayList")) {

//changeTime.add(sumAddTotalTime/i);

////System.out.println("Время добавления при размере ArrayList " + (i+1) + ": "+ currentTime );

//oldTime = sumAddTotalTime;

capacity = (int) ((capacity * 3)/2 + 1);

}

if (((i+1) == capacity && (i+1) != 10) && collectionType.equals("ArrayList")) {

//changeTime.add(sumAddTotalTime/i);

////System.out.println("Время добавления при размере ArrayList " + (i+1) + ": "+ currentTime );

oldTime = sumAddTotalTime;

capacity = (int) ((capacity * 3)/2 + 1);

}

}

//System.out.println("Коллекция: " + collection);

long addTotalCount = size;

long addTotalTime = sumAddTotalTime;

long addMedianTime = sumAddTotalTime / size;

logProcessor.writeAddInformation(logFileName, addTotalCount, addTotalTime, addMedianTime);

int removalCount = (int) (size * REMOVAL_PERCENTAGE);

//System.out.println("Количество удалений:" + removalCount);

//Iterator<Product> iterator = collection.iterator();

currentTime = 0;

long sumRemoveTotalTime = 0;

for (int i = 0; i < removalCount; i++) {

int randomIndex = new Random().nextInt(collection.size());

startTime = System.nanoTime();

collection.remove(randomIndex);

//Product product = collection.get(randomIndex);

currentTime = getCurrentTimeDifference(startTime);

logProcessor.writeRemove(logFileName, currentTime, randomIndex);

//writer.println("remove, ID = " + (randomIndex + 1) + ", " + currentTime);

//product.load();

sumRemoveTotalTime += currentTime;

}

long removeTotalCount = removalCount;

long removeTotalTime = sumRemoveTotalTime;

long removeMedianTime = sumRemoveTotalTime / removalCount;

logProcessor.writeRemoveInformation(logFileName, removeTotalCount, removeTotalTime, removeMedianTime);

logProcessor.writeEndLog(logFileName, getCurrentDateTime());

//System.out.println("Файл: " + logFileName + " создан и заполнен успешно.");

//System.out.println("Коллекция c удалением: " + collection);

timeInformation[0] = addTotalTime;

timeInformation[1] = addMedianTime;

timeInformation[2] = removeTotalTime;

timeInformation[3] = removeMedianTime;

//System.out.println(timeInformation[0]);

//collection.clear();

return timeInformation;

}

public String generateRandomString() {

String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

Random random = new Random();

StringBuilder sb = new StringBuilder();

for (int i = 0; i < 6; i++) {

int index = random.nextInt(characters.length());

char randomChar = characters.charAt(index);

sb.append(randomChar);

}

return sb.toString();

}

public long[][] generateCollections() {

//ArrayList<long[]> timeList = new ArrayList<>();

int count = 0;

for (int size : COLLECTION_SIZES) {

arrayList = new ArrayList<>();

linkedList = new LinkedList<>();

long[] aList = generateCollection("ArrayList", arrayList, size);

long[] arrList = new long[4];

System.arraycopy(aList, 0, arrList, 0, aList.length);

//System.out.println(arrList);

long[] linkList = generateCollection("LinkedList", linkedList, size);

//System.out.println(arrList[0]);

//System.out.println(linkList[0]);

//logProcessor.writeLog("ArrayList", arrayList, size);

//logProcessor.writeLog("LinkedList", linkedList, size);

//long[] generalTime = new long[8];

System.arraycopy(arrList, 0, generalTime, 0, arrList.length);

System.arraycopy(linkList, 0, generalTime, linkList.length, linkList.length);

//allTime[count][0] = generalTime;

System.arraycopy(arrList, 0, allTime[count], 0, arrList.length);

System.arraycopy(linkList, 0, allTime[count], linkList.length, linkList.length);

count+=1;

//timeList.add(generalTime);

if (arrList[0] > linkList[0]) {

//System.out.println("Общее время выполнения добавления меньше у LinkedList.");

}

if (arrList[0] < linkList[0]) {

//System.out.println("Общее время выполнения добавления меньше у ArrayList.");

}

if (arrList[0] == linkList[0]) {

//System.out.println("Общее время выполнения добавления одинаково.");

}

if (arrList[1] > linkList[1]) {

//System.out.println("Среднее время выполнения добавления меньше у LinkedList.");

}

if (arrList[1] < linkList[1]) {

//System.out.println("Среднее время выполнения добавления меньше у ArrayList.");

}

if (arrList[1] == linkList[1]) {

//System.out.println("Среднее время выполнения добавления одинаково.");

}

if (arrList[2] > linkList[2]) {

//System.out.println("Общее время выполнения удаления меньше у LinkedList.");

}

if (arrList[2] < linkList[2]) {

//System.out.println("Общее время выполнения удаления меньше у ArrayList.");

}

if (arrList[2] == linkList[2]) {

//System.out.println("Общее время выполнения удаления одинаково.");

}

if (arrList[3] > linkList[3]) {

//System.out.println("Среднее время выполнения удаления меньше у LinkedList.");

}

if (arrList[3] < linkList[3]) {

//System.out.println("Среднее время выполнения удаления меньше у ArrayList.");

}

if (arrList[3] == linkList[3]) {

//System.out.println("Среднее время выполнения удаления одинаково.");

}

//System.out.println("Разница в нансекундах между общим и средним временем добавления в ArrayList: " + Math.abs(arrList[0] - arrList[1]));

//System.out.println("Разница в нансекундах между общим и средним временем удаления в ArrayList: " + Math.abs(arrList[2] - arrList[3]));

//System.out.println("Разница в нансекундах между общим и средним временем добавления в LinkedList: " + Math.abs(linkList[0] - linkList[1]));

//System.out.println("Разница в нансекундах между общим и средним временем удаления в LinkedList: " + Math.abs(linkList[2] - linkList[3]));

//System.out.println("\n");

arrayList.clear();

linkedList.clear();

}

return allTime;

}

public LogProcessor getLogProcessor() {

return logProcessor;

}

private String getCurrentDateTime() {

LocalDateTime currentDateTime = LocalDateTime.now();

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");

return currentDateTime.format(formatter);

}

private long getCurrentTimeDifference(long startTime) {

return System.nanoTime() - startTime;

}

}

LogProcessor

package lab_3;

import java.io.BufferedWriter;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.PrintWriter;

import java.sql.Date;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

import java.util.List;

import java.util.Random;

public class LogProcessor{

private static final String LOG_FILE_PREFIX = "log_";

private static final String LOG_FILE_EXTENSION = ".txt";

//private ErrorProcessor errorCount;

private int errorCount;

//private PrintWriter writer;

//private ProductList productList;

public LogProcessor() {

errorCount = 0;

}

public void writeHeadLog(String logFileName, String currentTime, String collectionType) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName))) {

writer.println("Start program: " + currentTime);

writer.println(collectionType);

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeHeadLog");

//errorCount.processError("Ошибка в методе writeHeadLog");

}

}

public void writeAdd(String logFileName, long currentTime, int i) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName, true))) {

writer.println("add, ID = " + (i + 1) + ", " + currentTime);

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeAdd");

//errorCount.processError("Ошибка в методе writeAdd");

}

}

public void writeAddInformation(String logFileName, long addTotalCount, long addTotalTime, long addMedianTime) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName, true))) {

writer.println("addTotalCount = " + addTotalCount);

writer.println("addTotalTime = " + addTotalTime);

writer.println("addMedianTime = " + addMedianTime);

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeAddInformation");

//errorCount.processError("Ошибка в методе writeAddInformation");

}

}

public void writeRemove(String logFileName, long currentTime, int i) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName, true))) {

writer.println("remove, ID = " + (i + 1) + ", " + currentTime);

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeRemove");

//errorCount.processError("Ошибка в методе writeRemove");

}

}

public void writeRemoveInformation(String logFileName, long removeTotalCount, long removeTotalTime, long removeMedianTime) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName, true))) {

writer.println("removeTotalCount = " + removeTotalCount);

writer.println("removeTotalTime = " + removeTotalTime);

writer.println("removeMedianTime = " + removeMedianTime);

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeRemoveInformation");

//errorCount.processError("Ошибка в методе writeRemoveInformation");

}

}

public void writeEndLog(String logFileName, String currentTime) {

try (PrintWriter writer = new PrintWriter(new FileWriter(logFileName, true))) {

writer.println("Finish program: " + currentTime);

System.out.println("Файл: " + logFileName + " создан и заполнен успешно.");

} catch (FileNotFoundException e) {

handleError("Ошибка при записи в файл: " + logFileName);

//errorCount.processError("Ошибка при записи в файл: " + logFileName);

}catch (Exception e) {

handleError("Ошибка в методе writeEndLog");

//errorCount.processError("Ошибка в методе writeEndLog");

}

}

private void handleError(String errorMessage) {

System.err.println(errorMessage);

errorCount++;

}

public int getErrorCount() {

return errorCount;

}

}

Draw

package lab_3;

import javax.swing.*;

import java.awt.*;

import java.util.ArrayList;

import java.util.Arrays;

public class Draw extends JPanel {

/*

private double[] addTotalTimeAL;

private double[] addTotalTimeLL;

private double[] addMedianTimeAL;

private double[] addMedianTimeLL;

private double[] removeTotalTimeAL;

private double[] removeTotalTimeLL;

private double[] removeMedianTimeAL;

private double[] removeMedianTimeLL;

*/

private double[] timeCollectionAL;

private double[] timeCollectionLL;

//private static final int[] COLLECTION_SIZES = {10, 100, 1000, 10000, 100000};

private static int[] COLLECTION_SIZES = {};

//private static final String[] labels = {"addTotalTime", "addMedianTime", "removeTotalTime", "removeMedianTime"};

//private static final String[] operations = {"Addition", "Removal"};

Draw(double[] collectionAL, double[] collectionLL, int[] collection) {

timeCollectionAL = collectionAL;

timeCollectionLL = collectionLL;

COLLECTION_SIZES = collection;

}

/*

public void getData(long[][] allTime) {

for (int i = 0; i < 5; i++) {

addTotalTimeAL[i] = (double) allTime[i][0];

addMedianTimeAL[i] = (double) allTime[i][1];

removeTotalTimeAL[i] = (double) allTime[i][2];

removeMedianTimeAL[i] = (double) allTime[i][3];

addTotalTimeLL[i] = (double) allTime[i][4];

addMedianTimeLL[i] = (double) allTime[i][5];

removeTotalTimeLL[i] = (double) allTime[i][6];

removeMedianTimeLL[i] = (double) allTime[i][7];

}

}

*/

/*

public static void createAndShowGUI() {

// Создание окон

JFrame[] frames = new JFrame[4];

for (int i = 0; i < 4; i++) {

frames[i] = new JFrame(labels[i]);

frames[i].setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

// Создание панелей с графиками

ChartPanel[][] chartPanels = new ChartPanel[4][2];

for (int i = 0; i < 4; i++) {

for (int j = 0; j < 2; j++) {

chartPanels[i][j] = new ChartPanel(i, j);

frames[i].getContentPane().add(chartPanels[i][j]);

}

}

// Установка размеров окон

for (JFrame frame : frames) {

frame.pack();

frame.setVisible(true);

}

}

*/

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

Graphics2D g2 = (Graphics2D) g;

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

int xStep = 50;

int yStep = 28;

int width = getWidth();

//int width = 1000;

////System.out.println("width: " + width);

int height = getHeight();

//int height = 500;

////System.out.println("height " + height);

double minX = Double.MAX_VALUE;

double maxX = Double.MIN_VALUE;

double minYAL = Double.MAX_VALUE;

double maxYAL = Double.MIN_VALUE;

double minYLL = Double.MAX_VALUE;

double maxYLL = Double.MIN_VALUE;

for (int i = 0; i < COLLECTION_SIZES.length; i++) {

minX = Math.min(minX, COLLECTION_SIZES[i]);

maxX = Math.max(maxX, COLLECTION_SIZES[i]);

minYAL = Math.min(minYAL, timeCollectionAL[i]);

maxYAL = Math.max(maxYAL, timeCollectionAL[i]);

minYLL = Math.min(minYLL, timeCollectionLL[i]);

maxYLL = Math.max(maxYLL, timeCollectionLL[i]);

}

/*

System.out.println("minX: " + minX);

System.out.println("maxX: " + maxX);

System.out.println("minY: " + minYAL);

System.out.println("maxY: " + maxYAL);

System.out.println("minZ: " + minYLL);

System.out.println("maxZ: " + maxYLL);

*/

double min;

if (minYAL < minYLL) {

min= minYAL;

}

else {

min= minYLL;

}

double max;

if (maxYAL > maxYLL) {

max= maxYAL + min;

}

else {

max= maxYLL + min;

}

//int xStepTwo = 1;

//int collectionLength = COLLECTION_SIZES.length;

//Определение масштаба для отображения графика

double xScale = 1000 / maxX;

int graphWidth = width - xStep * 2;

int graphHeight = (int) ((height - 60) + (0.1 / xScale));

//int graphHeight = height - xStep;

double yScaleAL = (graphHeight / (max - min));

////System.out.println("yScale: " + yScaleAL);

double yScaleLL = (graphHeight / (max - min));

////System.out.println("zScale: " + yScaleLL);

//Перевод координат в пиксели

int[] xPixels = new int[COLLECTION_SIZES.length];

int[] yPixelsAL = new int[timeCollectionAL.length];

int[] yPixelsLL = new int[timeCollectionLL.length];

for (int i = 0; i < COLLECTION_SIZES.length; i++) {

//System.out.println("Точка: " + i);

xPixels[i] = (int) (((COLLECTION_SIZES[i])) * xScale) + xStep;

//System.out.println("Координата х: " + (xPixels[i] - xStep));

yPixelsAL[i] = (int) ((max - timeCollectionAL[i]) * yScaleAL);

//System.out.println("addTotalTimeAL: " + timeCollectionAL[i]);

//System.out.println("Координата у: " + yPixelsAL[i]);

yPixelsLL[i] = (int) ((max - timeCollectionLL[i]) * yScaleLL);

//System.out.println("addTotalTimeLL: " + timeCollectionLL[i]);

//System.out.println("Координата z: " + yPixelsLL[i]);

}

//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

//Перекрас пространства для графика

g2.setColor(Color.WHITE);

g2.fillRect(xStep, 0, width, height - xStep);

//Нанесение клетки

g2.setColor(Color.lightGray);

int yStarstPoint = 0;

int xStarstPoint = 0;

//int len = yStep*50;

for (int i = 0; i <= 50; i++) {

g2.drawLine(0, yStarstPoint, getWidth(), yStarstPoint);

g2.drawLine(xStarstPoint, 0, xStarstPoint, getHeight());

yStarstPoint += yStep;

xStarstPoint += xStep;

}

Color lineColorAL = Color.BLUE;

Color pointColorAL = Color.RED;

Color lineColorLL = Color.GREEN;

Color pointColorLL = Color.ORANGE;

int sizePoint = 6;

//Отрисовка линий и точек

drawLineAndPoint(g2, xPixels, yPixelsAL, lineColorAL, pointColorAL, sizePoint);

drawLineAndPoint(g2, xPixels, yPixelsLL, lineColorLL, pointColorLL, sizePoint);

//Создание легенды

g2.setColor(Color.lightGray);

g2.fillRect(xStep * 9, 0, xStep * 3, yStep * 2);

g2.setColor(Color.BLACK);

g2.drawString("ArrayList", 10 * xStep - yStep - 5, yStep / 2 + 5);

g2.drawString("LinkedList", 10 * xStep - yStep - 5, yStep / 2 + yStep + 5);

g2.setColor(lineColorAL);

g2.drawLine(11 * xStep - 15, yStep / 2, 12 * xStep - 15, yStep / 2);

g2.setColor(lineColorLL);

g2.drawLine(11 * xStep - 15, yStep / 2 + yStep, 12 * xStep - 15, yStep / 2 + yStep);

g2.setColor(pointColorAL);

g2.fillOval((11 * xStep + (xStep / 2)) - (sizePoint / 2) - 15, yStep / 2 - (sizePoint / 2), sizePoint, sizePoint);

g2.setColor(pointColorLL);

g2.fillOval((11 * xStep + (xStep / 2)) - (sizePoint / 2) - 15, yStep / 2 + yStep - (sizePoint / 2), sizePoint, sizePoint);

//Закрашевание оставшегося пространства

g2.setColor(Color.lightGray);

g2.fillRect(0, 0, xStep, height);

g2.fillRect(0, height - xStep, width, height);

/*

g2.setColor(Color.BLACK);

g2.setStroke(new BasicStroke(3));

g2.drawLine(1, 0, 1, this.getHeight());

g2.drawLine(0, this.getHeight()-1, this.getWidth(), this.getHeight()-1);

*/

//Значения по оси х

g2.setColor(Color.BLACK);

//g2.drawString("0", 50 - 3, height - 50 + 10);

int xAxisStep = (int) (xStep / xScale);

for (int i = xAxisStep; i < width / xScale; i+=xAxisStep) {

g2.drawString(String.valueOf(i - xAxisStep), (int) (i * xScale) - 10, height - xStep + 10);

}

int maxYPixelsAL = getMaxValue(yPixelsAL);

int maxYPixelsLL = getMaxValue(yPixelsLL);

int minYPixelsAL = getMinValue(yPixelsAL);

int minYPixelsLL = getMinValue(yPixelsLL);

int minPixels;

if (minYPixelsAL < minYPixelsLL) {

minPixels = minYPixelsAL;

}

else {

minPixels = minYPixelsLL;

}

//System.out.println("minPixels: " + minPixels);

int maxPixels;

if (maxYPixelsAL > maxYPixelsLL) {

maxPixels = maxYPixelsAL;

}

else {

maxPixels = maxYPixelsLL;

}

/*

System.out.println("maxYPixels: " + maxYPixelsAL);

System.out.println("maxZPixels: " + maxYPixelsLL);

System.out.println("maxPixels: " + maxPixels);

*/

//Шаги по оси у

long onePixel = (long) ((max - min)/(maxPixels - minPixels)) * yStep;

long step = onePixel;

for (int i = height - xStep; i > yStep + 1; i-=yStep) {

g2.drawString(String.valueOf(onePixel), 1, i - yStep);

onePixel+=step;

}

//Подпись осей

g2.drawString("n, кол-во", getWidth() - yStep * 2, getHeight() - yStep);

g2.drawString("t, нс", yStep, yStep / 2);

/*

g2.drawString("1", getWidth()/2, getHeight()/2-50);

g2.drawString("2", getWidth()/2, getHeight()/2-100);

g2.drawString("3", getWidth()/2, getHeight()/2-150);

*/

/*

//Пунктир

g2.setColor(Color.BLACK);

for (int i = 0; i < xPixels.length; i++) {

int x1 = xPixels[i];

int y1 = yPixels[i];

//int x2 = xPixels[i + 1];

//int y2 = yPixels[i + 1];

int z1 = zPixels[i];

//int z2 = zPixels[i + 1];

//g2.drawLine(x1, y1, x2, y2);

//g2.drawLine(x1, z1, x2, z2);

float[] dashPattern = {5, 5};

BasicStroke dashedStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, dashPattern, 0);

g2.setStroke(dashedStroke);

g2.drawLine(0, y1, x1, y1);

g2.drawLine(0, z1, x1, z1);

}

*/

}

private int getMaxValue(int[] data) {

int maxValue = data[0];

for (int i = 1; i < data.length; i++) {

if (data[i] > maxValue) {

maxValue = data[i];

}

}

return maxValue;

}

private int getMinValue(int[] data) {

int minValue = data[0];

for (int i = 1; i < data.length; i++) {

if (data[i] < minValue) {

minValue = data[i];

}

}

return minValue;

}

private void drawLineAndPoint(Graphics2D g2, int[] xPixels, int[] yPixels, Color colorLine, Color colorPoint, int sizePoint) {

g2.setColor(colorLine);

//Отрисовка линий между точками

for (int i = 0; i < xPixels.length - 1; i++) {

int x1 = xPixels[i];

int x2 = xPixels[i + 1];

int y1 = yPixels[i];

int y2 = yPixels[i + 1];

g2.drawLine(x1, y1, x2, y2);

}

//Отрисовка точек

g2.setColor(colorPoint);

for (int i = 0; i < xPixels.length; i++) {

int x = xPixels[i];

int y = yPixels[i];

g2.fillOval(x - (sizePoint / 2), y - (sizePoint / 2), sizePoint, sizePoint);

}

}

}

Main

public static void main(String[] args) {

int len = 5;

int[] collection = {10, 100, 1000, 10000, 100000};

//int[] collection = {10, 100, 1000, 10000};

//int[] collection = {10, 100, 1000};

String[] labels = {"addTotalTime", "addMedianTime", "removeTotalTime", "removeMedianTime"};

double[] addTotalTimeAL = new double[len];

double[] addTotalTimeLL = new double[len];

double[] addMedianTimeAL = new double[len];

double[] addMedianTimeLL = new double[len];

double[] removeTotalTimeAL = new double[len];

double[] removeTotalTimeLL = new double[len];

double[] removeMedianTimeAL = new double[len];

double[] removeMedianTimeLL = new double[len];

ProductList generator = new ProductList(collection);

long[][] allTime = generator.generateCollections();

for (int i = 0; i < len; i++) {

addTotalTimeAL[i] = (double) allTime[i][0];

addMedianTimeAL[i] = (double) allTime[i][1];

removeTotalTimeAL[i] = (double) allTime[i][2];

removeMedianTimeAL[i] = (double) allTime[i][3];

addTotalTimeLL[i] = (double) allTime[i][4];

addMedianTimeLL[i] = (double) allTime[i][5];

removeTotalTimeLL[i] = (double) allTime[i][6];

removeMedianTimeLL[i] = (double) allTime[i][7];

}

ArrayList<double[]> collectionsAL = new ArrayList<>();

collectionsAL.add(addTotalTimeAL);

collectionsAL.add(addMedianTimeAL);

collectionsAL.add(removeTotalTimeAL);

collectionsAL.add(removeMedianTimeAL);

ArrayList<double[]> collectionsLL = new ArrayList<>();

collectionsLL.add(addTotalTimeLL);

collectionsLL.add(addMedianTimeLL);

collectionsLL.add(removeTotalTimeLL);

collectionsLL.add(removeMedianTimeLL);

LogProcessor logProcessor = new LogProcessor();

//ErrorProcessor errorProcessor = new ErrorProcessor();

int errorCount = logProcessor.getErrorCount();

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 8; j++) {

//System.out.println("Элемент " + i + ", " + j + ": " + allTime[i][j]);

}

}

//draw.getData(allTime);

//Draw.createAndShowGUI();

for (int i = 0; i < labels.length; i++) {

JFrame frame = new JFrame(labels[i]);

Draw draw = new Draw(collectionsAL.get(i), collectionsLL.get(i), collection);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(1100, 650);

frame.add(draw);

frame.setVisible(true);

}

if (errorCount > 0) {

System.out.println("Количество ошибок: " + errorCount);

} else {

System.out.println("Всё успешно выполнено.");

}

}

Соседние файлы в предмете Основы языка Java