Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions CountMostImport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.io.*;
import java.util.*;
import java.util.Map.Entry;



public class CountMostImport {

static HashMap<String,Integer> importCount;
//输出import最多的前NUMBER个类
public static final int NUMBER = 10;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入java项目的路径:");
importCount = new HashMap<String,Integer>();
countMostImport(scan.nextLine());
}

public static void countMostImport(String path) {
File file = new File(path);

if (!file.isDirectory())
{ //目录不存在
System.out.println("java项目路径不存在!");
return;
}
//遍历各个文件并进行统计
filesList(file, importCount);

//对统计结果进行排序并打印
printImportClass(importCount);

}
public static void printImportClass(HashMap<String, Integer> importCount) {
//对对HashMap按值进行排序
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(importCount.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String,Integer>>() {
//降序排序
@Override
public int compare(Entry<String, Integer> o1, Entry<String,Integer> o2) {
if(o2.getValue().compareTo(o1.getValue())==0){
//如果值相等,则按照字典序列进行排序
String str1 = o1.getKey().toLowerCase();//转换成小写是因为在ASICC中大写字符一定在小写字母前面,与字典序列不符
String str2 = o2.getKey().toLowerCase();
return str1.compareTo(str2);
}
else
return o2.getValue().compareTo(o1.getValue());
}
});

//遍历输出被import最多前NUMBER个的类
int count = 0;
for (Entry<String, Integer> mapping : list) {
if( count<NUMBER ){
System.out.println(mapping.getKey() + "******被import的次数为******" + mapping.getValue());
count++;
}
else return;
}
}
public static void filesList(File file, HashMap<String, Integer> importCount) {
File[] files = file.listFiles();
for(File fileName : files) {
//如果是文件夹,遍历每个文件和文件夹
if(fileName.isDirectory()) {
filesList(fileName, importCount);
}
else {
String suffix = fileName.getName().substring(fileName.getName().lastIndexOf(".") + 1);
//判断是否是java文件
if(suffix.equals("java")) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
String sentence = null;
while((sentence = bufferedReader.readLine()) != null){
String trimSentence = sentence.trim();
//判断是否为引用包语句
if(trimSentence.indexOf("import ") == -1 || !trimSentence.trim().startsWith("import "))
continue;

String importClassName = trimSentence.substring( trimSentence.indexOf("import ")+"import ".length() ).trim();
if(importCount.containsKey(importClassName))
importCount.put(importClassName, importCount.get(importClassName)+1);
else
importCount.put(importClassName, 1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(bufferedReader != null) {
bufferedReader.close();
}
} catch (Exception e) {
}
}
}
}
}
}
}
67 changes: 67 additions & 0 deletions EffectiveLines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class EffectiveLines {

private static int whiteLines = 0;
private static int commentLines = 0;
private static int normalLines = 0;


/**
* @param args
*/
public static void main(String[] args) {
File f = new File("F:\\Idea_pro\\EffectiveLines.java");
sumCode(f);
}

private static void sumCode(File file) {
BufferedReader br = null;
boolean comment = false;
try {
br = new BufferedReader(new FileReader(file));
String line = "";
try {
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.trim().equals("")) {
whiteLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
commentLines++;
comment = true;
} else if (true == comment) {
commentLines++;
if (line.endsWith("*/")) {
comment = false;
}
} else if (line.startsWith("//")) {
commentLines++;
} else {
normalLines++;
}
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
//System.out.println("空行数:"+whiteLines);
//System.out.println("注释行数:"+commentLines);
System.out.println("有效行数:"+normalLines);
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
178 changes: 178 additions & 0 deletions ExchangeRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;



public class ExchangeRate {
private File crawlerResult;
private String rateResult;
public ExchangeRate(){
crawlerResult = new File("F:\\Idea_pro\\crawlerResult.html");
rateResult = "F:\\Idea_pro\\rateResult.xls";
}
public void crawler_30_days(){
String address = "http://www.safe.gov.cn/AppStructured/view/project_RMBQuery.action";
Date date = new Date();
GregorianCalendar gc =new GregorianCalendar();
gc.setTime(date);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//获取系统的日期
String endDate = df.format(gc.getTime());
gc.add(5, -29);
String beginDate = df.format(gc.getTime());
System.out.println("从:"+beginDate);
System.out.println("到:"+endDate);
String param = "projectBean.startDate=" + beginDate + "&projectBean.endDate=" + endDate + "&queryYN=true";
PrintWriter out = null;
BufferedReader in = null;
OutputStreamWriter outWriter = null;
try{
URL url = new URL(address);
URLConnection conn = url.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
outWriter = new OutputStreamWriter(new FileOutputStream(crawlerResult),"UTF-8");
String str = null;
while((str = in.readLine()) != null){
outWriter.write(str + "\n");
}
}catch(Exception e){
System.out.println("在发送Post请求时发生错误!");
e.printStackTrace();
}finally{
try{
if(outWriter != null)
outWriter.close();
if(in != null)
in.close();
if(out != null)
out.close();
}catch(Exception e){
e.printStackTrace();
}
}

}

public void writeExcel(){
Document doc = null;
try {
doc = Jsoup.parse(crawlerResult,"UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
Elements links = doc.getElementsByAttributeValue("class", "first");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("汇率表");
HSSFRow row = sheet.createRow((int) 0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

HSSFCell cell = row.createCell((int)0);
cell.setCellValue("日期");
cell.setCellStyle(style);
cell = row.createCell((int) 1);
cell.setCellValue("美元");
cell.setCellStyle(style);
cell = row.createCell((int) 2);
cell.setCellValue("欧元");
cell.setCellStyle(style);
cell = row.createCell((int) 3);
cell.setCellValue("港币");
cell.setCellStyle(style);
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
date = df.parse(df.format(date));
} catch (ParseException e1) {
e1.printStackTrace();
}
GregorianCalendar gc =new GregorianCalendar();
gc.setTime(date);
gc.add(5,1);
int rowno = 0;

for(int i = 0; i < links.size(); ++i){
String tmp = links.get(i).text().replace(Jsoup.parse("&nbsp;").text(), " ");
String rate[] = tmp.split("[ ]{1,}");
String d = rate[0];
Date tmpDate = null;
try {
tmpDate = df.parse(d);
} catch (ParseException e) {
e.printStackTrace();
}
while((date.getTime() - tmpDate.getTime())/(24*60*60*1000) > 1){
row = sheet.createRow((int) rowno + 1);
gc.add(5, -1);
row.createCell((int) 0).setCellValue(df.format(gc.getTime()));
row.createCell((int) 1).setCellValue("--");
row.createCell((int) 2).setCellValue("--");
row.createCell((int) 3).setCellValue("--");
++rowno;

date = gc.getTime();
}
row = sheet.createRow((int) rowno + 1);
rowno++;
row.createCell((int) 0).setCellValue(rate[0]);
row.createCell((int) 1).setCellValue(rate[1]);
row.createCell((int) 2).setCellValue(rate[2]);
row.createCell((int) 3).setCellValue(rate[4]);
gc.add(5,-1);//减一天
date = gc.getTime();
}
while(rowno < 30){
row = sheet.createRow((int) rowno + 1);
rowno++;
gc.add(5,-1);
row.createCell((int) 0).setCellValue(df.format(gc.getTime()));
row.createCell((int) 1).setCellValue("--");
row.createCell((int) 2).setCellValue("--");
row.createCell((int) 3).setCellValue("--");
}
try
{
FileOutputStream fout = new FileOutputStream(rateResult);
wb.write(fout);
fout.close();
System.out.println("Excel文件生成成功!");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[]) throws IOException{
ExchangeRate rate = new ExchangeRate();
rate.crawler_30_days();
rate.writeExcel();
}
}
1 change: 1 addition & 0 deletions Top10Ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awk '{print $1}' access.log|sort|uniq -c|sort -nr|head -n10
1 change: 1 addition & 0 deletions linux2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scp /tmp/filename username@l-test.dev.cn1:/tmp/