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
public class Fraction { | |
private final int num; | |
private final int denom; | |
public Fraction(int num, int denom) { | |
this.num = num; | |
this.denom = denom; | |
} | |
public int getNum() { |
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
public class Employee { | |
private Address addr; | |
private int age; | |
// Getters and setters | |
} | |
class Address { | |
private String streetAddr1; | |
private String streetAddr2; |
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
trait Logged { def log(msg: String) {} } | |
trait Chattery extends Logged { def chatter = log("I chatter. Do you mind?") } | |
trait ConsoleLogger extends Logged { override def log(msg: String) = println(msg) } | |
scala> val ch = new Chattery() with ConsoleLogger | |
ch: Chattery with ConsoleLogger = $anon$1@1ef7fe8e | |
scala> ch.chatter |
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
sealed abstract class BinaryTree | |
case class BinTreeLeaf(value: Int) extends BinaryTree | |
case class BinTreeNode(left: BinaryTree, right: BinaryTree) extends BinaryTree | |
def leafSum(tree: BinaryTree): Int = tree match { | |
case node: BinTreeNode => leafSum(node.left) + leafSum(node.right) | |
case leaf: BinTreeLeaf => leaf.value | |
} | |
"Method leafSum" should "traverse a binary tree in order" in { |
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
public class FrequencyCalculator extends RecursiveTask<Map<Character, Integer>> { | |
private static final long serialVersionUID = -5328480156308631556L; | |
private static final int NUM_PROCESSORS = Runtime.getRuntime() | |
.availableProcessors(); | |
private final String word; | |
public FrequencyCalculator(String word) { | |
this.word = word; |
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
ConnectableFlowable<Integer> pub = Flowable.range(1, 10000) | |
.publish(); | |
pub.debounce(1, SECONDS) | |
.subscribeOn(computation()) | |
.subscribe(new DefaultSubscriber<Integer>() { | |
@Override | |
public void onStart() { | |
request(1); | |
} |
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
@SpringCloudApplication | |
@EnableFeignClients | |
public class DemoApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
@FeignClient(name = "httpbin", url = "httpbin.org") | |
public interface HttpBinClient { | |
@RequestMapping(path = "/post", method = POST, produces = APPLICATION_JSON_VALUE) |
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
val l = (1 to 20) | |
val isEven = (i: Int) => i % 2 == 0 | |
val isLtTen = (i: Int) => i < 10 | |
val isGtTen = (i: Int) => i > 10 | |
val p1 = List(isEven, isLtTen) | |
val p2 = List(isEven, isGtTen) | |
val r1 = l.find(i => p1.forall(_ (i))) | |
val r2 = l.find(i => p2.forall(_ (i))) |
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
blocking-io-dispatcher { | |
type = Dispatcher | |
executor = "thread-pool-executor" | |
thread-pool-executor { | |
fixed-pool-size = 16 | |
} | |
throughput = 1 | |
} | |
--- |
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
package org.asarkar.data | |
sealed trait Edge[T] { | |
def tail: T | |
def head: T | |
} | |
sealed trait WeightedEdge[T] extends Edge[T] { | |
def weight: Double |
OlderNewer