Skip to content

Instantly share code, notes, and snippets.

Dusan Odalovic dodalovic

Block or report user

Report or block dodalovic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dodalovic
dodalovic / a.State.kt
Last active Jun 20, 2019
State pattern implemented in kotlin
View a.State.kt
package patterns.head_first
class CoffeeMachine {
var state: CoffeeMachineState
val MAX_BEANS_QUANTITY = 100
val MAX_WATER_QUANTITY = 100
var beansQuantity = 0
var waterQuantity = 0
val offState = Off(this)
val noIngredients = NoIngredients(this)
@dodalovic
dodalovic / Decorator.kt
Last active Dec 6, 2017
Decorator pattern in Kotlin
View Decorator.kt
package patterns
interface CarService {
fun doService()
}
interface CarServiceDecorator : CarService
class BasicCarService : CarService {
override fun doService() = println("Doing basic checkup ... DONE")
@dodalovic
dodalovic / h1.kts
Last active Jun 25, 2017
Overloaded constructors in Kotlin
View h1.kts
class Hotel {
val name: String
val city: String
val stars: Int
private var jimIncluded = false
constructor(name: String, city: String, stars: Int) {
this.name = name
this.city = city
this.stars = stars
@dodalovic
dodalovic / Sealed.kt
Created Jun 14, 2017
Sealed classes kotlin
View Sealed.kt
sealed class Student(val indexNumber: String)
class GraduateStudent(indexNumber: String, val graduationYear: Int) : Student(indexNumber)
class UnderGraduateStudent(indexNumber: String, val currentGrade: Int) : Student(indexNumber)
fun main(args: Array<String>) {
val student: Student = UnderGraduateStudent("123", 3)
when (student) {
is UnderGraduateStudent -> println("UnderGraduateStudent :: indexNumber: ${student.indexNumber} :: current grade : ${student.currentGrade}")
is GraduateStudent -> println("GraduateStudent :: indexNumber: ${student.indexNumber} :: graduation year : $ { student.currentGrade}")
@dodalovic
dodalovic / README.adoc
Last active May 30, 2017
Strategy pattern implementation in kotlin
View README.adoc

Strategy pattern implementation in kotlin (kotlinlang.org) language

Important
make sure to have kotlinc on your $PATH

Running

  • Without any command line arguments

View RepeatedMocker.java
package com.mydomain;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@dodalovic
dodalovic / CollectorsDemo.java
Created Mar 30, 2016
Transforming Java 8 collections - Collectors API
View CollectorsDemo.java
package rs.dodalovic.streams.collect.collectors_api;
import rs.dodalovic.fn_interfaces.predicate.persons_test.Person;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.*;
@dodalovic
dodalovic / Person.java
Last active Mar 17, 2016
blog - Java 8 Stream API - reduce operator
View Person.java
package rs.dodalovic.streams.reduce;
class Person {
private String name;
private Gender gender;
private Integer age;
public Person(String name, Gender gender, Integer age) {
this.name = name;
this.gender = gender;
@dodalovic
dodalovic / ApacheCommonsEmailSenderMain.java
Last active Mar 16, 2016
Send mail via Gmail / SMTP using Apache commons mail
View ApacheCommonsEmailSenderMain.java
package rs.dodalovic.send_mail;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import javax.mail.util.ByteArrayDataSource;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@dodalovic
dodalovic / User.java
Last active Mar 9, 2016
Strategy pattern - User persistence - java 8
View User.java
package rs.dodalovic.design_patterns.behavioral.strategy.user_persistence;
class User {
private final int id;
private final String username;
private final String location;
public User(int id, String username, String location) {
this.id = id;
this.username = username;
You can’t perform that action at this time.