diff --git a/.gitignore b/.gitignore index a06e3a169b423bbadd092ef04b26524def7f7aeb..0fec4265363e11773ca5fdf357d498dc25f389da 100644 --- a/.gitignore +++ b/.gitignore @@ -47,10 +47,6 @@ local.properties *.iws target/ .DS_Store -/test/src/test/resources/jdbc.properties -/test/src/test/resources/log4j.properties -/test/info.log.* -/test/warn.log.* ### Example user template template ### Example user template @@ -59,3 +55,4 @@ target/ #*.iml #out gen +javadoc/ diff --git a/pom.xml b/pom.xml index bce3364713cf18ad6898c3953ccb4339bee7fc23..4a17127f90b2eb6c8073427adc18fccdca4b7c16 100644 --- a/pom.xml +++ b/pom.xml @@ -10,13 +10,81 @@ Utils + jar + UTF-8 1.8 1.8 + 1.2.61 + 1.16.8 + 2.5 + 2.0.1 + 1.6.4 + 5.5.10 + 5.2.0 + 2.0.11 + 2.6.3 + 3.0.0 + 3.14 + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + 1.7.25 + + + org.slf4j + slf4j-nop + 1.7.25 + + + org.slf4j + slf4j-simple + 1.7.5 + + + log4j + log4j + 1.2.17 + + + + + com.itextpdf + itextpdf + ${itextpdf.version} + + + com.itextpdf + itext-asian + ${itext-asian.version} + + + org.apache.pdfbox + pdfbox + ${pdfbox.version} + + + e-iceblue + spire.pdf.free + ${spire.pdf.free.version} + + + + org.apache.poi + poi-ooxml + ${poi-ooxml.version} + + junit junit @@ -26,17 +94,17 @@ com.alibaba fastjson - 1.2.61 + ${alibaba.fastjson.version} org.projectlombok lombok - 1.16.8 + ${lombok.version} javax.servlet servlet-api - 2.5 + ${servlet-api.version} org.jetbrains @@ -47,33 +115,41 @@ commons-io commons-io - 2.0.1 - - - - org.slf4j - slf4j-api - 1.6.4 - - - - com.itextpdf - itextpdf - 5.5.10 + ${commons-io.version} + + - com.itextpdf - itext-asian - 5.2.0 + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven-plugin.version} - - org.apache.poi - poi-ooxml - 3.14 + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-plugin.version} + + + maven-ali + http://maven.aliyun.com/nexus/content/groups/public// + + true + + + true + always + fail + + + + com.e-iceblue + http://repo.e-iceblue.cn/repository/maven-public/ + + + @@ -116,6 +192,11 @@ maven-project-info-reports-plugin 3.0.0 + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.0 + diff --git a/src/main/java/com/lin/Dto/BookDto.java b/src/main/java/com/lin/dto/BookDto.java similarity index 73% rename from src/main/java/com/lin/Dto/BookDto.java rename to src/main/java/com/lin/dto/BookDto.java index a7fbe9fc6fdac61a9940a67a0e4025bca1ad57ad..49e35932ed322afaa17ac4fce753668401e25647 100644 --- a/src/main/java/com/lin/Dto/BookDto.java +++ b/src/main/java/com/lin/dto/BookDto.java @@ -1,7 +1,10 @@ -package com.lin.Dto; +package com.lin.dto; import lombok.Data; +/** + * @author linqiankun + */ @Data public class BookDto { String name; diff --git a/src/main/java/com/lin/Dto/SenseCallbackDto.java b/src/main/java/com/lin/dto/SenseCallbackDto.java similarity index 94% rename from src/main/java/com/lin/Dto/SenseCallbackDto.java rename to src/main/java/com/lin/dto/SenseCallbackDto.java index c86b6dedf9756268178c09337f33fb195ddec9be..291f5b79eebd4f09eb02d1d3d072a5aacbf5e69d 100644 --- a/src/main/java/com/lin/Dto/SenseCallbackDto.java +++ b/src/main/java/com/lin/dto/SenseCallbackDto.java @@ -1,7 +1,10 @@ -package com.lin.Dto; +package com.lin.dto; import lombok.Data; +/** + * @author linqiankun + */ @Data public class SenseCallbackDto { diff --git a/src/main/java/com/lin/Dto/TestDto.java b/src/main/java/com/lin/dto/TestDto.java similarity index 77% rename from src/main/java/com/lin/Dto/TestDto.java rename to src/main/java/com/lin/dto/TestDto.java index 9daad1a6bb9cd408b8b0e016d3f59316ce9ccfd0..cca714c9fad72375e6956cce5e4aee7a6b4cc31e 100644 --- a/src/main/java/com/lin/Dto/TestDto.java +++ b/src/main/java/com/lin/dto/TestDto.java @@ -1,5 +1,8 @@ -package com.lin.Dto; +package com.lin.dto; +/** + * @author linqiankun + */ public class TestDto { diff --git a/src/main/java/com/lin/enums/ResponseStatusCode.java b/src/main/java/com/lin/enums/ResponseStatusCode.java new file mode 100644 index 0000000000000000000000000000000000000000..a134685630b7f20be48f8389f2cd74b37936d77f --- /dev/null +++ b/src/main/java/com/lin/enums/ResponseStatusCode.java @@ -0,0 +1,44 @@ +package com.lin.enums; + +/** + * http相应响应状态码 + * + * @author linqiankun + */ +public enum ResponseStatusCode { + + + /** + * 200,请求成功成功 + */ + OK(200, "ok"), + + /** + * 404,资源未找到 + */ + NOT_EXIST(404, "notfound"); + + int code; + String desc; + + ResponseStatusCode(int code, String desc) { + this.code = code; + this.desc = desc; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/src/main/java/com/lin/enums/StatusCode.java b/src/main/java/com/lin/enums/SortStatusCode.java similarity index 65% rename from src/main/java/com/lin/enums/StatusCode.java rename to src/main/java/com/lin/enums/SortStatusCode.java index dadd128b86274d9faaf17b1ea716a04422562120..13e7f3e9e248c3e1f303d1365298fb3a9c3faf3d 100644 --- a/src/main/java/com/lin/enums/StatusCode.java +++ b/src/main/java/com/lin/enums/SortStatusCode.java @@ -1,17 +1,31 @@ package com.lin.enums; -public enum StatusCode { +/** + * 排序状态吗 + * + * @author linqiankun + */ +public enum SortStatusCode { + /** + * 小到大排序 + */ MIX_SORT(-1, "小到大"), + /** + * 大到小排序 + */ MAX_SORT(1, "大到小"), + /** + * 两值相等 + */ EQUAL(0, "相等"); int code; String desc; - StatusCode(int code, String desc) { + SortStatusCode(int code, String desc) { this.code = code; this.desc = desc; } diff --git a/src/main/java/com/lin/io/bio/Stream.java b/src/main/java/com/lin/io/bio/Stream.java new file mode 100644 index 0000000000000000000000000000000000000000..3217363a3b7c2f65f170585b26399bfd064b391e --- /dev/null +++ b/src/main/java/com/lin/io/bio/Stream.java @@ -0,0 +1,31 @@ +package com.lin.io.bio; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * @author 九分石人 + */ +public class Stream { + + /** + * 通过IO流进行文件传输 + * + * @throws IOException 文件传输异常 + */ + private static void fileCopyStream() throws IOException { + File file = new File("D:\\util\\BingWallpaper.jpg"); + File filecopy = new File("D:\\util\\BingWallpaper-copy-bio.jpg"); + FileInputStream fileInputStream = new FileInputStream(file); + FileOutputStream fileOutputStream = new FileOutputStream(filecopy); + byte[] bytes = new byte[1024]; + while (fileInputStream.read(bytes) > 0) { + fileOutputStream.write(bytes); + fileOutputStream.flush(); + } + fileInputStream.close(); + fileOutputStream.close(); + } +} diff --git a/src/main/java/com/lin/io/nio/Channel.java b/src/main/java/com/lin/io/nio/Channel.java new file mode 100644 index 0000000000000000000000000000000000000000..a8d0875c13f86efe1643166ee8a8ca107e7e211a --- /dev/null +++ b/src/main/java/com/lin/io/nio/Channel.java @@ -0,0 +1,37 @@ +package com.lin.io.nio; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +/** + * @author 九分石人 + */ +public class Channel { + + + /** + * 通过NIO通道进行文件拷贝 + * + * @throws IOException 文件异常 + */ + private static void fileCopyChannel() throws IOException { + File file = new File("D:\\util\\BingWallpaper.jpg"); + File filecopy = new File("D:\\util\\BingWallpaper-copy.jpg"); + FileChannel fileChannel = new FileInputStream(file).getChannel(); + FileChannel fileChannel1 = new FileOutputStream(filecopy).getChannel(); + ByteBuffer byteBuffer = ByteBuffer.allocate(1024); + while (fileChannel.read(byteBuffer) > 0) { + byteBuffer.flip(); + fileChannel1.write(byteBuffer); + byteBuffer.clear(); + } + fileChannel.close(); + fileChannel1.close(); + } + + +} diff --git a/src/main/java/com/lin/pdfutil/ExcelToPdfUtil.java b/src/main/java/com/lin/pdfutil/ExcelToPdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..b10abc86becb8945cc8296483bce918b881a645a --- /dev/null +++ b/src/main/java/com/lin/pdfutil/ExcelToPdfUtil.java @@ -0,0 +1,10 @@ +package com.lin.pdfutil; + +import lombok.extern.slf4j.Slf4j; + +/** + * @author linqiankun + */ +@Slf4j +public class ExcelToPdfUtil { +} diff --git a/src/main/java/com/lin/pdfutil/HtmlToPdfUtil.java b/src/main/java/com/lin/pdfutil/HtmlToPdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..ca735b4ef8b5471d38234db3a40500c9a1de6adb --- /dev/null +++ b/src/main/java/com/lin/pdfutil/HtmlToPdfUtil.java @@ -0,0 +1,7 @@ +package com.lin.pdfutil; + +/** + * @author 九分石人 + */ +public class HtmlToPdfUtil { +} diff --git a/src/main/java/com/lin/pdfutil/MultiPdfToOnePdfUtil.java b/src/main/java/com/lin/pdfutil/MultiPdfToOnePdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..e842e47f0fc2040c1b0b9fc272e81ed2e2078a7b --- /dev/null +++ b/src/main/java/com/lin/pdfutil/MultiPdfToOnePdfUtil.java @@ -0,0 +1,119 @@ +package com.lin.pdfutil; + +import com.itextpdf.text.*; +import com.itextpdf.text.Image; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.PdfCopy; +import com.itextpdf.text.pdf.PdfImportedPage; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfWriter; +import lombok.extern.slf4j.Slf4j; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; + +/** + * @author linqiankun + */ +@Slf4j +public class MultiPdfToOnePdfUtil { + + + /** + * 将多个图片转成一个pdf + * + * @param imageFolderPath 图片文件夹地址 + * @param pdfPath pdf路径 + */ + public static void picToPdf(String imageFolderPath, String pdfPath) { + try { + // 图片地址 + String imagePath; + // 获取图片文件夹对象 + File filePath = new File(imageFolderPath); + File[] files = filePath.listFiles(); + // 循环获取图片文件夹内的图片 + assert files != null; + + // 输入流 + FileOutputStream fos = new FileOutputStream(pdfPath); + // 创建文档 + Document doc = new Document(); + doc.setMargins(0, 0, 0, 0); + // 写入PDF文档 + PdfWriter.getInstance(doc, fos); + // 读取图片流 + BufferedImage img; + // 实例化图片 + Image image; + doc.open(); + + for (File file : files) { + if (file.getName().toLowerCase().endsWith(".png") + || file.getName().toLowerCase().endsWith(".jpg") + || file.getName().toLowerCase().endsWith(".gif") + || file.getName().toLowerCase().endsWith(".jpeg") + || file.getName().toLowerCase().endsWith(".tif")) { + imagePath = imageFolderPath + File.separator + file.getName(); + System.out.println(file.getName()); + // 读取图片流 + img = ImageIO.read(new File(imagePath)); + // 根据图片大小设置文档大小 + // doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight())); + doc.setPageSize(PageSize.A4); + doc.newPage(); + // 实例化图片 + image = Image.getInstance(imagePath); + image.scaleToFit(PageSize.A4); + // 添加图片到文档 + doc.add(image); + } + } + // 关闭文档 + doc.close(); + } catch (IOException | DocumentException e) { + log.error(e.getMessage()); + } + } + + + /** + * 多个pdf合一工具 + * + * @param bytes 需要合成的pdf数组 + * @return 合成后的pdf + * @throws DocumentException 文本异常 + * @throws IOException 流异常 + */ + public static byte[] pdfmMix(List bytes) throws DocumentException, IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + // 创建一个新的PDF + Document document = new Document(); + PdfCopy copy = new PdfCopy(document, bos); + document.open(); + // 取出单个PDF的数据 + for (byte[] bs : bytes) { + PdfReader reader = new PdfReader(bs); + int pageTotal = reader.getNumberOfPages(); + log.info("pdf的页码数是 ==> {}", pageTotal); + for (int pageNo = 1; pageNo <= pageTotal; pageNo++) { + document.newPage(); + PdfImportedPage page = copy.getImportedPage(reader, pageNo); + copy.addPage(page); + } + reader.close(); + } + document.close(); + byte[] pdfs = bos.toByteArray(); + bos.close(); + copy.close(); + return pdfs; + } + + +} diff --git a/src/main/java/com/lin/pdfutil/PPTToPdfUtil.java b/src/main/java/com/lin/pdfutil/PPTToPdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..de3f697c6c66cbd6b62ce3214d6519086c76e98e --- /dev/null +++ b/src/main/java/com/lin/pdfutil/PPTToPdfUtil.java @@ -0,0 +1,10 @@ +package com.lin.pdfutil; + +import lombok.extern.slf4j.Slf4j; + +/** + * @author linqiankun + */ +@Slf4j +public class PPTToPdfUtil { +} diff --git a/src/main/java/com/lin/pdfutil/PdfToPicUtil.java b/src/main/java/com/lin/pdfutil/PdfToPicUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..772b98c6ce99a807ee6051abf5968eeb6032b4f6 --- /dev/null +++ b/src/main/java/com/lin/pdfutil/PdfToPicUtil.java @@ -0,0 +1,78 @@ +package com.lin.pdfutil; + +import com.spire.pdf.PdfDocument; +import lombok.extern.slf4j.Slf4j; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.rendering.PDFRenderer; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * pdf转图片工具 + * + * @author 九分石人 + */ +@Slf4j +public class PdfToPicUtil { + + /** + * pdf转图片 + * 遍历pdf每一页都生成一个图片 + * + * @param inputStream 将pdf以流的方式传进来传进来 + * @return 返会图片的流的集合 + */ + public static List pdfToPic1(InputStream inputStream) { + String imageType = "jpg"; + List outputStreamList = new ArrayList<>(); + try { + PDDocument pdDocument = PDDocument.load(inputStream); + PDFRenderer renderer = new PDFRenderer(pdDocument); + int numberOfPages = pdDocument.getNumberOfPages(); + for (int i = 0; i < numberOfPages; i++) { + ByteArrayOutputStream temp = new ByteArrayOutputStream(); + BufferedImage image = renderer.renderImageWithDPI(i, 90); + ImageIO.write(image, imageType, temp); + outputStreamList.add(temp); + } + } catch (IOException e) { + log.error(e.getMessage()); + } + return outputStreamList; + } + + /** + * pdf转图片,仅支持png格式格式 + * + * @param inputStream 将pdf以流的方式传进来传进来 + * @return 返会图片的流的集合 + */ + public static List pdfToPic2(InputStream inputStream) { + List outputStreamList = new ArrayList<>(); + try { + //加载PDF文件 + PdfDocument pdfDocument = new PdfDocument(); + pdfDocument.loadFromStream(inputStream); + BufferedImage image; + //保存PDF的每一页到图片 + for (int i = 0; i < pdfDocument.getPages().getCount(); i++) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + image = pdfDocument.saveAsImage(i); + ImageIO.write(image, "PNG", byteArrayOutputStream); + outputStreamList.add(byteArrayOutputStream); + } + pdfDocument.close(); + } catch (IOException e) { + log.error(e.getMessage()); + } + return outputStreamList; + } + + +} diff --git a/src/main/java/com/lin/pdfutil/PicToPdfUtil.java b/src/main/java/com/lin/pdfutil/PicToPdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..9d6969142f0cb07f4e6b5834d3d9d68f2bd00a2f --- /dev/null +++ b/src/main/java/com/lin/pdfutil/PicToPdfUtil.java @@ -0,0 +1,172 @@ +package com.lin.pdfutil; + +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.PdfWriter; + +import com.spire.pdf.PdfDocument; +import com.spire.pdf.PdfPageBase; +import com.spire.pdf.graphics.PdfImage; + +import lombok.extern.slf4j.Slf4j; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; + + +/** + * 图片转pdf工具 + * + * @author linqiankun + */ +@Slf4j +public class PicToPdfUtil { + + /** + * 将pdf转换为图片 + * + * @param inputStream 图片输入流 + * @return pdf 输出流 + */ + public static ByteArrayOutputStream picToPdf1(InputStream inputStream) { + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + //创建pdf文档 + PdfDocument document = new PdfDocument(); + //添加页面 + PdfPageBase pdfPageBase = document.getPages().add(); + //加载图片 + PdfImage pdfImage = PdfImage.fromStream(inputStream); + + //绘制图片到pdf并设置其在pdf文件中的位置和大小 + double width = getImgWidth(inputStream) / pdfPageBase.getActualBounds(true).getWidth(); + double height = getImgHeight(inputStream) / pdfPageBase.getActualBounds(true).getHeight(); + + double fitRate = Math.max(width, height); + double fitWidth = getImgWidth(inputStream) / fitRate * 0.707f; + double fitHeight = getImgHeight(inputStream) / fitRate * 1.0f; + + pdfPageBase.getCanvas().drawImage(pdfImage, 0, 0, fitWidth, fitHeight); + + //保存并关闭 + document.saveToStream(outputStream); + document.close(); + + return outputStream; + } + + /** + * @param inputStream 图片文件 + * @return 图片的宽度 + */ + private static double getImgHeight(InputStream inputStream) { + BufferedImage src = null; + int ret = -1; + try { + src = javax.imageio.ImageIO.read(inputStream); + ret = src.getWidth(null); + } catch (Exception e) { + log.error(e.getMessage()); + } + return ret; + } + + /** + * @param inputStream 图片文件 + * @return 图片的高度 + */ + private static double getImgWidth(InputStream inputStream) { + BufferedImage src = null; + int ret = -1; + try { + src = javax.imageio.ImageIO.read(inputStream); + ret = src.getHeight(null); + } catch (Exception e) { + log.error(e.getMessage()); + } + return ret; + } + + + /** + * 图片转pdf,位置不准确 + * + * @param imgFilePath 图片文件路径 + * @param pdfFilePath pdf文件路径 + * @return 转换成功 + * @throws IOException 文件读取异常 + */ + public static boolean imgToPdf2(String imgFilePath, String pdfFilePath) throws IOException { + File file = new File(imgFilePath); + if (file.exists()) { + Document document = new Document(); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(pdfFilePath); + PdfWriter.getInstance(document, fos); + // 添加PDF文档的某些信息,比如作者,主题等等 + document.addAuthor("linqiankun"); + document.addSubject("linqiankun"); + // 设置文档的大小 + document.setPageSize(PageSize.A4); + // 打开文档 + document.open(); + // 写入一段文字 + // document.add(new Paragraph("JUST TEST ...")); + // 读取一个图片 + Image image = Image.getInstance(imgFilePath); + float imageHeight = image.getScaledHeight(); + float imageWidth = image.getScaledWidth(); + int i = 0; + while (imageHeight > 500 || imageWidth > 500) { + image.scalePercent(100 - i); + i++; + imageHeight = image.getScaledHeight(); + imageWidth = image.getScaledWidth(); + System.out.println("imageHeight->" + imageHeight); + System.out.println("imageWidth->" + imageWidth); + } + + image.setAlignment(Image.ALIGN_CENTER); + // 设置图片的绝对位置 + // image.setAbsolutePosition(0, 0); + // image.scaleAbsolute(500, 400); + // 插入一个图片 + document.add(image); + } catch (DocumentException | IOException de) { + log.error(de.getMessage()); + } + document.close(); + if (fos != null) { + fos.flush(); + fos.close(); + } + return true; + } else { + return false; + } + } + + + /** + * 图片转pdf + * + * @param imagePath 图片路径 + * @param pdfPath pdf路径 + * @throws DocumentException 文本异常 + * @throws IOException 流异常 + */ + public static void imageToPdf3(String imagePath, String pdfPath) throws IOException, DocumentException { + BufferedImage img = ImageIO.read(new File(imagePath)); + FileOutputStream fos = new FileOutputStream(pdfPath); + Document doc = new Document(null, 0, 0, 0, 0); + doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight())); + Image image = Image.getInstance(imagePath); + PdfWriter.getInstance(doc, fos); + doc.open(); + doc.add(image); + doc.close(); + } + + +} diff --git a/src/main/java/com/lin/pdfutil/WordToPdfUtil.java b/src/main/java/com/lin/pdfutil/WordToPdfUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..d260192c385b07ed5cc37f45b7f999108eb792b7 --- /dev/null +++ b/src/main/java/com/lin/pdfutil/WordToPdfUtil.java @@ -0,0 +1,10 @@ +package com.lin.pdfutil; + +import lombok.extern.slf4j.Slf4j; + +/** + * @author linqiankun + */ +@Slf4j +public class WordToPdfUtil { +} diff --git a/src/main/java/com/lin/sort/BubbleSort.java b/src/main/java/com/lin/sort/BubbleSort.java index 2bbfa36e6f0d666eb880e0aecdd32c843c1e7f2f..684f15b2f67f63ac6e4480e1965fa4f780f028a8 100644 --- a/src/main/java/com/lin/sort/BubbleSort.java +++ b/src/main/java/com/lin/sort/BubbleSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 冒泡排序 *

O(n)~O(n^2)~O(n^2)

* 稳定 + * + * @author linqiankun */ public class BubbleSort { @@ -14,15 +16,15 @@ public class BubbleSort { /** * 冒泡排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void bubbleSorted(int[] array, StatusCode statusCode) { + public static void bubbleSorted(int[] array, SortStatusCode sortStatusCode) { for (int i = 0; i < array.length; i++) { for (int j = 0; j < array.length; j++) { int falg = SortUtil.compare(array[i], array[j]); //可修改排序方向 - if (falg == statusCode.getCode()) { + if (falg == sortStatusCode.getCode()) { SortUtil.swap(array, i, j); } } @@ -33,22 +35,23 @@ public class BubbleSort { /** * 鸡尾酒排序 * - * @param array - * @param n + * @param array 需要排序的数组 + * @param n 数组大小 */ public static void CocktailSort(int[] array, int n) { - int left = 0; // 初始化边界 + // 初始化边界 + int left = 0; int right = n - 1; while (left < right) { - for (int i = left; i < right; i++) // 前半轮,将最大元素放到后面 - { + // 前半轮,将最大元素放到后面 + for (int i = left; i < right; i++) { if (array[i] > array[i + 1]) { SortUtil.swap(array, i, i + 1); } } right--; - for (int i = right; i > left; i--) // 后半轮,将最小元素放到前面 - { + // 后半轮,将最小元素放到前面 + for (int i = right; i > left; i--) { if (array[i - 1] > array[i]) { SortUtil.swap(array, i - 1, i); } diff --git a/src/main/java/com/lin/sort/BucketSort.java b/src/main/java/com/lin/sort/BucketSort.java index 9dab05fe57dbc920f34946ba014ba0bb56183bcc..c966feb57986a2d2d7f8de6e7612a124cb5a95b2 100644 --- a/src/main/java/com/lin/sort/BucketSort.java +++ b/src/main/java/com/lin/sort/BucketSort.java @@ -1,18 +1,22 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import java.util.Arrays; +/** + * 桶排序 + * + * @author linqiankun + */ public class BucketSort { /** * 桶排序 * - * @param sourceArray - * @return - * @throws Exception + * @param sourceArray 需要排序的数组 + * @return 排序后的数组 */ public static int[] bucketSorted(int[] sourceArray) { // 对 arr 进行拷贝,不改变参数内容 @@ -24,10 +28,9 @@ public class BucketSort { /** * 桶排序 * - * @param arr - * @param bucketSize - * @return - * @throws Exception + * @param arr 需要排序的数组 + * @param bucketSize 桶大小 + * @return 排序后的数组 */ private static int[] bucketSort(int[] arr, int bucketSize) { if (arr.length == 0) { @@ -48,9 +51,9 @@ public class BucketSort { int[][] buckets = new int[bucketCount][0]; // 利用映射函数将数据分配到各个桶中 - for (int i = 0; i < arr.length; i++) { - int index = (int) Math.floor((arr[i] - minValue) / bucketSize); - buckets[index] = arrAppend(buckets[index], arr[i]); + for (int item : arr) { + int index = (int) Math.floor((item - minValue) / bucketSize); + buckets[index] = arrAppend(buckets[index], item); } int arrIndex = 0; @@ -59,10 +62,8 @@ public class BucketSort { continue; } // 对每个桶进行排序,这里使用了插入排序 - - InsertionSort.insertionSorted(bucket, StatusCode.MIX_SORT); - -// bucket = insertSort.sort(bucket); + InsertionSort.insertionSorted(bucket, SortStatusCode.MIX_SORT); + // bucket = insertSort.sort(bucket); for (int value : bucket) { arr[arrIndex++] = value; } @@ -74,8 +75,9 @@ public class BucketSort { /** * 自动扩容,并保存数据 * - * @param arr - * @param value + * @param arr 桶 + * @param value 值 + * @return 桶 */ private static int[] arrAppend(int[] arr, int value) { arr = Arrays.copyOf(arr, arr.length + 1); diff --git a/src/main/java/com/lin/sort/CountingSort.java b/src/main/java/com/lin/sort/CountingSort.java index f000a3a4f4f9d8031f78879a583809c43b63fa9d..9cf65895a1ee088215a8bccee3b45a67b9b0cc49 100644 --- a/src/main/java/com/lin/sort/CountingSort.java +++ b/src/main/java/com/lin/sort/CountingSort.java @@ -4,6 +4,8 @@ import java.util.Arrays; /** * 计数排序 + * + * @author linqiankun */ public class CountingSort { @@ -11,7 +13,7 @@ public class CountingSort { /** * 计数排序 * - * @param sourceArray + * @param sourceArray 需要排序的数组 * @return 返回排序后的数组 */ public static int[] countingsorted(int[] sourceArray) { @@ -26,9 +28,9 @@ public class CountingSort { /** * 统计排序 * - * @param arr - * @param maxValue - * @return + * @param arr 排序的数组 + * @param maxValue 最大值 + * @return 排序后的数组 */ private static int[] sort(int[] arr, int maxValue) { int bucketLen = maxValue + 1; @@ -51,8 +53,8 @@ public class CountingSort { /** * 获取最大值 * - * @param arr - * @return + * @param arr 需要排序的数组 + * @return 最大值 */ private static int getMaxValue(int[] arr) { int maxValue = arr[0]; diff --git a/src/main/java/com/lin/sort/HeapSort.java b/src/main/java/com/lin/sort/HeapSort.java index 6ab5f7f907cd86e490642c715394e94b697eb9e7..caa6de89a60a515caea15c45b74c2bf2d8b7df25 100644 --- a/src/main/java/com/lin/sort/HeapSort.java +++ b/src/main/java/com/lin/sort/HeapSort.java @@ -1,69 +1,87 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 堆排序 *

O(nlogn)~O(nlogn)~O(nlogn)

* 不稳定 + * + * @author linqiankun */ public class HeapSort { /** * 堆排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void heapSorted(int[] array, StatusCode statusCode) { - int heap_size = buildHeap(array, array.length, statusCode); // 建立一个最大堆 - while (heap_size > 1) { // 堆(无序区)元素个数大于1,未完成排序 + public static void heapSorted(int[] array, SortStatusCode sortStatusCode) { + // 建立一个最大堆 + int heapSize = buildHeap(array, array.length, sortStatusCode); + // 堆(无序区)元素个数大于1,未完成排序 + while (heapSize > 1) { // 将堆顶元素与堆的最后一个元素互换,并从堆中去掉最后一个元素 // 此处交换操作很有可能把后面元素的稳定性打乱,所以堆排序是不稳定的排序算法 - SortUtil.swap(array, 0, --heap_size); - heapify(array, 0, heap_size, statusCode); // 从新的堆顶元素开始向下进行堆调整,时间复杂度O(logn) + SortUtil.swap(array, 0, --heapSize); + // 从新的堆顶元素开始向下进行堆调整,时间复杂度O(logn) + heapify(array, 0, heapSize, sortStatusCode); } } /** * 堆结构调整 + * 从A[i]向下进行堆调整 * - * @param array - * @param i + * @param array 堆数组 + * @param i 当前节点索引 * @param size + * @param sortStatusCode 排序方式 */ - private static void heapify(int[] array, int i, int size, StatusCode statusCode) // 从A[i]向下进行堆调整 - { - int left_child = 2 * i + 1; // 左孩子索引 - int right_child = 2 * i + 2; // 右孩子索引 - int max = i; // 选出当前结点与其左右孩子三者之中的最大值 - if (left_child < size && statusCode.getCode() == SortUtil.compare(array[max], array[left_child])) -// if (left_child < size && array[left_child] > array[max]) - max = left_child; - if (right_child < size && statusCode.getCode() == SortUtil.compare(array[max], array[right_child])) -// if (right_child < size && array[right_child] > array[max]) - max = right_child; + private static void heapify(int[] array, int i, int size, SortStatusCode sortStatusCode) { + // 左孩子索引 + int leftChild = 2 * i + 1; + // 右孩子索引 + int rightChild = 2 * i + 2; + // 选出当前结点与其左右孩子三者之中的最大值 + int max = i; + if (leftChild < size && sortStatusCode.getCode() == SortUtil.compare(array[max], array[leftChild])) + // if (leftChild < size && array[leftChild] > array[max]) + { + max = leftChild; + } + if (rightChild < size && sortStatusCode.getCode() == SortUtil.compare(array[max], array[rightChild])) + // if (rightChild < size && array[rightChild] > array[max]) + { + max = rightChild; + } if (max != i) { - SortUtil.swap(array, i, max); // 把当前结点和它的最大(直接)子节点进行交换 - heapify(array, max, size, statusCode); // 递归调用,继续从当前结点向下进行堆调整 + // 把当前结点和它的最大(直接)子节点进行交换 + SortUtil.swap(array, i, max); + // 递归调用,继续从当前结点向下进行堆调整 + heapify(array, max, size, sortStatusCode); } } /** * 构造堆 + * 建堆,时间复杂度O(n) * - * @param array - * @param n + * @param array 堆数组 + * @param n 当前节点 + * @param sortStatusCode 排序方式 * @return */ - private static int buildHeap(int[] array, int n, StatusCode statusCode) // 建堆,时间复杂度O(n) - { - int heap_size = n; - for (int i = heap_size / 2 - 1; i >= 0; i--) // 从每一个非叶结点开始向下进行堆调整 - heapify(array, i, heap_size, statusCode); - return heap_size; + private static int buildHeap(int[] array, int n, SortStatusCode sortStatusCode) { + int heapSize = n; + // 从每一个非叶结点开始向下进行堆调整 + for (int i = heapSize / 2 - 1; i >= 0; i--) { + heapify(array, i, heapSize, sortStatusCode); + } + return heapSize; } diff --git a/src/main/java/com/lin/sort/InsertionSort.java b/src/main/java/com/lin/sort/InsertionSort.java index f19c696bf14a8d15a0fc80c1b4d34d19fe5ff3ed..78767d5f8abdacd4978f068763ad8ac359b08625 100644 --- a/src/main/java/com/lin/sort/InsertionSort.java +++ b/src/main/java/com/lin/sort/InsertionSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 插入排序 *

O(n)~O(n^2)~O(n^2)

* 稳定 + * + * @author linqiankun */ public class InsertionSort { @@ -14,16 +16,16 @@ public class InsertionSort { /** * 插入排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void insertionSorted(int[] array, StatusCode statusCode) { + public static void insertionSorted(int[] array, SortStatusCode sortStatusCode) { //默认第0个是排好序的,i以前的排好序 for (int i = 1; i < array.length; i++) { int get = array[i]; int j = i - 1; //从当前位值倒序往前查找 - while (j >= 0 && statusCode.getCode() == SortUtil.compare(get, array[j])) { + while (j >= 0 && sortStatusCode.getCode() == SortUtil.compare(get, array[j])) { array[j + 1] = array[j]; j--; } @@ -36,28 +38,28 @@ public class InsertionSort { /** * 二分插入排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void insertionSortedDichotomy(int[] array, StatusCode statusCode) { + public static void insertionSortedDichotomy(int[] array, SortStatusCode sortStatusCode) { for (int i = 1; i < array.length; i++) { int get = array[i]; int left = 0; int right = i - 1; //二分查找数据所处的位置,也是在之前的队列中 - while (left <= right) - { + while (left <= right) { int mid = (left + right) / 2; - if (statusCode.getCode() == SortUtil.compare(get,array[mid])) -// if (array[mid] > get) + if (sortStatusCode.getCode() == SortUtil.compare(get, array[mid])) + // if (array[mid] > get) + { right = mid - 1; - else + } else { left = mid + 1; + } } //拿走的是位置i的数据,left之后的往后移动 - for (int j = i - 1; j >= left; j--) - { - array[j + 1] = array[j]; + if (i - left >= 0) { + System.arraycopy(array, left, array, left + 1, i - left); } array[left] = get; } diff --git a/src/main/java/com/lin/sort/MergeSort.java b/src/main/java/com/lin/sort/MergeSort.java index 5df23b9f949973600d3a134daa4693c69ff8d39e..389abc3c3e8da6ca1aa2898888c75969cf773ba3 100644 --- a/src/main/java/com/lin/sort/MergeSort.java +++ b/src/main/java/com/lin/sort/MergeSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 归并排序 *

O(nlogn)~O(nlogn)~O(nlogn)

* 稳定 + * + * @author linqiankun */ public class MergeSort { @@ -14,17 +16,17 @@ public class MergeSort { /** * 非递归归并排序(错误) * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void mergeSortedIteration(int array[], StatusCode statusCode) { + public static void mergeSortedIteration(int[] array, SortStatusCode sortStatusCode) { int left, mid, right; for (int i = 1; i < array.length; i *= 2) { left = 0; while (left + i < array.length) { mid = left + i - 1; right = mid + 1 < array.length ? mid + 1 : array.length - 1; - merge(array, statusCode, left, mid, right); + merge(array, sortStatusCode, left, mid, right); left = mid + 1; } } @@ -34,33 +36,34 @@ public class MergeSort { /** * 递归使用归并排序 * - * @param array - * @param statusCode - * @param left - * @param right + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 + * @param left 左边界 + * @param right 右边界 */ - public static void mergeSortedRecursion(int[] array, StatusCode statusCode, int left, int right) { - if (left == right) + public static void mergeSortedRecursion(int[] array, SortStatusCode sortStatusCode, int left, int right) { + if (left == right) { return; + } int mid = (left + right) / 2; //前半段数组归并 - mergeSortedRecursion(array, statusCode, left, mid); + mergeSortedRecursion(array, sortStatusCode, left, mid); //后半段数组归并 - mergeSortedRecursion(array, statusCode, mid + 1, right); + mergeSortedRecursion(array, sortStatusCode, mid + 1, right); //归并合并 - merge(array, statusCode, left, mid, right); + merge(array, sortStatusCode, left, mid, right); } /** * 数组合并 * - * @param array - * @param statusCode - * @param left - * @param mid - * @param right + * @param array 需要合并的数组 + * @param sortStatusCode 排序方式 + * @param left 左边界 + * @param mid 中间位置 + * @param right 有边界 */ - private static void merge(int[] array, StatusCode statusCode, int left, int mid, int right) { + private static void merge(int[] array, SortStatusCode sortStatusCode, int left, int mid, int right) { int len = right - left + 1; int[] temp = new int[len]; int index = 0; @@ -70,7 +73,7 @@ public class MergeSort { int j = mid + 1; //两组数据归并操作 while (i <= mid && j <= right) { - temp[index++] = statusCode.getCode() == SortUtil.compare(array[i], array[j]) ? array[i++] : array[j++]; + temp[index++] = sortStatusCode.getCode() == SortUtil.compare(array[i], array[j]) ? array[i++] : array[j++]; } //上面的循环无法将两个子数组的数据全部循环到 while (i <= mid) { diff --git a/src/main/java/com/lin/sort/QuickSort.java b/src/main/java/com/lin/sort/QuickSort.java index f4f76c4e3f82b72927e0890ef89c9d6d09fa599d..19a1d722acac4cc30226e9332abf0f8820ef8735 100644 --- a/src/main/java/com/lin/sort/QuickSort.java +++ b/src/main/java/com/lin/sort/QuickSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 快速排序 *

O(nlogn)~O(nlogn)~O(n^2)

* 不稳定 + * + * @author linqiankun */ public class QuickSort { @@ -14,38 +16,51 @@ public class QuickSort { /** * 分治块 * - * @param array - * @param left - * @param right - * @param statusCode - * @return + * @param array 分治数组 + * @param left 左边界 + * @param right 右边界 + * @param sortStatusCode 排序方式 + * @return 基准的索引 */ - private static int partition(int[] array, int left, int right, StatusCode statusCode) // 划分函数 + private static int partition(int[] array, int left, int right, SortStatusCode sortStatusCode) // 划分函数 { - int pivot = array[right]; // 这里每次都选择最后一个元素作为基准 - int tail = left - 1; // tail为小于基准的子数组最后一个元素的索引 - for (int i = left; i < right; i++) // 遍历基准以外的其他元素 - { - if (SortUtil.compare(pivot, array[i]) == 0 || !(statusCode.getCode() == SortUtil.compare(pivot, array[i]))) //会破环稳定性 -// if (array[i] <= pivot) // 把小于等于基准的元素放到前一个子数组末尾 + // 这里每次都选择最后一个元素作为基准 + int pivot = array[right]; + // tail为小于基准的子数组最后一个元素的索引 + int tail = left - 1; + // 遍历基准以外的其他元素 + for (int i = left; i < right; i++) { + // 把小于等于基准的元素放到前一个子数组末尾 + //会破环稳定性 + if (SortUtil.compare(pivot, array[i]) == 0 || (sortStatusCode.getCode() != SortUtil.compare(pivot, array[i]))) + // if (array[i] <= pivot) { SortUtil.swap(array, ++tail, i); } - } - SortUtil.swap(array, tail + 1, right); // 最后把基准放到前一个子数组的后边,剩下的子数组既是大于基准的子数组 + } // 最后把基准放到前一个子数组的后边,剩下的子数组既是大于基准的子数组 // 该操作很有可能把后面元素的稳定性打乱,所以快速排序是不稳定的排序算法 - return tail + 1; // 返回基准的索引 + SortUtil.swap(array, tail + 1, right); + // 返回基准的索引 + return tail + 1; } + /** * 快速排序 + * + * @param array 排序数组 + * @param left 左边界 + * @param right 右边界 + * @param sortStatusCode 排序方式 */ - public static void quickSorted(int[] array, int left, int right, StatusCode statusCode) { - if (left >= right) + public static void quickSorted(int[] array, int left, int right, SortStatusCode sortStatusCode) { + if (left >= right) { return; - int pivot_index = partition(array, left, right, statusCode); // 基准的索引 - quickSorted(array, left, pivot_index - 1, statusCode); - quickSorted(array, pivot_index + 1, right, statusCode); + } + // 基准的索引 + int pivotIndex = partition(array, left, right, sortStatusCode); + quickSorted(array, left, pivotIndex - 1, sortStatusCode); + quickSorted(array, pivotIndex + 1, right, sortStatusCode); } diff --git a/src/main/java/com/lin/sort/RadixSort.java b/src/main/java/com/lin/sort/RadixSort.java index 6c66253f38846e2914347e58d43f9949e2812eca..9b4bf181501fca08f3ffcb548656f9b04b3523af 100644 --- a/src/main/java/com/lin/sort/RadixSort.java +++ b/src/main/java/com/lin/sort/RadixSort.java @@ -4,6 +4,8 @@ import java.util.Arrays; /** * 基数排序 + * + * @author linqiankun */ public class RadixSort { @@ -11,8 +13,8 @@ public class RadixSort { /** * 基数排序 * - * @param sourceArray - * @return + * @param sourceArray 需要排序的数组 + * @return 排序后的数组 */ public static int[] radixSorted(int[] sourceArray) { // 对 arr 进行拷贝,不改变参数内容 @@ -25,7 +27,7 @@ public class RadixSort { /** * 获取最高位数 * - * @param arr + * @param arr 需要排序的数组 * @return */ private static int getMaxDigit(int[] arr) { @@ -36,8 +38,8 @@ public class RadixSort { /** * 获取最大值 * - * @param arr - * @return + * @param arr 排序数组 + * @return 最大值 */ private static int getMaxValue(int[] arr) { int maxValue = arr[0]; @@ -49,7 +51,7 @@ public class RadixSort { return maxValue; } - protected static int getNumLenght(long num) { + private static int getNumLenght(long num) { if (num == 0) { return 1; } @@ -63,9 +65,9 @@ public class RadixSort { /** * 基数排序 * - * @param arr + * @param arr 排序数组 * @param maxDigit - * @return + * @return 排序后数组 */ private static int[] radixSort(int[] arr, int maxDigit) { int mod = 10; @@ -75,9 +77,9 @@ public class RadixSort { // 考虑负数的情况,这里扩展一倍队列数,其中 [0-9]对应负数,[10-19]对应正数 (bucket + 10) int[][] counter = new int[mod * 2][0]; - for (int j = 0; j < arr.length; j++) { - int bucket = ((arr[j] % mod) / dev) + mod; - counter[bucket] = arrayAppend(counter[bucket], arr[j]); + for (int item : arr) { + int bucket = ((item % mod) / dev) + mod; + counter[bucket] = arrayAppend(counter[bucket], item); } int pos = 0; @@ -94,8 +96,8 @@ public class RadixSort { /** * 自动扩容,并保存数据 * - * @param arr - * @param value + * @param arr 数组 + * @param value 扩容后数组 */ private static int[] arrayAppend(int[] arr, int value) { arr = Arrays.copyOf(arr, arr.length + 1); diff --git a/src/main/java/com/lin/sort/SelectionSort.java b/src/main/java/com/lin/sort/SelectionSort.java index 3b6e7d3db5ac2c5d49bb47a5122dc585c63b5879..af7ee00f941dbd6644faf7c8fd75ef5a3b34809f 100644 --- a/src/main/java/com/lin/sort/SelectionSort.java +++ b/src/main/java/com/lin/sort/SelectionSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 选择排序 *

O(n^2)~O(n^2)~O(n^2)

* 不稳定 + * + * @author linqiankun */ public class SelectionSort { @@ -14,17 +16,17 @@ public class SelectionSort { /** * 选择排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void selectionSorted(int[] array, StatusCode statusCode) { + public static void selectionSorted(int[] array, SortStatusCode sortStatusCode) { //确定最小的位置 for (int i = 0; i < array.length; i++) { int min = i; //确定最小的位置存放的数据 for (int j = i + 1; j < array.length; j++) { //用标志为查出为排序队列中最小/大的 - if (statusCode.getCode() == SortUtil.compare(array[j], array[min])) { + if (sortStatusCode.getCode() == SortUtil.compare(array[j], array[min])) { min = j; } } diff --git a/src/main/java/com/lin/sort/ShellSort.java b/src/main/java/com/lin/sort/ShellSort.java index 9bc773920f250d02b42ea2a516efc51a1bd078f7..76ffd6ddebe281c2a0827db0fd3bd282317c862b 100644 --- a/src/main/java/com/lin/sort/ShellSort.java +++ b/src/main/java/com/lin/sort/ShellSort.java @@ -1,12 +1,14 @@ package com.lin.sort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.util.SortUtil; /** * 希尔排序 *

O(n^1.3)~O(nlogn)~O(n^2)~O(n^2)

* 不稳定 + * + * @author linqiankun */ public class ShellSort { @@ -14,10 +16,10 @@ public class ShellSort { /** * 希尔排序 * - * @param array - * @param statusCode + * @param array 需要排序的数组 + * @param sortStatusCode 排序方式 */ - public static void shellSorted(int[] array, StatusCode statusCode) { + public static void shellSorted(int[] array, SortStatusCode sortStatusCode) { int shell = 0; //寻找最大的希尔值 while (shell <= array.length) { @@ -29,7 +31,7 @@ public class ShellSort { for (int i = shell; i < array.length; i++) { int j = i - shell; int get = array[i]; - while (j >= 0 && statusCode.getCode() == SortUtil.compare(get, array[j])) { + while (j >= 0 && sortStatusCode.getCode() == SortUtil.compare(get, array[j])) { array[j + shell] = array[j]; j = j - shell; } diff --git a/src/main/java/com/lin/sort/util/SortUtil.java b/src/main/java/com/lin/sort/util/SortUtil.java index 331e81f7af337e46802c2723ffef5e6fe3abb77b..e65c31e77af2080b6addab5d369c2a1c16fb1eb1 100644 --- a/src/main/java/com/lin/sort/util/SortUtil.java +++ b/src/main/java/com/lin/sort/util/SortUtil.java @@ -2,15 +2,17 @@ package com.lin.sort.util; /** * 排序工具 + * + * @author linqiankun */ public class SortUtil { /** * 交换 * - * @param array - * @param a - * @param b + * @param array 数组 + * @param a 索引 + * @param b 索引 */ public static void swap(int[] array, int a, int b) { int temp = array[a]; @@ -21,18 +23,12 @@ public class SortUtil { /** * 比较器 * - * @param a - * @param b - * @return + * @param a 索引 + * @param b 索引 + * @return 结果,0,—1,1 */ public static int compare(int a, int b) { - if (a > b) { - return 1; - } else if (a < b) { - return -1; - } else { - return 0; - } + return Integer.compare(a, b); } } diff --git a/src/main/java/com/lin/tree/nome/BSTree.java b/src/main/java/com/lin/tree/nome/BSTree.java index 362584caf6232366c777a3ae5da5baabc8afb703..16c1646da2116144aa577016d3f07e98677da023 100644 --- a/src/main/java/com/lin/tree/nome/BSTree.java +++ b/src/main/java/com/lin/tree/nome/BSTree.java @@ -5,7 +5,7 @@ import lombok.Data; /** * 二叉搜索树 * - * @param + * @param 数据泛型 */ public class BSTree> { @@ -35,21 +35,22 @@ public class BSTree> { /** * 二叉搜索树递归查找 * - * @param x - * @param key - * @return + * @param x 跟节点 + * @param key 查找的数据 + * @return 查找到的节点 */ private BSTNode search(BSTNode x, T key) { - if (x == null) + if (x == null) { return x; - + } int cmp = key.compareTo(x.key); - if (cmp < 0) + if (cmp < 0) { return search(x.left, key); - else if (cmp > 0) + } else if (cmp > 0) { return search(x.right, key); - else + } else { return x; + } } public BSTNode search(T key) { @@ -59,20 +60,21 @@ public class BSTree> { /** * 二叉搜索树非递归查找 * - * @param x - * @param key - * @return + * @param x 跟节点 + * @param key 查找的数据 + * @return 具备数据的节点 */ private BSTNode iterativeSearch(BSTNode x, T key) { while (x != null) { int cmp = key.compareTo(x.key); - if (cmp < 0) + if (cmp < 0) { x = x.left; - else if (cmp > 0) + } else if (cmp > 0) { x = x.right; - else + } else { return x; + } } return x; @@ -85,22 +87,30 @@ public class BSTree> { /** * 查找最大节点 * - * @param tree - * @return + * @param tree 跟节点 + * @return 最大节点 */ private BSTNode maximum(BSTNode tree) { - if (tree == null) + if (tree == null) { return null; + } - while (tree.right != null) + while (tree.right != null) { tree = tree.right; + } return tree; } + /** + * 查找最大节数据 + * + * @return 最大节点 + */ public T maximum() { BSTNode p = maximum(mRoot); - if (p != null) + if (p != null) { return p.key; + } return null; } @@ -108,22 +118,29 @@ public class BSTree> { /** * 查找最小节点 * - * @param tree - * @return + * @param tree 跟节点 + * @return 最小节点 */ private BSTNode minimum(BSTNode tree) { - if (tree == null) + if (tree == null) { return null; - - while (tree.left != null) + } + while (tree.left != null) { tree = tree.left; + } return tree; } + /** + * 查找最小数据 + * + * @return 最小节点 + */ public T minimum() { BSTNode p = minimum(mRoot); - if (p != null) + if (p != null) { return p.key; + } return null; } @@ -131,14 +148,14 @@ public class BSTree> { /** * 查找前驱节点 * - * @param x - * @return + * @param x 当前节点 + * @return 前驱节点 */ public BSTNode predecessor(BSTNode x) { // 如果x存在左孩子,则"x的前驱结点"为 "以其左孩子为根的子树的最大结点"。 - if (x.left != null) + if (x.left != null) { return maximum(x.left); - + } // 如果x没有左孩子。则x有以下两种可能: // (01) x是"一个右孩子",则"x的前驱结点"为 "它的父结点"。 // (01) x是"一个左孩子",则查找"x的最低的父结点,并且该父结点要具有右孩子",找到的这个"最低的父结点"就是"x的前驱结点"。 @@ -154,14 +171,14 @@ public class BSTree> { /** * 查找后继节点 * - * @param x - * @return + * @param x 当前节点 + * @return 后继节点 */ public BSTNode successor(BSTNode x) { // 如果x存在右孩子,则"x的后继结点"为 "以其右孩子为根的子树的最小结点"。 - if (x.right != null) + if (x.right != null) { return minimum(x.right); - + } // 如果x没有右孩子。则x有以下两种可能: // (01) x是"一个左孩子",则"x的后继结点"为 "它的父结点"。 // (02) x是"一个右孩子",则查找"x的最低的父结点,并且该父结点要具有左孩子",找到的这个"最低的父结点"就是"x的后继结点"。 @@ -177,8 +194,8 @@ public class BSTree> { /** * 将节点插入二叉树 * - * @param bst - * @param z + * @param bst 二叉树 + * @param z 插入的节点 */ private void insert(BSTree bst, BSTNode z) { int cmp; @@ -189,121 +206,140 @@ public class BSTree> { while (x != null) { y = x; cmp = z.key.compareTo(x.key); - if (cmp < 0) + if (cmp < 0) { x = x.left; - else + } else { x = x.right; + } } z.parent = y; - if (y == null) + if (y == null) { bst.mRoot = z; - else { + } else { cmp = z.key.compareTo(y.key); - if (cmp < 0) + if (cmp < 0) { y.left = z; - else + } else { + y.right = z; + } } } + /** + * 插入数据 + * + * @param key 要插入的数据 + */ public void insert(T key) { BSTNode z = new BSTNode(key, null, null, null); - - // 如果新建结点失败,则返回。 - if (z != null) - insert(this, z); + insert(this, z); } /** * 删除节点并返回 * - * @param bst - * @param z - * @return + * @param bst 二叉树 + * @param z 要删除的节点 + * @return 要删除的的节点 */ private BSTNode remove(BSTree bst, BSTNode z) { - BSTNode x = null; - BSTNode y = null; + BSTNode x; + BSTNode y; - if ((z.left == null) || (z.right == null)) + if ((z.left == null) || (z.right == null)) { y = z; - else + } else { y = successor(z); - - if (y.left != null) + } + if (y.left != null) { x = y.left; - else + } else { x = y.right; - - if (x != null) + } + if (x != null) { x.parent = y.parent; - - if (y.parent == null) + } + if (y.parent == null) { bst.mRoot = x; - else if (y == y.parent.left) + } else if (y == y.parent.left) { y.parent.left = x; - else + } else { y.parent.right = x; - - if (y != z) + } + if (y != z) { z.key = y.key; - + } return y; } + /** + * 删除数据 + * + * @param key 要删除的数据 + */ public void remove(T key) { BSTNode z, node; - if ((z = search(mRoot, key)) != null) - if ((node = remove(this, z)) != null) - node = null; + if ((z = search(mRoot, key)) != null) { + node = remove(this, z); + } } /** * 打印二叉搜索树 * - * @param tree - * @param key - * @param direction + * @param tree 跟节点 + * @param key 数据 + * @param direction 层级 */ private void print(BSTNode tree, T key, int direction) { - + // tree是根节点 if (tree != null) { - - if (direction == 0) // tree是根节点 + if (direction == 0) { System.out.printf("%2d is root\n", tree.key); - else // tree是分支节点 + } + // tree是分支节点 + else { System.out.printf("%2d is %2d's %6s child\n", tree.key, key, direction == 1 ? "right" : "left"); - + } print(tree.left, tree.key, -1); print(tree.right, tree.key, 1); } } + /** + * 打印二叉树 + */ public void print() { - if (mRoot != null) + if (mRoot != null) { print(mRoot, mRoot.key, 0); + } } /** * 销毁二叉树 * - * @param tree + * @param tree 跟节点 */ private void destroy(BSTNode tree) { - if (tree == null) + if (tree == null) { return; - - if (tree.left != null) + } + if (tree.left != null) { destroy(tree.left); - if (tree.right != null) + } + if (tree.right != null) { destroy(tree.right); - + } tree = null; } + /** + * 销毁二叉树 + */ public void clear() { destroy(mRoot); mRoot = null; diff --git a/src/main/java/com/lin/tree/nome/Tree.java b/src/main/java/com/lin/tree/nome/Tree.java index 91694a48ba2fa75eea4a4a2bad42b7a5354e1eac..96b0001866812368e751cdc780e0fb2a52271bf3 100644 --- a/src/main/java/com/lin/tree/nome/Tree.java +++ b/src/main/java/com/lin/tree/nome/Tree.java @@ -9,13 +9,15 @@ import java.util.concurrent.LinkedBlockingQueue; /** * 普通二叉树 + * + * @author linqiankun */ public class Tree { /** * 递归实现前序遍历 * - * @param node + * @param node 跟节点 */ public void preOrderTraverse(Node node) { if (node != null) { @@ -28,7 +30,7 @@ public class Tree { /** * 非递归实现的前序遍历 * - * @param root + * @param root 跟节点 */ public void nrPreOrderTraverse(Node root) { //借助栈实现 @@ -50,7 +52,7 @@ public class Tree { /** * 递归实现的中序遍历 * - * @param node + * @param node 跟节点 */ public void inOrderTraverse(Node node) { if (node != null) { @@ -63,7 +65,7 @@ public class Tree { /** * 非递归实现的中序遍历 * - * @param root + * @param root 跟节点 */ public void nrInOrderTraverse(Node root) { Stack> stack = new Stack>(); @@ -82,7 +84,7 @@ public class Tree { /** * 递归实现的后续遍历 * - * @param node + * @param node 跟节点 */ public void postOrderTraverse(Node node) { if (node != null) { @@ -95,13 +97,14 @@ public class Tree { /** * 非递归实现的后续遍历 * - * @param root + * @param root 跟节点 */ public void nrPostOrderTraverse(Node root) { Stack> stack = new Stack>(); Node node = root; - Node preNode = null;//表示最近一次访问的节点 + //表示最近一次访问的节点 + Node preNode = null; while (node != null || !stack.isEmpty()) { while (node != null) { @@ -125,7 +128,7 @@ public class Tree { /** * 借助队列实现的层序遍历 * - * @param node + * @param node 跟节点 */ public void levelTraverse(Node node) { //借助队列实现 @@ -145,29 +148,30 @@ public class Tree { /** * 获取树的深度 * - * @param node - * @return + * @param node 跟节点 + * @return 树的深度 */ private Integer getHeight(Node node) { - if (node == null) + if (node == null) { return 0; - else { + } else { int left = getHeight(node.getLeft()); int right = getHeight(node.getRight()); - return left > right ? left + 1 : right + 1;//左子树 右子树最深的,再加上父节点本身深度1 + //左子树 右子树最深的,再加上父节点本身深度1 + return left > right ? left + 1 : right + 1; } } /** * 获取节点数量 * - * @param node - * @return + * @param node 跟节点 + * @return 节点数量 */ private Integer getSize(Node node) { - if (node == null) + if (node == null) { return 0; - else { + } else { int leftSize = getSize(node.getLeft()); int rightSize = getSize(node.getRight()); return leftSize + rightSize + 1; diff --git a/src/main/java/com/lin/Util/ArraySortUtil.java b/src/main/java/com/lin/util/ArraySortUtil.java similarity index 73% rename from src/main/java/com/lin/Util/ArraySortUtil.java rename to src/main/java/com/lin/util/ArraySortUtil.java index f9154eb129c0bff2b091784431d97486dc3134cb..00d1b4144e1b0b777e8a1eb5045f9b1ebb548f30 100644 --- a/src/main/java/com/lin/Util/ArraySortUtil.java +++ b/src/main/java/com/lin/util/ArraySortUtil.java @@ -1,9 +1,9 @@ -package com.lin.Util; +package com.lin.util; import lombok.extern.slf4j.Slf4j; /** - * excel导出工具 + * 数组排序工具 * * @author 九分石人,2020-02-24 */ @@ -11,5 +11,4 @@ import lombok.extern.slf4j.Slf4j; public class ArraySortUtil { - } diff --git a/src/main/java/com/lin/util/ExcelExportUtil.java b/src/main/java/com/lin/util/ExcelExportUtil.java index bd263362ec830e9db53df4390e4c45c5868ed1c8..ce330185cd911b5537416bec5f534a03d55da5f0 100644 --- a/src/main/java/com/lin/util/ExcelExportUtil.java +++ b/src/main/java/com/lin/util/ExcelExportUtil.java @@ -26,6 +26,7 @@ public class ExcelExportUtil { /** * 导出Excel主方法,调用此方法即可(该方法未测试) * + * @param 类型泛型 * @param fileName 文件名 * @param list 数据源 * @param title 标题数组 @@ -35,8 +36,9 @@ public class ExcelExportUtil { public static void exportExcel(String fileName, @NotNull List list, String[] title, HttpServletResponse response) { // 制作导出文件 HSSFWorkbook excel; + int maxNum = 5000; try { - if (list.size() > 5000) { + if (list.size() > maxNum) { fileName = "数据量过大"; List listError = new ArrayList<>(); listError.add("数据量超过5000,无法导出"); @@ -68,6 +70,7 @@ public class ExcelExportUtil { /** * 制作HSSFWorkbook格式的Excel文件 * + * @param 类型泛型 * @param list 数据源,要导出的数据 * @param title 标题列表 * @return excel格式的文件 diff --git a/src/main/java/com/lin/util/ExcelImportUtil.java b/src/main/java/com/lin/util/ExcelImportUtil.java index c9da58c2f5edbfb07272c08da9dbcd99048b71e7..502027663319894970f01b77813d1054b21cf60d 100644 --- a/src/main/java/com/lin/util/ExcelImportUtil.java +++ b/src/main/java/com/lin/util/ExcelImportUtil.java @@ -43,7 +43,8 @@ public class ExcelImportUtil { public static List readExcelFile(InputStream fileInputStream, int validColumn, int startRow) { try { Workbook workbook = getWeebWork(fileInputStream); - Sheet sheet = workbook.getSheetAt(0);// 只取sheet1的数据 + // 只取sheet1的数据 + Sheet sheet = workbook.getSheetAt(0); return readFromSheet(sheet, validColumn, startRow); } catch (Exception e) { log.error(e.getMessage()); @@ -97,13 +98,18 @@ public class ExcelImportUtil { @NotNull private static List readFromSheet(@NotNull Sheet sheet, int validColumn, int startRow) { List list = new ArrayList<>(); - int rownum = sheet.getLastRowNum();// 获取总行 - int totalCellNum = sheet.getRow(1).getLastCellNum();// 获取总列数 + // 限制不能超过5000条数据 + int maxNum = 5000; + // 获取总行 + int rowNum = sheet.getLastRowNum(); + // 获取总列数 + int totalCellNum = sheet.getRow(1).getLastCellNum(); // 设置获取总行数,如果大于5000,则截止为5000. - if (rownum >= 5000) - rownum = 5000; + if (rowNum >= maxNum) { + rowNum = 5000; + } // 从第三行开始处理数据 - for (int i = (startRow - 1); i <= rownum; i++) { + for (int i = (startRow - 1); i <= rowNum; i++) { Row row = sheet.getRow(i); if (row != null) { // 第X列数据不完整的话 视为无效数据 不予添加进list中 @@ -111,16 +117,19 @@ public class ExcelImportUtil { continue; } try { - row.getCell(validColumn).setCellType(Cell.CELL_TYPE_STRING); //设置成文本格式 + //设置成文本格式 + row.getCell(validColumn).setCellType(Cell.CELL_TYPE_STRING); } catch (Exception e) { log.error(e.getMessage()); } - String[] cells = new String[totalCellNum];// 根据标题行生成相同列数的String数组 + // 根据标题行生成相同列数的String数组 + String[] cells = new String[totalCellNum]; for (int j = 0; j < totalCellNum; j++) { Cell cell = row.getCell(j); if (cell != null) { if (!"".equals(String.valueOf(cell).trim())) { - cells[j] = String.valueOf(cell).trim();// 每个有效数据单元格都转化为String类型 + // 每个有效数据单元格都转化为String类型 + cells[j] = String.valueOf(cell).trim(); } else { cells[j] = null; } diff --git a/src/main/java/com/lin/util/FileReadUtil.java b/src/main/java/com/lin/util/FileReadUtil.java index 2e33e8fa863ae40239efb8b5e48fb1b60c4d88ab..c195747e7057af1b84a87fb5988ce4a9e83bac0b 100644 --- a/src/main/java/com/lin/util/FileReadUtil.java +++ b/src/main/java/com/lin/util/FileReadUtil.java @@ -22,7 +22,7 @@ public class FileReadUtil { */ public static File readToFile(String filePath) { File file = new File(filePath); - if(file.exists()){ + if (file.exists()) { return file; } return null; @@ -42,23 +42,30 @@ public class FileReadUtil { try { is = new FileInputStream(filePath); reader = new BufferedReader(new InputStreamReader(is)); + // 用来保存每行读取的内容 + String line; + // 读取第一行 + line = reader.readLine(); - String line; // 用来保存每行读取的内容 - line = reader.readLine(); // 读取第一行 - - while (line != null) { // 如果 line 为空说明读完了 - buffer.append(line); // 将读到的内容添加到 buffer 中 - buffer.append("\n"); // 添加换行符 - line = reader.readLine(); // 读取下一行 + // 如果 line 为空说明读完了 + while (line != null) { + // 将读到的内容添加到 buffer 中 + buffer.append(line); + // 添加换行符 + buffer.append("\n"); + // 读取下一行 + line = reader.readLine(); } } catch (IOException e) { log.error(e.getMessage()); } finally { try { - if (reader != null) + if (reader != null) { reader.close(); - if (is != null) + } + if (is != null) { is.close(); + } } catch (IOException e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/lin/util/FileWriteUtil.java b/src/main/java/com/lin/util/FileWriteUtil.java index ca6a7051711d5126545299eccf78e11c28c98a86..160ae542ba014cb2f01780735ef9bdf4dbf41ff6 100644 --- a/src/main/java/com/lin/util/FileWriteUtil.java +++ b/src/main/java/com/lin/util/FileWriteUtil.java @@ -52,10 +52,12 @@ public class FileWriteUtil { log.error(e.getMessage()); } finally { try { - if (writer != null) + if (writer != null) { writer.close(); - if (outputStream != null) + } + if (outputStream != null) { outputStream.close(); + } } catch (IOException e) { log.error(e.getMessage()); } @@ -84,8 +86,9 @@ public class FileWriteUtil { e.printStackTrace(); } finally { try { - if (outputStream != null) + if (outputStream != null) { outputStream.close(); + } } catch (IOException e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/lin/util/HttpConnectionUtil.java b/src/main/java/com/lin/util/HttpConnectionUtil.java index 911d3cc58eac6eff83eee4995d8df13704134026..5ce1c3506d132adbbd4d33330031b6cc76d01adb 100644 --- a/src/main/java/com/lin/util/HttpConnectionUtil.java +++ b/src/main/java/com/lin/util/HttpConnectionUtil.java @@ -1,5 +1,6 @@ package com.lin.util; +import com.lin.enums.ResponseStatusCode; import lombok.extern.slf4j.Slf4j; import java.io.*; @@ -9,7 +10,7 @@ import java.net.URLEncoder; /** * Http连接工具 - * + * * @author 九分石人, 2019-12-31 */ @Slf4j @@ -32,8 +33,8 @@ public class HttpConnectionUtil { InputStream inputStream = null; String result = ""; try { - String newURL = getNewUrlByUrlEncodeParam(url); - URL realUrl = new URL(newURL); + String newUrl = getNewUrlByUrlEncodeParam(url); + URL realUrl = new URL(newUrl); String method = "GET"; connection = (HttpURLConnection) realUrl.openConnection(); @@ -45,7 +46,7 @@ public class HttpConnectionUtil { connection.connect(); int responseCode = connection.getResponseCode(); - if (responseCode == 200) { + if (responseCode == ResponseStatusCode.OK.getCode()) { inputStream = connection.getInputStream(); } else { inputStream = connection.getErrorStream(); @@ -73,8 +74,8 @@ public class HttpConnectionUtil { InputStream inputStream = null; String result = ""; try { - String newURL = getNewUrlByUrlEncodeParam(url); - URL realUrl = new URL(newURL); + String newUrl = getNewUrlByUrlEncodeParam(url); + URL realUrl = new URL(newUrl); String method = "POST"; connection = (HttpURLConnection) realUrl.openConnection(); @@ -90,7 +91,7 @@ public class HttpConnectionUtil { out.flush(); int responseCode = connection.getResponseCode(); - if (responseCode == 200) { + if (responseCode == ResponseStatusCode.OK.getCode()) { inputStream = connection.getInputStream(); } else { inputStream = connection.getErrorStream(); @@ -167,7 +168,7 @@ public class HttpConnectionUtil { */ private static String getNewUrlByUrlEncodeParam(String url) throws UnsupportedEncodingException { StringBuilder urlForEncode = new StringBuilder(); - String newURL; + String newUrl; if (url.contains("=")) { String[] urlBeforeEncode = url.split("="); for (int i = 1; i < urlBeforeEncode.length; i++) { @@ -179,13 +180,13 @@ public class HttpConnectionUtil { if (i == urlBeforeEncode.length - 1) { urlBeforeEncode[i] = URLEncoder.encode(urlBeforeEncode[i], encode); } - urlForEncode = urlForEncode.append(urlBeforeEncode[i]); + urlForEncode.append(urlBeforeEncode[i]); if (i != urlBeforeEncode.length - 1) { urlForEncode = urlForEncode.append("="); } } - newURL = urlBeforeEncode[0] + "=" + urlForEncode.toString(); - return newURL; + newUrl = urlBeforeEncode[0] + "=" + urlForEncode.toString(); + return newUrl; } return url; } diff --git a/src/main/java/com/lin/util/HttpUrlConnectionUtil.java b/src/main/java/com/lin/util/HttpUrlConnectionUtil.java index 520aa756a195198e197ea38ecbf5c8dff2f53cf8..02aacb9b5dc174c5e3f5eecafcbe45c9809524f2 100644 --- a/src/main/java/com/lin/util/HttpUrlConnectionUtil.java +++ b/src/main/java/com/lin/util/HttpUrlConnectionUtil.java @@ -1,5 +1,6 @@ package com.lin.util; +import com.lin.enums.ResponseStatusCode; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; @@ -8,6 +9,7 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import java.io.DataOutputStream; import java.net.HttpURLConnection; +import java.net.ResponseCache; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -37,7 +39,7 @@ public class HttpUrlConnectionUtil { try { url = new URL(urlStr); connection = (HttpURLConnection) url.openConnection(); -// SSLSocketFactory ssl = HttpUrlConnectionUtil.getSSL(); +// SSLSocketFactory ssl = HttpUrlConnectionUtil.getSsl(); // https请求需要 // connection.setSSLSocketFactory(ssl); connection.setDoOutput(true); @@ -51,7 +53,7 @@ public class HttpUrlConnectionUtil { int responseCode = connection.getResponseCode(); // 结果 String result; - if (responseCode != 200) { + if (responseCode != ResponseStatusCode.OK.getCode()) { result = IOUtils.toString(connection.getErrorStream()); } else { result = IOUtils.toString(connection.getInputStream()); @@ -81,7 +83,7 @@ public class HttpUrlConnectionUtil { try { url = new URL(urlStr); connection = (HttpURLConnection) url.openConnection(); -// SSLSocketFactory ssl = HttpUrlConnectionUtil.getSSL(); +// SSLSocketFactory ssl = HttpUrlConnectionUtil.getSsl(); // https请求需要 // connection.setSSLSocketFactory(ssl); connection.setDoOutput(true); @@ -98,7 +100,7 @@ public class HttpUrlConnectionUtil { int responseCode = connection.getResponseCode(); String result; - if (responseCode != 200) { + if (responseCode != ResponseStatusCode.OK.getCode()) { result = IOUtils.toString(connection.getErrorStream()); } else { result = IOUtils.toString(connection.getInputStream()); @@ -123,7 +125,7 @@ public class HttpUrlConnectionUtil { * @throws KeyManagementException 异常 * @author com.lin, 2019-12-21 */ - private static SSLSocketFactory getSSL() throws NoSuchProviderException, NoSuchAlgorithmException, KeyManagementException { + private static SSLSocketFactory getSsl() throws NoSuchProviderException, NoSuchAlgorithmException, KeyManagementException { TrustManager[] trustManager = new TrustManager[]{}; SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); sslContext.init(null, trustManager, new java.security.SecureRandom()); diff --git a/src/main/java/com/lin/util/ProvinceCityUtil.java b/src/main/java/com/lin/util/ProvinceCityUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..05cb4a716e8429ebbc55fa785d5bcbe71c401773 --- /dev/null +++ b/src/main/java/com/lin/util/ProvinceCityUtil.java @@ -0,0 +1,121 @@ +package com.lin.util; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author 九分石人 + */ +@Slf4j +public class ProvinceCityUtil { + + /** + * 解析地址 + * + * @param address 地址 + * @return 解析后的地址 + */ + public static List> addressResolution(String address) { + String regex = "(?[^省]+自治区|.*?省|.*?行政区|.*?市)(?[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?[^区]+区|.+镇)?(?.*)"; + Matcher m = Pattern.compile(regex).matcher(address); + String province = null, city = null, county = null, town = null, village = null; + List> table = new ArrayList>(); + Map row = null; + while (m.find()) { + row = new LinkedHashMap(); + province = m.group("province"); + row.put("province", province == null ? "" : province.trim()); + city = m.group("city"); + row.put("city", city == null ? "" : city.trim()); + county = m.group("county"); + row.put("county", county == null ? "" : county.trim()); + town = m.group("town"); + row.put("town", town == null ? "" : town.trim()); + village = m.group("village"); + row.put("village", village == null ? "" : village.trim()); + table.add(row); + } + return table; + } + + /** + * 解析地址 + * + * @param address 地址 + * @return 解析后的地址 + */ + public static Map addressResolutionNo(String address) { + String regex = "(?[^省]+自治区|.*?省|.*?行政区|.*?市)(?[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?[^区]+区|.+镇)?(?.*)"; + Matcher m = Pattern.compile(regex).matcher(address); + String province = null, city = null, county = null, town = null, village = null; +// List> table = new ArrayList>(); + Map row = null; + while (m.find()) { + row = new LinkedHashMap(); + province = m.group("province"); + row.put("province", province == null ? "" : province.trim().substring(0, province.length() - 1)); + city = m.group("city"); + row.put("city", city == null ? "" : city.trim()); + county = m.group("county"); + row.put("county", county == null ? "" : county.trim()); + town = m.group("town"); + row.put("town", town == null ? "" : town.trim()); + village = m.group("village"); + row.put("village", village == null ? "" : village.trim()); +// table.add(row); + } + if ("市辖区".equals(row.get("city"))) { + row.put("city", row.get("county")); + } + return row; + } + + + public static Map addressResolutionNoTwo(String address) { + String regex = "(?[^省]+自治区|.*?省|.*?行政区|.*?市)(?[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?[^区]+区|.+镇)?(?.*)"; + Matcher m = Pattern.compile(regex).matcher(address); + String province = null, city = null, county = null, town = null, village = null; + Map row = new LinkedHashMap(); + ; + while (m.find()) { + province = m.group("province"); + if (province != null) { + province = province.trim().substring(0, province.length() - 1); + if (province.length() > 3) { + province = province.trim().substring(0, 3); + } + if (province.length() == 3) { + if ("内蒙古".equals(province) || "黑龙江".equals(province)) { + } else { + province = province.trim().substring(0, 2); + } + } + row.put("province", province); + } +// row.put("province", province == null ? "" : province.trim().substring(0, province.length() - 1)); + city = m.group("city"); + row.put("city", city == null ? "" : city.trim()); + county = m.group("county"); + row.put("county", county == null ? "" : county.trim()); + town = m.group("town"); + row.put("town", town == null ? "" : town.trim()); + village = m.group("village"); + row.put("village", village == null ? "" : village.trim()); + } + // 直辖市特殊处理 + if (StringUtils.isNotEmpty(row.get("city"))) { + if ("市辖区".equals(row.get("city"))) { + row.put("city", row.get("county")); + } + } + return row; + } + +} diff --git a/src/main/java/com/lin/util/XmlParseUtil.java b/src/main/java/com/lin/util/XmlParseUtil.java index 0d132879c998a0934bb01b039562edc7f4926a63..7b318ee216586ca488f1fdf2101bb890a4f0ca9d 100644 --- a/src/main/java/com/lin/util/XmlParseUtil.java +++ b/src/main/java/com/lin/util/XmlParseUtil.java @@ -31,7 +31,7 @@ public class XmlParseUtil { * @author com.lin, 2020-02-20 */ public static Map getAttrByNode(Node node) { - Map attrMap = new HashMap<>(); + Map attrMap = new HashMap<>(0); NamedNodeMap attributes = node.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Node attr = attributes.item(j); @@ -50,7 +50,7 @@ public class XmlParseUtil { * @author com.lin, 2020-02-20 */ public static Map getChildNodeValueByNode(Node node) { - Map nodeMap = new HashMap<>(); + Map nodeMap = new HashMap<>(0); NodeList childNodes = node.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { //排除掉换行造成的无效节点 diff --git a/src/main/resources/OIP.jpeg b/src/main/resources/OIP.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c609fbfee8f10bf7fbd29ccb088dd64fcd4ff9b6 Binary files /dev/null and b/src/main/resources/OIP.jpeg differ diff --git a/src/main/resources/templates/SourceHanSerifCN-Regular.ttf b/src/main/resources/templates/SourceHanSerifCN-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..dbafe4eabfcedea2dc2b0a9a36884c60c60dc145 Binary files /dev/null and b/src/main/resources/templates/SourceHanSerifCN-Regular.ttf differ diff --git a/src/test/java/com/lin/TestIO/nio/NioRead.java b/src/test/java/com/lin/TestIO/nio/NioRead.java new file mode 100644 index 0000000000000000000000000000000000000000..b432d1bf42a9c4318e0a1a7df6b29a685bed334b --- /dev/null +++ b/src/test/java/com/lin/TestIO/nio/NioRead.java @@ -0,0 +1,31 @@ +package com.lin.TestIO.nio; + +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +/** + * nio读取文件 + * + * @author linqiankun + */ +public class NioRead { + + public static void main(String[] args) throws Exception { + + File file = new File("test.txe"); + // 创建输入流 + FileInputStream fileInputStream = new FileInputStream(file); + // 得到一个通道 + FileChannel channel = fileInputStream.getChannel(); + // 准备一个缓冲区 + ByteBuffer allocate = ByteBuffer.allocate((int) file.length()); + // 从通道里读取数据并存到缓冲区 + channel.read(allocate); + // 打印数据 + System.out.println(new String(allocate.array())); + // 关闭 + fileInputStream.close(); + } +} diff --git a/src/test/java/com/lin/TestIO/nio/NioWrite.java b/src/test/java/com/lin/TestIO/nio/NioWrite.java new file mode 100644 index 0000000000000000000000000000000000000000..99c6eecd007dedda739958501b7bd5e41c2fb6dc --- /dev/null +++ b/src/test/java/com/lin/TestIO/nio/NioWrite.java @@ -0,0 +1,32 @@ +package com.lin.TestIO.nio; + +import java.io.FileOutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +/** + * nio写入文件 + * + * @author linqiankun + */ +public class NioWrite { + + public static void main(String[] args) throws Exception { + + // 创建输出流 + FileOutputStream fileOutputStream = new FileOutputStream("test.txe"); + // 从流中得到一个通道 + FileChannel channel = fileOutputStream.getChannel(); + // 提供一个缓冲区 + ByteBuffer allocate = ByteBuffer.allocate(1024); + // 往缓冲区存入数据 + String string = "我是要输入的数据"; + allocate.put(string.getBytes()); + // 翻转缓冲区,将位置设为初始位置 + allocate.flip(); + // 把缓冲区写到通道中 + channel.write(allocate); + // 关闭 + fileOutputStream.close(); + } +} diff --git a/src/test/java/com/lin/TestIO/qq/qq1/NIOClient.java b/src/test/java/com/lin/TestIO/qq/qq1/NIOClient.java new file mode 100644 index 0000000000000000000000000000000000000000..49630a2ec9886a4a044e3aef5dfb23657cff6fe9 --- /dev/null +++ b/src/test/java/com/lin/TestIO/qq/qq1/NIOClient.java @@ -0,0 +1,32 @@ +package com.lin.TestIO.qq.qq1; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.util.Scanner; + +/** + * @author 九分石人 + */ +public class NIOClient { + + + public static void main(String[] args) throws IOException { + ByteBuffer buffer = ByteBuffer.allocate(1024); + SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(InetAddress.getLocalHost(), 3333)); + socketChannel.configureBlocking(false); + while (true) { + Scanner sc = new Scanner(System.in); + String msg = sc.next(); + if (msg.equals("return")) { + break; + } + buffer.put(msg.getBytes()); + buffer.flip(); + socketChannel.write(buffer); + buffer.clear(); + } + } +} diff --git a/src/test/java/com/lin/TestIO/qq/qq1/NIOServer.java b/src/test/java/com/lin/TestIO/qq/qq1/NIOServer.java new file mode 100644 index 0000000000000000000000000000000000000000..3ac71443e27cba9c7f64e676448149f8ccf08d11 --- /dev/null +++ b/src/test/java/com/lin/TestIO/qq/qq1/NIOServer.java @@ -0,0 +1,111 @@ +package com.lin.TestIO.qq.qq1; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; +import java.time.LocalDateTime; +import java.util.*; + +/** + * @author 九分石人 + */ +public class NIOServer { + + + static Selector serverSelector; + static Selector clientSelector; + + static { + try { + serverSelector = Selector.open(); + clientSelector = Selector.open(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) throws IOException { + + + NIOServer nioServer = new NIOServer(); + new Thread(() -> { + try { + ServerSocketChannel socketChannel = ServerSocketChannel.open(); + socketChannel.socket().bind(new InetSocketAddress(3333)); + socketChannel.configureBlocking(false); + socketChannel.register(serverSelector, SelectionKey.OP_ACCEPT); + nioServer.acceptListener(); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + new Thread(() -> { + try { + nioServer.clientListener(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + + } + + public void acceptListener() throws IOException { + while (true) { + if (serverSelector.select(1) > 0) { + Set selectionKeys = serverSelector.selectedKeys(); + Iterator iterator = selectionKeys.iterator(); + while (iterator.hasNext()) { + SelectionKey next = iterator.next(); + if (next.isAcceptable()) { + try { + SocketChannel accept = ((ServerSocketChannel) next.channel()).accept(); + accept.configureBlocking(false); + accept.register(clientSelector, SelectionKey.OP_READ); + } finally { + iterator.remove(); + } + } + } + } + } + } + + /** + * 客户端消息的监听 + * + * @throws IOException + */ + public void clientListener() throws IOException { + while (true) { + if (clientSelector.select(1) > 0) { + Set selectionKeys = clientSelector.selectedKeys(); + Iterator iterator = selectionKeys.iterator(); + while (iterator.hasNext()) { + SelectionKey next = iterator.next(); + if (next.isReadable()) { + try { + SocketChannel channel = (SocketChannel) next.channel(); + ByteBuffer buffer = ByteBuffer.allocate(1024); + channel.read(buffer); + buffer.flip(); + System.out.println(LocalDateTime.now().toString() + " Server 端接收到来自 Client 端的消息: " + + Charset.defaultCharset().decode(buffer).toString()); + } finally { + iterator.remove(); + next.interestOps(SelectionKey.OP_READ); + } + } + } + } + } + + + } + + +} diff --git a/src/test/java/com/lin/TestIO/qq/qq2/NioClient.java b/src/test/java/com/lin/TestIO/qq/qq2/NioClient.java new file mode 100644 index 0000000000000000000000000000000000000000..04f5147781211cef84ce39a524af73601ea7d7b8 --- /dev/null +++ b/src/test/java/com/lin/TestIO/qq/qq2/NioClient.java @@ -0,0 +1,38 @@ +package com.lin.TestIO.qq.qq2; + +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +/** + * nio客户端 + * + * @author linqiankun + */ +public class NioClient { + + public static void main(String[] args) throws Exception { + + // 得到一个网络通道 + SocketChannel socketChannel = SocketChannel.open(); + // 设置非阻塞模式 + socketChannel.configureBlocking(false); + // 提供服务器端的ip地址和端口号 + InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 9001); + // 连接服务器 + if (!socketChannel.connect(inetSocketAddress)) { + // 循环-直到某一时刻连接到(在连接的时候可以做别的事情,比如下面打印数据,这就是NIO的优势) + while (!socketChannel.finishConnect()) { + System.out.println("还没有连接到。。。"); + } + System.out.println("连接到了。。。"); + } + // 得到一个缓冲区并存入数据 + String string = "NIO测试,我是客户端传的数据"; + ByteBuffer writeBuffer = ByteBuffer.wrap(string.getBytes()); + // 发送数据 + socketChannel.write(writeBuffer); + // 这里关闭通道,服务器端会报异常,所以这里就先设置阻塞 + System.in.read(); + } +} diff --git a/src/test/java/com/lin/TestIO/qq/qq2/NioServer.java b/src/test/java/com/lin/TestIO/qq/qq2/NioServer.java new file mode 100644 index 0000000000000000000000000000000000000000..7bd7c5f9ab01938b79bed042ff3e83c4d40e5ebd --- /dev/null +++ b/src/test/java/com/lin/TestIO/qq/qq2/NioServer.java @@ -0,0 +1,68 @@ +package com.lin.TestIO.qq.qq2; + +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.Iterator; + +/** + * nio服务端 + * + * @author linqiankun + */ +public class NioServer { + + public static void main(String[] args) throws Exception { + + // 得到一个ServerSocketChannel对象 + ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); + // 得到一个Selector对象 + Selector selector = Selector.open(); + // 绑定一个端口号 + serverSocketChannel.bind(new InetSocketAddress(9001)); + // 设置非阻塞式 + serverSocketChannel.configureBlocking(false); + // 把ServerSocketChannel对象注册给Selector对象 + serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); + // 做事 + for (; ; ) { + // 监控客户端 + if (selector.select(2000) == 0) { + System.out.println("没有客户端连接我,我可以干别的事情"); + continue; + } + + // 得到SelectionKey,判断通道里的事件 + Iterator iterator = selector.selectedKeys().iterator(); + while (iterator.hasNext()) { + SelectionKey key = iterator.next(); + + // 如果是客户端连接事件 + if (key.isAcceptable()) { + System.out.println("连接事件"); + // 接收连接 + SocketChannel socketChannel = serverSocketChannel.accept(); + // 设置非阻塞式 + socketChannel.configureBlocking(false); + // 注册 + socketChannel.register(selector, SelectionKey.OP_READ, ByteBuffer.allocate(1024)); + } + + // 读取客户端数据事件 + if (key.isReadable()) { + SocketChannel channel = (SocketChannel) key.channel(); + ByteBuffer buffer = (ByteBuffer) key.attachment(); + channel.read(buffer); + System.out.println("客户端发来数据:" + new String(buffer.array())); + } + + // 手动从集合中移除当前key,防止重复处理 + iterator.remove(); + } + } + } +} + diff --git a/src/test/java/com/lin/TestPdfUtil/GenPdf.java b/src/test/java/com/lin/TestPdfUtil/GenPdf.java new file mode 100644 index 0000000000000000000000000000000000000000..9898eb12c8274e2fe6b641697e42b9f32d37ddf0 --- /dev/null +++ b/src/test/java/com/lin/TestPdfUtil/GenPdf.java @@ -0,0 +1,193 @@ +package com.lin.TestPdfUtil; + +import com.itextpdf.text.*; +import com.itextpdf.text.Font; +import com.itextpdf.text.pdf.*; +import com.lin.util.FileWriteUtil; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.rendering.PDFRenderer; +import org.junit.Test; + + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.*; + +/** + * 生成pdf并盖章 + * + * @author linqiankun + */ +public class GenPdf { + + + String p = "/Users/linqiankun/Documents/需求文件/"; + int dataNums = 120; + + @Test + public void test1() throws FileNotFoundException {//生成pdf +// FileOutputStream outputStream = new FileOutputStream(p + "a.pdf"); + + ByteArrayOutputStream b = new ByteArrayOutputStream(); + Document document = new Document(); + try { + PdfCopy.getInstance(document, b); + document.setPageSize(PageSize.A4); + document.open(); + + // 文字部分 + BaseFont bfTitle; +// bfTitle = BaseFont.createFont("src/main/resources/templates/SourceHanSerifCN-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); + Font fonttTitle; + bfTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//创建字体 + fonttTitle = new Font(bfTitle, 18); + fonttTitle.setStyle("bold"); + + //表头部分 + BaseFont bf; + Font font; + bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//创建字体 + font = new Font(bf, 12);//使用字体 + + + float[] widths = {10f, 25f, 10f, 40f, 15f}; + PdfPTable table = new PdfPTable(widths); + table.setSpacingBefore(30f); + table.setWidthPercentage(80); + + PdfPCell cellTitle; + Paragraph card = new Paragraph("证据清单", fonttTitle); + card.setSpacingBefore(30f); + cellTitle = new PdfPCell(card); + cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER); + cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE); + cellTitle.setColspan(5); + cellTitle.setPaddingBottom(10f); + cellTitle.setBorderWidth(0); + table.addCell(cellTitle); + + + String[] titles = new String[]{"编号", "证据名称", "份数", "证明对象", "形式"}; + PdfPCell cellt; + for (String title : titles) { + cellt = new PdfPCell(new Paragraph(title, font)); + setStyleData(cellt); + table.addCell(cellt); + } + + //以下代码的作用是创建100行数据,其中每行有四列,列依次为 编号 姓名 性别 备注 + for (int i = 1; i <= dataNums; i++) { + //设置编号单元格 + PdfPCell cell11 = new PdfPCell(new Paragraph(i + "", font)); + PdfPCell cell22 = new PdfPCell(new Paragraph("bb女", font)); + PdfPCell cell33 = new PdfPCell(new Paragraph(1 + "", font)); + PdfPCell cell44 = new PdfPCell(new Paragraph("ccasdfghjksdfghjkllkjhgfdsasdfghjklkjhgfdsadfghj", font)); + PdfPCell cell55 = new PdfPCell(new Paragraph("复印件", font)); + + setStyleData(cell11); + setStyleData(cell22); + setStyleData(cell33); + setStyleData(cell44); + setStyleData(cell55); + + table.addCell(cell11); + table.addCell(cell22); + table.addCell(cell33); + table.addCell(cell44); + table.addCell(cell55); + } + + // 设置提交人位置 + for (int i = 1; i <= 3; i++) { + PdfPCell cellBlank; + for (int j = 0; j < 5; j++) { + if (i == 3 && j == 3) { + cellBlank = new PdfPCell(new Paragraph("提交人:", font)); + } else { + cellBlank = new PdfPCell(new Paragraph(" ", font)); + } + setStyleBlank(cellBlank); + table.addCell(cellBlank); + } + } + + document.add(table); + document.close(); + byte[] bytes = b.toByteArray(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); + test2(inputStream); + +// outputStream.write(bytes); +// outputStream.flush(); +// outputStream.close(); + + b.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + + } + + + private void setStyleBlank(PdfPCell cell) { + cell.setFixedHeight(20); + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + cell.setVerticalAlignment(Element.ALIGN_MIDDLE); + cell.setBorderWidth(0); + + } + + private void setStyleData(PdfPCell cell) { + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + cell.setVerticalAlignment(Element.ALIGN_MIDDLE); + cell.setFixedHeight(20); + } + + + public void test2(ByteArrayInputStream inputStream) throws IOException { + byte[] b = new byte[inputStream.available()]; + inputStream.read(b); + PDDocument pdDocument = PDDocument.load(b); + PDFRenderer renderer = new PDFRenderer(pdDocument); + int numberOfPages = pdDocument.getNumberOfPages(); + int heightSum = ((25) * (dataNums + 1)) + (24 * (3)) + 30 + 10 + 18 + ((numberOfPages - 1) * 100); + int he = heightSum - ((numberOfPages - 1) * 1053); + + + ByteArrayOutputStream temp; + String p = "/Users/linqiankun/Documents/需求文件/"; + for (int i = 0; i < numberOfPages; i++) { + String path = p + i + ".jpg"; + BufferedImage image = renderer.renderImageWithDPI(i, 90); + temp = new ByteArrayOutputStream(); + if (i == numberOfPages - 1) { + // 债转第二张 要画个章子 + BufferedImage img = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); + // 得到画笔 + Graphics2D graphics = (Graphics2D) img.getGraphics(); + graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + // 背景 + graphics.drawImage(image, 0, 0, null); + // 盖章 +// String signImageFilePath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); + String signImageFilePath = "src/main/resources/OIP.jpeg"; + Image signImg = ImageIO.read(new File(signImageFilePath)); + graphics.drawImage(signImg, 480, he, 200, 200, null); + ImageIO.write(img, "jpg", temp); + } else { + ImageIO.write(image, "jpg", temp); + } + byte[] bytes = temp.toByteArray(); + FileWriteUtil.canCreatFile(path); + FileOutputStream outputStream = new FileOutputStream(path); + outputStream.write(bytes); + outputStream.flush(); + temp.close(); + outputStream.close(); + } + } +} + diff --git a/src/test/java/com/lin/TestPdfUtil/MultiToOneTest.java b/src/test/java/com/lin/TestPdfUtil/MultiToOneTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ab0376b2cbc90af950811d862d5d98383d05c7af --- /dev/null +++ b/src/test/java/com/lin/TestPdfUtil/MultiToOneTest.java @@ -0,0 +1,56 @@ +package com.lin.TestPdfUtil; + +import com.itextpdf.text.DocumentException; +import com.lin.pdfutil.MultiPdfToOnePdfUtil; +import com.lin.util.FileWriteUtil; +import org.junit.Test; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * 多合一 + * + * @author linqiankun + */ +public class MultiToOneTest { + + + @Test + public void testOne() { + String filePath = "/Users/linqiankun/Downloads/ll"; + String pdfPath = filePath + "1.pdf"; + FileWriteUtil.canCreatFile(pdfPath); + MultiPdfToOnePdfUtil.picToPdf(filePath, pdfPath); + } + + + @Test + public void testTwo() throws IOException, DocumentException { + FileInputStream in = new FileInputStream("/Users/linqiankun/Documents/需求文件/法催3.4的副本.pdf"); + FileInputStream ins = new FileInputStream("/Users/linqiankun/Documents/需求文件/法催3.4的副本2.pdf"); + byte[] buf = new byte[in.available()]; + byte[] bufs = new byte[ins.available()]; + int read = in.read(buf); + int read1 = ins.read(bufs); + + List bytes = new ArrayList<>(); + bytes.add(buf); + bytes.add(bufs); + + byte[] bytes1 = MultiPdfToOnePdfUtil.pdfmMix(bytes); + + String pdf = "/Users/linqiankun/Documents/需求文件/1.pdf"; + + FileWriteUtil.canCreatFile(pdf); + FileOutputStream o = new FileOutputStream(pdf); + o.write(bytes1); + + o.flush(); + o.close(); + + } + + +} diff --git a/src/test/java/com/lin/TestPdfUtil/PdfToPicTest.java b/src/test/java/com/lin/TestPdfUtil/PdfToPicTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4771f3bcf92c7933a3e0d9922f9569e46b1ffe68 --- /dev/null +++ b/src/test/java/com/lin/TestPdfUtil/PdfToPicTest.java @@ -0,0 +1,52 @@ +package com.lin.TestPdfUtil; + +import com.lin.pdfutil.PdfToPicUtil; +import com.lin.util.FileWriteUtil; +import org.junit.Test; + +import java.io.*; +import java.util.List; + +/** + * pdf转图片 + * + * @author linqiankun + */ +public class PdfToPicTest { + + @Test + public void testOne() throws IOException { + FileInputStream in = new FileInputStream("/Users/linqiankun/Documents/需求文件/法催3.4的副本.pdf"); + List byteArrayOutputStreams = PdfToPicUtil.pdfToPic1(in); + for (int i = 0; i < byteArrayOutputStreams.size(); i++) { + String filePath = "/Users/linqiankun/Documents/需求文件/" + i + 2 + ".jpg"; + FileWriteUtil.canCreatFile(filePath); + FileOutputStream outputStream = new FileOutputStream(filePath); + ByteArrayOutputStream byteArrayOutputStream = byteArrayOutputStreams.get(i); + byte[] bytes = byteArrayOutputStream.toByteArray(); + outputStream.write(bytes); + outputStream.flush(); + byteArrayOutputStream.close(); + outputStream.close(); + } + } + + @Test + public void testTwo() throws IOException { + FileInputStream in = new FileInputStream("/Users/linqiankun/Documents/需求文件/法催3.4的副本.pdf"); + List byteArrayOutputStreams = PdfToPicUtil.pdfToPic2(in); + for (int i = 0; i < byteArrayOutputStreams.size(); i++) { + String filePath = "/Users/linqiankun/Documents/需求文件/" + i + ".PNG"; + FileWriteUtil.canCreatFile(filePath); + FileOutputStream outputStream = new FileOutputStream(filePath); + ByteArrayOutputStream byteArrayOutputStream = byteArrayOutputStreams.get(i); + byte[] bytes = byteArrayOutputStream.toByteArray(); + outputStream.write(bytes); + outputStream.flush(); + byteArrayOutputStream.close(); + outputStream.close(); + } + } + + +} diff --git a/src/test/java/com/lin/TestPdfUtil/PicToPdfTest.java b/src/test/java/com/lin/TestPdfUtil/PicToPdfTest.java new file mode 100644 index 0000000000000000000000000000000000000000..52a4878320531eca6c688425a43dfe7982cd1b13 --- /dev/null +++ b/src/test/java/com/lin/TestPdfUtil/PicToPdfTest.java @@ -0,0 +1,51 @@ +package com.lin.TestPdfUtil; + +import com.itextpdf.text.DocumentException; +import com.lin.pdfutil.PicToPdfUtil; +import com.lin.util.FileWriteUtil; +import org.junit.Test; + +import java.io.*; + +/** + * 图片转pdf + * + * @author linqiankun + */ +public class PicToPdfTest { + + + @Test + public void testOne() throws IOException { + String filePath = "/Users/linqiankun/Documents/需求文件/"; + FileInputStream in = new FileInputStream(filePath + "02.jpg"); + String pdfPath = filePath + "1.pdf"; + FileWriteUtil.canCreatFile(pdfPath); + FileOutputStream outputStream = new FileOutputStream(pdfPath); + ByteArrayOutputStream byteArrayOutputStream = PicToPdfUtil.picToPdf1(in); + byteArrayOutputStream.writeTo(outputStream); + byteArrayOutputStream.close(); + outputStream.close(); + in.close(); + } + + + @Test + public void testTwo() throws IOException { + String filePath = "/Users/linqiankun/Documents/需求文件/"; + String imgPath = filePath + "02.jpg"; + String pdfPath = filePath + "02.pdf"; + PicToPdfUtil.imgToPdf2(imgPath, pdfPath); + } + + + @Test + public void testThree() throws IOException, DocumentException { + String filePath = "/Users/linqiankun/Documents/需求文件/"; + String imgPath = filePath + "02.jpg"; + String pdfPath = filePath + "02.pdf"; + PicToPdfUtil.imageToPdf3(imgPath, pdfPath); + } + + +} diff --git a/src/test/java/com/lin/TestSort/BubbleSortTest.java b/src/test/java/com/lin/TestSort/BubbleSortTest.java index ba6176f0da3f7449d5531ba76747c6355da17226..a42a9fcf140b8dc2c1ee01718a192e0b07612c7b 100644 --- a/src/test/java/com/lin/TestSort/BubbleSortTest.java +++ b/src/test/java/com/lin/TestSort/BubbleSortTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.BubbleSort; import org.junit.Test; +/** + * 冒泡排序 + * + * @author linqiankun + */ public class BubbleSortTest { @Test - public void bubbleSortedTest(){ + public void bubbleSortedTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - BubbleSort.bubbleSorted(a, StatusCode.MAX_SORT); + BubbleSort.bubbleSorted(a, SortStatusCode.MAX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/BucketSortTest.java b/src/test/java/com/lin/TestSort/BucketSortTest.java index 41abc9e1425964ea5f1c7b99d75c2fd257209d73..ee6a0d5088e81465167568b58bd242cb41071302 100644 --- a/src/test/java/com/lin/TestSort/BucketSortTest.java +++ b/src/test/java/com/lin/TestSort/BucketSortTest.java @@ -3,6 +3,11 @@ package com.lin.TestSort; import com.lin.sort.BucketSort; import org.junit.Test; +/** + * 桶排序 + * + * @author linqiankun + */ public class BucketSortTest { diff --git a/src/test/java/com/lin/TestSort/CountingSortTest.java b/src/test/java/com/lin/TestSort/CountingSortTest.java index ee183b38b2895c3e74841f8993e3fba3a7ae5a3d..19776056ffe9dbfec7254fbfbe1226eb987d68d0 100644 --- a/src/test/java/com/lin/TestSort/CountingSortTest.java +++ b/src/test/java/com/lin/TestSort/CountingSortTest.java @@ -3,6 +3,11 @@ package com.lin.TestSort; import com.lin.sort.CountingSort; import org.junit.Test; +/** + * 计数排序 + * + * @author linqiankun + */ public class CountingSortTest { diff --git a/src/test/java/com/lin/TestSort/HeapSortTest.java b/src/test/java/com/lin/TestSort/HeapSortTest.java index fe9a2fed853ad1b3cb41cc4c1ebdab195a05a9d6..ac2a83fbc2cebe14da400ef4aba7458b64731f76 100644 --- a/src/test/java/com/lin/TestSort/HeapSortTest.java +++ b/src/test/java/com/lin/TestSort/HeapSortTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.HeapSort; import org.junit.Test; +/** + * 堆排序 + * + * @author linqiankun + */ public class HeapSortTest { @Test public void heapSrotTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - HeapSort.heapSorted(a, StatusCode.MAX_SORT); + HeapSort.heapSorted(a, SortStatusCode.MAX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/InsertionSortTest.java b/src/test/java/com/lin/TestSort/InsertionSortTest.java index 267f3245993ae7a38f1c54903b2818540bb2aaac..4e2d225178b48ecf33aeea42057788b590c41908 100644 --- a/src/test/java/com/lin/TestSort/InsertionSortTest.java +++ b/src/test/java/com/lin/TestSort/InsertionSortTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.InsertionSort; import org.junit.Test; +/** + * 插入排序 + * + * @author linqiankun + */ public class InsertionSortTest { @Test public void insertionSortedtest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - InsertionSort.insertionSorted(a, StatusCode.MIX_SORT); + InsertionSort.insertionSorted(a, SortStatusCode.MIX_SORT); for (int i : a) { System.out.println(i); } @@ -19,7 +24,7 @@ public class InsertionSortTest { @Test public void insertionSortedDichotomyTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - InsertionSort.insertionSortedDichotomy(a, StatusCode.MIX_SORT); + InsertionSort.insertionSortedDichotomy(a, SortStatusCode.MIX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/MergeSortTest.java b/src/test/java/com/lin/TestSort/MergeSortTest.java index 8e8897788a3ab91cf6ffc74e0a7842e49a35d4ed..67d38f811e695aff140e550cf9d66958980e1233 100644 --- a/src/test/java/com/lin/TestSort/MergeSortTest.java +++ b/src/test/java/com/lin/TestSort/MergeSortTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.MergeSort; import org.junit.Test; +/** + * 归并排序 + * + * @author linqiankun + */ public class MergeSortTest { @Test public void mergeSortedRecursionTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - MergeSort.mergeSortedRecursion(a, StatusCode.MAX_SORT, 0, a.length - 1); + MergeSort.mergeSortedRecursion(a, SortStatusCode.MAX_SORT, 0, a.length - 1); for (int i : a) { System.out.println(i); } @@ -19,7 +24,7 @@ public class MergeSortTest { @Test public void mergeSortedIterationTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - MergeSort.mergeSortedIteration(a, StatusCode.MIX_SORT); + MergeSort.mergeSortedIteration(a, SortStatusCode.MIX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/QuickSortedTest.java b/src/test/java/com/lin/TestSort/QuickSortedTest.java index 2127f637043cef909152f7639ceb5e9e89a338de..b3b6b62b89f9a2a94aa51a2f20ab25e7a850c67f 100644 --- a/src/test/java/com/lin/TestSort/QuickSortedTest.java +++ b/src/test/java/com/lin/TestSort/QuickSortedTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.QuickSort; import org.junit.Test; +/** + * 快速排序 + * + * @author linqiankun + */ public class QuickSortedTest { @Test public void quickSortedTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - QuickSort.quickSorted(a, 0, a.length - 1, StatusCode.MAX_SORT); + QuickSort.quickSorted(a, 0, a.length - 1, SortStatusCode.MAX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/RadixSortTest.java b/src/test/java/com/lin/TestSort/RadixSortTest.java index bc424bdbca609481f485f23e6714b55223daf917..b5eef0393b72270ed3acddc1dbfb5d0ec3732fad 100644 --- a/src/test/java/com/lin/TestSort/RadixSortTest.java +++ b/src/test/java/com/lin/TestSort/RadixSortTest.java @@ -3,6 +3,11 @@ package com.lin.TestSort; import com.lin.sort.RadixSort; import org.junit.Test; +/** + * 基数排序 + * + * @author linqiankun + */ public class RadixSortTest { @@ -16,5 +21,4 @@ public class RadixSortTest { } - } diff --git a/src/test/java/com/lin/TestSort/SelectionSortTest.java b/src/test/java/com/lin/TestSort/SelectionSortTest.java index 3981aa6331e3cab68f4b2a472aa5f418eb44ed3c..472fd8fb354aa63b0a1632825dbe456a74a98be8 100644 --- a/src/test/java/com/lin/TestSort/SelectionSortTest.java +++ b/src/test/java/com/lin/TestSort/SelectionSortTest.java @@ -1,16 +1,21 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.SelectionSort; import org.junit.Test; +/** + * 选择排序 + * + * @author linqiankun + */ public class SelectionSortTest { @Test public void selectionSortedTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - SelectionSort.selectionSorted(a, StatusCode.MIX_SORT); + SelectionSort.selectionSorted(a, SortStatusCode.MIX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/ShellSortTest.java b/src/test/java/com/lin/TestSort/ShellSortTest.java index 86807ae0666ac9e8760264300b0cd6e42b4f6b17..f2a3fa42f8307f8b577d4a926ebd73b24bfadf95 100644 --- a/src/test/java/com/lin/TestSort/ShellSortTest.java +++ b/src/test/java/com/lin/TestSort/ShellSortTest.java @@ -1,15 +1,20 @@ package com.lin.TestSort; -import com.lin.enums.StatusCode; +import com.lin.enums.SortStatusCode; import com.lin.sort.ShellSort; import org.junit.Test; +/** + * 希尔排序 + * + * @author linqiankun + */ public class ShellSortTest { @Test public void shellSortTest() { int[] a = {1, 6, 8, 2, 4, 5, 7, 1, 0}; - ShellSort.shellSorted(a, StatusCode.MIX_SORT); + ShellSort.shellSorted(a, SortStatusCode.MIX_SORT); for (int i : a) { System.out.println(i); } diff --git a/src/test/java/com/lin/TestSort/v3.0.md b/src/test/java/com/lin/TestSort/v3.0.md deleted file mode 100644 index 4305f784f548b7a44cb2735377ad06610c5087c2..0000000000000000000000000000000000000000 --- a/src/test/java/com/lin/TestSort/v3.0.md +++ /dev/null @@ -1,9 +0,0 @@ -# V3.0 - -1. 冒泡排序工具 -2. 选择排序 -3. 插入排序 -4. 选择排序 -5. 归并排序 -6. 希尔排序 -7. 堆排序 \ No newline at end of file diff --git a/src/test/java/com/lin/TestTree/AVLTree1Test.java b/src/test/java/com/lin/TestTree/AVLTree1Test.java index 09bd06cffcd5da44d0156543af935487a4aa8611..0298d75bbd813a3a3a4f9fcae6909f6100777cb3 100644 --- a/src/test/java/com/lin/TestTree/AVLTree1Test.java +++ b/src/test/java/com/lin/TestTree/AVLTree1Test.java @@ -2,6 +2,11 @@ package com.lin.TestTree; import com.lin.tree.nome.avltree.AVLTree1; +/** + * AVL树测试 + * + * @author linqiankun + */ public class AVLTree1Test { public static void main(String[] args) { diff --git a/src/test/java/com/lin/TestTree/RBTree2Test.java b/src/test/java/com/lin/TestTree/RBTree2Test.java index ffbd302675a67cfae9f4e8a60908fef67eb1279f..3bb0a1681818be37ef007618094ea4e320e45649 100644 --- a/src/test/java/com/lin/TestTree/RBTree2Test.java +++ b/src/test/java/com/lin/TestTree/RBTree2Test.java @@ -2,21 +2,23 @@ package com.lin.TestTree; import com.lin.tree.nome.rbtree.RBTree2; - +/** + * 红黑树测试 + * + * @author linqiankun + */ public class RBTree2Test { - - public static void main(String[] args) { - RBTree2 T = new RBTree2(); - RBTree2.RedBlackTreeNode node1 = T.RB_NODE(10); - T.RB_INSERT(T, node1); - RBTree2.RedBlackTreeNode node2 = T.RB_NODE(20); - T.RB_INSERT(T, node2); - RBTree2.RedBlackTreeNode node3 = T.RB_NODE(30); - T.RB_INSERT(T, node3); - T.preorder(T.getRoot()); - } - + public static void main(String[] args) { + RBTree2 T = new RBTree2(); + RBTree2.RedBlackTreeNode node1 = T.RB_NODE(10); + T.RB_INSERT(T, node1); + RBTree2.RedBlackTreeNode node2 = T.RB_NODE(20); + T.RB_INSERT(T, node2); + RBTree2.RedBlackTreeNode node3 = T.RB_NODE(30); + T.RB_INSERT(T, node3); + T.preorder(T.getRoot()); + } } diff --git a/src/test/java/com/lin/TestUtil/ExcelTest.java b/src/test/java/com/lin/TestUtil/ExcelTest.java index f13923a2dfc648a9dbe97550b044f66fc515ba48..d6fd9b4f7c58b5d8b5cf350a44138d24610563ab 100644 --- a/src/test/java/com/lin/TestUtil/ExcelTest.java +++ b/src/test/java/com/lin/TestUtil/ExcelTest.java @@ -1,6 +1,6 @@ package com.lin.TestUtil; -import com.lin.Dto.BookDto; +import com.lin.dto.BookDto; import com.lin.util.ExcelExportUtil; import com.lin.util.ExcelImportUtil; import com.lin.util.FileWriteUtil; @@ -13,6 +13,8 @@ import java.util.List; /** * excel测试 + * + * @author linqiankun */ public class ExcelTest { diff --git a/src/test/java/com/lin/TestUtil/FileTest.java b/src/test/java/com/lin/TestUtil/FileTest.java index a24d1cb7a0f4c73f624559d7b10ec788c7cdd75a..1f978ee9f36a37e2c771427dac3032ec26f22519 100644 --- a/src/test/java/com/lin/TestUtil/FileTest.java +++ b/src/test/java/com/lin/TestUtil/FileTest.java @@ -1,7 +1,7 @@ package com.lin.TestUtil; import com.alibaba.fastjson.JSON; -import com.lin.Dto.SenseCallbackDto; +import com.lin.dto.SenseCallbackDto; import com.lin.util.FileReadUtil; import com.lin.util.FileWriteUtil; import org.junit.Test; @@ -12,6 +12,8 @@ import java.util.List; /** * 文件读取测试,将读取到的文件反射进对象集合中 + * + * @author linqiankun */ public class FileTest { @@ -38,7 +40,7 @@ public class FileTest { InputStream in = this.getClass().getClassLoader().getResourceAsStream("book.xml"); // String filepath = "/Users/linqiankun/Desktop/test1"; String filepath = "src/test/resources/test"; - FileWriteUtil.writeFromInputStream(in,filepath); + FileWriteUtil.writeFromInputStream(in, filepath); } } \ No newline at end of file diff --git a/src/test/java/com/lin/TestUtil/HttpConnectionTest.java b/src/test/java/com/lin/TestUtil/HttpConnectionTest.java index 4e2651460803af7dc23a7753a88c2149b16d84ed..50de472b2edb295af6cdeca103aeddc0eb320030 100644 --- a/src/test/java/com/lin/TestUtil/HttpConnectionTest.java +++ b/src/test/java/com/lin/TestUtil/HttpConnectionTest.java @@ -6,19 +6,21 @@ import org.junit.Test; /** * http连接测试 + * + * @author linqiankun */ public class HttpConnectionTest { @Test public void httpConnectionTest() { String get = HttpConnectionUtil.sendGet("http://www.baidu.com"); - String post = HttpConnectionUtil.sendPost("http://www.baidu.com",null); + String post = HttpConnectionUtil.sendPost("http://www.baidu.com", null); } @Test public void httpUrlConnectionTest() { String get = HttpUrlConnectionUtil.doGet("http://www.baidu.com"); - String post = HttpUrlConnectionUtil.doPost("http://www.baidu.com",null); + String post = HttpUrlConnectionUtil.doPost("http://www.baidu.com", null); } diff --git a/src/test/java/com/lin/TestUtil/InvokeTest.java b/src/test/java/com/lin/TestUtil/InvokeTest.java index 17438fffa602b2b0d721414f3e1fe9f676d004e7..7f49e5c0f575f0c7c730c9088477132267899ee8 100644 --- a/src/test/java/com/lin/TestUtil/InvokeTest.java +++ b/src/test/java/com/lin/TestUtil/InvokeTest.java @@ -1,8 +1,8 @@ package com.lin.TestUtil; -import com.lin.Dto.BookDto; -import com.lin.Dto.SenseCallbackDto; -import com.lin.Dto.TestDto; +import com.lin.dto.BookDto; +import com.lin.dto.SenseCallbackDto; +import com.lin.dto.TestDto; import com.lin.util.InvokeUtil; import com.lin.util.XmlParseUtil; import org.junit.Test; @@ -16,6 +16,8 @@ import java.util.Map; /** * 反射测试 + * + * @author linqiankun */ public class InvokeTest { diff --git a/src/test/java/com/lin/TestUtil/ProvinceCityTest.java b/src/test/java/com/lin/TestUtil/ProvinceCityTest.java new file mode 100644 index 0000000000000000000000000000000000000000..682ea787bc669782aa4dccdd98d4f1200944de94 --- /dev/null +++ b/src/test/java/com/lin/TestUtil/ProvinceCityTest.java @@ -0,0 +1,28 @@ +package com.lin.TestUtil; + + +import com.lin.util.ProvinceCityUtil; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +/** + * 根据地址解析城市测试 + * + * @author linqiankun + */ +public class ProvinceCityTest { + + @Test + public void provinceCityTest() { + List> maps = ProvinceCityUtil.addressResolution("北京市市辖区丰台区"); + System.out.println(maps); + } + + @Test + public void provinceCityTestNo() { + Map maps = ProvinceCityUtil.addressResolutionNoTwo("内蒙古维吾尔组自治区胡琦市"); + System.out.println(maps); + } +} diff --git a/src/test/java/com/lin/TestUtil/XmlTest.java b/src/test/java/com/lin/TestUtil/XmlTest.java index 92282561206022efc0b2f0f673cb838e63255177..705ce33dd25681969204dbc809530e070d45856d 100644 --- a/src/test/java/com/lin/TestUtil/XmlTest.java +++ b/src/test/java/com/lin/TestUtil/XmlTest.java @@ -9,13 +9,15 @@ import java.io.IOException; /** * Xml相关测试工具 + * + * @author linqiankun */ public class XmlTest { @Test public void xmlParseTest() throws ParserConfigurationException, IOException, SAXException { String filepath = "src/test/resources/book.xml"; - XmlParseUtil.ReadXml(filepath,"book"); + XmlParseUtil.ReadXml(filepath, "book"); // InputStream is = this.getClass().getResourceAsStream("/book.xml"); // 拿到资源 // InputStream in = this.getClass().getClassLoader().getResourceAsStream("book.xml"); diff --git a/src/test/java/com/lin/TestUtil/v2.0.md b/src/test/java/com/lin/markdown/v2.0.md similarity index 60% rename from src/test/java/com/lin/TestUtil/v2.0.md rename to src/test/java/com/lin/markdown/v2.0.md index adda5a8568bf162486415bf38e5a52b35c6d6a3d..2759d29e6604d25319277bccc3285c3816aa806a 100644 --- a/src/test/java/com/lin/TestUtil/v2.0.md +++ b/src/test/java/com/lin/markdown/v2.0.md @@ -5,4 +5,12 @@ 3. Http(Https)连接工具(测试已通过) 4. Xml解析工具(测试已通过) 5. 反射工具(测试已通过) -6. pdf导出工具(未完成) \ No newline at end of file +6. pdf导出工具(未完成) + +### TEST + +1. Excel导出导入测试 +2. 文件读写测试 +3. http连接测试 +4. 反射测试 +5. xml解析测试 diff --git a/src/test/java/com/lin/markdown/v3.0.md b/src/test/java/com/lin/markdown/v3.0.md new file mode 100644 index 0000000000000000000000000000000000000000..3030e534feaa5fd80deac1936ad07783fbb496d4 --- /dev/null +++ b/src/test/java/com/lin/markdown/v3.0.md @@ -0,0 +1,25 @@ +# V3.0 + +1. 冒泡排序工具 +2. 选择排序 +3. 插入排序 +4. 计数排序 +5. 归并排序 +6. 希尔排序 +7. 堆排序 +8. 基数排序 +9. 桶排序 +10. 快速排序 + +### TEST + +1. 冒泡排序 +2. 桶排序 +3. 计数排序 +4. 堆排序 +5. 插入排序 +6. 归并排序 +7. 快速排序 +8. 基数排序 +9. 选择排序 +10. 希尔排序 \ No newline at end of file diff --git a/src/test/java/com/lin/TestTree/v4.0.md b/src/test/java/com/lin/markdown/v4.0.md similarity index 63% rename from src/test/java/com/lin/TestTree/v4.0.md rename to src/test/java/com/lin/markdown/v4.0.md index f3f3f470c0ca785279eae09cdf3e214a92d6d1be..f8c313e5241375417ceb60a7389b3358ef672a87 100644 --- a/src/test/java/com/lin/TestTree/v4.0.md +++ b/src/test/java/com/lin/markdown/v4.0.md @@ -5,4 +5,9 @@ 3. 红黑树实现算法1 4. 红黑树实现算法2 5. 二叉平衡树实现算法 -6. 普通二叉树6 \ No newline at end of file +6. 普通二叉树6 + +### TEST + +1. AVL树算法1测试 +2. 红黑树算法2测试 \ No newline at end of file diff --git a/src/test/java/com/lin/markdown/v5.0.md b/src/test/java/com/lin/markdown/v5.0.md new file mode 100644 index 0000000000000000000000000000000000000000..3c522a7d87b40a866ef6b81e152c922cf5eb974e --- /dev/null +++ b/src/test/java/com/lin/markdown/v5.0.md @@ -0,0 +1,12 @@ +# V5.0 + +1. 图片转pdf工具,多图片转pdf工具 +2. pdf转图片工具 +3. 多个pdf合成工具 + +### TEST + +1. genPdf,生成pdf +2. 多图片合一pdf +3. pdf转图片 +4. 图片转pdf \ No newline at end of file