package com.platform.test;

import java.beans.IntrospectionException;
import java.lang.reflect.Field;

import org.junit.Test;

import com.platform.entities.SqlFileInfoEntity;
import com.platform.entities.PreDataInfo;
import com.platform.utils.BeanCopy;

public class BeanCopyTest {
	
	@Test
	public void testCopy() {
		PreDataInfo preDataInfo = new PreDataInfo();
		preDataInfo.setAreaCode("area");
		preDataInfo.setCityName("setCityName");
		preDataInfo.setDistrictName("setDistrictName");
		preDataInfo.setSysCode(4);
		preDataInfo.setSysName("sysName");
		SqlFileInfoEntity myfile = new SqlFileInfoEntity();
		
		BeanCopy.copyBean(preDataInfo, myfile, "id");
		System.out.println(myfile.getSysName());
		
		myfile = new SqlFileInfoEntity();
		
		try {
			BeanCopy.copyField(preDataInfo, myfile, "id");
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		System.out.println(myfile.getSysName());
	}
	
	@Test
	public void testString() {
		String id = "";
		System.out.println(id.isEmpty());
	}
	
	@Test
	public void testIntOr() {
		int tableScript = 0; // 1111
		int res = tableScript | 1;
		System.out.println(res);
		System.out.println(Integer.toBinaryString(res));
		System.out.println("----");
		res = res | 2;
		System.out.println(res);
		System.out.println(Integer.toBinaryString(res));
		System.out.println("--------");
		int tableScript2 = 0; // 1111
		res = tableScript2 | 2;
		System.out.println(res);
		System.out.println(Integer.toBinaryString(res));
	}
	
	@Test
	public  void testIntAnd() {
		Integer[] num = new Integer[3];
		num[0] = 2;
		num[1] = 3;
		num[2] = 0;
		System.out.println(getTotalStatus(num));
		
	}
	
	private String getTotalStatus(Integer[] numArr) {
		Integer result = 1;
		for (Integer integer : numArr) {
			if (integer != 1) {
				result = integer;
			}
		}
		if (result == 1) {
			return String.valueOf(result);
		}
		for (Integer integer : numArr) {
			if (integer != 1) {
				result = result & integer;
			}
		}
		return String.valueOf(result);
	}
	
	@Test
	public void testFiels() {
		PreDataInfo pre = new PreDataInfo();
		Field[] f = pre.getClass().getDeclaredFields();
		for (int i = 0; i < f.length; i++) {
			Field tm = f[i];
			tm.setAccessible(true);
			System.out.println(tm.getGenericType().toString());
		}

	}

}
