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
package com.mkyong.dao; | |
import com.mkyong.model.Customer; | |
import org.springframework.data.jpa.repository.Query; | |
import org.springframework.data.repository.CrudRepository; | |
import org.springframework.data.repository.query.Param; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.stream.Stream; |
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
package jcg.zheng.demo.jpademo.repository; | |
import java.util.List; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.jpa.repository.Query; | |
import org.springframework.data.repository.query.Param; | |
import org.springframework.stereotype.Repository; | |
import org.springframework.transaction.annotation.Transactional; | |
import jcg.zheng.demo.jpademo.entity.Contact; | |
import jcg.zheng.demo.jpademo.type.PhoneType; | |
@Repository |
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 logging | |
import time | |
#fix for "AttributeError: module 'time' has no attribute 'clock'" | |
time.clock=time.time | |
import contextlib | |
from atexit import register as atexit_register | |
from sqlalchemy import create_engine | |
from sqlalchemy.schema import MetaData | |
from sqlalchemy.event import listen | |
from sqlalchemy.sql import text, bindparam |
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
from numba import jit | |
import random | |
@jit(nopython=True) | |
def monte_carlo_pi(nsamples): | |
acc = 0 | |
for i in range(nsamples): | |
x = random.random() | |
y = random.random() | |
if (x ** 2 + y ** 2) < 1.0: |
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
enum Letter { | |
A, B, C | |
} | |
Letter letter = Letter.valueOf("A") | |
// and just switch | |
switch (letter) { | |
case A: ...; break; | |
case B: ...; break; | |
case C: ...; break; |
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
/** | |
* A Java enum switch statement (switch/case) example. | |
* @author alvin alexander, http://alvinalexander.com | |
*/ | |
public class JavaEnumSwitchCaseExample | |
{ | |
public static void main(String[] args) | |
{ | |
// loop through the enum values, calling the |
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 java.util.Objects; | |
public class CocaCola implements Delivarable { | |
private DelivarableStatus status = DelivarableStatus.IN_PROGRESS; | |
private CocaColaDeliveryStrategy strategy; | |
public CocaCola(CocaColaDeliveryStrategy strategy){ |
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 enum CocaColaDeliveryStrategy implements DeliveryStrategy<CocaCola> { | |
EXPRESS { | |
@Override | |
public void deliver(CocaCola cc) { | |
System.out.println("CocaCola will be delivered in express mode"); | |
} | |
}, | |
NORMAL { | |
@Override | |
public void deliver(CocaCola cc) { |
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 interface DeliveryStrategy<E extends Deliverable> { | |
public void deliver(E pizza) | |
} |
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 Demo { | |
public static void main(String[] args){ | |
Pizza pz = new Pizza(PizzaDeliveryStrategy.NORMAL); | |
pz.setStatus(DeliverableStatus.READY); | |
pz.deliver(); | |
if(pz.getStatus() != DeliverableStatus.DELIVERED){ | |
throw new AssertionError("Wrong DeliverableStatus"); | |
} | |
} | |
} |