Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ecd1c4
feat: implement Cube interface for RubicsCube
mirotvoretts Feb 6, 2026
c2ee820
atm: solved
mirotvoretts Feb 7, 2026
c0ce423
feat: implement Cube interface for RubicsCube
mirotvoretts Feb 6, 2026
5d4af8c
atm: solved
mirotvoretts Feb 7, 2026
ab64a83
cube: rerun tests
mirotvoretts Feb 7, 2026
9fb4e35
cube: rerun tests
mirotvoretts Feb 7, 2026
52f83c1
cube: try one more time
mirotvoretts Feb 7, 2026
01f4cce
cube: fix atm tests
mirotvoretts Feb 7, 2026
84c0ef5
cube: fix reverse direction for permutation matrixes
mirotvoretts Feb 7, 2026
534303a
cube: fix right clockwise
mirotvoretts Feb 7, 2026
0250036
randomset: first working version
mirotvoretts Feb 13, 2026
be13706
randomset: throw exception on empty set access
mirotvoretts Feb 13, 2026
7c40a94
randomset: remove throwing exception on first insert
mirotvoretts Feb 13, 2026
c5d1b7d
randomset: remove throwing exception on contains
mirotvoretts Feb 13, 2026
cdd2f79
randomset: fix infinite recursion
mirotvoretts Feb 13, 2026
7d513d8
randomset: T must be comparable
mirotvoretts Feb 13, 2026
02cc65f
randomset: fix nulling tree if insert duplicate
mirotvoretts Feb 13, 2026
b485960
randomset: trying to fix
mirotvoretts Feb 13, 2026
de59e56
randomset: rewrite to treap
mirotvoretts Feb 13, 2026
ffaf577
randomset: refactor - split treap and randomset
mirotvoretts Feb 13, 2026
af30199
Merge branch 'Panov_I_A_task_2' of github.com:mirotvoretts/hse-java
mirotvoretts Feb 27, 2026
eac9376
commander: implement far manager clone
mirotvoretts Feb 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 95 additions & 19 deletions commander/src/main/java/hse/java/commander/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,111 @@

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;

public class MainController {
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class MainController {
@FXML
public Button move;
@FXML
public ListView<String> left;
@FXML
public ListView<String> right;
@FXML
public Label leftPathLabel;
@FXML
public Label rightPathLabel;

private File leftDirectory = new File(System.getProperty("user.home"));
private File rightDirectory = new File(System.getProperty("user.home"));

public void initialize() {
move.setOnMouseClicked(event -> {
refresh(left, leftDirectory);
refresh(right, rightDirectory);

left.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
handleNavigation(left, true);
}
});
System.out.println(System.getProperty("user.home"));
left.getItems().add("Kek");

left.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
int index = left.getSelectionModel().getSelectedIndex();
if (index >= 0) {
left.getItems().set(index, "clicked");
}
}
});
}

@FXML
public ListView<String> left;
right.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
handleNavigation(right, false);
}
});

@FXML
public ListView<String> right;
move.setOnAction(event -> moveFile());
}

private void refresh(ListView<String> list, File directory) {
list.getItems().clear();
list.getItems().add("..");
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
list.getItems().add(file.isDirectory() ? "[" + file.getName() + "]" : file.getName());
}
}
if (list == left) {
leftPathLabel.setText(directory.getAbsolutePath());
} else {
rightPathLabel.setText(directory.getAbsolutePath());
}
}

private void handleNavigation(ListView<String> list, boolean isLeft) {
String selected = list.getSelectionModel().getSelectedItem();
if (selected == null) return;

File currentDir = isLeft ? leftDirectory : rightDirectory;
File nextDirectory;

if (selected.equals("..")) {
nextDirectory = currentDir.getParentFile();
} else {
String name = selected.replace("[", "").replace("]", "");
nextDirectory = new File(currentDir, name);
}

if (nextDirectory != null && nextDirectory.isDirectory()) {
if (isLeft) {
leftDirectory = nextDirectory;
} else {
rightDirectory = nextDirectory;
}
refresh(list, nextDirectory);
}
}

private void moveFile() {
boolean moveFromLeft = left.getSelectionModel().getSelectedItem() != null;
ListView<String> fromList = moveFromLeft ? left : right;
File fromDirectory = moveFromLeft ? leftDirectory : rightDirectory;
File toDirectory = moveFromLeft ? rightDirectory : leftDirectory;

String selected = fromList.getSelectionModel().getSelectedItem();

if (selected == null || selected.equals("..")) {
return;
}

String name = selected.replace("[", "").replace("]", "");
Path source = new File(fromDirectory, name).toPath();
Path destination = new File(toDirectory, name).toPath();

}
try {
Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
refresh(left, leftDirectory);
refresh(right, rightDirectory);
} catch (IOException e) {
System.err.println("Анлак, не удалось перенести: " + e.getMessage());
}
}
}
25 changes: 19 additions & 6 deletions commander/src/main/resources/hse/java/commander/commander-ui.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="421.0" prefWidth="627.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hse.java.commander.MainController">
<HBox prefHeight="370.0" prefWidth="627.0">
<VBox prefHeight="500.0" prefWidth="700.0" spacing="10" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hse.java.commander.MainController">
<padding>
<Insets top="10" right="10" bottom="10" left="10"/>
</padding>

<ListView fx:id="left" prefHeight="318.0" prefWidth="311.0" />
<ListView fx:id="right" prefHeight="318.0" prefWidth="321.0" />
<HBox spacing="10" VBox.vgrow="ALWAYS">
<VBox HBox.hgrow="ALWAYS" spacing="5">
<Label fx:id="leftPathLabel" style="-fx-font-weight: bold;"/>
<ListView fx:id="left" VBox.vgrow="ALWAYS" />
</VBox>

<VBox HBox.hgrow="ALWAYS" spacing="5">
<Label fx:id="rightPathLabel" style="-fx-font-weight: bold;"/>
<ListView fx:id="right" VBox.vgrow="ALWAYS" />
</VBox>
</HBox>
<Button fx:id="move" mnemonicParsing="false" text="Move" />
</VBox>

<HBox spacing="10" alignment="CENTER_LEFT">
<Button fx:id="move" text="Move" prefWidth="120" />
</HBox>
</VBox>
22 changes: 20 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
<maven.surefire.version>3.1.2</maven.surefire.version>
<!-- Lombok version property to keep versions consistent -->
<lombok.version>1.18.38</lombok.version>
</properties>

<dependencies>
Expand All @@ -38,6 +40,12 @@
<version>2.17.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -47,8 +55,18 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package hse.java.lectures.lecture3.practice.randomSet;

import lombok.Getter;
import lombok.Setter;

@Getter
public class Node<T> {
@Setter
private T value;
@Setter
private Node<T> left;
@Setter
private Node<T> right;
private int size;

public Node(T value) {
size = 1;
this.value = value;
this.left = null;
this.right = null;
}

public void recalculateSize() {
size = 1;
if (left != null) {
size += left.getSize();
}
if (right != null) {
size += right.getSize();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package hse.java.lectures.lecture3.practice.randomSet;

public record Pair<L, R>(L left, R right) {
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package hse.java.lectures.lecture3.practice.randomSet;

public class RandomSet<T> {
import java.util.Random;

public class RandomSet<T extends Comparable<T>> {
private final Treap<T> treap;
private final Random random = new Random();

public RandomSet() {
treap = new Treap<>();
}

public boolean insert(T value) {
throw new UnsupportedOperationException("Not implemented");
return treap.tryInsert(value);
}

public boolean remove(T value) {
throw new UnsupportedOperationException("Not implemented");
return treap.tryRemove(value);
}

public boolean contains(T value) {
throw new UnsupportedOperationException("Not implemented");
return treap.contains(value);
}

public T getRandom() {
throw new UnsupportedOperationException("Not implemented");
if (treap.getSize() == 0) {
throw new EmptySetException("Set is empty");
}
int randomIndex = random.nextInt(treap.getSize());
return treap.get(randomIndex);
}

}
110 changes: 110 additions & 0 deletions src/main/java/hse/java/lectures/lecture3/practice/randomSet/Treap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package hse.java.lectures.lecture3.practice.randomSet;

import java.util.Optional;
import java.util.Random;

public class Treap<T extends Comparable<T>> {
private Node<T> root;
private final Random random;

public Treap() {
root = null;
random = new Random();
}

private boolean findByValue(Node<T> node, T value) {
if (node == null) {
return false;
}
int compareResult = node.getValue().compareTo(value);
if (compareResult == 0) {
return true;
}
if (compareResult > 0) {
return findByValue(node.getLeft(), value);
}
return findByValue(node.getRight(), value);
}

private Optional<T> findByIndex(Node<T> currentNode, int index) {
if (currentNode == null) {
return Optional.empty();
}
int leftSize = currentNode.getLeft() != null ? currentNode.getLeft().getSize() : 0;
if (index < leftSize) {
return findByIndex(currentNode.getLeft(), index);
} else if (index == leftSize) {
return Optional.of(currentNode.getValue());
} else {
return findByIndex(currentNode.getRight(), index - leftSize - 1);
}
}

private Pair<Node<T>, Node<T>> split(Node<T> currentNode, T value) {
if (currentNode == null) {
return new Pair<>(null, null);
}
int compareResult = currentNode.getValue().compareTo(value);
if (compareResult == 0) {
return new Pair<>(currentNode.getLeft(), currentNode.getRight());
} else if (compareResult < 0) {
var splitResult = split(currentNode.getRight(), value);
currentNode.setRight(splitResult.left());
currentNode.recalculateSize();
return new Pair<>(currentNode, splitResult.right());
} else {
var splitResult = split(currentNode.getLeft(), value);
currentNode.setLeft(splitResult.right());
currentNode.recalculateSize();
return new Pair<>(splitResult.left(), currentNode);
}
}

private Node<T> merge(Node<T> leftNode, Node<T> rightNode) {
if (leftNode == null) {
return rightNode;
}
if (rightNode == null) {
return leftNode;
}
if (random.nextInt(leftNode.getSize() + rightNode.getSize()) < leftNode.getSize()) {
leftNode.setRight(merge(leftNode.getRight(), rightNode));
leftNode.recalculateSize();
return leftNode;
} else {
rightNode.setLeft(merge(leftNode, rightNode.getLeft()));
rightNode.recalculateSize();
return rightNode;
}
}

public int getSize() {
return root != null ? root.getSize() : 0;
}

public boolean contains(T value) {
return findByValue(root, value);
}

public boolean tryInsert(T value) {
if (contains(value)) {
return false;
}
var splitResult = split(root, value);
root = merge(merge(splitResult.left(), new Node<>(value)), splitResult.right());
return true;
}

public boolean tryRemove(T value) {
if (!contains(value)) {
return false;
}
var splitResult = split(root, value);
root = merge(splitResult.left(), splitResult.right());
return true;
}

public T get(int index) {
return findByIndex(root, index).orElseThrow(() -> new IllegalArgumentException("Index out of bounds"));
}
}
Loading
Loading