Utility.java ( File view )

  • By jiajia333666 2013-11-28
  • View(s):119
  • Download(s):3
  • Point(s): 2
			package dbscan;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Utility {

	
	/**
	 * 测试两个点之间的距离
	 * @param p 点
	 * @param q 点
	 * @return 返回两个点之间的距离
	 */
	public static double getDistance(Point p,Point q){

		int dx=p.getX()-q.getX();
		int dy=p.getY()-q.getY();
		double distance=Math.sqrt(dx*dx+dy*dy);
		return distance;
	
}

	/**
	 * 检查给定点是不是核心点
	 * @param lst 存放点的链表
	 * @param p 待测试的点
	 * @param e e半径
	 * @param minp 密度阈值
	 * @return 暂时存放访问过的点
	 */
	public static List isKeyPoint(List lst,Point p,int e,int minp){

		int count=0;
		List tmpLst=new ArrayList();
		for(Iterator it=lst.iterator();it.hasNext();){

			Point q=(Point) it.next();
			if(getDistance(p,q)<=e){

				++count;
				if(!tmpLst.contains(q)){

					tmpLst.add(q);
				
}
			
}
		
}
		if(count>=minp){

			p.setKey(true);
			return tmpLst;
		
}
		return null;
	
}

	public static void setListClassed(List<Point> lst){

		for(Iterator<Point> it=lst.iterator();it.hasNext();){

			Point p=it.next();
			if(!p.isClassed()){

				p.setClassed(true);
			
}
		
}
	
}

	/**
	 * 如果b中含有a中包含的元素,则把两个集合合并
	 * @param a
	 * @param b
	 * @return a
	 */

	public static boolean mergeList(List<Point> a,List<Point> b){

		boolean merge=false;
		for(int index=0;index<b.size();++index){

			if(a.contains(b.get(index))){

				merge=true;
				break;
			
}
		
}

		if(merge){

			for(int index=0;index<b.size();++index){

				if(!a.contains(b.get(index))){

					a.add(b.get(index));
				
}
			
}
		
}
		return merge;
	
}

	/**
	 * 返回文本中的点集合
	 * @return 返回文本中点的集合
	 * @throws IOException
	 */
	public static List<Point> getPointsList() throws IOException{

		List<Point> lst=new ArrayList<Point>();
		String txtPath="src\\com\\sunzhenxing\\points.txt";
		BufferedReader br=new BufferedReader(new FileReader(txtPath));
		String str="";
		while((str=br.readLine())!=null && str!=""){

			lst.add(new Point(str));
		
}
		br.close();
		return lst;
	
}

}
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
.classpath301.00 B26-10-13 22:00
.project382.00 B26-10-13 22:00
org.eclipse.jdt.core.prefs598.00 B26-10-13 22:00
Dbscan.class2.94 kB26-10-13 22:13
Point.class1.75 kB26-10-13 22:02
Utility.class2.89 kB26-10-13 22:08
Dbscan.java1.90 kB26-10-13 22:13
Point.java960.00 B26-10-13 22:02
Utility.java2.15 kB26-10-13 22:08
<dbscan>0.00 B26-10-13 22:09
<dbscan>0.00 B26-10-13 22:09
<.settings>0.00 B26-10-13 22:00
<bin>0.00 B26-10-13 22:00
<src>0.00 B26-10-13 22:00
<DBSCAN>0.00 B26-10-13 22:00
...
Sponsored links

Utility.java (7.66 kB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D