`
oham_一1一
  • 浏览: 50017 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
vpn
http://freesstpvpn.net/setup-sstp-vpn/




http://support.winhong.com:82/
用于电子书分割上传到iteye(禁止U盘的解决方案1)
package org.oham.testfile;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class PartitionFileTool {

	private int maxSize;
	
	private static final int BUF_SIZE = 1024;
	
	public PartitionFileTool() 
	{
		// 9MB
		this.maxSize = 1024 * 1024 * 9;
	}
	
	public PartitionFileTool( int maxSize ) 
	{
		this.maxSize = maxSize;
	}
	
	private String convertGzipFileNm(String fileNm, boolean toCompress)
	{
		if( toCompress )
		{
			return fileNm + ".gz";
		}
		
		return fileNm.substring(0, fileNm.indexOf(".gz"));
	}
	
	private void gzipFiles(List<String> partitionFiles)
	{
		InputStream in = null;
		OutputStream out = null;
		int size = partitionFiles.size();
		
		for( String fileNm : partitionFiles )
		{
			try 
			{
				in = new BufferedInputStream(new FileInputStream(fileNm));
				
				out = new FileOutputStream(this.convertGzipFileNm(fileNm, true));
				out = new BufferedOutputStream(new GZIPOutputStream(out));
				
				int data;
				while( (data = in.read()) != -1 )
				{
					out.write(data);
				}
				
				out.flush();
			} 
			catch (FileNotFoundException e) 
			{
				e.printStackTrace();
			} 
			catch (IOException e) 
			{
				e.printStackTrace();
			}
			finally
			{
				try 
				{
					out.close();
					in.close();
					
					if(size > 1)
					{
						File file = new File(fileNm);
						file.delete();
					}
				} 
				catch (Exception e2) {}
			}
		}
	}
	
	private List<String> unGzipFiles(List<String> files)
	{
		InputStream in = null;
		OutputStream out = null;
		
		List<String> partitionFiles = new ArrayList<String>();
		for( String gzFileNm : files )
		{
			try 
			{
				in = new FileInputStream(gzFileNm);
				in = new BufferedInputStream(new GZIPInputStream(in));
				
				String partitionFileNm = this.convertGzipFileNm(gzFileNm, false);
				partitionFiles.add(partitionFileNm);
				
				out = new FileOutputStream(partitionFileNm);
				out = new BufferedOutputStream(out);
				
				int data;
				while( (data = in.read()) != -1 )
				{
					out.write(data);
				}
				out.flush();
				
			} 
			catch (FileNotFoundException e) 
			{
				e.printStackTrace();
			} 
			catch (IOException e) 
			{
				e.printStackTrace();
			}
			finally
			{
				try 
				{
					out.close();
					in.close();
				} 
				catch (Exception e2) {}
			}
		}
		
		return partitionFiles;
	}
	
	public void partitionSrcFile( String srcFileName )  
    {  
		System.out.println("Begin split file: " + srcFileName);
		
        File srcFile = new File(srcFileName);  
        
        List<String> partitionFiles = new ArrayList<String>();
        
        DataInputStream in = null;  
        DataOutputStream out = null;  
        try   
        {  
            in = new DataInputStream(new FileInputStream(srcFile));  
            
            long srcFileSize = in.available();   
            if( srcFileSize > maxSize )
            {
            	byte[] buf = new byte[BUF_SIZE];
            	int readed = 0;
            	int len = 0;
            	int cnt = 1;
            	
            	String partitionFileNm = srcFile.getAbsolutePath() + "_" + cnt;
            	out = new DataOutputStream(new FileOutputStream(partitionFileNm));
            	partitionFiles.add(partitionFileNm);
            	
            	while( (len = in.read(buf)) > 0 )
            	{
            		out.write(buf, 0, len);
            		readed = readed + len;
            		
            		if( readed >= maxSize * cnt )
            		{
            			cnt++;
            			out.flush();
            			out.close();
            			out = new DataOutputStream(new FileOutputStream(srcFile.getAbsolutePath() + "_" + cnt));
            			partitionFileNm = srcFile.getAbsolutePath() + "_" + cnt;
            			partitionFiles.add(partitionFileNm);
            		}
            	}
            }
            else
            {
            	partitionFiles.add(srcFileName);
            }
        }   
        catch (FileNotFoundException e)   
        {  
            e.printStackTrace();  
        }   
        catch (IOException e)   
        {  
            e.printStackTrace();  
        }  
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        finally  
        {  
            try   
            {  
                in.close();  
                if( out != null )  
                {  
                    out.close();  
                }  
            } catch (Exception e2) {}  
        }  
        
        this.gzipFiles(partitionFiles);
        
        System.out.println("Split done");
    }  
	
	
	public void uniteFiles(List<String> files, String trgFileName)  
    {  
		System.out.println("Begin unite the partition files...");
        FileOutputStream out = null;  
        DataInputStream in = null;  
        
        List<String> partitionFiles = this.unGzipFiles(files);
        try   
        {  
            out = new FileOutputStream(trgFileName);  
            for( String fileName : partitionFiles )  
            {  
                in = new DataInputStream(new FileInputStream(fileName));  
                  
                byte[] data = new byte[BUF_SIZE];  
                  
                while( in.read(data) != -1 )  
                {  
                    out.write(data);  
                }  
                  
                out.flush();  
                in.close();  
                
                File f = new File(fileName);
                f.delete();
            }  
        }   
        catch (FileNotFoundException e)   
        {  
            e.printStackTrace();  
        }   
        catch (IOException e)   
        {  
            e.printStackTrace();  
        }  
        finally  
        {  
            try   
            {  
                out.close();  
                in.close();  
                System.out.println("Unite done. see: " + trgFileName);
            }   
            catch (Exception e2) {}  
        }  
    }  
	
	
	public static void main(String[] args) 
	{
		PartitionFileTool tool = new PartitionFileTool();
		
		// patition action
		
//		tool.partitionSrcFile("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf");
		
		//unite action
		List<String> list = new ArrayList<String>();
		
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_1.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_2.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_3.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_4.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_5.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_6.gz");
		list.add("C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java中文版(第2版).pdf_7.gz");
		
		tool.uniteFiles(list, "C:\\Users\\43799538\\Desktop\\old_mac_tmp\\books\\Effective Java.pdf");
	}
}
t1
package org.oham.testthread.effetive;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class TestSynchronizer {

	
	final static class Action implements Runnable {
		
		public List<String> arrangeIndex(int num)
		{
			List<String> list = new ArrayList<String>();
			int levl = (num % 2) == 0 ? num/2: (num+1)/2;
			
			String sep = ",";
			StringBuilder sb = new StringBuilder();
			for( int i=1; i<=levl; i++ )
			{
				int r = i-1;
				int c = i-1;
				int t = num-i;
				
				while( c <= t )
				{
					list.add(sb.append(r).append(sep).append(c).toString());
					sb.delete(0, sb.length());
					c++;
				}
				c = t;
				r++;
				
				while( r <= t )
				{
					list.add(sb.append(r).append(sep).append(c).toString());
					sb.delete(0, sb.length());
					r++;
				}
				r = t;
				c--;
				
				while( c >= (i-1) )
				{
					list.add(sb.append(r).append(sep).append(c).toString());
					sb.delete(0, sb.length());
					c--;
				}
				c = i-1;
				r--;
				
				while( r >= i )
				{
					list.add(sb.append(r).append(sep).append(c).toString());
					sb.delete(0, sb.length());
					r--;
				}
			}
		
			return list;
		}
		
		private void print(String[][] arr, int num)
		{
			System.out.println("Number " + num + "'s Matrix:");
			
			int cnt = 1;
			for(int i=0; i<num; i++)
			{
				for(int j=0; j<num; j++)
				{
					System.out.print(arr[i][j] + "  ");
					
					if( cnt % num == 0 )
					{
						System.out.println();
					}
					
					cnt++;
				}
			}
			
			System.out.println();
			System.out.println();
		}
		
		public void run() 
		{
//			int num = new Random().nextInt(20)+1;
			int num = 10;
			String[][] arr = new String[num][num];
			
			int pow = new Double(Math.pow(num, 2)).intValue();
			int len = Integer.toString(pow).length();
			System.out.println(len);
			
			List<String> list = arrangeIndex(num);
			StringBuilder sb = new StringBuilder();
			for( int i=1; i<=pow; i++ )
			{
				sb.append(i);
				int iLen = sb.length();
				if( iLen < len )
				{
					sb.delete(0, sb.length());
					while( iLen < (len -1) )
					{
						sb.append("0");
						iLen++;
					}
					sb.append(i);
				}
				String[] rc = list.get(i-1).split(",");
				int r = Integer.parseInt(rc[0]);
				int c = Integer.parseInt(rc[1]);
				
				arr[r][c] = sb.toString();
				sb.delete(0, sb.length());
			}
			print(arr, num);
		}
	}
	
	public static void time(Executor executor, int concurrency, final Runnable action) 
					throws InterruptedException
	{
		final CountDownLatch ready = new CountDownLatch(concurrency);
		final CountDownLatch start = new CountDownLatch(1);
		final CountDownLatch done = new CountDownLatch(concurrency);
		
		for( int i = 0; i < concurrency; i++ )
		{
			executor.execute(new Runnable() {
				public void run() 
				{
					ready.countDown();
					try 
					{
						start.await();
						action.run();
					} 
					catch (InterruptedException e) 
					{
						e.printStackTrace();
						Thread.currentThread().interrupt();
					}
					finally
					{
						done.countDown();
					}
				}
			});
		}
		
		ready.await();
		long startTime = System.nanoTime();
		start.countDown();
		done.await();
		long endTime = System.nanoTime();
		System.out.println("taked: " + (endTime-startTime) + "  seconds");
		
	}
	
	
	public static void main(String[] args) 
	{
		Executor executor = Executors.newCachedThreadPool();
		
		Action action = new Action();
		try 
		{
			TestSynchronizer.time(executor, 5, action);
		} 
		catch (InterruptedException e) 
		{
			e.printStackTrace();
		}
	}
}
近期目标
1. 缓存技术,memecache, redis
2. 系统架构配置
3。mysql 优化
4。流行开源框架
5。并发优化


•http://dojotoolkit.org/documentation/tutorials/1.10/hitch/
•http://dojotoolkit.org/reference-guide/1.10/dojo/on.html
•http://dojotoolkit.org/reference-guide/1.10/dojo/Stateful.html
•http://dojotoolkit.org/reference-guide/1.10/dojo/store.html
•http://dojotoolkit.org/reference-guide/1.10/dojo/topic.html
fanhhu bu
package org.oham.csdn;

import java.util.*;

public class FanhuHuan {

    private int lb = (int)'A';
    private int rb = (int)'Z';
    
    private String _getFanHuString(String trg, boolean rollback)
    {
    	
        StringBuilder sb = new StringBuilder();
        if(rollback)
        {
        	for( int i = 0; i < trg.length(); i++ )
            {
                int ascii = trg.charAt(i) - 13;

                if( lb <= ascii && rb >= ascii )
                {
                    sb.append(Character.toString(((char)ascii)));
                }
            }
        }
        else
        {
        	for( int i = 0; i < trg.length(); i++ )
        	{
        		int ascii = trg.charAt(i) + 13;
        		
        		if( lb <= ascii && rb >= ascii )
        		{
        			sb.append(Character.toString(((char)ascii)));
        		}
        	}
        }
        return sb.toString();
    }
    
    
    
    private String _getReverseStr(String trg)
    {
        String str = new StringBuilder(trg).reverse().toString();
        
        return str;
    }
    
    private void _getSubString(String trg, Set<String> set, int limit)
    {
        if( trg.length() > limit )
        {
            this._getSubString(trg.substring(0, trg.length()/2), set, limit);
            this._getSubString(trg.substring(trg.length()/2, trg.length()), set, limit);
        }
        else
        {
        	if( trg.length() > 1 && !set.contains(trg) )
        	{
        		set.add(trg);
        		this._getSubString(trg.substring(0, trg.length()-1), set, limit);
        		this._getSubString(trg.substring(0, trg.length()-1), set, limit);
        	}
        }
    }
    
    private Set<String> _getPopCharString(String src)
    {
        Set<String> set = new HashSet<String>();
        for( int i = 0; i < src.length(); i++ )
        {
            set.add(src.substring(0, i)+src.substring(i+1, src.length()));
        }
        
        Set<String> subSet = new HashSet<String>(); 
        for( String str : set )
        {
            for( int i = 0; i < str.length(); i++ )
            {
                subSet.add(str.substring(0, i)+str.substring(i+1, str.length()));
            }
        }
        
        set.addAll(subSet);
        return set;
    }
    
    private Set<String> _findMatch(Set<String> fhSet, Set<String> revSet, String trg)
    {
    	Set<String> result = new HashSet<String>();
        for( String revStr : revSet )
        {
        	if( fhSet.contains(revStr) && this._isChongDie(trg, revStr, revStr) )
        	{
    			result.add(revStr);
        	}
        	else
        	{
        		Set<String> subSet = this._getPopCharString(revStr);
        		for( String subStr : subSet )
        		{
        			if( fhSet.contains(subStr) && this._isChongDie(trg, subStr, revStr) )
        			{
        				result.add(subStr);
        				break;
        			}
        		}
        	}
        }
        
        return result;
    }
    
    private boolean _isChongDie(String trg, String fhStr, String revStr)
    {
        int fnIdx = trg.indexOf(this._getFanHuString(fhStr, true));
        int revIdx = trg.indexOf(this._getReverseStr(revStr));
        
        if( fnIdx == -1 || revIdx == -1 )
        {
            return false;
        }
        
        if( fnIdx > revIdx )
        {
            if( (revIdx+revStr.length()) <= fnIdx )
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else if( fnIdx < revIdx )
        {
            if( (fnIdx+fhStr.length()) <= revIdx )
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    
    
    //测试入口
    public void printResult(String trg)
    {
        System.out.println("输入参数:" + trg);
        
        String fhStr = this._getFanHuString(trg, false);
        Set<String> fhSet = new HashSet<String>();
        this._getSubString(fhStr, fhSet, trg.length()/2);
        Set<String> revSet = new HashSet<String>();
        String reverse = this._getReverseStr(trg);
        this._getSubString(reverse, revSet, trg.length()/2);
        
        Set<String> matchSet = this._findMatch(fhSet, revSet, trg);
        
        int len = 0;
        for(String matchStr : matchSet )
        {
        	if(matchStr.length() > len)
        	{
        		len = matchStr.length();
        	}
        		
        }
        
        System.out.println("结果: " + len);
    }
    
    public static void main(String[] args) 
    {
        FanhuHuan test = new FanhuHuan();
        
        for(String str : args)
        {
            test.printResult(str.toUpperCase());
        }        
        
    }
}
android sdk 更新
http://jingyan.baidu.com/article/b0b63dbfd0948c4a483070ea.html
信息
https://www.youtube.com/watch?v=ZOi2UgaSTJE
位操作
一半,比如使用一个字节来保存一张扑克牌,字节高位表示花色,字节低位表示数字,如果0代表黑桃,那么黑桃三就应该是0x03,这个需要靠位操作来实现:   int m=0; int n=3;  byte card=(byte)(m)<<4)|((byte)n; //m左移四位,然后与n左或操作      游戏中需要传递用户的积分,这是一个大整数,使用四个字节来保存比较保险,将整数转换为四个字节的操作如下:   public static byte[] translateLong(long mark) {  byte[] b = new byte[4]; for (int i = 0; i < 4; i++) {  b[i] = (byte) (mark >>> (24 - i * 8)); }  return b; }      将四个字节转回来的操作如下:   public static long translateByte(byte[] b) {  int mask = 0xff; int temp = 0; int res = 0;  for (int i = 0; i < 4; i++) {  res <<= 8;  temp = b[i] & mask; res |= temp; }  return res; } 
JSON json
package jsonparser;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class CommonJsonUtil {
	
	public static final String FAULT_STR = "N/A";

	public String parseObjectToJson(Object obj) throws SecurityException, 
														IllegalAccessException, 
														IllegalArgumentException, 
														InvocationTargetException {
		StringBuffer buffer = new StringBuffer();
		buffer.append("{");
		if(obj == null) return null; 
		
		_returnObjJsonStr(obj, buffer);
		
		buffer.append("}");
		return buffer.toString();
	}
	
	private void _returnObjJsonStr(Object obj, StringBuffer buffer) throws SecurityException, 
																				IllegalAccessException, 
																				IllegalArgumentException, 
																				InvocationTargetException {
		
		if(obj instanceof Map) {
			buffer.append("{");
			Map map = (Map)obj;
			Iterator keyIt = map.keySet().iterator();
			while(keyIt.hasNext()) {
				String keyName = keyIt.next().toString();
				buffer.append("," + keyName + ":");
				_returnObjJsonStr(map.get(keyName), buffer);
				
			}
			buffer.append("}");
			
		}else {
			String isAtomic = _getAtomicDataTypeValue(obj);
			if(!FAULT_STR.equals(isAtomic)) {
				buffer.append(isAtomic);
				return;
			}
			
			Object[] isArrayOrList = _isArrayOrListObject(obj);
			if(isArrayOrList != null){
				_returnArrayJsonStr(isArrayOrList, buffer);
			}else {
				if(obj == null) {
					buffer.append("");
					return;
				}
				
				buffer.append("{");
				
				Class classType = obj.getClass();
				Field[] props = classType.getDeclaredFields();
				
				for(Field prop : props) {
					
					try {
						String keyName = prop.getName();
						
						String getMethodName = "get" + keyName.substring(0,1).toUpperCase() + 
								keyName.substring(1, keyName.length());
						
						Method getMethod = classType.getMethod(getMethodName, new Class[]{});
						Object valueObj = getMethod.invoke(obj, new Object[]{});
						
						buffer.append("," + keyName + ":");
						_returnObjJsonStr(valueObj, buffer);
					} catch (NoSuchMethodException e) {
						continue;
					}
				}
				
				buffer.append("}");
				
			}
		}
	}
	
	private void _returnArrayJsonStr(Object[] arr, StringBuffer buffer) throws SecurityException,
																				IllegalAccessException,
																				IllegalArgumentException,
																				InvocationTargetException {
		
		buffer.append("[");
		for(Object obj : arr) {
			_returnObjJsonStr(obj, buffer);
		}
		
		buffer.append("]");
			
		
	}
	
	private Object[] _isArrayOrListObject(Object obj) {
		if(obj.getClass().isArray()) {
			return (Object[]) obj;
		}else if(obj instanceof List) {
			return ((List) obj).toArray();
		}
		return null;
		
	}
	
	private String _getAtomicDataTypeValue(Object obj) {
		if(obj == null) return "";
		
		if(obj.getClass().equals(Integer.class)) {
			return String.valueOf(obj);
		}
		if(obj.getClass().equals(String.class)) {
			return String.valueOf(obj);
		}
		if(obj.getClass().equals(Boolean.class)) {
			return String.valueOf(obj);
		}
		if(obj.getClass().equals(Long.class)) {
			return String.valueOf(obj);
		}
		if(obj.getClass().equals(Double.class)) {
			return String.valueOf(obj);
		}
		if(obj.getClass().equals(char[].class)) {
			return String.valueOf(obj);
		}
		
		return FAULT_STR;
	}
}













import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import jsonparser.CommonJsonUtil;


public class TestCase {

	public class AClass {
		private String aclsId;
		private String aclsName;
		private String aclsDesc;
		
		public AClass(String aclsId, String aclsName, String aclsDesc) {
			this.aclsId = aclsId;
			this.aclsName = aclsName;
			this.aclsDesc = aclsDesc;
		}
		
		public String getAclsId() {
			return aclsId;
		}
		public void setAclsId(String aclsId) {
			this.aclsId = aclsId;
		}
		public String getAclsName() {
			return aclsName;
		}
		public void setAclsName(String aclsName) {
			this.aclsName = aclsName;
		}
		public String getAclsDesc() {
			return aclsDesc;
		}
		public void setAclsDesc(String aclsDesc) {
			this.aclsDesc = aclsDesc;
		}
		
		
		
		
	}
	public class BClass {
		private String bclsId;
		private String bclsName;
		private String bclsDesc;
		private AClass bclsAcls;
		
		public BClass(String bclsId, String bclsName, String bclsDesc) {
			this.bclsId = bclsId;
			this.bclsName = bclsName;
			this.bclsDesc = bclsDesc;
		}
		
		public String getBclsId() {
			return bclsId;
		}
		public void setBclsId(String bclsId) {
			this.bclsId = bclsId;
		}
		public String getBclsName() {
			return bclsName;
		}
		public void setBclsName(String bclsName) {
			this.bclsName = bclsName;
		}
		public String getBclsDesc() {
			return bclsDesc;
		}
		public void setBclsDesc(String bclsDesc) {
			this.bclsDesc = bclsDesc;
		}
		public AClass getBclsAcls() {
			return bclsAcls;
		}
		public void setBclsAcls(AClass bclsAcls) {
			this.bclsAcls = bclsAcls;
		}
	}
	
	
	public static void main(String[] args) {
		new TestCase().testJSONParse();
	}
	
	public void testJSONParse() {
		AClass acls = new AClass("1234", "Oham", "A normal human");
		BClass bcls = new BClass("1235", "Lulu", "A normal dog");
		bcls.setBclsAcls(acls);
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("name", "i'am a Map");
		map.put("bean", bcls);
		
		CommonJsonUtil jsonParser = new CommonJsonUtil();
		try {
			String json1 = jsonParser.parseObjectToJson(acls);
			String json2 = jsonParser.parseObjectToJson(bcls);
			String json3 = jsonParser.parseObjectToJson(map);
			
			
			
			System.out.println(json1);
			System.out.println();
			System.out.println();
			System.out.println(json2);
			System.out.println();
			System.out.println();
			System.out.println(json3);
			
			
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
堆与优先队列
import java.util.*;

public class Heap <T extends Comparable<T>> {

    private T[] heap;
    private int size;

    public Heap() {
		heap = (T[])new Comparable[9];
	}
    
    public T[] getHeap() {
        List<T> list = new ArrayList<T>();
        for(T e : heap) {
            if(e != null){
                list.add(e);
            }
		}
        
        T[] result = (T[])new Comparable[list.size()];
        heap = list.toArray(result);
        return heap;
    }

	
	public void heapSort(T[] elems) {
        for(T elem : elems) {
            add(elem);
        }
        
        if(heap.length >= elems.length) {
            System.arraycopy(heap, 0, elems, 0, elems.length);   
        }else {
            elems = heap;
        }
	}

	public void add(T elem) {
		if(++size >= heap.length) {	
			T[] newHeap = (T[])new Comparable[2*heap.length];
			System.arraycopy(heap, 0, newHeap, 0, size-1);   
		    heap = newHeap; 
		}
		heap[size-1] = elem;
		adjustUp();
	}
    
    public void remove(T elem) {
    	int pos = returnElementPos(elem);
        if(pos != -1) {
    		heap[pos-1] = heap[size-1];
    		adjustDown(pos);
            heap[--size] = null;
        }
        
	}
    
    public void levelSort(T elem) {
        if(size == 0) return;
        int pos =  returnElementPos(elem);
        
        if(pos == -1) return;
        
       /* System.out.print(elem + "-");
        if(pos*2 <= size) {
            int leftChildElem = pos * 2;
            levelSort(heap[leftChildElem-1]);
        }
        
        if(pos*2+1 <= size) {
            int rightChildElem = pos * 2 + 1;
            levelSort(heap[rightChildElem-1]);
        }*/
        
        
        LinkedList queue = new LinkedList();   
        queue.add(pos);   
        while (!queue.isEmpty()) {   
            int num = (Integer) queue.removeFirst();   
            System.out.print(heap[num - 1] + "-");   
            if (num * 2 <= size) {                   
                queue.add(num * 2);   
                if (num * 2 + 1 <= size) {   
                    queue.add(num * 2 + 1);   
                }   
            }   
       }   

    }
    
    private int returnElementPos(T elem) {
        int pos = 0;
    	for(T e: heap) {
			pos++;
			if(e.compareTo(elem) == 0){
				return pos;
			}
		}
        return -1;
    }

	private void adjustUp() {
		int childNum = size;

		while(childNum > 1) {
			int parentNum = childNum/2;
		
			if(heap[childNum-1].compareTo(heap[parentNum-1]) >= 0 ) break;
			
			T tmp = heap[parentNum-1];
			heap[parentNum-1] = heap[childNum-1];
			heap[childNum-1] = tmp;

			childNum = parentNum;
			
		}
		
	}
    
    private void adjustDown(int pos) {
    	int parentNum = pos; 
        
		while(parentNum < size) {
	        int childNum = 2 * parentNum;   
			int minChildNum = parentNum;

			if(childNum < size && heap[childNum-1].compareTo(heap[parentNum-1]) <= 0 ) {
				minChildNum = childNum - 1;
			}

			if( childNum+1 <= size && heap[childNum].compareTo(heap[childNum-1]) <= 0 ) {
				minChildNum = childNum + 1;
			}

		    if(parentNum != minChildNum) {
    			T tmp = heap[parentNum-1];
    			heap[parentNum-1] = heap[minChildNum-1];
    			heap[minChildNum-1] = tmp;
    		
    			parentNum = minChildNum;
		    }else {
    	        break;   
		    }
		}
		
	}

}




public class HelloWorld{

     public static void main(String []args){
        Integer[] preArr = { 12,32,50,37,8,88,11,43,77,89,56};
        
        Heap<Integer> heap = new Heap<Integer>();
        
        
        heap.heapSort(preArr);
        System.out.print("Sort option : ");
        for(Integer i : preArr) {
            System.out.print(i + "-");
        }
        
        System.out.println();   
        
        
        heap.remove(12);
        Comparable[] arr1 = heap.getHeap();
        System.out.print("Remove option : ");
        for(int i=0; i<arr1.length; i++) {
            System.out.print(arr1[i] + "-");
        }
        
        System.out.println(); 
        
        heap.add(13);
        Comparable[] arr2 = heap.getHeap();
        
        System.out.print("Add option : ");
        for(int i=0; i<arr2.length; i++) {
            System.out.print(arr2[i] + "-");
        }
        
        System.out.println(); 
    
        System.out.print("Sort option : ");
        heap.levelSort(11);
        
     }
}




package org.oham.priorityqueque;

import java.util.ArrayList;
import java.util.ListIterator;


public class PriorityQueue <T extends Comparable<T>> {

	private ArrayList<T> list;
	
	public PriorityQueue() {
		list = new ArrayList<T>();
	}
	
	public void add(T elem) {
		
		if( list.isEmpty() || elem.compareTo(list.get(list.size() - 1)) >=0 ) {
			list.add(elem);
		}else{
			ListIterator<T> iterator = list.listIterator();
			
			while( iterator.hasNext() && elem.compareTo(iterator.next()) >=0 );
			
			iterator.previous();
			iterator.add(elem);
		}
	}
	
	public T getMin() {
		if(list.size() == 0){
			throw new NullPointerException("queue is empty");
		}else {
			return list.get(0);
		}
	}
	
	public T removeMin() {
		if(list.size() == 0){
			throw new NullPointerException("queue is empty");
		}else {
			return list.remove(0);
		}
		
    }  
}
文思密码
邮箱密码:wind@1987


https://auth.pactera.com/login?service=http%3a%2f%2fattendance.pactera.com%2findex.aspx


http://elearning.pactera.com. 

 http://ptts.pactera.com 
文思mail
Hello, Bryan,
 
Please activate email address. Thanks.
 
 
 
Best Regards,
 
Erica Liu (劉爱灵)
 
Desk: +86.020.22020041
Mobile: +86.186 2095 0889
Pactera Technology International Limited
Pactera Technology International Limited
This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient or have received this transmission in error, please contact the sender by reply email and destroy all copies of the original message.  Any unauthorized review, use, copy, dissemination, or disclosure of this email is strictly prohibited.
 
发件人: Alan Chen [mailto:chen_weilong@pactera.com] 
发送时间: 2013年9月5日 17:05
收件人: Yulanda Wang (wang_yu-gz@pactera.com); Erica Liu (liu_ailing@pactera.com)
主题: 转发: 欢迎[欧航]加盟文思海辉大家庭!
 
Hi Both,
 
FYI.
 
Best Regards,
 
Alan Chen (陈伟龙)
Desk: +86.20.2202.0073
Mobile: +86.186.8844.7472
Email: chen_weilong@pactera.com

Pactera Technology International Limited
This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient or have received this transmission in error, please contact the sender by reply email and destroy all copies of the original message.  Any unauthorized review, use, copy, dissemination, or disclosure of this email is strictly prohibited.
 
发件人: Service Desk 
发送时间: 2013年9月5日 16:54
收件人: hang.ou@pactera.com; Alan Chen
抄送: GZ_ESC; Luo,Yanwu; li_xiangjiao-gz
主题: 欢迎[欧航]加盟文思海辉大家庭!
 
 
cid:image001.png@01CE22EB.512792D0
温馨提示:请直线经理或者您指派的同事在员工入职当天将员工邮箱信息告知员工,谢谢您对新员工的关注。
亲爱的欧航,您好!
文思海辉正热情的张开双臂,欢迎您的加入!
刚刚投入文思海辉的怀抱,您是不是有些陌生感,会不会因为这样或者那样的问题而感到困扰?请不要着急,文思海辉的每一位成员都会热心的帮助您尽快熟悉环境,并顺利的融入这个大家庭!
以下内容将能够很好的帮助您了解如何开始在文思海辉的工作,请仔细阅读:
cid:image002.png@01CE22EB.512792D0
n  工作时间:
l  公司实行每天8小时标准工作日,每周5天标准工作周制度,周工作小时为40小时,特殊岗位执行不定时工作制。具体上下班时间以People Manager告知的为准。
             上下班需打卡!
cid:image002.png@01CE22EB.512792D0
n  文思海辉帐户:
从您加入文思海辉的那一刻,您就拥有了一个将一直伴随您的员工编号和邮箱帐户,也是您登陆内部各种平台的帐户。
l  员工编号:P0033456
l  邮箱帐户:hang.ou,您的邮箱地址是 hang.ou@pactera.com
l  首次登陆邮箱时,请务必登录https://ldap.vanceinfo.com  修改初始密码。    Ps:帐号:hang.ou初始密码:mr104hkgeqgt
l   Web方式登陆邮箱:您可以登陆http://webmail.pactera.com
cid:image002.png@01CE22EB.512792D0
n  新员工培训:
l  NEO在线:您在入职后第二个月内,将收到来自人力资源部的NEO通知邮件,告知您要学习的课程及相应的学习要求。您需要在规定的时间内完成NEO在线培训并通过课程测试。
通过课程的学习,您将会很快了解文思海辉、了解您的工作环境、以及您需要做好的准备。  如未收到邮件,请发送邮件至L&D@pactera.com联系!
 特别提示:是否完成NEO在线培训并通过考试,将作为您转正的必要条件之一。
l  面对面沟通:人力资源部将不定期组织由Site manager或公司管理层与新员工的面对面沟通,请注意查收来自人力资源部的邮件。
cid:image002.png@01CE22EB.512792D0
n  交付人员完善个人信息:
如果您是在中国大陆地区工作的交付项目组成员(工作角色为:工程师、助理工程师、项目组长、项目经理等),请登录以下系统,完善您的个人信息。
每位员工个人信息的有效及时更新,对公司、部门及您的直线经理全面掌握交付资源信息,合理规划并使用交付资源至关重要,也是您向公司、部门、直线经理,全面展示能力的好机会,请务必认真对待。
 
1.      网址:http://ptts.pactera.com/

2.      用户名:员工编号

3.      密码:文思海辉邮箱密码

4.      填写路径:我的淘宝/基本信息维护

n  说明:
1.      请于入职1个月内完成个人信息的更新,数据完整性将作为转正的必要条件之一。
2.      数据完整性的标准:以语言技能、工作经验、个人技能这三项作为填写完整度的标准。
cid:image003.png@01CE22EB.512792D0
n  公司内部各种平台:
平台
功能及内容
地址
登陆帐户
文思海辉内网
信息发布
http://hub.pactera.com
用户名:邮箱帐户
密码:邮箱密码
文思海辉SERP
工时票填写、考勤管理
http://serp.pactera.com/
用户名:员工编号
密码:初始密码同员工编号(首字母大写)
文思海辉在线学习平台
在线学习,资源共享
http://learning.pactera.com/
用户名:邮箱帐户
密码:邮箱密码
文思海辉出差申请平台
出差申请
http://travel.pactera.com/
用户名:邮箱帐户
密码:邮箱密码
文思海辉内部推荐系统
员工推荐
http://irs.pactera.com
用户名:邮箱帐户
密码:邮箱密码
 
 
 
cid:image002.png@01CE22EB.512792D0
n  常用的办事联系信息:
主要事宜
联系人
邮箱(@pactera.com)
联系电话
IT支持
Yang,Jieheng(津滨)
gzservicedesk
020-22123820
Yang,Jieheng(广电)
gzservicedesk
020-22123820
办公用品申领
Li,Jinxuna(广电)
li_jinxuna
18902206535
Judy,Peng(津滨)
judy.peng
18961828940
社保、公积金、商保手续办理
Mao,Dan
denie.mao
020-22123804
薪资查询
fu_shunping
fu_shunping
0755-3688009
借款、报销、付款及费用预提
Xu,Yan
xu_yan-crystal
0755-26716753
(文思海辉技术有限公司广州分公司)
Sun,Yang
maggie.sun
0755-86680166
(无锡文思海辉软件有限公司广州分公司)
 
 
好了,通过以上的介绍,您是不是对您的工作环境有了一定的了解。当然,如果还有其他疑问,您可以随时与文思海辉的每一位成员咨询沟通,大家都会热心的为您解答。
最后,祝您在文思海辉工作的第一天,快乐!
Global site tag (gtag.js) - Google Analytics