Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 5157b19

Browse files
authored
Merge pull request #644 from AndrewSkrypov/Future
Лабораторные 1-32
2 parents dc304e3 + ef378be commit 5157b19

File tree

136 files changed

+3758
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+3758
-1
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
<module>students/23K0186</module>
8282
<module>students/23K0755</module>
8383
<module>students/23K1292</module>
84-
8584
</modules>
8685
<dependencies>
8786
<dependency>

students/23K0368/23K0368-p21/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0368</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0368-p21</artifactId>
12+
<description>Стирание типов в Java</description>
13+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.mirea.practice.s0000001.prog1;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public abstract class Main {
7+
public static List<String> convertArrayToList(String[] array) {
8+
return Arrays.asList(array);
9+
}
10+
11+
// Метод для конвертации массива чисел в список
12+
public static List<Integer> convertArrayToList(Integer[] array) {
13+
return Arrays.asList(array);
14+
}
15+
16+
public static void main(String[] args) {
17+
String[] stringArray = {"apple", "banana", "cherry"};
18+
Integer[] intArray = {1, 2, 3, 4, 5};
19+
20+
List<String> stringList = convertArrayToList(stringArray);
21+
List<Integer> intList = convertArrayToList(intArray);
22+
23+
System.out.println("Список строк: " + stringList);
24+
System.out.println("Список чисел: " + intList);
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.mirea.practice.s0000001.prog2;
2+
3+
import java.util.Arrays;
4+
5+
public class AllType {
6+
private final Object[] array;
7+
8+
public AllType(Object[] array) {
9+
this.array = array;
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return Arrays.toString(array);
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.mirea.practice.s0000001.prog2;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
Integer[] mas1 = {1, 2, 3, 4};
6+
AllType intmas1 = new AllType(mas1);
7+
System.out.println("Integer array: " + intmas1);
8+
}
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001.prog3;
2+
3+
import java.util.Arrays;
4+
5+
public class AllType<T> {
6+
private T[] array;
7+
8+
public AllType(T[] array) {
9+
this.array = array;
10+
}
11+
12+
public T getElement(int index) {
13+
if (index >= 0 && index < array.length) {
14+
return array[index];
15+
} else {
16+
throw new IndexOutOfBoundsException("Index is out of bounds");
17+
}
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return Arrays.toString(array);
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.mirea.practice.s0000001.prog3;
2+
3+
public abstract class Main {
4+
public static void main(String[] args) {
5+
AllType<Integer> intAllType = new AllType<>(new Integer[]{1, 2, 3, 4, 5});
6+
System.out.println("Integer array: " + intAllType);
7+
8+
AllType<String> stringAllType = new AllType<>(new String[]{"apple", "banana", "cherry"});
9+
System.out.println("String array: " + stringAllType);
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s0000001.prog4;
2+
3+
import java.util.Arrays;
4+
5+
public class AllType<T> {
6+
private T[] array;
7+
8+
public AllType(T[] array) {
9+
this.array = array;
10+
}
11+
12+
public T getElement(int index) {
13+
if (index >= 0 && index < array.length) {
14+
return array[index];
15+
} else {
16+
throw new IndexOutOfBoundsException("Index is out of bounds");
17+
}
18+
}
19+
20+
public int getLength() {
21+
return array.length;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return Arrays.toString(array);
27+
}
28+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package ru.mirea.practice.s0000001.prog4;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
public abstract class Main {
9+
public static List<Object> getDirectoryContents(String directorypath) {
10+
File directory = new File(directorypath);
11+
List<Object> contents = new ArrayList<>();
12+
13+
if (directory.isDirectory()) {
14+
File[] files = directory.listFiles();
15+
if (files != null) {
16+
contents.addAll(Arrays.asList(files));
17+
}
18+
} else {
19+
System.out.println("Указанный путь ошибочен");
20+
throw new IllegalStateException("Invalid");
21+
}
22+
23+
return contents;
24+
}
25+
26+
public static void print(AllType<Object> list) {
27+
System.out.println("Первые 5 элементов содержимого каталога:");
28+
for (int i = 0; i < Math.min(5, list.getLength()); i++) {
29+
System.out.println((i + 1) + ". " + list.getElement(i));
30+
}
31+
}
32+
33+
public static void main(String[] args) {
34+
String path = "Path";
35+
try {
36+
List<Object> content = getDirectoryContents(path);
37+
38+
AllType<Object> directoryContents = new AllType<>(content.toArray());
39+
print(directoryContents);
40+
} catch (IllegalStateException e) {
41+
System.out.println("Ошибка: " + e.getMessage());
42+
}
43+
}
44+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s0000001.prog5;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
public abstract class Main {
8+
public static void main(String[] args) {
9+
List<Integer> list = Solution.newArrayList(1, 2, 3, 4);
10+
System.out.println("Integer elements(ArrayList)" + list);
11+
12+
Set<String> set = Solution.newHashSet("T90", "T80", "T54", "T72Б3");
13+
System.out.println("String elements(HashSet)" + set);
14+
15+
Map<String, Integer> map = Solution.newHashMap(
16+
new Pair<>("T90", 90),
17+
new Pair<>("T80", 80),
18+
new Pair<>("T54", 54),
19+
new Pair<>("T72Б3", 72)
20+
);
21+
System.out.println("Map<String, Integer>" + map);
22+
}
23+
}

0 commit comments

Comments
 (0)