hbw-utils - ColUtils
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
ColUtils功能:
- 封装各种集合的创建,指定默认初始长度
- 封装各种Map的创建,指定默认初始长度
- 封装LinkedBlockingQueue的创建,也可指定长度
https://github.com/houbbbbb/utils
public class ColUtilsTest {@Testpublic void hashMapTest() {Map<String, Integer> map = ColUtils.newHashMap(String.class, Integer.class);map.put("a", 1);map.put("b", 2);System.out.println(map);System.out.println(map.getClass());}@Testpublic void concurrentHashMapTest() {Map<String, Integer> map = ColUtils.newConcurrentHashMap(String.class, Integer.class);map.put("a", 1);map.put("b", 2);System.out.println(map);System.out.println(map.getClass());}@Testpublic void propertiesTest() {Properties properties = ColUtils.newProperties();properties.put("a", "b");properties.put("c", "d");System.out.println(properties);System.out.println(properties.getClass());}@Testpublic void hashTableTest() {Hashtable<String, Integer> hashtable = ColUtils.newHashTable(String.class, Integer.class);hashtable.put("a", 1);hashtable.put("b", 2);System.out.println(hashtable);System.out.println(hashtable.getClass());}@Testpublic void treeMapTest() {Map<Integer, String> map = ColUtils.newTreeMap(Integer.class, String.class);map.put(2, "a");map.put(1, "b");System.out.println(map);System.out.println(map.getClass());Map<Count, String> map2 = ColUtils.newTreeMap(Count.class, String.class, new Comparator<Count>() {@Overridepublic int compare(Count o1, Count o2) {return o1.getAge().compareTo(o2.getAge());}});map2.put(new Count("a", 5), "a");map2.put(new Count("b", 6), "b");map2.put(new Count("c", 4), "c");System.out.println(map2);System.out.println(map2.getClass());}static class Count {public Count() {}public Count(String name, Integer age) {this.name = name;this.age = age;}private String name;private Integer age;public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}@Overridepublic String toString() {return "Count{" +"name='" + name + '\'' +", age=" + age +'}';}}@Testpublic void arrayListTest() {List<String> ls = ColUtils.newArrayList(String.class);ls.add("a");ls.add("b");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newArrayList(String.class, "c", "d");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newArrayList(String.class, ls);System.out.println(ls);System.out.println(ls.getClass());}@Testpublic void linkedListTest() {List<String> ls = ColUtils.newLinkedList(String.class);ls.add("a");ls.add("b");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newLinkedList(String.class, "c", "d", "e");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newLinkedList(String.class, ls);System.out.println(ls);System.out.println(ls.getClass());}@Testpublic void vectorTest() {List<String> ls = ColUtils.newVector(String.class);ls.add("ab");ls.add("cd");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newVector(String.class, "k", "l", "m");System.out.println(ls);System.out.println(ls.getClass());ls = ColUtils.newVector(String.class, ls);System.out.println(ls);System.out.println(ls.getClass());}@Testpublic void hashSetTest() {Set<String> set = ColUtils.newHashSet(String.class);set.add("abc");set.add("def");System.out.println(set);System.out.println(set.getClass());set = ColUtils.newHashSet(String.class, "a", "c", "b", "a", "c");System.out.println(set);System.out.println(set.getClass());set = ColUtils.newHashSet(String.class, set);System.out.println(set);System.out.println(set.getClass());}@Testpublic void treeSetTest() {Set<String> set = ColUtils.newTreeSet(String.class);set.add("a");set.add("b");System.out.println(set);System.out.println(set.getClass());set = ColUtils.newTreeSet(String.class, "b", "a");System.out.println(set);System.out.println(set.getClass());set = ColUtils.newTreeSet(String.class, set);System.out.println(set);System.out.println(set.getClass());Set<Count> set1 = ColUtils.newTreeSet(Count.class, new Comparator<Count>() {@Overridepublic int compare(Count o1, Count o2) {return o1.getAge().compareTo(o2.getAge());}});set1.add(new Count("name", 3));set1.add(new Count("b", 5));set1.add(new Count("c", 4));System.out.println(set1);System.out.println(set1.getClass());set1 = ColUtils.newTreeSet(Count.class, new Comparator<Count>() {@Overridepublic int compare(Count o1, Count o2) {return o1.getAge().compareTo(o2.getAge());}}, new Count("d", 5), new Count("u", 3), new Count("e", 7));System.out.println(set1);System.out.println(set1.getClass());}@Testpublic void linkedBlockingQueueTest() {LinkedBlockingQueue<String> queue = ColUtils.newLinkedBlockingQueue(String.class);queue.offer("a");queue.offer("b");queue.offer("c");System.out.println(queue);System.out.println(queue.getClass());queue = ColUtils.newLinkedBlockingQueue(String.class, 2);queue.offer("a");queue.offer("b");queue.offer("c");System.out.println(queue);System.out.println(queue.getClass());}
}
hbw-utils - ColUtils相关推荐
- openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old
具体错误如下: openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file ...
- Error: module pages/utils/util is not defined
错误如下: 处理方法是两个../上再加一个../ 自己之前写的会报错,const util = require('../../utils/util') 修改之后:const util = requir ...
- $g.$utils.实用工具类
$g.$utils = {/**舒工Ajax-lite 1.0 -- 最精简的ajax自定义访问方法*/ajax: function (o) {var p = o.post, g = o.get, d ...
- 【Qt】通过QtCreator源码学习Qt(十一):Utils::Icon,根据不同主题、不同状态变换图标
1.简介 在QtCreator中Utils::Icon封装的图标可以根据主题变换,还可以设置不同状态下的图标的颜色.不同状态下的颜色变换,由QIcon::addPixmap函数实现: void QIc ...
- 【原创】Kakfa utils源代码分析(三)
Kafka utils包最后一篇~~~ 十五.ShutdownableThread.scala 可关闭的线程抽象类! 继承自Thread同时还接收一个boolean变量isInterruptible表 ...
- 使用Tape和Vue Test Utils编写快速的Vue单元测试
by Edd Yerburgh 埃德·耶堡(Edd Yerburgh) 使用Tape和Vue Test Utils编写快速的Vue单元测试 (Write blazing fast Vue unit t ...
- Keras中神经网络可视化模块keras.utils.vis_util 的安装
Bug: ModuleNotFoundError: No module named 'keras.utils.vis_util' 解决方案: pip install pydot_ngpip insta ...
- tensorflow tf.keras.utils.plot_model 画深度学习神经网络拓扑图
tensorflow tf.keras.utils.plot_model 画网络拓扑图 # pip install graphviz # pip install pydot # 下载 graphviz ...
- 为什么在notebook里面还是显示torch_torch.utils.cpp_extension对c++/cuda进行拓展
为什么pytorch要对c++/cuda进行拓展 在初始阶段,使用pytorch提供的接口组合搭配自己的神经网络就可以了,但是,随着深入进行,比如说要实现一个自己新的算法,或者是自己定义的新的层,光使 ...
最新文章
- 推荐一款非常不错的子网计算器
- We Chall-Training: Get Sourced-Writeup
- css框架之960 Grid System 基本原理及使用方法
- 利用python脚本(re)抓取美空mm图片
- 微软向Chromium贡献代码以优化浏览器滚动体验
- JAVA 构造 MAP 并初始化 MAP、定义时就初始化
- 软件“美不美”,UI测试一下就知道
- 用前考虑清楚,伤敌一千自损八百的字体反爬虫
- python实现数据恢复_数据恢复/电子取证 非常有用的python库——Construct | 学步园...
- fastdfs-client-java操作fastdfs
- 数据库学习笔记3-隔离级别 Read Uncommitted
- SOS Dynamic Programming
- thymeleaf菜鸟教程_Spring MVC应用程序中的Thymeleaf模板布局,无扩展
- 你必须知道的10项大数据思维原理
- 华为手机为什么不用鸿蒙系统,华为手机为何迟迟不搭载鸿蒙系统
- 当系统中存在多个浏览器,如何设置IE为自己的默认浏览器
- HR 真的会嫌弃面试者跳槽频繁吗?
- 计算机网络谢希仁(1)
- 上海首届暑期大学生实习专场,名头看上去非常不错,决定去体验一下招聘会,看看自己的简历会被如何的无视..
- 车牌识别系统四:Pyqt5编写简易车牌识别界面