This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address { | |
String number | |
String firstLine | |
String secondLine | |
String postCode | |
String City | |
String State | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
String firstName | |
String lastName | |
Address address | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println person.getAddress().getFirstLine() | |
println person.getAddress().getSecondLine() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
String firstName | |
String lastName | |
private Address address | |
String getAddressFirstLine() { | |
address.firstLine | |
} | |
String getAddressSecondLine() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println person.getAddressFirstLine() | |
println person.getAddressSecondLine() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static File generateFile(String prefix, String suffix, File dir) | |
throws IOException | |
{ | |
long n = LazyInitialization.random.nextLong(); | |
if (n == Long.MIN_VALUE) { | |
n = 0; // corner case | |
} else { | |
n = Math.abs(n); | |
} | |
return new File(dir, prefix + Long.toString(n) + suffix); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mergeSort(list) { | |
def size = list.size() | |
if (size < 2) { | |
return list | |
} else { | |
def m = (int)(size / 2) | |
def left = list[0..<m] | |
def right = list[m..<size] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def heapSort(list) { | |
def size = list.size() | |
if (size < 2) { | |
return list | |
} | |
/*We need to create a valid binary heap first*/ | |
heapify(list) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quickSort(list) { | |
/*Make sure there are at least 2 elements in the list*/ | |
if (list == null || list.size() < 2) { | |
return list | |
} | |
/*break the list to three different groups | |
group 1: with elements less than pivot | |
group 2: with elements equal to pivot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriorityQueue { | |
/*a list to contains the queue elments in a binary heap format*/ | |
def list = [] | |
/*Add new item to the queue*/ | |
def add(item) { | |
list.add(item) | |
/*After adding new item, we need to re-validate the heap*/ | |
siftUp(list, 0, list.size() - 1) |
OlderNewer