Interface | Common Implementation(s) | Comparison Method |
---|---|---|
Set |
HashSet |
hashCode → equals |
Map |
HashMap |
hashCode → equals (for keys) |
List |
ArrayList , LinkedList |
equals only (sequential) |
SortedSet |
TreeSet |
compareTo / Comparator |
SortedMap |
TreeMap |
compareTo / Comparator |
LinkedHashSet |
Linked hash table (ordered) | hashCode → equals |
LinkedHashMap |
Linked hash table (ordered) | hashCode → equals |
This file contains hidden or 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
public class Person { | |
private final String firstName; | |
private final String lastName; | |
public Person(String firstName, String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
@Override |
This file contains hidden or 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(val firstName: String, val lastName: String) { | |
override fun equals(other: Any?): Boolean { | |
val otherPerson = other as? Person ?: return false | |
return otherPerson.firstName == firstName && | |
otherPerson.lastName == lastName | |
} | |
override fun hashCode(): Int = | |
firstName.hashCode() * 31 + lastName.hashCode() |
This file contains hidden or 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
override fun hashCode(): Int = firstName.hashCode() * 37 + lastName.hashCode() |
This file contains hidden or 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
override fun equals(other: Any?): Boolean { | |
val otherPerson = other as? Person ?: return false | |
return otherPerson.firstName == firstName && | |
otherPerson.lastName == lastName | |
} |
This file contains hidden or 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(val firstName: String, val lastName: String) { | |
override fun equals(other: Any?): Boolean { | |
val otherPerson = other as? Person ?: return false | |
return otherPerson.firstName == firstName && | |
otherPerson.lastName == lastName | |
} | |
override fun hashCode(): Int = firstName.hashCode() * 37 + lastName.hashCode() | |
} |
This file contains hidden or 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
val program = | |
for { | |
_ <- Console.printLine("Starting…") | |
_ <- Console.printLine("Doing work…") | |
_ <- Console.printLine("Finished!") | |
} yield () | |
Runtime.default.unsafeRun(program) // single execution point |
This file contains hidden or 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
// (1) Pure computation stage | |
fun calculateSomething(input: Int): Int = | |
input * 2 + 1 | |
// (2) Stage that *describes* an effect | |
data class WriteToFileCommand(val path: String, val content: String) | |
// (3) Stage that *performs* the effect | |
fun executeCommand(cmd: WriteToFileCommand) { | |
File(cmd.path).writeText(cmd.content) |
This file contains hidden or 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
import kafka.utils.ZkUtils | |
object KafkaTopicTest { | |
def createZkUtils(): ZkUtils = { | |
val zookeepers = "localhost:2181" | |
val timeout = 10000 | |
ZkUtils(zookeepers, timeout, timeout, isZkSecurityEnabled = false) | |
} | |
def getPartitionsForTopics(topics: Seq[String]): Map[String, Seq[Int]] = { |
This file contains hidden or 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
#!/bin/bash | |
kafka_home=$1 | |
zookeeper=$2 | |
group_name=$3 | |
lag_threshold=$4 | |
lag_data_sampling_count=$5 | |
if [ ! -z $6 ] ; then | |
lag_data_file=$6 | |
else |