forked from rbmonster/learning-note
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
654 additions
and
200 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# head first 设计模式 | ||
## 设计原则: | ||
## 设计原则 | ||
- 多用组合少用继承。 | ||
- 找出应用中可能需要变化之处,把他们独立出来,不要和那些不需要变化的代码混合在一起。 | ||
- 针对接口编程,而不是针对实现编程。 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# DDD 领域驱动 | ||
# 领域驱动设计(Domain Driven Design,DDD) | ||
|
||
基本元素:分层架构、实体、值对象、服务、模块、聚合、工厂、资源库 | ||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.learning.algorithm; | ||
|
||
|
||
public class BitOperation { | ||
|
||
public static void main(String[] args) { | ||
toLowerCase(); | ||
toUpperCase(); | ||
exchangeCase(); | ||
assertNumberMinus(); | ||
exchangeNum(); | ||
countBit(); | ||
isPowerOfTwo(16); | ||
} | ||
|
||
|
||
/** | ||
* 统一转小写 | ||
* ('A' | ' ') = 'a'; | ||
* ('a' | ' ') = 'a'; | ||
*/ | ||
private static void toLowerCase() { | ||
char ch1 = 'c'; | ||
char ch2 = 'C'; | ||
System.out.println("('c'|' ') == 'c' :" + ((ch1 | ' ') == 'c')); | ||
System.out.println("('C'|' ') == 'c' :" + ((ch2 | ' ') == 'c')); | ||
} | ||
|
||
/** | ||
* 统一转大写 | ||
* ('b' & '_') = 'B' | ||
* ('B' & '_') = 'B' | ||
*/ | ||
private static void toUpperCase() { | ||
char ch1 = 'c'; | ||
char ch2 = 'C'; | ||
System.out.println("('c' & '_') == 'C' :" + ((ch1 & '_') == 'C')); | ||
System.out.println("('C' & '_') == 'C' :" + ((ch2 & '_') == 'C')); | ||
} | ||
|
||
/** | ||
* 大小写交换 | ||
* ('d' ^ ' ') = 'D' | ||
* ('D' ^ ' ') = 'd' | ||
*/ | ||
private static void exchangeCase() { | ||
char ch1 = 'c'; | ||
char ch2 = 'C'; | ||
System.out.println("('c' ^ ' ') == 'C' :" + ((ch1 ^ ' ') == 'C')); | ||
System.out.println("('C' ^ ' ') == 'c' :" + ((ch2 ^ ' ') == 'c')); | ||
} | ||
|
||
/** | ||
* 判断负数 | ||
*/ | ||
private static void assertNumberMinus() { | ||
int num1 = 1231; | ||
int num2 = -12; | ||
System.out.println("(1231 ^ -12) < 0 :" + ((num1 ^ num2) < 0)); | ||
} | ||
|
||
/** | ||
* 数字交换 | ||
*/ | ||
private static void exchangeNum() { | ||
int a = 12312; | ||
int b = 22; | ||
System.out.println("before num[a]:" + a + " num[b]:" + b); | ||
a ^= b; | ||
b ^= a; | ||
a ^= b; | ||
System.out.println("after num[a]:" + a + " num[b]:" + b); | ||
} | ||
|
||
/** | ||
* 计算一个数二进制中1的个数 | ||
*/ | ||
private static void countBit() { | ||
int res = 0; | ||
int num = 1002930; | ||
int n = num; | ||
while (n != 0) { | ||
n = n & (n - 1); | ||
res++; | ||
} | ||
System.out.println("num:" + num + ",count one number:" + res); | ||
} | ||
|
||
/** | ||
* 判断一个数是否为二的指数 | ||
* @param n | ||
* @return | ||
*/ | ||
private static boolean isPowerOfTwo(int n) { | ||
if (n <= 0) return false; | ||
return (n & (n - 1)) == 0; | ||
} | ||
} |
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
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
Oops, something went wrong.