Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
--- eigene generische liste (http://www.informatikerboard.de/board/thread.php?threadid=3297)


Geschrieben von generischeliste_ am 13.11.2016 um 15:40:

  eigene generische liste

Meine Frage:
Erstellen Sie auf Basis Ihrer IntList eine Klasse, die als Liste für beliebige Typen fungiert.

Meine Ideen:
public class SimpleArrayList <ListedType>
{
private int length;
private int grow;
private ListedType[] buffer;
public SimpleArrayList(
int InitialLength, int grow){}
public SimpleArrayList (
ListedType[] InitialArray, int grow){}
private void ArrayCopy (
ListedType[] Source,
ListedType[] Destination){}
public int getLength(){}
public void setAt(
int index, ListedType value){}
public ListedType getAt(int index){}
}


public SimpleArrayList(
int InitialLength,
int grow)


public SimpleArrayList (
ListedType[] InitialArray, int grow) throws ArrayCopyException
{
length = InitialArray.length;
this.grow = grow;
buffer = (ListedType[])
Array.newInstance(
buffer.getClass().getComponentType(), InitialArray.length);
ArrayCopy (InitialArray, buffer);
}

private void ArrayCopy (
ListedType[] Source,
ListedType[] Destination)
throws ArrayCopyException
{
if (Source.length <= Destination.length)
{
for (int i = 0; i < Source.length; i++)
{
Destination[i] = Source[i];
}
}
else
{
throw new ArrayCopyException(
Source.length,
Destination.length);
}
}

public int getLength()
{
return length;
}

public ListedType getAt(int index)
{
// Wirft im Fehlerfall die gleiche
// Exception, wie ein Array
return buffer[index];
}

public void setAt(int index, ListedType value)
throws ArrayCopyException
{
int NewLength = buffer.length;
while (index >= NewLength)
{
NewLength += grow;
}
if (NewLength != buffer.length)
{
ListedType[] tmp = (ListedType[])
Array.newInstance(
buffer.getClass().getComponentType(), NewLength);
ArrayCopy(buffer, tmp);
buffer = tmp;
}
buffer[index] = value;
if (length <= index)
{
length = index+1;
}
}

import java.util.ArrayList;


public class Lecture
{
public String Semester;
public Lecturer Lecturer;
public ArrayList<Student> Participants;
}




{
length= 0;
this.grow = grow;
buffer = (ListedType[])
Array.newInstance(
buffer.getClass().getComponentType(), InitialLength);
}

könnt ihr mir bitte dabei helfen, wie ich diesen Quellcode richtig zusammenstelle?


Forensoftware: Burning Board, entwickelt von WoltLab GmbH