java 输出 lambda 生成的类
2024-01-10 16:21:01
文章目录
- 启动添加参数
-Djdk.internal.lambda.dumpProxyClasses
就会在运行源码目录输出 class 文件
/**
* <p>Copyright © qww 版权所有。</p>
*/
package manageSystemOfStudentInfo;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
/**
* <b>Application name:</b>qww 维护<br>
* <b>Application describing:</b> <br>
* <b>Copyright:</b>Copyright © qww 版权所有。<br>
* <b>Company:</b>qww<br>
* <b>Date:</b>2016年7月25日,下午5:34:07<br>
*
* @author qww
* @version $Revision$
*/
public class ManageXMLFile {
/**************** 下面是一些方法 ****************/
/**
*
* {获取XML文件中ID的最大值}
*
* @param url
* @return
* @author: qww
*/
public static int getMaxId(String url) {
int max = 0;
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element e : list) {
int id = Integer.parseInt(e.attributeValue("id"));
if (id > max) {
max = id;
}
} // end foreach()
return max;
}// end getMaxId() method
/**
*
* {查询输入的用户名密码在数据库中书否存在,并验证是否对应}
*
* @param url
* @return
* @author: qww
*/
public static boolean queryAccount(String url, String username,
String password) {
boolean b = false;
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element element : list) {
if (String.valueOf(username).equals(
element.attributeValue("username"))
&& String.valueOf(password).equals(
element.attributeValue("password"))) {
b = true;
}// end if
}// end foreach loop list
return b;
}// end queryAccount(String url) method
/**
*
* {获取Document对象}
*
* @param url
* @return
* @author: qww
*/
public static Document getDocument(String url) {
SAXReader reader = new SAXReader();
Document dom = null;
try {
dom = reader.read(new File(url));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dom;
}// end getDocument()方法
/**
*
* {写入XML文件,目的地是 url}
*
* @param url
* @param dom
* @throws IOException
* @author: qww
*/
public static void writerXML(String url, Document dom) throws IOException {
OutputFormat format = OutputFormat.createCompactFormat();
format.setIndent(" ");
format.setNewlines(true);
format.setEncoding("gbk");
XMLWriter xml = new XMLWriter(new FileOutputStream(url), format);
xml.write(dom);
}// end writerXML() method
/**
*
* {创建一个只含有根节点<person>的XML文件,目的地url}
*
* @param url
* @param rootElement
* @author: qww
*/
public static void creatNullXmlFile(String url, String rootElement) {
Document dom = DocumentHelper.createDocument();
Element person = dom.addElement(rootElement);
dom.setRootElement(person);
try {
writerXML(url, dom);
} catch (IOException e) {
e.printStackTrace();
System.out.println("“创建空XML文件方法”中的异常");
}
}// end creatNullXmlFile(String url) method
/**
*
* {重载的方法,向源路径为url的XML文件中添加 用户注册 的数据}
*
* @param url
* @param st
* @author: qww
*/
public static void add(String url, String account[]) {
Document dom = getDocument(url);
Element person = dom.getRootElement();
Element act = person.addElement("account");
act.addAttribute("username", account[0]);
act.addAttribute("password", account[1]);
// 写入文件
try {
writerXML(url, dom);
} catch (IOException e) {
e.printStackTrace();
}
}// end add(String url, Student stu) method
/**
*
* {向源路径为url的XML文件中添加 Student 类的数据}
*
* @param url
* @param st
* @author: qww
*/
public static void add(String url, Student st) {
Document dom = getDocument(url);
Element person = dom.getRootElement();
Element stu = person.addElement("student");
stu.addAttribute("id", String.valueOf(getMaxId(url) + 1));
/*********** 添加子节点 *********************/
Element name = stu.addElement("name");
name.setText(st.getName());
Element sex = stu.addElement("sex");
sex.setText(st.getSex());
Element address = stu.addElement("address");
address.setText(st.getAddress());
Element age = stu.addElement("age");
age.setText(String.valueOf(st.getAge()));
Element grade = stu.addElement("grade");
grade.setText(st.getGrade());
Element email = stu.addElement("email");
email.setText(st.getEmail());
Element phone = stu.addElement("phone");
phone.setText(st.getPhone());
Element school = stu.addElement("school");
school.setText(st.getSchool());
/*********** 添加子节点 结束 *********************/
// 写入文件
try {
writerXML(url, dom);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}// end add(String url, Student stu) method
/**
*
* {向源路径为url的XML文件中添加 Student 类的数据;重载的add方法,用于自己添加ID}
*
* @param url
* @param st
* @author: qww
*/
public static void add(String url, Student st, int id) {
Document dom = getDocument(url);
Element person = dom.getRootElement();
/*********** 添加子节点 *********************/
Element stu = person.addElement("student");
stu.addAttribute("id", String.valueOf(id));
Element name = stu.addElement("name");
name.setText(st.getName());
Element address = stu.addElement("address");
address.setText(st.getAddress());
Element grade = stu.addElement("grade");
grade.setText(st.getGrade());
Element sex = stu.addElement("sex");
sex.setText(st.getSex());
Element school = stu.addElement("school");
school.setText(st.getSchool());
Element email = stu.addElement("email");
email.setText(st.getEmail());
Element phone = stu.addElement("phone");
phone.setText(st.getPhone());
Element age = stu.addElement("age");
age.setText(String.valueOf(st.getAge()));
/*********** 添加子节点 结束 *********************/
// 写入文件
try {
writerXML(url, dom);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}// end add(String url, Student stu) method
/**
*
* {从源路径为url的XML文件中,根据学生ID删除相应学生信息}
*
* @param url
* @param id
* @author: qww
*/
public static int del(String url, int id) {
int flag = 0;// 这是一个删除成功与否的标志
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element element : list) {
if (String.valueOf(id).equals(element.attributeValue("id"))) {
person.remove(element);
flag++;
}
}// end foreach()
try {
if (1 == flag) {
System.out.println("确认删除ID=" + id + "的学生信息(y或Y确认,其他取消删除操作)");
Scanner sc = new Scanner(System.in);
if (sc.next().equalsIgnoreCase("Y")) {
writerXML(url, dom);
flag++;
}// end
}// end if(1==flag)
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// end catch (IOException e)
if (2 == flag) {
System.out.println("删除ID=" + id + "的学生信息成功……");
} else if (1 == flag) {
System.out.println("取消删除操作……");
} else {
System.out.println("没有ID=" + id + "的学生, 无法完成删除操作……");
}// end else{}
return flag;
}// end del(String url,int id) method
/**
*
* {从控制台<修改>学生信息}
*
* @param s
* @return
* @author: qww
*/
public static Students inputStud(Students s) {
Students stu = s;
Scanner sc = new Scanner(System.in);
// while (true) {
// System.out.println("ID=" + s.getId() + "学生的 Name 属性修改前的值为:"
// + s.getName() + "\n请输入新值:");// 1
// String str3 = sc.next();
// if (ManageStudentInfo.regex("[\\u4e00-\\u9fa5]+", str3)) {
// stu.setName(str3);
// break;
// } else {
// System.out.println("您输入有误,只能输入中文!");
// }
// } // end while(true) loop name
// while (true) {
// System.out.println("ID=" + s.getId() + "学生的 Sex 属性修改前的值为:"
// + s.getSex() + "\n请输入新值, 只能输入'男'或'女':");// 2
// String str3 = sc.next();
// if (str3.equals("男") || str3.equals("女")) {
// stu.setSex(str3);
// break;
// } else {
// System.out.println("输入有误,只能输入'男'或'女'!");
// }
// } // end while(true) loop sex
System.out.println("ID=" + s.getId() + "学生的 Address 属性修改前的值为:"
+ s.getAddress() + "\n请输入新值:");// 3
stu.setAddress(sc.next());
while (true) {
System.out.println("ID=" + s.getId() + "学生的 Age 属性修改前的值为:"
+ s.getAge() + "\n请输入新值:");// 4
String str3 = sc.next();
if (ManageStudentInfo.regex("^([8-9]|((1|2|3|4)[0-9])|50)*", str3)) {
stu.setAge(Integer.parseInt(str3));
break;
} else {
System.out.println("年龄太大或太小,请输入8-50");
}
} // end while(true) loop age
while (true) {
System.out.println("ID=" + s.getId() + "学生的 Grade 属性修改前的值为:"
+ s.getGrade() + "\n请输入新值(只能输入'初级'、'中级'、'高级'):");// 5
String str3 = sc.next();
if (str3.equals("初级") || str3.equals("中级") || str3.equals("高级")) {
stu.setGrade(str3);
break;
} else {
System.out.println("输入错误,请重新输入。只能输入'初级'、'中级'、'高级':");
}
} // end while(true) loop grade
System.out.println("ID=" + s.getId() + "学生的 Email 属性修改前的值为:"
+ s.getEmail() + "\n请输入新值: ");// 6
stu.setEmail(sc.next());
while (true) {
System.out.println("ID=" + s.getId() + "学生的 Phone 属性修改前的值为:"
+ s.getPhone() + "\n请输入新值: ");// 7
String str3 = sc.next();
if (ManageStudentInfo.regex("^[1][358]\\d{9}$", str3)) {
stu.setPhone(str3);
break;
} else {
System.out.println("请输入 有效的11位电话号码");
}
} // end while(true) loop phone
System.out.println("ID=" + s.getId() + "学生的 School 属性修改前的值为:"
+ s.getSchool() + "\n请输入新值: ");
;// 8
stu.setSchool(sc.next());
return stu;
}// end inputStud(Students s) method
/**
*
* {根据学生ID修改学生信息}
*
* @param url
* @param st
* @author: qww
*/
public static void edit(String url, Students st) {
int flag = 0;
try {
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element element : list) {
if (String.valueOf(st.getId()).equals(
element.attributeValue("id"))) {
flag++;
/*****************************/
st = inputStud(st);
/*****************************/
/*
* element.element("name").setText(st.getName());
* element.element("sex").setText(st.getSex());
*/
element.element("address").setText(st.getAddress());
element.element("grade").setText(st.getGrade());
element.element("school").setText(st.getSchool());
element.element("email").setText(st.getEmail());
element.element("phone").setText(st.getPhone());
element.element("age").setText(String.valueOf(st.getAge()));
writerXML(url, dom);
flag++;
}// end if()
}// end foreach() loop
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// end catch (IOException e)
if (2 == flag)
System.out.println("修改ID=" + st.getId() + "的学生信息成功……");
else if (flag == 0)
System.out.println("ID=" + st.getId() + "不存在");
}// end edit(String url, Student st) method
/**
*
* {重载的edit方法,根据ID修改部分学生部分信息}
*
* @param url
* @param st
* @param attribute
* @author: qww
*/
public static void edit(String url, Student st, String attribute) {
int flag = 0;
try {
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element element : list) {
if (String.valueOf(st.getId()).equals(
element.attributeValue("id"))) {
flag++;
if (attribute.equals("age")) {// age是int型的——独立出来
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("ID=" + st.getId() + "学生的"
+ attribute + "属性,修改前的值为:"
+ element.elementText(attribute)
+ "\n请输入新值:");// 4
String str3 = sc.next();
if (ManageStudentInfo.regex(
"^([8-9]|((1|2|3|4)[0-9])|50)*", str3)) {
element.element("age").setText(str3);
break;
} else {
System.out.println("年龄太大或太小,请输入8-50");
}
} // end while(true) loop age
} else {// _——————
Scanner sc = new Scanner(System.in);
if (attribute.equals("phone")) {
while (true) {
System.out.println("ID=" + st.getId()
+ "学生的 Phone 属性修改前的值为:"
+ element.elementText(attribute)
+ "\n请输入新值: ");// 7
String str3 = sc.next();
if (ManageStudentInfo.regex("^[1][358]\\d{9}$",
str3)) {
element.element("phone").setText(str3);
break;
} else {
System.out.println("请输入 有效的11位电话号码");
}
} // end while(true) loop phone
} else if (attribute.equals("grade")) {
while (true) {
System.out.println("ID=" + st.getId()
+ "学生的 Grade 属性修改前的值为:"
+ element.elementText(attribute)
+ "\n请输入新值(只能输入'初级'、'中级'、'高级'):");// 5
String str3 = sc.next();
if (str3.equals("初级") || str3.equals("中级")
|| str3.equals("高级")) {
element.element("grade").setText(str3);
break;
} else {
System.out
.println("输入错误,请重新输入。只能输入'初级'、'中级'、'高级':");
}
} // end while(true) loop grade
} else {
System.out.println("id为" + st.getId() + "学生的"
+ attribute + "属性修改前的值为:"
+ element.elementText(attribute)
+ "\n请输入新值:");
element.element(attribute).setText(sc.next());
}
}// end else{//_——————
writerXML(url, dom);
flag++;
}// end if()
}// end foreach() loop
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// end catch (IOException e)
if (2 == flag)
System.out.println("修改ID=" + st.getId() + "的学生信息成功……");
else if (flag == 0)
System.out.println("ID=" + st.getId() + "不存在");
}// end edit(String url, Student st,String attribute) method
/**
*
* {根据学生ID查询学生 所有信息}
*
* @param url
* @param id
* @return
* @author: qww
*/
public static Students queryById(String url, int id) {
Document dom;
Students stuD = new Students();
dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
int flag = 0;
for (Element element : list) {
if (String.valueOf(id).equals(element.attributeValue("id"))) {
flag = 1;
stuD.setId(Integer.parseInt(element.attributeValue("id")));
stuD.setAge(Integer.parseInt(element.elementText("age")));
// 下面是String型的元素
stuD.setName(element.elementText("name"));
stuD.setSex(element.elementText("sex"));
stuD.setAddress(element.elementText("address"));
stuD.setGrade(element.elementText("grade"));
stuD.setEmail(element.elementText("email"));
stuD.setPhone(element.elementText("phone"));
stuD.setSchool(element.elementText("school"));
// System.out.println("查询到ID=" + id + "的学生信息并返回……");
}
}// end foreach(Element ) loop
if (flag == 0) {
System.out.println("没有ID=" + id + "的学生, 请重新输入……");
return null;
}// end if (flag == 0)
return stuD;
}// end queryStudentInfoById() method
/**
*
* {查询所有学生信息}
*
* @param url
* @return
* @author: qww
*/
public static List<Students> queryAll(String url) {
List<Students> list = null;
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> listErgodic = person.elements();
List<Students> listSave = new ArrayList<Students>();
for (Element element : listErgodic) {
Students stuD = new Students();
stuD.setId(Integer.parseInt(element.attributeValue("id")));
stuD.setAge(Integer.parseInt(element.elementText("age")));
// 下面是String型的元素
stuD.setName(element.elementText("name"));
stuD.setSex(element.elementText("sex"));
stuD.setAddress(element.elementText("address"));
stuD.setGrade(element.elementText("grade"));
stuD.setEmail(element.elementText("email"));
stuD.setPhone(element.elementText("phone"));
stuD.setSchool(element.elementText("school"));
listSave.add(stuD);
}// end foreach() loop
list = listSave;
return list;
}// end queryAllStudentInfo(String url)
/**
*
* {查询ID并返回防止ID重复,返回1则表示ID存在}
*
* @param url
* @param id
* @author: qww
*/
public static int queryId(String url, int id) {
int flag = 0;
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
for (Element element : list) {
if (String.valueOf(id).equals(element.attributeValue("id"))) {
flag = 1;
}
}// end foreach()
return flag;
}// end queryId(String url, int id) method
/**
*
* {重载的方法,用于添加学生信息提示}
*
* @param url
* @author: qww
*/
public static void queryId(String url) {
// public static List<int[]> queryId(String url) {
int flag = -1;
int arrId[] = new int[1];
List<int[]> lit = new ArrayList<int[]>();
Document dom = getDocument(url);
Element person = dom.getRootElement();
List<Element> list = person.elements();
System.out.print("不能添加的ID=");
int i = 1, j = 1;
for (Element element : list) {
if (1 == i) {
for (Element e : list) {
i++;
}// end inner foreach() loop
}
j++;// 标志XML没有到结尾
if (j != i) {
System.out.print(element.attributeValue("id") + ", ");
} else {
System.out.println(element.attributeValue("id"));
}
}// end foreach()
System.out.print("建议添加的ID=");
outerFor: for (int n = 1; n < getMaxId(url); n++) {
int k = 0;
for (Element e : list) {
k = Integer.parseInt(e.attributeValue("id"));
if (k == n) {
flag = 1;
continue outerFor;
}
}// end inner foreach() loop
System.out.print(n + ", ");
}// end for(int n=0;n<getMaxId(url);n++){ loop
if (-1 == flag) {
System.out.println("建议输入ID= " + (getMaxId(url) + 1));
} else {
System.out.println((getMaxId(url) + 1) + "及更大值");
}
// // System.out.println();
// // return lit;
}// end queryId(String url, int id) method
}// end class ManageXMLFile
文章来源:https://blog.csdn.net/wwq921220/article/details/135418364
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!