Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/Generics/Generics.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-24" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
35 changes: 35 additions & 0 deletions src/Generics/src/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class ArrayList <T> {

private int currentSize;
private Object[] arrayList;
private final int DEFAULT_SIZE = 10;

public ArrayList() {
this.currentSize = 0;
this.arrayList = new Object[DEFAULT_SIZE];
}

public void add(T added) {
if (currentSize == arrayList.length) {
Object [] arrayList2 = new Object[arrayList.length+ DEFAULT_SIZE];
for (int i = 0; i < arrayList.length; i++) {
arrayList2[i] = arrayList[i];
}
Comment on lines +15 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this, but System.arraycopy is faster and cleaner

arrayList = arrayList2;
}
arrayList[currentSize] = added;
currentSize++;
}

public T get(int place) {
return (T)arrayList[place];
}

public void set(int place, Object newValue) {
arrayList[place] = newValue;
}

public int getCurrentSize() {
return currentSize;
}
}
7 changes: 7 additions & 0 deletions src/Generics/src/InformationSignal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public interface InformationSignal <T> {

T getLastestValue();
void Update();
asArray();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your code should compile


}
19 changes: 19 additions & 0 deletions src/Generics/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Main {

public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();

list.add(1);


for (int i = 0; i < 3; i++) {
System.out.println(list.get(i));
}
}

public <T> void arrayListPrint(ArrayList<T> list) {
for (int i = 0; i < list.getCurrentSize(); i++) {
System.out.println(list.get(i).toString());
}
}
}
25 changes: 14 additions & 11 deletions src/src/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.

public class Main {

public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
ArrayList<Integer> list = new ArrayList<>(10);

list.add(1);
list.add("1");
list.add(true)

for (int i = 0; i < 3; i++) {
System.out.println(list.get(i));
}
}



}