package testAle;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.time.DateUtils;
import com.budco.bmp.core.util.DateUtil;
public class TestForAndFor {
public TestForAndFor() {
// TODO Auto-generated constructor stub
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
TestForAndFor ta = new TestForAndFor();
long a =1;
long n;
long m;
for(n=1;n<=3;n++){
// System.out.println("n="+n);
for(m=1;m<=n;m++){
// System.out.println("m="+m);
a*=m;
// System.out.println(a);// a=12
}
}
System.out.println("===========");
Map map = new HashMap();
map.put("bat0", "test0");
map.put("bat1", "test1");
map.put("bat2", "test2");
if (map != null && map.size() > 0) {
// System.out.println("------size="+map.size());
String s1 = (String)map.get("bat3");
String s2 = (String)map.get("bat1");
// System.out.println("------s1="+s1);
// System.out.println("------s2="+s2);
// for (int i = 0; i < map.size();i++) {
// String s1 = (String)map.get("bat0");
//
// }
}
// System.out.println("方法一 Start");
// 方法一: 通过Map.entrySet().iterator()方法来取得key值和value值
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> me = (Map.Entry<String, String>)iter.next();
String key = me.getKey();
String values = me.getValue();
// System.out.println("key: "+key+" values: "+values);
}
final Calendar today = Calendar.getInstance();
final Calendar today2 = Calendar.getInstance();
int min1 = today2.get(today.DAY_OF_WEEK)-1;
int min2 = today2.get(today.DAY_OF_WEEK);
System.out.println("------min1="+min1);
System.out.println("------min2="+min2);
today.add(today.DATE, -min1);
final Date titleDate = DateUtil.getPastDate(12);
//titleDate.g
today.setTime(titleDate);
final Date start = DateUtil.date(today.get(Calendar.YEAR), today.get(Calendar.MONTH), 1);
Date preDate = DateUtils.addMonths(start, -1);
String DATE_FORMAT = "dd-MMM-yy";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
final SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy");
String currentDateStr = sdf1.format(start);
String header = sdf.format(preDate).toUpperCase();
System.out.println("-----------currentDateStr="+currentDateStr);
System.out.println("-----------header="+header);
today2.add(today2.DATE, -min2);
String end = new java.sql.Date(today2.getTime().getTime()).toString();
System.out.println("-----------end="+end);
today2.add(today2.DATE, -6);
String startDate = new java.sql.Date(today2.getTime().getTime()).toString();
System.out.println("-----------startDate="+startDate);
// String Email ="haolg@homtail.com";
// String Email ="haolg@homtail.com..";
String Email ="10.0.com";
String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(Email);
boolean isMatched = matcher.matches();
if(isMatched){
System.out.println("its a email");
}else{
System.out.println("its not a email");
}
int[] columnLocate = new int[10];
for (int i = 0; i < columnLocate.length; i++){
columnLocate[i] = -1;
}
for (int h : columnLocate) {
System.out.println(h);
}
String[] salePerson = new String[]{"jimm_hi1","jimm_hi2","jimm_hi3","jimm_hi4","jimm_hi5","jimm_hi6"};
Vector va = new Vector();
// va.insertElementAt("test haol", 0);
Vector va2 = new Vector();
va2.addElement("test -eee");
va.add(salePerson);
Vector vt = new Vector();
vt.add("ale1");
vt.add("ale2");
vt.add("ale3");
vt.add("ale4");
vt.add("ale5");
vt.add("ale6");
vt.add("ale7");
vt.add("ale8");
vt.add("ale9");
vt.add("ale10");
String[] tmame = new String[vt.size()];
// 'copyInto'把Vector拷贝到数组中去
vt.copyInto(tmame);
System.out.println(tmame[0]);
// for (int i = 0; i < vt.size(); i++) {
// String ng = (String)vt.get(i);
// System.out.println("ng ="+ng);
// }
Hashtable filter = new Hashtable();
filter.put("SALESPERSON", va);
filter.put("key1", va2);
filter.put("key2", vt);
// 矢量 Vector 存在在 Hashtable中
ta.getContactReportsSelectSalesPerson(filter);
StringBuffer sb = new StringBuffer();
String selectLables[] = {"Company","Contact","Phone","Email","Industry","Sales_Person","Credit_Limit","Client_Source"};
int[] selectColumnNumes = new int[selectLables.length];
int[] labesLoad = ta.getLoadLableColumn();
String[] originally = ta.getContactReportsColumnLabels();
for (int i = 0; i < originally.length; i++){
for (int j =0; j < selectLables.length; j++) {
if (originally[i].equalsIgnoreCase(selectLables[j])) {
labesLoad[j] = i;
selectColumnNumes[j] = i;
break;
}
}
}
for (int k1 : labesLoad) {
System.out.println("---="+k1);
}
for (int k : selectColumnNumes) {
System.out.println("---="+k);
}
for (int ik =0; ik < 5; ik++) {
for (int i=0; i < selectLables.length; i++){
if (selectColumnNumes[i]==-1) {
throw new Exception(originally[i] + " can not be selected!");
}
switch(selectColumnNumes[i]){
case 0:
sb.append("Company0"+ik+"||");
break;
case 1:
sb.append("Contact0"+ik+"||");
break;
case 2:
sb.append("Phone0"+ik+"||");
break;
case 3:
sb.append("Email0"+ik+"||");
break;
case 4:
sb.append("\"Industry0\""+ik+"||");
break;
case 5:
sb.append("Sales_Person0"+ik+"||");
break;
case 6:
sb.append("Sales_Person0"+ik+"||");
break;
case 7:
sb.append("Status0"+ik+"||");
break;
case 8:
sb.append("Tag0"+ik+"||");
break;
case 16:
sb.append("Credit_Limit0"+ik+"||");
break;
case 19:
sb.append("Client_Source0"+ik+"||\n\r");
break;
default:
sb.append("");
}
}
}
System.out.println(sb.toString());
String[][] strArray =new String[][] { { "NVP_TX_SITE_REFERRED_BY", "referred_by_040" },
{ "NVP_TX_ALL_COMMUNIC_OPTIN", "1" }, { "NVP_TX_IP_ADDRESS", "ip_address_040" }};
//定义数组转参数
Object[][] objectArray = ta.getAarryList(strArray);
for (int i=0; i < strArray.length; i++) {
for (int j =0; j < strArray[i].length; j++) {
System.out.println("--------> shu zhu= "+ (String)strArray[i][j]);
}
}
String str0 = "TEST00";
String str1 = "TEST10";
String str2 = "TEST20";
String str3 = "TEST30";
Object[] oi = ta.getOneDimensionalArray(str0,str1,str2,str3);
for (int i =0; i <oi.length; i++) {
String output = (String)oi[i];
System.out.println("------output----> "+output);
}
}
private int[] getLoadLableColumn(){
int[] lablecolumn = new int[20];
for (int i = 0; i < 20; i++) {
lablecolumn[i] = -1;
}
return lablecolumn;
}
private String[] getContactReportsColumnLabels () {
String[] columnLabels = {"Company","Contact","Phone","Email","Industry","Sales_Person","Status",
"Tag","Add_Date","Web_Site","Address","City","State","Zip","Country",
"Payment","Credit_Limit","Rating","Description","Client_Source"};
return columnLabels;
}
private String[] getContactReportsSelectSalesPerson(Hashtable filter) {
//String[] salesPersonLabels = getContactReportsSalesPersonLabels();
//String[] salesPersonValues = getContactReportsSalesPersonValues();
Vector vet = new Vector();
if (filter.containsKey("SALESPERSON")){
vet = (Vector)filter.get("SALESPERSON");
Iterator it = vet.iterator();
while (it.hasNext()){
for (String ig : (String[])it.next()) {
System.out.println("--------------SALESPERSON------="+ig);
}
}
System.out.println("--------------SALESPERSON---size---="+vet.size());
}
if (filter.containsKey("key1")) {
Vector strkey1 = (Vector)filter.get("key1");
System.out.println("test--->"+strkey1.elementAt(0));
// strkey1.removeElement("test -eee");
// strkey1.removeElementAt(0);
// setElementAt() 设的值index 不可以大于等于 Vector.size()
strkey1.setElementAt("test-00", 0);
strkey1.insertElementAt("test22", 1);
strkey1.insertElementAt("test23", 2);
// 索引存在的值从index值开始
int iy = strkey1.indexOf("test23",0);
System.out.println("--------index i=>"+iy);
Iterator it = strkey1.iterator();
while (it.hasNext()){
System.out.println("-----------"+(String)it.next());
}
System.out.println("-------------------------vector key1 ="+strkey1);
}
// 获得对象的值:一个用For , 令一个是Iterator 用法
if (filter.containsKey("key2")) {
Vector vaKey2 = (Vector)filter.get("key2");
for (int i =0; i < vaKey2.size(); i++){
System.out.println("va => "+vaKey2.elementAt(i));
}
Iterator its = vaKey2.iterator();
while (its.hasNext()){
Object ts = its.next();
System.out.println("-------------------------vector key2 ="+ts.toString());
}
}
String[] selectSalesPerson = new String[vet.size()];
System.out.println("--------selectSalesPerson-----------="+selectSalesPerson.toString());
// vet.copyInto(selectSalesPerson);
return selectSalesPerson;
}
private Object[][] getAarryList(Object[]...parameters){
String[][] arr = new String[3][2];
Object[][] ob = parameters;
for(int k = 0; k < parameters.length; k++){
for (int n =0; n < parameters[k].length;n++){
if (((String)parameters[k][n]).equals("NVP_TX_SITE_REFERRED_BY")) {
arr[k][n] ="TEST_00";
}else {
arr[k][n] = (String)parameters[k][n];
}
System.out.println("--------get shu zu=>"+arr[k][n]);
}
}
// arr = parameters;
return ob;
}
private Object[] getOneDimensionalArray(Object...oneDimArray){
Object[] o = oneDimArray;
for (Object oo : o){
if (((String)oo).equals("TEST20")) {
System.out.println("ooooooo->"+(String)oo);
}
}
return o;
}
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.time.DateUtils;
import com.budco.bmp.core.util.DateUtil;
public class TestForAndFor {
public TestForAndFor() {
// TODO Auto-generated constructor stub
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
TestForAndFor ta = new TestForAndFor();
long a =1;
long n;
long m;
for(n=1;n<=3;n++){
// System.out.println("n="+n);
for(m=1;m<=n;m++){
// System.out.println("m="+m);
a*=m;
// System.out.println(a);// a=12
}
}
System.out.println("===========");
Map map = new HashMap();
map.put("bat0", "test0");
map.put("bat1", "test1");
map.put("bat2", "test2");
if (map != null && map.size() > 0) {
// System.out.println("------size="+map.size());
String s1 = (String)map.get("bat3");
String s2 = (String)map.get("bat1");
// System.out.println("------s1="+s1);
// System.out.println("------s2="+s2);
// for (int i = 0; i < map.size();i++) {
// String s1 = (String)map.get("bat0");
//
// }
}
// System.out.println("方法一 Start");
// 方法一: 通过Map.entrySet().iterator()方法来取得key值和value值
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> me = (Map.Entry<String, String>)iter.next();
String key = me.getKey();
String values = me.getValue();
// System.out.println("key: "+key+" values: "+values);
}
final Calendar today = Calendar.getInstance();
final Calendar today2 = Calendar.getInstance();
int min1 = today2.get(today.DAY_OF_WEEK)-1;
int min2 = today2.get(today.DAY_OF_WEEK);
System.out.println("------min1="+min1);
System.out.println("------min2="+min2);
today.add(today.DATE, -min1);
final Date titleDate = DateUtil.getPastDate(12);
//titleDate.g
today.setTime(titleDate);
final Date start = DateUtil.date(today.get(Calendar.YEAR), today.get(Calendar.MONTH), 1);
Date preDate = DateUtils.addMonths(start, -1);
String DATE_FORMAT = "dd-MMM-yy";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
final SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy");
String currentDateStr = sdf1.format(start);
String header = sdf.format(preDate).toUpperCase();
System.out.println("-----------currentDateStr="+currentDateStr);
System.out.println("-----------header="+header);
today2.add(today2.DATE, -min2);
String end = new java.sql.Date(today2.getTime().getTime()).toString();
System.out.println("-----------end="+end);
today2.add(today2.DATE, -6);
String startDate = new java.sql.Date(today2.getTime().getTime()).toString();
System.out.println("-----------startDate="+startDate);
// String Email ="haolg@homtail.com";
// String Email ="haolg@homtail.com..";
String Email ="10.0.com";
String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(Email);
boolean isMatched = matcher.matches();
if(isMatched){
System.out.println("its a email");
}else{
System.out.println("its not a email");
}
int[] columnLocate = new int[10];
for (int i = 0; i < columnLocate.length; i++){
columnLocate[i] = -1;
}
for (int h : columnLocate) {
System.out.println(h);
}
String[] salePerson = new String[]{"jimm_hi1","jimm_hi2","jimm_hi3","jimm_hi4","jimm_hi5","jimm_hi6"};
Vector va = new Vector();
// va.insertElementAt("test haol", 0);
Vector va2 = new Vector();
va2.addElement("test -eee");
va.add(salePerson);
Vector vt = new Vector();
vt.add("ale1");
vt.add("ale2");
vt.add("ale3");
vt.add("ale4");
vt.add("ale5");
vt.add("ale6");
vt.add("ale7");
vt.add("ale8");
vt.add("ale9");
vt.add("ale10");
String[] tmame = new String[vt.size()];
// 'copyInto'把Vector拷贝到数组中去
vt.copyInto(tmame);
System.out.println(tmame[0]);
// for (int i = 0; i < vt.size(); i++) {
// String ng = (String)vt.get(i);
// System.out.println("ng ="+ng);
// }
Hashtable filter = new Hashtable();
filter.put("SALESPERSON", va);
filter.put("key1", va2);
filter.put("key2", vt);
// 矢量 Vector 存在在 Hashtable中
ta.getContactReportsSelectSalesPerson(filter);
StringBuffer sb = new StringBuffer();
String selectLables[] = {"Company","Contact","Phone","Email","Industry","Sales_Person","Credit_Limit","Client_Source"};
int[] selectColumnNumes = new int[selectLables.length];
int[] labesLoad = ta.getLoadLableColumn();
String[] originally = ta.getContactReportsColumnLabels();
for (int i = 0; i < originally.length; i++){
for (int j =0; j < selectLables.length; j++) {
if (originally[i].equalsIgnoreCase(selectLables[j])) {
labesLoad[j] = i;
selectColumnNumes[j] = i;
break;
}
}
}
for (int k1 : labesLoad) {
System.out.println("---="+k1);
}
for (int k : selectColumnNumes) {
System.out.println("---="+k);
}
for (int ik =0; ik < 5; ik++) {
for (int i=0; i < selectLables.length; i++){
if (selectColumnNumes[i]==-1) {
throw new Exception(originally[i] + " can not be selected!");
}
switch(selectColumnNumes[i]){
case 0:
sb.append("Company0"+ik+"||");
break;
case 1:
sb.append("Contact0"+ik+"||");
break;
case 2:
sb.append("Phone0"+ik+"||");
break;
case 3:
sb.append("Email0"+ik+"||");
break;
case 4:
sb.append("\"Industry0\""+ik+"||");
break;
case 5:
sb.append("Sales_Person0"+ik+"||");
break;
case 6:
sb.append("Sales_Person0"+ik+"||");
break;
case 7:
sb.append("Status0"+ik+"||");
break;
case 8:
sb.append("Tag0"+ik+"||");
break;
case 16:
sb.append("Credit_Limit0"+ik+"||");
break;
case 19:
sb.append("Client_Source0"+ik+"||\n\r");
break;
default:
sb.append("");
}
}
}
System.out.println(sb.toString());
String[][] strArray =new String[][] { { "NVP_TX_SITE_REFERRED_BY", "referred_by_040" },
{ "NVP_TX_ALL_COMMUNIC_OPTIN", "1" }, { "NVP_TX_IP_ADDRESS", "ip_address_040" }};
//定义数组转参数
Object[][] objectArray = ta.getAarryList(strArray);
for (int i=0; i < strArray.length; i++) {
for (int j =0; j < strArray[i].length; j++) {
System.out.println("--------> shu zhu= "+ (String)strArray[i][j]);
}
}
String str0 = "TEST00";
String str1 = "TEST10";
String str2 = "TEST20";
String str3 = "TEST30";
Object[] oi = ta.getOneDimensionalArray(str0,str1,str2,str3);
for (int i =0; i <oi.length; i++) {
String output = (String)oi[i];
System.out.println("------output----> "+output);
}
}
private int[] getLoadLableColumn(){
int[] lablecolumn = new int[20];
for (int i = 0; i < 20; i++) {
lablecolumn[i] = -1;
}
return lablecolumn;
}
private String[] getContactReportsColumnLabels () {
String[] columnLabels = {"Company","Contact","Phone","Email","Industry","Sales_Person","Status",
"Tag","Add_Date","Web_Site","Address","City","State","Zip","Country",
"Payment","Credit_Limit","Rating","Description","Client_Source"};
return columnLabels;
}
private String[] getContactReportsSelectSalesPerson(Hashtable filter) {
//String[] salesPersonLabels = getContactReportsSalesPersonLabels();
//String[] salesPersonValues = getContactReportsSalesPersonValues();
Vector vet = new Vector();
if (filter.containsKey("SALESPERSON")){
vet = (Vector)filter.get("SALESPERSON");
Iterator it = vet.iterator();
while (it.hasNext()){
for (String ig : (String[])it.next()) {
System.out.println("--------------SALESPERSON------="+ig);
}
}
System.out.println("--------------SALESPERSON---size---="+vet.size());
}
if (filter.containsKey("key1")) {
Vector strkey1 = (Vector)filter.get("key1");
System.out.println("test--->"+strkey1.elementAt(0));
// strkey1.removeElement("test -eee");
// strkey1.removeElementAt(0);
// setElementAt() 设的值index 不可以大于等于 Vector.size()
strkey1.setElementAt("test-00", 0);
strkey1.insertElementAt("test22", 1);
strkey1.insertElementAt("test23", 2);
// 索引存在的值从index值开始
int iy = strkey1.indexOf("test23",0);
System.out.println("--------index i=>"+iy);
Iterator it = strkey1.iterator();
while (it.hasNext()){
System.out.println("-----------"+(String)it.next());
}
System.out.println("-------------------------vector key1 ="+strkey1);
}
// 获得对象的值:一个用For , 令一个是Iterator 用法
if (filter.containsKey("key2")) {
Vector vaKey2 = (Vector)filter.get("key2");
for (int i =0; i < vaKey2.size(); i++){
System.out.println("va => "+vaKey2.elementAt(i));
}
Iterator its = vaKey2.iterator();
while (its.hasNext()){
Object ts = its.next();
System.out.println("-------------------------vector key2 ="+ts.toString());
}
}
String[] selectSalesPerson = new String[vet.size()];
System.out.println("--------selectSalesPerson-----------="+selectSalesPerson.toString());
// vet.copyInto(selectSalesPerson);
return selectSalesPerson;
}
private Object[][] getAarryList(Object[]...parameters){
String[][] arr = new String[3][2];
Object[][] ob = parameters;
for(int k = 0; k < parameters.length; k++){
for (int n =0; n < parameters[k].length;n++){
if (((String)parameters[k][n]).equals("NVP_TX_SITE_REFERRED_BY")) {
arr[k][n] ="TEST_00";
}else {
arr[k][n] = (String)parameters[k][n];
}
System.out.println("--------get shu zu=>"+arr[k][n]);
}
}
// arr = parameters;
return ob;
}
private Object[] getOneDimensionalArray(Object...oneDimArray){
Object[] o = oneDimArray;
for (Object oo : o){
if (((String)oo).equals("TEST20")) {
System.out.println("ooooooo->"+(String)oo);
}
}
return o;
}
}