ls -al wc -l
2.此目錄的總k數
du -h
3. awk 後計算加總 :
awk "BEGIN { sum = 0 } { sum += \$1 } END { print sum;}"
4.查詢所有目錄的容量
du -h --max-depth=1
du -hs /*
du -h
4.查詢所有目錄的容量
du -h --max-depth=1
du -hs /*
du -h
public class TeaBeverage{
ArrayList allTea;
public TeaBeverage{
allTea = new ArrayList();
Item item = new Item();
item.setName("紅茶");
allTea.add(item);
item = new Item();
item.setName("奶茶");
allTea.add(item);
}
public ArrayList getAllItem(){
return allTea;
}
}
public class CafeBeverage{
ArrAllCafe[] arrAllCafe;
public CafeBeverage{
arrAllCafe = new ArrAllCafe[2];
Item item = new Item();
item.setName("紅茶");
arrAllCafe[0] = item;
item = new Item();
item.setName("奶茶");
arrAllCafe[1] = item;
}
public ArrayList getAllItem(){
return arrAllCafe;
}
}
public interface IIterator{
boolean hasNext();
Object next();
}
public class CafeBeverageIterator implements IIterator{
ArrAllCafe[] arrAllCafe;
int position = 0;
public CafeBeverageIterator(ArrAllCafe[] arrAllCafe){
this.arrAllCafe = arrAllCafe;
}
public Object next(){
Item item = arrAllCafe[position];
position = position + 1;
return item;
}
public boolean hasNext(){
if(position >= arrAllCafe.length || arrAllCafe[position] == null){
return false;
}else{
return true;
}
}
}
public class CafeBeverage{
//同上
//public ArrayList getAllItem(){
//return arrAllCafe;
//}
public IIterator createIterator(){
return CafeBeverageIterator(arrAllCafe);
}
}
// 將日期轉為字串
Date date1 = new Date();
String formatDate = DateFormatUtils.format(date1, "yyyy-MM-dd");
System.out.println(formatDate);
// 將字串轉為日期
Date date2 = DateUtils.parseDate(formatDate, new String[] {"yyyyMMdd", "yyyy-MM-dd" });
System.out.println(date2);
// 只有比較日期, 沒有比較時間, 所以會回傳 true
boolean isSameDay = DateUtils.isSameDay(date1, date2);
System.out.println(isSameDay);
public boolean equals(Object obj) {
if (obj == null) { return false; }
if (obj == this) { return true; }
if (obj.getClass() != getClass()) {
return false;
}
MyClass rhs = (MyClass) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(field1, rhs.field1)
.append(field2, rhs.field2)
.append(field3, rhs.field3)
.isEquals();
}
// or
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
public class Person {
String name;
int age;
boolean smoker;
...
public int hashCode() {
// you pick a hard-coded, randomly chosen, non-zero, odd number
// ideally different for each class
return new HashCodeBuilder(17, 37).
append(name).
append(age).
append(smoker).
toHashCode();
}
}
// or
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public class Person {
String name;
int age;
boolean smoker;
...
public String toString() {
return new ToStringBuilder(this).
append("name", name).
append("age", age).
append("smoker", smoker).
toString();
}
}
Person P = new Person();
p.setName("hank");
...
ToStringBuilder.reflectionToString(p);
// or
ToStringBuilder.reflectionToString(ToStringStyle.MULTI_LINE_STYLE, p);
public abstract class CocoBeverage{
//boilWater(), pourlnCup(), 是共用的方法
public void addWater(){
//實作
}
public void putCup(){
//實作
}
public abstract void prepareRecipt();
}
public class MilkTea extends CocoBeverage{
public void prepareRecipt(){
addMilk();
}
public void addMilk(){
...
}
}
public class LemonTea extends CocoBeverage{
//略
public void addLemon(){
...
}
}
public abstract class CocoBeverage{
public void addWater(){
...
}
public void putCup(){
...
}
final void executeBeverage(){ //final 注意, 不希望被繼承
addWater();
addCondiment();
putCup();
}
public abstract void addCondiment();
}
public class MilkTea extends CocoBeverage{
public void addCondiment(){
//實作加入milk
}
}
public class LemonTea extends CocoBeverage{
public void addCondiment(){
//實作加入lemon
}
}
public abstract class CocoBeverage{
...略
final void executeBeverage(){
addWater();
if(hook()){ //預設一定會加調味料
addCondiment();
}
putCup();
}
public abstract void addCondiment();
public boolean hook(){ 這就是一個勾子, 子類別可以override, 以控制這template的步驟
return true;
}
}
package hank.jakarta.common.configuration;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ConfigurationTest {
public static final Log log = LogFactory.getLog(ConfigurationTest.class);
public static final String propName = "mmmm.properties";
private String name;
private String working;
private Properties prop;
private ConfigurationTest() {
// do something
try {
initProp();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
private static class SingletonHolder {
private static final ConfigurationTest instance = new ConfigurationTest();
}
public static ConfigurationTest getInstance() {
return SingletonHolder.instance;
}
private void initProp() throws IOException {
if (prop == null) {
prop = new Properties();
String realPath = getClass().getClassLoader().getResource(propName)
.getPath();
File f = new File(realPath);
if (!f.isFile()) {
throw new FileNotFoundException("path not found!! : " + realPath);
} else {
prop.load(new FileInputStream(f));
// load properties ......
setName(prop.getProperty("name"));
setWorking(prop.getProperty("working"));
}
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWorking() {
return working;
}
public void setWorking(String working) {
this.working = working;
}
public static void main(String[] args) {
// test
ConfigurationTest config = ConfigurationTest.getInstance();
System.out.println(config.getName());
System.out.println(config.getWorking());
}
}
package hank.jakarta.common.configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ConfigurationTest1 {
public static final Log log = LogFactory.getLog(ConfigurationTest1.class);
public static final String propName = "mmmm.properties";
private String name;
private String working;
private PropertiesConfiguration prop;
private ConfigurationTest1() {
// do something
try {
initProp();
} catch (ConfigurationException e) {
log.error(e.getMessage(), e);
}
}
private static class SingletonHolder {
private static final ConfigurationTest1 instance = new ConfigurationTest1();
}
public static ConfigurationTest1 getInstance() {
return SingletonHolder.instance;
}
private void initProp() throws ConfigurationException {
if (prop == null) {
prop = new PropertiesConfiguration(propName);
}
// load properties ......
// String
setName(prop.getString("name"));
setWorking(prop.getString("working"));
// 如果是 double, 可以這樣寫, 就會幫你轉好了.
// prop.getDouble("double");
// 其它像 integer, ...都是.
// 那如何動態 reload 呢?, 其實很簡單
prop.setReloadingStrategy(new FileChangedReloadingStrategy());
// FileChangedReloadingStrategy <-- 這個是指, 當你修改了 attribute 時, 下一次去存取時, 會先去檢查最後修改日期, 來判斷他是否有修改, 如果有, 就 reaload.
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWorking() {
return working;
}
public void setWorking(String working) {
this.working = working;
}
public static void main(String[] args) {
ConfigurationTest1 config = ConfigurationTest1.getInstance();
System.out.println(config.getName());
System.out.println(config.getWorking());
}
}
Seconds 0-59 , - * /
Minutes 0-59 , - * /
Hours 0-23 , - * /
Day-of-month 1-31 , - * ? / L W
Month 1-12 or JAN-DEC , - * /
Day-of-Week 1-7 or SUN-SAT , - * ? / L #
Year (Optional) empty, 1970-2099 , - * /
'?' - It is used to specify 'no specific value'. (used in Day-of-month, Day-of-Week only)
This is useful when you need to specify something in one of the two fields, but not the other.
<a href="http://mmmmtodd.blogger.com/">學海無涯<a>
<span id="myHref">
<a href="javascript:void(0);" to="http://tw.yahoo.com/">yahoo<a>
<a href="javascript:void(0);" to="http://www.google.com.tw/">google<a>
</span>
var myHref = $("#myHref a");
myHref.click(function() {
var to = $(this).attr("to");
alert(to);
// do something , ex: window.location.href=to
});
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
height與width必須符合w3的規定,加上px
div name=item id=item style=position:relative;visibility:;height:250px;width:300px
略
public interface ICustomer{
public String sync();
public String save();
}
public class Customer implements ICustomer{
public String sync(){
//客戶資料的同步
}
public String save(){
//客戶資料儲存
}
}
public class BusinessLogic{
ICustomer customer;
Public BusinessLogic(ICustomer customer){
this.customer = customer;
}
public void syncCustomer(){
customer.sync();
}
public void saveCustomer(){
customer.save();
}
}
public class DemoClients{
public static void main(String[] args){
//logic
Customer c = new Customer(); //要處理customer資料時
BusinessLogic bl = new BusinessLogic(c);
bl.syncCustomer();
bl.saveCustomer();
}
}
public interface IDealer{
public String buildXML();
public String save();
}
public class Dealer implements IDealer{
public String buildXML(){
//經銷商的實作xml
}
public String save(){
//經銷商的實作save
}
}
public class DealerAdapter implements ICustomer{
private Dealer dealer;
public dealerAdapter(IDealer dealer){
this.dealer = dealer;
}
public String sync(){
dealer.sync();
}
public String save(){
dealer.save();
}
}
public class DemoNewClients{
public static void main(String[] args){
//logic
Customer c = new Customer(); //要處理customer資料時
BusinessLogic bl = new BusinessLogic(c);
bl.syncCustomer();
bl.saveCustomer();
//logic
Dealer dealer = new Dealer(); //當要處理dealer的資料時
DealerAdapter dealerAdapter = new DealerAdapter(dealer);
BusinessLogic bl = new BusinessLogic(dealerAdapter);
bl.syncCustomer(); //對user來講, 使用的接口是相同的, 但行為變了
bl.saveCustomer();
}
}
WildcardQuery wq1 = new WildcardQuery(new Term("id", "*hank*"));
WildcardQuery wq2 = new WildcardQuery(new Term("id", "*todd*"));
bq = new BooleanQuery();
bq.add(wq1, Occur.SHOULD);
bq.add(wq2, Occur.SHOULD);
query = bq;
TermQuery clauses are generated from for example prefix queries and
* fuzzy queries. Each TermQuery needs some buffer space during search,
* so this parameter indirectly controls the maximum buffer requirements for
* query search.
*
When this parameter becomes a bottleneck for a Query one can use a
* Filter. For example instead of a {@link RangeQuery} one can use a
* {@link RangeFilter}.
*
Normally the buffers are allocated by the JVM. When using for example
* {@link org.apache.lucene.store.MMapDirectory} the buffering is left to
* the operating system.
*/
public interface ICommand{
public String execute();
//public String executeXML(); //也可吐xml回去
}
public class CustomerCommand implements ICommand{
Customer customer;
public CustomerCommand(Customer customer){
this.customer = customer;
}
public String execute(){
customer.getDB();
String result = customer.setXML();
return result;
}
}
public class EmployeeCommand implements Icommand(){ ... }
//實作如何取得資料, 並轉成xml
public class Customer{
getDB();
setXML();
...
}
public class Employee{ ... }
public class APIControl(){
Command command;
public APIControl(){}
public void setCommand(Command command){
this.command = command;
}
public String doExecute(){
return command.execute();
}
}
public class DemoCallAPIP{
public static void main(String[] args){
APIControl api = new APIControl();
Customer customer = new Customer();
CustomerCommand customerCommand = new customer(customer);
api.setCommand(customerCommand); //傳入要執行的命令
String xmlResult = api.doExecute(); //就執行囉
}
}
public static void main(String[] args) {
String oriStr = "我是小胖123444#$%^*(";
String afterStr = getChinese(oriStr);
System.out.println(afterStr); // 顯示 "我是小胖"
}
public static String getChinese(String in) {
if (in == null || ("".equals(in))) {
return "";
}
Matcher matcher = Pattern.compile("\\p{InCJKUnifiedIdeographs}").matcher(in);
StringBuffer out = new StringBuffer();
while (matcher.find()) {
out.append(matcher.group());
}
return out.toString();
}
// regex pattern
String filterPattern = "<[^>]+>";
Sring oriStr = "< b>我是小胖< /b>"
System.out.println(oriStr.replaceAll(fileterPattern, "");