跳到主要內容

發表文章

目前顯示的是 11月, 2016的文章

Java HashCode and Equals

Equals 在實現 equals 這個方法之前, 應該先想的是怎樣才算是相等? 先看個例子 http://openhome.cc/Gossip/JavaEssence/ObjectEquality.html String s1 = new String("Java"); String s2 = new String("Java"); System.out.println(s1 == s2); // 顯示 false System.out.println(s1.equals(s2)); // 顯示 true 使用 Apache commons 可以協助更快的定義 entity 的差異, 比如說 Item(商品), 用商品的 uId 來定義是否相等。 文章建議, 在定義 equals() 的同時, 最好也定義 hashCode() , 這是兩件不同的事情, hashCode() 就像物件的身分證, 會更嚴格的處理物件身份的問題, 在 Collection 類的操作會常用到。 隨便的例子 package entitys; import lombok.AllArgsConstructor; import lombok.Data; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; /** * Created by jerry on 2017/9/22. */ @Data @AllArgsConstructor public class Apple { private String name; private String type; private String price; @Override public boolean equals(Object obj) { if (!(obj instanceof Apple)) { return false; } if(obj == this) { ...

Git Sync Remote Branch

pull master 遇到 error: cannot lock ref 'refs/remotes/origin/feature/lambda/dynamoDb': 'refs/remotes/origin/feature/lambda' exists; cannot create 'refs/remotes/origin/feature/lambda/dynamoDb' source tree 提示 error: some local refs could not be updated; try running 'git remote prune origin' to remove any old, conflicting branches 會發生這個原因, 是因為 remote 端的 branch 已經被刪除了,所以造成跟本地端的 branch 不同步。 prune 翻譯為修剪, 可以用這個指令來修剪本地的分支, 解決分支不同步的問題。 按照指示操作 git remote prune origin 查了一下文件 prune Deletes all stale remote-tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in "remotes/". With --dry-run option, report what branches will be pruned, but do not actually prune them. 指令後半段的 origin 是 Git 自動替你將 remote 的 repository 命名為 origin , 這個指令會自動修剪掉在 remote (origin) 上過期的分支。 加上 --dry-run 會列出哪些 branch 會被修剪。

修正 Git Remote 上面 Folder 大小寫問題

git mv git mv improper_Case improve_case2 git mv improve_case2 improve_case git commit -m "" 考慮設定 git config core.ignorecase false core.ignoreCase If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds "makefile" when Git expects "Makefile", Git will assume it is really the same file, and continue to remember it as "Makefile". The default is false, except git-clone[1] or git-init[1] will probe and set core.ignoreCase true if appropriate when the repository is created.