Compare commits
3 commits
5e93294c38
...
11983e0f08
Author | SHA1 | Date | |
---|---|---|---|
11983e0f08 | |||
aaea1a9d87 | |||
ce65993bee |
2 changed files with 373 additions and 329 deletions
|
@ -32,7 +32,7 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
private final Dimension UHDTHRESHOLD = new Dimension(2000, 1500);
|
private final Dimension UHDTHRESHOLD = new Dimension(2000, 1500);
|
||||||
private final String STANDARDENCODING = "UTF-8";
|
private final String STANDARDENCODING = "UTF-8";
|
||||||
|
|
||||||
private JMenuItem connect, exit, open, test, retest, textView, graphicView, clear;
|
private JMenuItem connect, reset, exit, open, test, retest, textView, graphicView, clear;
|
||||||
private JMenu menuServer;
|
private JMenu menuServer;
|
||||||
private JButton enter;
|
private JButton enter;
|
||||||
private JTextField arguments;
|
private JTextField arguments;
|
||||||
|
@ -80,6 +80,9 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
connect = new JMenuItem("Connect ...");
|
connect = new JMenuItem("Connect ...");
|
||||||
connect.addActionListener(this);
|
connect.addActionListener(this);
|
||||||
menuServer.add(connect);
|
menuServer.add(connect);
|
||||||
|
reset = new JMenuItem("Reset Server...");
|
||||||
|
reset.addActionListener(this);
|
||||||
|
menuServer.add(reset);
|
||||||
|
|
||||||
JMenu menuView = new JMenu("View");
|
JMenu menuView = new JMenu("View");
|
||||||
menuBar.add(menuView);
|
menuBar.add(menuView);
|
||||||
|
@ -183,10 +186,6 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(String args) throws Exception {
|
private void execute(String args) throws Exception {
|
||||||
if (lastServer != null) {
|
|
||||||
command = ServerFactory.createServer(lastServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!arguments.getText().equals(history.getItemAt(0))
|
if (!arguments.getText().equals(history.getItemAt(0))
|
||||||
&& !arguments.getText().equals(history.getSelectedItem())) {
|
&& !arguments.getText().equals(history.getSelectedItem())) {
|
||||||
history.insertItemAt(arguments.getText(), 0);
|
history.insertItemAt(arguments.getText(), 0);
|
||||||
|
@ -251,7 +250,7 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
|
|
||||||
private void connectCommand() throws Exception {
|
private void connectCommand() throws Exception {
|
||||||
String name = openFileDialog(getPathCompiled(), "*Server.class");
|
String name = openFileDialog(getPathCompiled(), "*Server.class");
|
||||||
command = ServerFactory.createServer(name);
|
loadServer(name);
|
||||||
lastServer = name;
|
lastServer = name;
|
||||||
String fullClassName = command.getClass().getName();
|
String fullClassName = command.getClass().getName();
|
||||||
String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
|
String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
|
||||||
|
@ -259,6 +258,16 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetCommand() throws Exception {
|
||||||
|
if (lastServer != null) {
|
||||||
|
loadServer(lastServer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadServer(String name) throws Exception {
|
||||||
|
command = ServerFactory.createServer(name);
|
||||||
|
}
|
||||||
|
|
||||||
private void openFile() throws Exception {
|
private void openFile() throws Exception {
|
||||||
String name = openFileDialog(null, null);
|
String name = openFileDialog(null, null);
|
||||||
|
|
||||||
|
@ -291,6 +300,8 @@ public class ExBoxFrame extends JFrame implements ActionListener, ItemListener {
|
||||||
execute(arguments.getText());
|
execute(arguments.getText());
|
||||||
} else if (e.getSource() == connect) {
|
} else if (e.getSource() == connect) {
|
||||||
connectCommand();
|
connectCommand();
|
||||||
|
} else if (e.getSource() == reset) {
|
||||||
|
resetCommand();
|
||||||
} else if (e.getSource() == test) {
|
} else if (e.getSource() == test) {
|
||||||
testCommand(false);
|
testCommand(false);
|
||||||
} else if (e.getSource() == retest) {
|
} else if (e.getSource() == retest) {
|
||||||
|
|
|
@ -6,37 +6,69 @@ import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class MyHashtable<K, V> implements Map<K, V> {
|
public class MyHashtable<K, V> implements Map<K, V> {
|
||||||
|
private int capacity;
|
||||||
|
private int size;
|
||||||
private K[] keys = (K[]) new Object[10];
|
private K[] keys = (K[]) new Object[10];
|
||||||
private V[] values = (V[]) new Object[10];
|
private V[] values = (V[]) new Object[10];
|
||||||
|
|
||||||
|
public MyHashtable(int size) {
|
||||||
|
capacity = size;
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hashEquals(Object x, Object y) {
|
||||||
|
if (x == null || y == null) {
|
||||||
|
return x == y;
|
||||||
|
} else {
|
||||||
|
return x.hashCode() == y.hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int hash(Object k) {
|
private int hash(Object k) {
|
||||||
int h = Math.abs(k.hashCode());
|
int h = Math.abs(k.hashCode());
|
||||||
return h % keys.length;
|
return h % keys.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyHashtable(int size) {
|
|
||||||
// to be done
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes all mappings from this map (optional operation).
|
// Removes all mappings from this map (optional operation).
|
||||||
public void clear() {
|
public void clear() {
|
||||||
// to be done
|
keys = (K[]) new Object[capacity];
|
||||||
throw new UnsupportedOperationException();
|
values = (V[]) new Object[capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associates the specified value with the specified key in this map (optional operation).
|
// Associates the specified value with the specified key in this map (optional
|
||||||
|
// operation).
|
||||||
public V put(K key, V value) {
|
public V put(K key, V value) {
|
||||||
// to be done
|
int hashCode = hash(key);
|
||||||
throw new UnsupportedOperationException();
|
int index = hashCode;
|
||||||
|
|
||||||
|
for (int i = 0; keys[index] != null && !hashEquals(keys[index], key); i++) {
|
||||||
|
index = hash(hashCode + (int) Math.pow(i, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keys[index] == null) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys[index] = key;
|
||||||
|
values[index] = value;
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the value to which this map maps the specified key.
|
// Returns the value to which this map maps the specified key.
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
// to be done
|
// to be done
|
||||||
throw new UnsupportedOperationException();
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
if (hashEquals(key, keys[i])) {
|
||||||
|
return values[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the mapping for this key from this map if present (optional operation).
|
// Removes the mapping for this key from this map if present (optional
|
||||||
|
// operation).
|
||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
// to be done (Aufgabe 3)
|
// to be done (Aufgabe 3)
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -44,11 +76,11 @@ public class MyHashtable<K, V> implements Map<K, V> {
|
||||||
|
|
||||||
// Returns the number of key-value mappings in this map.
|
// Returns the number of key-value mappings in this map.
|
||||||
public int size() {
|
public int size() {
|
||||||
// to be done
|
return size;
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnsupportedOperationException ===================================================================
|
// UnsupportedOperationException
|
||||||
|
// ===================================================================
|
||||||
// Returns a collection view of the values contained in this map.
|
// Returns a collection view of the values contained in this map.
|
||||||
public Collection<V> values() {
|
public Collection<V> values() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -74,7 +106,8 @@ public class MyHashtable<K, V> implements Map<K, V> {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copies all of the mappings from the specified map to this map (optional operation).
|
// Copies all of the mappings from the specified map to this map (optional
|
||||||
|
// operation).
|
||||||
public void putAll(Map<? extends K, ? extends V> t) {
|
public void putAll(Map<? extends K, ? extends V> t) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue