package chapter3.item8;

/**
 * Copyright [2017$] [Wuxinshui]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuxinshui on 2017/2/13.
 */
//Broken - violates symmetry
	//equals约定：自反性，对象必须等于其自身
public class CaseInsensitiveString {
	private final String s;

	public CaseInsensitiveString(String s) {
		if (s==null)
			throw new NullPointerException();
		this.s = s;
	}

	//Broken -violates symmetry
	//equals方法的意图很好，它企图与普通的字符串（String）对象进行互操作。
	@Override
	public boolean equals(Object o) {
		if (o instanceof  CaseInsensitiveString){
			return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
		}
		if (o instanceof String){
			return s.equalsIgnoreCase((String) o);
		}
		return false;
	}

	public static void main(String[] args) {
		CaseInsensitiveString cis=new CaseInsensitiveString("Polish");
		String s ="polish";

		System.out.println(cis.equals(s));
		System.out.println(s.equals(cis));

		CaseInsensitiveString cis1=cis;
		System.out.println(cis1.equals(cis));

		List<CaseInsensitiveString> cisList=new ArrayList<>();
		cisList.add(cis);
		if (cisList.contains(s)){
			System.out.println("cisList contains");
		}else {
			System.out.println("cisList not contains");
		}
	}

	//重构后的equals方法
	public boolean equalss(Object o){
		return o instanceof CaseInsensitiveString && s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
	}

}

@@ -990,48 +990,13 @@
 %0A%09//
-equals%E6%96%B9%E6%B3%95%E7%9A%84%E6%84%8F%E5%9B%BE%E5%BE%88%E5%A5%BD%EF%BC%8C%E5%AE%83%E4%BC%81%E5%9B%BE%E4%B8%8E%E6%99%AE%E9%80%9A%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%EF%BC%88String%EF%BC%89%E5%AF%B9%E8%B1%A1%E8%BF%9B%E8%A1%8C%E4%BA%92%E6%93%8D%E4%BD%9C%E3%80%82
+%E8%BF%9D%E5%8F%8D%E5%AF%B9%E7%A7%B0%E6%80%A7
 %0A%09@O
@@ -1147,16 +1147,61 @@
 s);%0A%09%09%7D%0A
+%09%09//equals%E6%96%B9%E6%B3%95%E7%9A%84%E6%84%8F%E5%9B%BE%E5%BE%88%E5%A5%BD%EF%BC%8C%E5%AE%83%E4%BC%81%E5%9B%BE%E4%B8%8E%E6%99%AE%E9%80%9A%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%EF%BC%88String%EF%BC%89%E5%AF%B9%E8%B1%A1%E8%BF%9B%E8%A1%8C%E4%BA%92%E6%93%8D%E4%BD%9C%E3%80%82%0A
 %09%09if (o 

add comments