Skip to content
Snippets Groups Projects
Commit 3e8310b2 authored by rasmusse's avatar rasmusse
Browse files

Main: Objekt vom Typ Buffer erstellt

parent 48373d22
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
public class Buffer<T>{ public class Buffer<T>{
public int size; public int size;
public Semaphore mutex; public Semaphore mutex;
List<T> items = new ArrayList<T>(); List<T> items = new ArrayList<T>();
public Buffer(int size) {
public Buffer(int size ) {
this.size= size; this.size= size;
}
public void push(Buffer<?> e) throws InterruptedException { public void push(Buffer<?> e) throws BufferOverflowException {
mutex.acquire(); mutex.acquire();
items.add(T.e); items.add(T.e);
mutex.release(); mutex.release();
} }
public void pop(){ public void pop() throws BufferUnderflowException {
} }
......
public class Car { public class Car {
} }
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello world!");
Buffer b1 = new Buffer(5); //Capacity of the Buffer
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment