id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
70a21784-12f1-492a-b500-7751b40e6c8c | public static ArrayList<Hash> getNeighbours(byte[] field, int levels) {
ArrayList<Hash> array = new ArrayList<>();
for (int i = 0; i < levels; i++) {
byte[] help = new byte[20];
System.arraycopy(field, i * 20, help, 0, 20);
array.add(new Hash(help));
}
return array;
} |
8e439d4f-4857-414f-9cbe-a1b3d898205e | private void write(ArrayList<byte[]> datas, int size) {
byte[] stream = new byte[size];
int offset = 0;
for (byte[] b : datas) {
System.arraycopy(b, 0, stream, offset, b.length);
offset += b.length;
}
ADSTool.saveByteArray(outputfile, ADSTool.depad(stream));
} |
84fc6b7d-8cf8-482e-8dbd-8d92a8c64759 | public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Verwendung: <Eingabedatei> <Blocklänge> <Fehlerquote in Promille>");
System.exit(-1);
}
String filename = args[0];
int blocksize = 0, errorquote = 0;
try {
blocksize = Integer.parseInt(args[1]);
errorquote = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
System.err.println("Blocklänge und Fehlerpromille müssen Ganzzahlwerte enthalten!");
System.exit(-1);
}
System.out.println("Starting server with file " + filename + ", blocksize " + blocksize + " and errorquote " + errorquote + "/1000");
HashServer server = new HashServer(filename, blocksize, errorquote);
ServeBytes byteServer = new ServeBytes(server);
byteServer.serve();
} |
0d15c4a4-0370-4418-9f2d-9c5a0fa17d45 | @Test
public void createBT() {
BinaryTree bt = new BinaryTree(10);
bt.add(5);
bt.add(6);
bt.add(7);
bt.add(8);
bt.add(1);
bt.add(3);
bt.add(2);
} |
2e35a773-af80-43ff-8810-2a1d8689dba8 | public static void main(String[] args) {
LinkedList ll = new LinkedList();
} |
f6ca50b3-b6c5-45e4-b8cc-e1bebe5a8a43 | @Test
public void addNewElement(){
LinkedList linkedList = new LinkedList();
assertTrue(linkedList.isEmpty());
linkedList.add("First");
assertFalse(linkedList.isEmpty());
linkedList.add("Second");
assertFalse(linkedList.isEmpty());
linkedList.add("Third");
assertFalse(linkedList.isEmpty());
linkedList.displayAll();
assertTrue(linkedList.contains("Second"));
linkedList.remove("Second");
assertFalse(linkedList.isEmpty());
linkedList.displayAll();
assertFalse(linkedList.contains("Second"));
linkedList.removeFirst();
linkedList.removeFirst();
assertTrue(linkedList.isEmpty());
} |
df17d168-1475-45d0-aea4-e06222128ff4 | public BinaryTree(int i) {
this.root = new Node(i);
} |
36dba472-efd2-4864-a48f-b9fd049c76f4 | public Node findLCA(Node root, int v1, int v2) {
if (root == null)
return null;
if (root.data == v1 || root.data == v2) // this is the LCA for this case as ROOT value equals to one of the V1-2 values
return root;
// check if ROOT.left or ROOT.right elements are the LCA
Node left = findLCA(root.left, v1, v2);
Node right = findLCA(root.right, v1, v2);
if (left != null && right != null) {
// v1 and v2 are on different branches so left and right elements' root is LCA
return root;
} else if (left != null) {
// v1 and v2 are on the same branch on the left
return left;
} else {
// v1 and v2 are on the same branch on the right
return right;
}
} |
ef136198-97b6-4f55-ba60-4e4cebfc6641 | public void add(int i) {
} |
e0c88685-c1cd-4841-8b0a-24b3d18e9383 | public Node(int data) {
this.data = data;
} |
53887032-46eb-46b8-83b1-51e413cd837b | @Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Node)) return false;
Node bstNode = (Node) o;
return bstNode.data == data;
} |
d21108ac-2c30-464a-8520-db97207bbc0e | @Override
public int hashCode() {
return data * 31;
} |
739ee752-f3a3-4e46-bb63-531614cc92e4 | public BST() {
} |
73a659dd-18cd-44ec-bd86-5f48602b4f89 | private static Node findLCA(Node root, int n1, int n2) {
if (root == null)
return null;
// if n1 and n2 smaller than root, then LCA lies in left
if (n1 < root.data && n2 < root.data) {
return findLCA(root.left, n1, n2);
}
// if n1 and n2 larger than root, then LCA lies in right
if (n1 > root.data && n2 > root.data) {
return findLCA(root.right, n1, n2);
}
return root;
} |
d2c3e4b9-7f23-4820-bbaa-44e42d1e9c3a | public static Node findLCAIterative(Node root, int v1, int v2) {
if (root == null)
return null;
while (root != null) {
if (v1 < root.data && v2 < root.data) {
root = root.left;
} else if (v1 > root.data && v2 > root.data) {
root = root.left;
} else {
break;
}
}
return root;
} |
399e5fb9-e719-45c2-ac4c-cae1b7e564e7 | public boolean isBST() {
return isBSTHelper(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
} |
adcfc3b0-49fa-45ad-b316-79e10c39e085 | private boolean isBSTHelper(Node root, int minValue, int maxValue) {
if (root == null) return true;
if (minValue < root.data && maxValue >= root.data) {
return isBSTHelper(root.left, minValue, root.data) && isBSTHelper(root.right, root.data, maxValue);
} else {
return false;
}
} |
a31e50fe-e2d4-4fc9-be31-f746e09df57c | public Item(String data) {
this.data = data;
} |
ea2dfa0a-5c5d-4f45-b102-f0bfe48d3ba3 | public void display(){
System.out.println(data);
} |
08bda1d8-8324-4059-9ddf-c76224fa76df | public boolean isEmpty() {
return first == null;
} |
1342626b-06d6-448f-a206-9d8c2c7907a2 | public void add(String newElement) {
Item newItem = new Item(newElement);
newItem.next = first;
first = newItem;
} |
c6b2856b-88bf-4bb0-978c-b06d343e3383 | public Item removeFirst() {
Item el1 = first;
if (!isEmpty()) {
first = first.next;
} else {
System.out.println("List empty");
}
return el1;
} |
eb60ae93-f3a4-4b99-81e3-fb43f8cdac72 | public void displayAll() {
if (!isEmpty()) {
Item i = first;
while (i != null) {
i.display();
i = i.next;
}
} else {
System.out.println("List empty");
}
} |
5d822de3-3bf9-4645-bb75-48983c5d1080 | public boolean contains(String match) {
Item i = first;
while (i != null) {
if (match != null && match.equals(i.data))
return true;
i = i.next;
}
return false;
} |
223cc14a-4334-4ad4-a5c8-1c3cd00a8b68 | public boolean remove(String match) {
if (isEmpty())
return false;
Item i = first;
Item previousItem = null;
while (i != null) {
if (match != null && match.equals(i.data)) {
if (previousItem != null) {
previousItem.next = i.next;
} else {
first = i.next;
}
return true;
}
previousItem = i;
i = i.next;
}
return false;
} |
288b8e84-603d-4f6e-95f7-64b13a5ded3a | public void addNode(String data){
Item node = new Item(data);
node.next = this.first;
this.first = node;
} |
dbe8cf0a-3fa9-44c8-9a25-217beadfd83f | public SetMinutesClockState(SimpleClock clock){
_clock = clock;
} |
6ff4812c-13b1-44a9-8224-6e38b41b90ea | @Override
public void Increment() {
_clock.addMinute();
} |
8af64770-fad0-426e-98b6-295c01c9118a | @Override
public void Decrement() {
_clock.subtractMinute();
} |
4b5bb669-ce26-4152-ac8f-99f180b3bb9c | @Override
public void ChangeMode() {
_clock.stopTimer();
_clock.SetState(new SetSecondsClockState(_clock));
} |
6d60d4b0-34a8-45fd-a507-42abdc07da6e | @Override
public void Cancel() {
_clock.SetState(new SetHoursClockState(_clock));
} |
a6869aa8-c8a9-44ef-8a32-d97b729109df | @Override
public boolean GetIsEditMinutes() {
// TODO Auto-generated method stub
return true;
} |
e682b400-91b8-43cc-8267-45c0f4b5018b | public SimpleClock() {
_timeKeeper = new TimeKeeper();
Thread t = new Thread(_timeKeeper, "timeKeeper");
t.start();
_currentClockState = new DisplayTimeClockState(this);
} |
a5036d9c-53c2-4656-aed6-538fd266ce8b | public void SetState(ClockState newState){
_currentClockState = newState;
} |
c8725247-f269-4c2d-9353-71a30a173c77 | public boolean GetIsEditMode() {
return _currentClockState.GetIsEditMode();
} |
c3a5da91-f3d0-4979-a5af-89667e748950 | public boolean GetIsEditHours() {
return _currentClockState.GetIsEditHours();
} |
17c0e21a-2ffc-4f4c-a0fc-99df22493374 | public boolean GetIsEditMinutes() {
return _currentClockState.GetIsEditMinutes();
} |
4272ca7d-ecb5-48da-a4ce-7d5ed8f08e17 | public boolean GetIsEditSeconds() {
return _currentClockState.GetIsEditSeconds();
} |
9655cde9-0ce6-4bf5-a13e-c47697415b5b | public long[] GetTime(){
return new long[]{_timeKeeper.getHoursDisplayed(),_timeKeeper.getMinutesDisplayed(), _timeKeeper.getSecondsDisplayed()};
} |
dfe3da35-a975-4bfe-b994-2b6c30d03295 | public void Increment() {
_currentClockState.Increment();
} |
5f23ba40-ef2b-442c-84ab-06aa61e6e9fc | public void Decrement() {
_currentClockState.Decrement();
} |
3a2274ae-5197-4a8d-adb4-33ec2006041f | public void ChangeMode() {
_currentClockState.ChangeMode();
} |
19aa6e86-0191-4008-a085-c5b984ef5241 | public void Cancel() {
_currentClockState.Cancel();
} |
e637f925-24d2-4e98-8a3b-630ce373a210 | public void addHour() {
_timeKeeper.addHour();
} |
c42a4517-df4e-4d2e-a6de-3381cb1eb147 | public void subtractHour() {
_timeKeeper.subtractHour();
} |
d546bd73-f981-4980-b2bf-4c4fe9da60f9 | public void addMinute() {
_timeKeeper.addMinute();
} |
0d336322-0029-430a-a5a9-feb63104d863 | public void subtractMinute() {
_timeKeeper.subtractMinute();
} |
ef8fdd95-70d9-4b45-9304-c06bb7aff74c | public void addSecond() {
_timeKeeper.addSecond();
} |
5a502a73-92b6-4a2b-859a-05b2c6665f73 | public void subtractSecond() {
_timeKeeper.subtractSecond();
} |
171b7a8c-585c-4160-b688-e1a7140ec86f | public void stopTimer() {
_timeKeeper.stop();
} |
35e2a3cb-07f1-45df-bd4c-1ae1774c1c42 | public void startTimer() {
_timeKeeper.start();
} |
ecaa0cd2-068a-4581-8e67-425530141059 | boolean GetIsEditMode(){
return true;
} |
b02c96f2-513a-4794-9b23-7442e4068eae | boolean GetIsEditHours(){
return false;
} |
1541f048-81f7-4f55-a9fc-97527f626183 | boolean GetIsEditMinutes(){
return false;
} |
8050387c-dacd-42cf-80d3-47e3fc3ee440 | boolean GetIsEditSeconds(){
return false;
} |
5a2027c8-f1cb-4a20-ad51-219538d5e059 | void Increment(){ } |
9543a7e7-5a30-425f-9a1d-a09d9046a056 | void Decrement(){ } |
7e1d7170-ba92-4fe2-8cd1-cfb9aa7c9600 | void ChangeMode(){ } |
5faf61c2-947f-4197-80d9-653e1ae5c6c3 | void Cancel(){ } |
8465e96f-45dc-4bbc-9cef-3181466ffee1 | public SetSecondsClockState(SimpleClock clock){
_clock = clock;
} |
15bf48f4-5256-4a0d-8892-99df4c0f4ad0 | @Override
public void Increment() {
_clock.addSecond();
} |
a173d05f-174c-495a-b995-1982f610c09e | @Override
public void Decrement() {
_clock.subtractSecond();
} |
e47528b6-b0cf-4a8d-a988-de1ec53ceefc | @Override
public void ChangeMode() {
_clock.startTimer();
_clock.SetState(new DisplayTimeClockState(_clock));
} |
b9473ce8-7fbe-4749-8b8a-d7b909cff86a | @Override
public void Cancel() {
_clock.startTimer();
_clock.SetState(new SetMinutesClockState(_clock));
} |
ee74f0b6-84eb-4125-9185-0b6a58f6c276 | @Override
public boolean GetIsEditSeconds() {
// TODO Auto-generated method stub
return true;
} |
413b6357-9be5-4099-a0cd-6f19ee9c2a64 | public SetHoursClockState(SimpleClock clock) {
_clock = clock;
} |
cf994399-3e62-416b-82fa-35f08ca6a2ab | @Override
public void Increment() {
_clock.addHour();
} |
a27a2dd3-466f-4952-8497-e3b8972fd8a4 | @Override
public void Decrement() {
_clock.subtractHour();
} |
ef072ec0-594d-47ca-8e49-cc0a36c90a9c | @Override
public void ChangeMode() {
_clock.SetState(new SetMinutesClockState(_clock));
} |
227fb566-cd00-433f-a505-2065f821e17a | @Override
public void Cancel() {
_clock.SetState(new DisplayTimeClockState(_clock));
} |
e2f50c37-4b75-4db0-b803-5619b22c8bab | @Override
public boolean GetIsEditHours() {
// TODO Auto-generated method stub
return true;
} |
efeb2101-9642-4da0-89c9-0cff457ac3c5 | public TimeKeeper() {
secondsSaved = 0;
minutesSaved = 0;
hoursSaved = 0;
startTime = System.currentTimeMillis();
isPaused = false;
} |
2a70d162-611d-49b9-a8bb-4ba9f97b16a8 | public long getMinutesDisplayed() {
return minutesDisplayed%60;
} |
c407b5de-e01d-4293-af2b-7f05a1ca35ba | public long getSecondsDisplayed() {
return secondsDisplayed%60;
} |
c5e39c2f-e967-4db0-aad9-303ee0d9f349 | public long getHoursDisplayed() {
if (hoursDisplayed % 12 == 0) {
return 12;
} else {
return hoursDisplayed % 12;
}
} |
a11d2cac-8162-4e92-9d90-9ee13b4d330a | public void addHour() {
hoursDisplayed += 1;
hoursSaved += 1;
} |
13b51acf-099c-4e35-8393-f0cfc5597587 | public void subtractHour() {
if (hoursDisplayed == 0) {
hoursDisplayed = 11;
} else {
hoursDisplayed -= 1;
}
if (hoursSaved == 0) {
hoursSaved = 11;
} else {
hoursSaved -= 1;
}
} |
cc93bb8d-064e-484a-9670-c065edd310aa | public void addMinute() {
if (minutesDisplayed == 59) {
minutesDisplayed = 0;
} else {
minutesDisplayed += 1;
}
if (minutesSaved == 59) {
minutesSaved = 0;
} else {
minutesSaved += 1;
}
} |
24434314-1ad7-490c-8047-2d9db44de3e9 | public void subtractMinute() {
if (minutesDisplayed == 0) {
minutesDisplayed = 59;
} else {
minutesDisplayed -= 1;
}
if (minutesSaved == 0) {
minutesSaved = 59;
} else {
minutesSaved -= 1;
}
} |
613f0082-7b18-4872-be59-44e15a363442 | public void addSecond() {
secondsDisplayed += 1;
secondsSaved += 1;
} |
5005511b-2bf8-4b4f-9214-a8e356b70745 | public void subtractSecond() {
if (secondsDisplayed == 0) {
secondsDisplayed = 59;
} else {
secondsDisplayed -= 1;
}
if (secondsSaved == 0) {
secondsSaved = 59;
} else {
secondsSaved -= 1;
}
} |
d235991a-853b-42e4-ac96-18a0f7c1f59a | @Override
public void run() {
try {
synchronized (this) {
while (true) {
if (!isPaused) {
tick();
}
wait(1000);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} |
3d9649ac-62b8-4737-8251-86fb2a397eee | private void tick() {
secondsElapsed = (System.currentTimeMillis() - startTime)/1000;
update();
} |
f00bec9d-f795-4964-b640-a59056398ac9 | private void update() {
secondsDisplayed = (secondsSaved + secondsElapsed) % 60;
minutesElapsed = (secondsSaved + secondsElapsed) / 60;
minutesDisplayed = (minutesSaved + minutesElapsed) % 60;
hoursElapsed = (minutesSaved + minutesElapsed) / 60;
if ((hoursSaved + hoursElapsed) % 12 == 0) {
hoursDisplayed = 12;
} else {
hoursDisplayed = (hoursSaved + hoursElapsed) % 12;
}
} |
33ae72a2-9bfa-4f1e-bde7-afab238b09cf | public void stop() {
isPaused = true;
secondsSaved = secondsDisplayed;
minutesSaved = minutesDisplayed;
hoursSaved = hoursDisplayed;
} |
e7c64f52-bea9-46e6-abc7-47a6f840aa1d | public void start() {
isPaused = false;
startTime = System.currentTimeMillis();
} |
cb24bfec-4db5-46de-a2ef-955f11d64400 | public DisplayTimeClockState(SimpleClock clock){
_clock = clock;
} |
deef4b61-503c-4d6e-91a3-077e00088215 | @Override
public void ChangeMode() {
_clock.SetState(new SetHoursClockState(_clock));
} |
b7c177cf-e69b-4a52-b84a-846e28d50f69 | @Override
public void Cancel() {
// Do Nothing
} |
56edb613-6db5-4cff-bc59-fa4d84f30b7f | @Override
public boolean GetIsEditMode() {
return false;
} |
3f0a29db-367f-470d-8032-e07c643aa3bb | public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ClockWindow window = new ClockWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} |
f2b2e977-bc90-459a-be3b-a02683caf21c | public void run() {
try {
ClockWindow window = new ClockWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} |
768ebf9f-59f3-4750-8ac5-a837b27ac03c | public ClockWindow() {
initialize();
} |
094d976c-377d-44b5-9e78-4b0649d3c0b8 | private void initialize() {
frame = new JFrame();
_simpleClock = new SimpleClock();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
SetupChangeModeButton();
SetupIncrementButton();
SetupDecrementButton();
SetupCancelButton();
SetupTimeDisplay();
UpdateTime();
StartUIRefresher();
} |
f2e658de-cd5f-478d-a00b-9aa4042094f0 | private void SetupChangeModeButton(){
_changeMode = new Button("Change Mode");
_changeMode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_simpleClock.ChangeMode();
UpdateVisibility();
}
});
_changeMode.setBounds(164, 219, 102, 28);
frame.getContentPane().add(_changeMode);
} |
e2e67015-eaeb-49b2-86dc-02e7e404226d | public void actionPerformed(ActionEvent e) {
_simpleClock.ChangeMode();
UpdateVisibility();
} |
1a68e8e3-fc7e-432a-8e79-714ab059e741 | private void SetupIncrementButton(){
_increment = new Button("+");
_increment.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_simpleClock.Increment();
}
});
_increment.setVisible(false);
_increment.setBounds(31, 219, 31, 28);
frame.getContentPane().add(_increment);
} |
036465d6-54e1-444d-8000-823689cf7714 | public void actionPerformed(ActionEvent e) {
_simpleClock.Increment();
} |
9a49dfb5-8d05-49be-b551-23da3832d728 | private void SetupDecrementButton(){
_decrement = new Button("-");
_decrement.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_simpleClock.Decrement();
}
});
_decrement.setVisible(false);
_decrement.setBounds(78, 219, 31, 28);
frame.getContentPane().add(_decrement);
} |
7dc9e277-1d36-42d1-b548-6cdc0f983a68 | public void actionPerformed(ActionEvent e) {
_simpleClock.Decrement();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.