Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4cd3a78
新建knowledge-point目录
onlyliuxin Jun 23, 2017
a5c9da9
refactor the sample of SRP in OOD.
ThomsonTang Jun 23, 2017
592e60b
refactor the sample
ThomsonTang Jun 23, 2017
3a5dd12
first
ISmallBlack Jun 25, 2017
c624979
测试编码
ISmallBlack Jun 25, 2017
bf6493b
前面的作业
ISmallBlack Jun 25, 2017
b9dcd70
srp homework
Jun 27, 2017
46f1749
read the file and resolve a line to a product.
ThomsonTang Jun 27, 2017
8bfc3ed
add a resource directory.
ThomsonTang Jun 27, 2017
adea855
ocp homework
Jun 28, 2017
171e348
UML作业(dice game / shopping)
MIMIEYES Jun 28, 2017
a0496c3
refactor srp
Jun 29, 2017
0ab140f
refactor the promotion email project.
ThomsonTang Jun 29, 2017
2bc74af
单一职责作业
Jun 30, 2017
52f16e2
开闭原则作业
Jul 1, 2017
8d716de
refactor the promotion email project.
ThomsonTang Jul 2, 2017
35e5c7b
Merge pull request #474 from chasing95/master
onlyliuxin Jul 2, 2017
f69a583
第一次srp重构作业
Jul 2, 2017
431217d
第一次作业
em14Vito Jul 2, 2017
616cf8d
payroll
onlyliuxin Jul 4, 2017
e49ac3d
Merge pull request #478 from em14Vito/master
onlyliuxin Jul 4, 2017
d7270d2
Merge pull request #477 from imhuster/master
onlyliuxin Jul 4, 2017
96092ed
Merge pull request #1 from onlyliuxin/master
wluqing Jul 4, 2017
70023ec
Merge pull request #476 from ThomsonTang/master
onlyliuxin Jul 5, 2017
6dfa138
Merge pull request #470 from MIMIEYES/master
onlyliuxin Jul 5, 2017
67e4eb4
Merge pull request #463 from starlight0405/master
onlyliuxin Jul 5, 2017
16fbe95
desktop commit
wluqing Jul 5, 2017
731e7e1
commit test
wluqing Jul 5, 2017
f20bea2
commit test2
wluqing Jul 5, 2017
f03f7ba
commit test undo
wluqing Jul 5, 2017
9c5a25d
commit test
wluqing Jul 5, 2017
048230a
commit and push test
wluqing Jul 5, 2017
fd74ffc
undo commit
wluqing Jul 5, 2017
0d1fbd3
Merge pull request #482 from wluqing/master
onlyliuxin Jul 6, 2017
30d1cb3
Merge pull request #457 from ISmallBlack/master
onlyliuxin Jul 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions liuxin/knowledge-point/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.coderising</groupId>
<artifactId>knowledge-point</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>knowledge-point</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

</dependencies>
<repositories>
<repository>
<id>aliyunmaven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
18 changes: 18 additions & 0 deletions liuxin/knowledge-point/src/main/java/cas/CASSequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CASSequence{

private AtomicInteger count = new AtomicInteger(0);

public int next(){
while(true){
int current = count.get();
int next = current +1;
if(count.compareAndSet(current, next)){
return next;
}
}
}
}
34 changes: 34 additions & 0 deletions liuxin/knowledge-point/src/main/java/cas/NoBlockingStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cas;

import java.util.concurrent.atomic.AtomicReference;

public class NoBlockingStack<E> {
static class Node<E> {
final E item;
Node<E> next;
public Node(E item) { this.item = item; }
}

AtomicReference<Node<E>> head = new AtomicReference<Node<E>>();

public void push(E item) {
Node<E> newHead = new Node<E>(item);
Node<E> oldHead;
do {
oldHead = head.get();
newHead.next = oldHead;
} while (!head.compareAndSet(oldHead, newHead));
}
public E pop() {
Node<E> oldHead;
Node<E> newHead;
do {
oldHead = head.get();
if (oldHead == null)
return null;
newHead = oldHead.next;
} while (!head.compareAndSet(oldHead,newHead));
return oldHead.item;
}

}
11 changes: 11 additions & 0 deletions liuxin/knowledge-point/src/main/java/cas/Sequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cas;

public class Sequence{

private int value;

public int next(){
return value ++;
}

}
20 changes: 20 additions & 0 deletions liuxin/knowledge-point/src/main/java/threadlocal/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package threadlocal;
import java.util.HashMap;
import java.util.Map;

public class Context {

private static final ThreadLocal<String> txThreadLocal
= new ThreadLocal<String>();

public static void setTransactionID(String txID) {
txThreadLocal.set(txID);

}

public static String getTransactionId() {
return txThreadLocal.get();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package threadlocal;

public class TransactionManager {
private static final ThreadLocal<String> context = new ThreadLocal<String>();

public static void startTransaction() {
// logic to start a transaction
// ...
String txID = null;
context.set(txID);
}

public static String getTransactionId() {
return context.get();
}

public static void endTransaction() {
// logic to end a transaction
// …
context.remove();
}
}
35 changes: 35 additions & 0 deletions liuxin/knowledge-point/src/main/java/threadpool/BlockingQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package threadpool;
import java.util.LinkedList;
import java.util.List;

public class BlockingQueue {

private List queue = new LinkedList();
private int limit = 10;

public BlockingQueue(int limit) {
this.limit = limit;
}

public synchronized void enqueue(Object item) throws InterruptedException {
while (this.queue.size() == this.limit) {
wait();
}
if (this.queue.size() == 0) {
notifyAll();
}
this.queue.add(item);
}

public synchronized Object dequeue() throws InterruptedException {
while (this.queue.size() == 0) {
wait();
}
if (this.queue.size() == this.limit) {
notifyAll();
}

return this.queue.remove(0);
}

}
5 changes: 5 additions & 0 deletions liuxin/knowledge-point/src/main/java/threadpool/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package threadpool;

public interface Task {
public void execute();
}
37 changes: 37 additions & 0 deletions liuxin/knowledge-point/src/main/java/threadpool/ThreadPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package threadpool;
import java.util.ArrayList;
import java.util.List;


public class ThreadPool {

private BlockingQueue taskQueue = null;
private List<WorkerThread> threads = new ArrayList<WorkerThread>();
private boolean isStopped = false;

public ThreadPool(int numOfThreads, int maxNumOfTasks){
taskQueue = new BlockingQueue(maxNumOfTasks);

for(int i=0; i<numOfThreads; i++){
threads.add(new WorkerThread(taskQueue));
}
for(WorkerThread thread : threads){
thread.start();
}
}

public synchronized void execute(Task task) throws Exception{
if(this.isStopped) throw
new IllegalStateException("ThreadPool is stopped");

this.taskQueue.enqueue(task);
}

public synchronized void stop(){
this.isStopped = true;
for(WorkerThread thread : threads){
thread.doStop();
}
}

}
33 changes: 33 additions & 0 deletions liuxin/knowledge-point/src/main/java/threadpool/WorkerThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package threadpool;


public class WorkerThread extends Thread {

private BlockingQueue taskQueue = null;
private boolean isStopped = false;

public WorkerThread(BlockingQueue queue){
taskQueue = queue;
}

public void run(){
while(!isStopped()){
try{
Task task = (Task) taskQueue.dequeue();
task.execute();
} catch(Exception e){
//log or otherwise report exception,
//but keep pool thread alive.
}
}
}

public synchronized void doStop(){
isStopped = true;
this.interrupt(); //break pool thread out of dequeue() call.
}

public synchronized boolean isStopped(){
return isStopped;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.payroll;

public interface Affiliation {
public double calculateDeductions(Paycheck pc);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.coderising.payroll;

import java.util.Date;

public class Employee {
String id;
String name;
String address;
Affiliation affiliation;


PaymentClassification classification;
PaymentSchedule schedule;
PaymentMethod paymentMethod;

public Employee(String name, String address){
this.name = name;
this.address = address;
}
public boolean isPayDay(Date d) {
return false;
}

public Date getPayPeriodStartDate(Date d) {
return null;
}

public void payDay(Paycheck pc){

}

public void setClassification(PaymentClassification classification) {
this.classification = classification;
}
public void setSchedule(PaymentSchedule schedule) {
this.schedule = schedule;
}
public void setPaymentMethod(PaymentMethod paymentMethod) {
this.paymentMethod = paymentMethod;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.coderising.payroll;

import java.util.Date;
import java.util.Map;

public class Paycheck {
private Date payPeriodStart;
private Date payPeriodEnd;
private double grossPay;
private double netPay;
private double deductions;

public Paycheck(Date payPeriodStart, Date payPeriodEnd){
this.payPeriodStart = payPeriodStart;
this.payPeriodEnd = payPeriodEnd;
}
public void setGrossPay(double grossPay) {
this.grossPay = grossPay;

}
public void setDeductions(double deductions) {
this.deductions = deductions;
}
public void setNetPay(double netPay){
this.netPay = netPay;
}
public Date getPayPeriodEndDate() {

return this.payPeriodEnd;
}
public Date getPayPeriodStartDate() {

return this.payPeriodStart;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.payroll;

public interface PaymentClassification {
public double calculatePay(Paycheck pc);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.payroll;

public interface PaymentMethod {
public void pay(Paycheck pc);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.coderising.payroll;

import java.util.Date;

public interface PaymentSchedule {
public boolean isPayDate(Date date);
public Date getPayPeriodStartDate( Date payPeriodEndDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.coderising.payroll;

import java.util.Date;

public class SalesReceipt {
private Date saleDate;
private double amount;
public Date getSaleDate() {
return saleDate;
}
public double getAmount() {
return amount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.coderising.payroll;

import java.util.Date;

public class TimeCard {
private Date date;
private int hours;

public Date getDate() {
return date;
}
public int getHours() {
return hours;
}
}
Loading