精华内容
下载资源
问答
  • util
    千次阅读
    2021-02-26 20:52:44

    Util是utiliy的缩写,是一个多功能、基于工具的包。

    java.util是包含集合框架、遗留的 collection 类、事件模型、日期和时间设施、国际化和各种实用工具类(字符串标记生成器、随机数生成器和位数组、日期Date类、堆栈Stack类、向量Vector类等)。集合类、时间处理模式、日期时间工具等各类常用工具包。

    Java的实用工具类库java.util包。在这个包中,Java提供了一些实用的方法和数据结构。例如,Java提供日期(Data)类、日历(Calendar)类来产生和获取日期及时间,提供随机数(Random)类产生各种类型的随机数,还提供了堆栈(Stack)、向量(Vector) 、位集合(Bitset)以及哈希表(Hashtable)等类来表示相应的数据结构。

    Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。

    Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

    更多相关内容
  • android.util.Base64类

    2018-05-10 09:17:13
    Android util包中的Base64类,在java工程中使用可以
  • asm-util.jar

    2016-08-04 21:41:31
    asm-util-1.3.4.jar, asm-util-1.3.5.jar, asm-util-1.4.1.jar, asm-util-1.4.3.jar, asm-util-1.5.1.jar, asm-util-1.5.2.jar, asm-util-1.5.3.jar, asm-util-2.0.jar, asm-util-2.1.jar, asm-util-2.2.1-sources....
  • util-linux-ng-2.17源码(含fdisk)

    热门讨论 2012-06-16 09:56:12
    util-linux-ng-2.17源码(含fdisk) Here is a list of all documented files with brief descriptions: util-linux-ng-2.17.2/disk-utils/blockdev.c [code] util-linux-ng-2.17.2/disk-utils/cramfs.h [code] ...
  • linux:apr-util安装包 apr-util-1.5.2.tar.gz

    热门讨论 2013-05-16 16:32:58
    linux:apr-util安装包 apr-util-1.5.2.tar.gz 另有apache安装步骤和必备安装包见本人博客和资源
  • ws-commons-util-1.0.2.jar

    热门讨论 2013-07-23 09:38:43
    ws-commons-util-1.0.2.jar 相关jar包
  • java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/recommender]] at java....

    错误:

    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/recommender]]
    	at java.util.concurrent.FutureTask.report(Unknown Source)
    	at java.util.concurrent.FutureTask.get(Unknown Source)
    	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
    	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/recommender]]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	... 6 more
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@5a3ef48a]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4968)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5101)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 6 more
    Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet@725c6763]
    	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:135)
    	at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:722)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 9 more
    Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)
    	at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:142)
    	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    	... 12 more
    Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    	at java.util.zip.ZipFile.read(Native Method)
    	at java.util.zip.ZipFile.access$1400(Unknown Source)
    	at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source)
    	at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source)
    	at java.util.zip.InflaterInputStream.read(Unknown Source)
    	at sun.misc.IOUtils.readFully(Unknown Source)
    	at java.util.jar.JarFile.getBytes(Unknown Source)
    	at java.util.jar.JarFile.getManifestFromReference(Unknown Source)
    	at java.util.jar.JarFile.getManifest(Unknown Source)
    	at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:140)
    	... 13 more
    
    一月 22, 2018 4:27:58 下午 org.apache.catalina.core.ContainerBase startInternal
    严重: A child container failed during start
    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    	at java.util.concurrent.FutureTask.report(Unknown Source)
    	at java.util.concurrent.FutureTask.get(Unknown Source)
    	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
    	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:630)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
    	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 6 more
    
    一月 22, 2018 4:27:58 下午 org.apache.catalina.startup.Catalina start
    严重: The required Server component failed to start so Tomcat is unable to start.
    org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:630)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 7 more
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 9 more
    Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
    	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    	... 11 more
    

    解决方法:找到 tomcat下的 server.xml,打开后删除以下的东东。

    造成此错误,是项目迁移时出现的错。
    自己也找了很久,找到这个大神的博客。https://www.cnblogs.com/yidan621/p/5252075.html

    展开全文
  • java.util.concurrent.RejectedExecutionException异常报错。 具体看了下代码,里面的执行逻辑也不难,没有外部依赖都是内存多线程cpu类型计算的逻辑。 下面是报错的线程池状态变化,由上到下,按照时间增长,最后...

    场景

    业务一切正常,突然收到一堆告警,发现全是
    java.util.concurrent.RejectedExecutionException异常报错。
    具体看了下代码,里面的执行逻辑也不难,没有外部依赖都是内存多线程cpu类型计算的逻辑。
    下面是报错的线程池状态变化,由上到下,按照时间增长,最后达到饱和。

    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 99, active threads = 75, queued tasks = 5000, completed tasks = 1595259]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 101, active threads = 74, queued tasks = 4999, completed tasks = 1595298]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 90, active threads = 70, queued tasks = 4998, completed tasks = 1595354]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 93, active threads = 75, queued tasks = 5000, completed tasks = 1595378]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 85, active threads = 72, queued tasks = 5000, completed tasks = 1595443]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 83, active threads = 70, queued tasks = 5000, completed tasks = 1595447]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 90, active threads = 81, queued tasks = 5000, completed tasks = 1595476]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 85, active threads = 74, queued tasks = 4994, completed tasks = 1595574]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 91, active threads = 80, queued tasks = 4999, completed tasks = 1595678]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 95, active threads = 85, queued tasks = 5000, completed tasks = 1595696]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 95, active threads = 87, queued tasks = 5000, completed tasks = 1595721]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 93, active threads = 85, queued tasks = 4999, completed tasks = 1595727]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 94, active threads = 85, queued tasks = 4998, completed tasks = 1595737]
    ...
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 109, active threads = 96, queued tasks = 4999, completed tasks = 1596150]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 113, active threads = 102, queued tasks = 4998, completed tasks = 1596191]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 109, queued tasks = 5000, completed tasks = 1596355]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 110, queued tasks = 5000, completed tasks = 1596517]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 119, active threads = 110, queued tasks = 4999, completed tasks = 1596519]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 113, active threads = 105, queued tasks = 5000, completed tasks = 1596553]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 122, active threads = 109, queued tasks = 4999, completed tasks = 1596602]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    java.util.concurrent.ThreadPoolExecutor@57b5ea0f[Running, pool size = 120, active threads = 120, queued tasks = 5000, completed tasks = 1597061]
    

    因为cpu4核,所以coresize = 40,maxsize = 120,都正常。

        private static BlockingQueue<Runnable> executorQueue = new LinkedBlockingQueue<>(5000);
        private static ExecutorService executorService = new ThreadPoolExecutor(
                Runtime.getRuntime().availableProcessors() * 10,
                Runtime.getRuntime().availableProcessors() * 30,
                60, TimeUnit.SECONDS, executorQueue);
    

    通过对ThreadPoolExecutor类分析,引发java.util.concurrent.RejectedExecutionException主要有两种原因:

    1. 线程池显示的调用了shutdown()之后,再向线程池提交任务的时候,如果你配置的拒绝策略是ThreadPoolExecutor.AbortPolicy的话,这个异常就被会抛出来。
    2. 当你的排队策略为有界队列,并且配置的拒绝策略是ThreadPoolExecutor.AbortPolicy,当线程池的线程数量已经达到了maximumPoolSize的时候,你再向它提交任务,就会抛出ThreadPoolExecutor.AbortPolicy异常。

    排查

    因为全机房、只有一个节点报错,而其他机器都正常,在这个一定保证正确的前提下。
    1、看了线上的请求量、并没有突增,所以排除外部因素
    2、看了代码逻辑,逻辑内部并没有打印报错日志,说明不是线程执行耗时导致后面的其他线程排队
    3、排除线程池是否提前关闭。并没有,因为手动没有显示关闭,另外看日志也知道里面的线程数还在变化,所以不存在关闭的说法。

    考虑是否是机器本身的原因,后面经过排查,看到那个点线上的cpu使用率突然升高、系统负载突然飙升,网卡流出、流入报文数目、tcp连接数也突然为0。具体干了什么,已经让运营去看了。至少说明我们代码没有问题。

    如下图,可以感受下:
    在这里插入图片描述

    解决

    线上第一时间出现这个问题,没想2秒,看了下报错代码逻辑,然后重启了这个节点实例(当时重启完后,观察又没问题了,带着疑惑然后才去排查)

    展开全文
  • JavaScript工具类:util.js用法实例

    千次阅读 2019-03-04 15:30:59
    _util.isEmpty() console.log(_util.isEmpty(undefined)); // true console.log(_util.isEmpty(null)); // true console.log(_util.isEmpty('')); // true console.log(_util.isEmpty([])); /...

    缓存方法


    _util.cookie.set()
    _util.cookie.set('user_name', 'guang');         // 关闭浏览器后失效。注:单独打开 demo.html 是没法缓存的,需要启动本地服务
    _util.cookie.set('user_id', '12', 1);           // 保存一天
    _util.cookie.set('user_type', 'admin', 1/24);   // 保存一个小时
    _util.cookie.set('is_login', '1', 1/24/60);     // 保存一分钟
    
    _util.cookie.get()
    console.log(_util.cookie.get('user_name'));     // guang
    console.log(_util.cookie.get('user_id'));       // 12
    console.log(_util.cookie.get('user_type'));     // admin
    console.log(_util.cookie.get('is_login'));      // '1'
    
    _util.cookie.remove()
    _util.cookie.remove('user_name');
    _util.cookie.remove('user_id');
    _util.cookie.remove('user_type');
    _util.cookie.remove('is_login');
    

    本地储存方法


    _util.storage.set()
    _util.storage.set('user', { name: 'guang', age: '25'}); // 'obj-{"name":"guang","age":"25"}'
    _util.storage.set('lang', 'zh-cn');                     // 'zh-cn'
    
    _util.storage.get()
    console.log(_util.storage.get('user'));     // { name: 'guang', age: '25'}
    console.log(_util.storage.get('lang'));     // 'zh-cn'
    
    _util.storage.remove()
    _util.storage.remove('user');	// 删除 user 及对应的值
    
    _util.storage.clear()
    _util.storage.clear();	// 清空所有 localStorage
    

    数据类型通用方法


    _util.isEmpty()
    console.log(_util.isEmpty(undefined));  // true
    console.log(_util.isEmpty(null));   // true
    console.log(_util.isEmpty(''));     // true
    console.log(_util.isEmpty([]));     // true
    console.log(_util.isEmpty({}));     // true
    
    _util.isString()
    console.log(_util.isString('q'));  // true
    
    _util.isArray()
    console.log(_util.isArray('q'));    // false
    console.log(_util.isArray(['q']));  // true
    
    _util.isObject()
    console.log(_util.isObject('q'));       // false
    console.log(_util.isObject(['q']));     // false
    console.log(_util.isObject({id:'q'}));  // true
    
    _util.isFunction()
    var fn = function(){};
    
    console.log(_util.isFunction(fn));  // true
    
    _util.length()
    var obj = {
        id: 'a',
        status: '0'
    };
    var arr = ['p','o','i'];
    var str = 'yeah';
    
    console.log(_util.length(obj));     // 2
    console.log(_util.length(arr));     // 3
    console.log(_util.length(str));     // 4
    
    _util.forEach()
    var source = [
        { id: 'c', status: '3', count: '46' },
        { id: 'd', status: '1', count: '41' }
    ];
    _util.forEach(source, function(i, item){
        console.log(i);
        console.log(item);  
        // 0
        // { id: 'c', status: '3', count: '46' }
        // 1
        // { id: 'd', status: '1', count: '41' }
    });
    
    var source = {
        id: 'c',
        status: '3'
    };
    _util.forEach(source, function(key, value){
        console.log(key);
        console.log(value);  
        // 'id'
        // 'c'
        // 'status'
        // '3'
    });
    
    _util.isEqual()
    var source1 = [
        'qw',
        ['q','w'],
        { id: 'a', status: '2', count: '19' },
    ];
    var source2 = [
        'qw',
        ['q','w'],
        { id: 'a', status: '2', count: '19' },
    ];
    var source3 = [
        'qw',
        ['q','w'],
        { id: 'b', status: '2', count: '19' },
    ];
    
    console.log(_util.isEqual(source1, source2));     // true
    console.log(_util.isEqual(source1, source3));     // false
    
    _util.copy()
    var s1 = { id: 'a' };
    var s2 = s1;
    s2.status = '2';
    console.log(s1);    // {id: "a", status: "2"}
    
    var s1 = { id: 'a' };
    var s2 = _util.copy(s1);
    s2.status = '2';
    console.log(_util.copy(s1));    // {id: "a"}
    
    var s1 = [{ id: 'a' }];
    var s2 = s1;
    s2.push({ id: 'b' });
    console.log(_util.copy(s1));    // [{id: "a"}, {id: "b"}]
    
    var s1 = [{ id: 'a' }];
    var s2 = _util.copy(s1);
    s2.push({ id: 'b' });
    console.log(_util.copy(s1));    // [{id: "a"}]
    

    字符串方法


    _util.trim()
    var str = '  qwe  rty ';
    
    console.log(_util.trim(str));       // 'qwe  rty'
    
    _util.trimAll()
    var str = '  qwe  rty ';
    
    console.log(_util.trimAll(str));    // 'qwerty'
    
    _util.string.format()
    var str = '确定要{0}单据【{1}】吗?';
    
    console.log(_util.string.format(str, '删除', 'QZYDYJZB201901300002'));   // '确定要删除单据【QZYDYJZB201901300002】吗?'
    
    _util.string.isStartWith()
    var str = 'qwerty';
    var startStr = 'qw';
    
    console.log(_util.string.isStartWith(str, startStr'));   // true
    
    _util.string.isEndWith()
    var str = 'qwerty';
    var endStr = 'ty';
    
    console.log(_util.string.isEndWith(str, endStr));   // true
    
    _util.string.firstUpperCase()
    var str = 'qwerty';
    
    console.log(_util.string.firstUpperCase(str));   // 'Qwerty'
    
    _util.string.reverse()
    var str = 'qwerty';
    
    console.log(_util.string.reverse(str));   // 'ytrewq'
    
    _util.string.split()
    var str = 'a,s,d';
    
    console.log(_util.string.split(str, ','));   // ["a", "s", "d"]
    
    _util.string.getNext()
    console.log(_util.string.getNext('0001'));     // '0002'
    console.log(_util.string.getNext('XM0001'));   // 'XM0002'
    

    数字方法


    _util.number.parseInt()
    console.log(_util.number.parseInt('25.36'));   // 25
    
    _util.number.parseFloat()
    console.log(_util.number.parseFloat('25.36'));   // 25.36
    
    _util.number.toFixed()
    console.log(_util.number.toFixed('25.3682', 2));   // '25.37'
    
    _util.number.round()
    console.log(_util.number.round('25.3682', 2));   // 25.37
    
    _util.number.ceil()
    console.log(_util.number.ceil('25.3612', 2));   // 25.37
    
    _util.number.floor()
    console.log(_util.number.floor('25.3682', 2));   // 25.36
    
    _util.number.mul()
    var n1 = 1.2;
    var n2 = 2.3;
    var n3 = 3.45;
    
    console.log(_util.number.mul(n1, n2 ,n3));   // 9.522
    
    _util.number.add()
    var n1 = 1.2;
    var n2 = 2.3;
    var n3 = 3.45;
    
    console.log(_util.number.add(n1, n2 ,n3));   // 6.95
    
    _util.number.random()
    console.log(_util.number.random(1, 100));   // 55
    

    数组方法


    _util.array.indexOf()
    var arr = [
        'qwert',
        ['q', 'w', 'e'],
        { id: 'a', name: '光' }
    ];
    
    console.log(_util.array.indexOf(arr, 'qwert'));         // 0
    console.log(_util.array.indexOf(arr, ['q', 'w', 'e'])); // 1
    console.log(_util.array.indexOf(arr, {id: 'a'}));       // 2。当检索数组中的对象时,只用匹配该对象的某一个(几个)属性即可查询到。
    
    _util.array.push()
    var arr = ['q'];
    var len = _util.array.push(arr, ['w','e']);
    
    console.log(arr);   // ["q", "w", "e"]
    console.log(len);   // 4
    
    _util.array.sort()
    var arr = [
        { billNo: 'CGAPD20190301000002', date: '2019-03-01', count: '22' },
        { billNo: 'CGAPD20190228000001', date: '2019-02-28', count: '14' },
        { billNo: 'CGAPD20190301000001', date: '2019-03-01', count: '36' },
    ];
    
    console.log(_util.array.sort(arr, 'billNo'));   // 输出结果为:  
    // [
    //    { billNo: 'CGAPD20190228000001', date: '2019-02-28', count: '14' },
    //    { billNo: 'CGAPD20190301000001', date: '2019-03-01', count: '36' },
    //    { billNo: 'CGAPD20190301000002', date: '2019-03-01', count: '22' },
    // ];
    
    _util.array.unique()
    var arr = [
        'qw',
        'qw',
        ['q','w'],
        ['w','q'],
        { id: 'a', status: '1', count: '22' },
        { id: 'a', status: '2', count: '19' },
    ];
    
    console.log(_util.array.unique(arr));   // 输出结果为:
    // [
    //     'qw',
    //     ['q','w'],
    //     ['w','q'],
    //     { id: 'a', status: '1', count: '22' },
    //     { id: 'a', status: '2', count: '19' },
    // ]
    
    console.log(_util.array.unique(arr, 'id')); // 输出结果为:
    // [
    //     'qw',
    //     ['q','w'],
    //     ['w','q'],
    //     { id: 'a', status: '1', count: '22' },
    // ]
    
    console.log(_util.array.unique(arr, 'id', true));   // 输出结果为:
    // [
    //     'qw',
    //     ['q','w'],
    //     { id: 'a', status: '1', count: '22' },
    // ]
    
    _util.array.filter()
    arr = [
        { id: 'a', status: '1', count: '22' },
        { id: 'b', status: '2', count: '19' },
        { id: 'c', status: '3', count: '46' },
        { id: 'd', status: '1', count: '41' },
    ];
    
    console.log(_util.array.filter(arr, { status: '1'}));   // 输出结果为:
    // [
    //     { id: 'a', status: '1', count: '22' },
    //     { id: 'd', status: '1', count: '41' }
    // ]
    
    console.log(_util.array.filter(arr, { status: '1', id: 'a'}));      // 输出结果为:
    // [
    //     { id: 'a', status: '1', count: '22' }
    // ]
    
    console.log(_util.array.filter(arr, { status: ['1', '2']}));        // 输出结果为:
    // [
    //     { id: 'a', status: '1', count: '22' },
    //     { id: 'b', status: '2', count: '19' },
    //     { id: 'd', status: '1', count: '41' }
    // ]
    
    console.log(_util.array.filter(arr, { status: ['1', '2']}, true));  // 输出结果为:
    // [
    //     { id: 'c', status: '3', count: '46' },
    // ]
    
    _util.array.select()
    var arr = [
        { id: 'a', status: '1', count: '22' },
        { id: 'b', status: '2', count: '19' },
        { id: 'c', status: '3', count: '46' },
    ];
    
    console.log(_util.array.select(arr, 'count'));    // ["22", "19", "46"]
    console.log(_util.array.select(arr, ['status', 'count']));    // 输出结果为:
    // [
    //     { status: '1', count: '22' },
    //     { status: '2', count: '19' },
    //     { status: '3', count: '46' }
    // ]
    
    _util.array.concat()
    var arr1 = ['q','w'];
    var arr2 = ['q','a'];
    
    console.log(_util.array.concat(arr1, arr2));    // ["q", "w", "a"]
    
    _util.array.group()
    var arr = [
        { size: 'S', color: '红色', price: '199' },
        { size: 'M', color: '蓝色', price: '299' },
        { size: 'M', color: '黄色', price: '159' },
        { size: 'S', color: '绿色', price: '168' },
    ];
    
    console.log(_util.array.group(arr, 'size'));    // 输出结果为:
    // [
    //     {
    //         "size":"S",
    //         "group":[
    //             {
    //                 "size":"S",
    //                 "color":"红色",
    //                 "price":"199"
    //             },
    //             {
    //                 "size":"S",
    //                 "color":"绿色",
    //                 "price":"168"
    //             }
    //         ]
    //     },
    //     {
    //         "size":"M",
    //         "group":[
    //             {
    //                 "size":"M",
    //                 "color":"蓝色",
    //                 "price":"299"
    //             },
    //             {
    //                 "size":"M",
    //                 "color":"黄色",
    //                 "price":"159"
    //             }
    //         ]
    //     }
    // ]
    
    _util.array.remove()
    var arr = ['s', 'g', '', null, undefined, { id:'q', status: '1'} ];
    
    _util.array.remove(arr);
    console.log(arr);   // ["s", "g", { id:'q', status: '1'}]
    
    _util.array.remove(arr, ['s', { id:'q' }]);
    console.log(arr);   // ["g"]
    
    _util.array.clear()
    var arr = ['s', 'h', 'i'];
    _util.array.clear(arr);
    
    console.log(arr);   // []
    

    对象方法


    _util.object.keys()
    var obj = {
        name: 'guang',
        age: '25'
    };
    
    console.log(_util.object.keys(obj));    // ["name", "age"]
    
    _util.object.values()
    var obj = {
        name: 'guang',
        age: '25'
    }
    
    console.log(_util.object.values(obj));  // ["guang", "25"]
    
    _util.object.assign()
    var obj2 = {
        type: 'admin',
        age: '26'
    };
    _util.object.assign(obj, obj2);
    
    console.log(obj);   // { name: "guang", age: "26", type: "admin" }
    
    _util.object.select()
    var obj = {
        name: 'guang',
        email: '123456@qq.com',
        phone: '13566668888'
    };
    
    console.log(_util.object.select(obj, ['name', 'phone'])); // {name: "guang", phone: "13566668888"}
    
    _util.object.remove()
    var obj = {
        name: 'guang',
        email: '123456@qq.com',
        phone: '13566668888',
        wrong: '',
        wrong2: undefined,
    };
    
    console.log(_util.object.remove(obj)); // {name: "guang", email: "123456@qq.com", phone: "13566668888"}
    console.log(_util.object.remove(obj, ['name', 'phone'])); // {email: "123456@qq.com"}
    
    _util.object.getValue()
    var obj = {
        name: 'guang',
        child: {
            name: 'lan'
        }
    };
    
    console.log(_util.object.getValue(obj, 'child.name'));  // lan
    
    _util.object.serialize()
    var obj = {
        id: 'a',
        billNo: 'CGDD20190228000001'
    };
    
    console.log(_util.object.serialize(obj));   // id=a&billNo=CGDD20190228000001
    
    _util.object.clear()
    var obj = {
        id: 'a',
        billNo: 'CGDD20190228000001'
    };
    _util.object.clear(obj);
    
    console.log(obj);  // {id: "", billNo: ""}
    

    json数据方法


    _util.json.toTreeData()
    var data = [
        { "id": "1", "level": "1", "name": "基础平台", "parentId": null },
        { "id": "2", "level": "1", "name": "财务平台", "parentId": null },
        { "id": "101", "level": "2", "name": "设置", "parentId": "1" },
        { "id": "102", "level": "2", "name": "系统", "parentId": "1" },
        { "id": "10101", "level": "3", "name": "参数设置", "parentId": "101" },
        { "id": "10201", "level": "3", "name": "权限设置", "parentId": "102" }
    ];
    
    console.log(_util.json.toTreeData(data, 'id', 'parentId', 'children')); // 输出结果为:
    // [
    //     {
    //         "id":"1",
    //         "level":"1",
    //         "name":"基础平台",
    //         "parentId":null,
    //         "children":[
    //             {
    //                 "id":"101",
    //                 "level":"2",
    //                 "name":"设置",
    //                 "parentId":"1",
    //                 "children":[
    //                     {
    //                         "id":"10101",
    //                         "level":"3",
    //                         "name":"参数设置",
    //                         "parentId":"101"
    //                     }
    //                 ]
    //             },
    //             {
    //                 "id":"102",
    //                 "level":"2",
    //                 "name":"系统",
    //                 "parentId":"1",
    //                 "children":[
    //                     {
    //                         "id":"10201",
    //                         "level":"3",
    //                         "name":"权限设置",
    //                         "parentId":"102"
    //                     }
    //                 ]
    //             }
    //         ]
    //     },
    //     {
    //         "id":"2",
    //         "level":"1",
    //         "name":"财务平台",
    //         "parentId":null
    //     }
    // ]
    

    时间方法


    _util.date.format()
    console.log(_util.date.format());
    console.log(_util.date.format('', 'YYYY月MM年DD日'));
    console.log(_util.date.format('', 'YYYY-MM-DD hh:mm:ss 星期WW'));
    
    _util.date.otherMonth()
    console.log(_util.date.otherMonth(-1, '2019-03-04'));	// 2019-02-04
    console.log(_util.date.otherMonth(1, '2019-03-04'));	// 2019-04-04
    
    _util.date.startOfMonth()
    console.log(_util.date.startOfMonth(0, '2019-03-04'));	// '2019-03-01'
    console.log(_util.date.startOfMonth(-1, '2019-03-04'));	// '2019-02-01'
    
    _util.date.endOfMonth()
    console.log(_util.date.endOfMonth(0, '2019-03-04'));	// '2019-03-31'
    console.log(_util.date.endOfMonth(-1, '2019-03-04'));	// '2019-02-28'
    
    _util.date.startOfWeek()
    console.log(_util.date.startOfWeek(0, '2019-03-04'));		// '2019-03-04'
    
    _util.date.endOfWeek()
    console.log(_util.date.endOfWeek(0, '2019-03-04'));		// '2019-03-10'
    
    _util.date.otherDate()
    console.log(_util.date.otherDate(-6, '2019-03-04'));	// '2019-02-26'
    
    _util.date.howManyDays()
    console.log(_util.date.howManyDays('2019-01-12', '2019-02-01'));    // 20
    
    _util.date.howManyMonths()
    console.log(_util.date.howManyMonths('2019-01', '2018-05'));    // 8
    
    _util.date.getDatesBetween()
    console.log(_util.date.getDatesBetween('2019-01-25', '2019-02-01'));    // ["2019-01-25", "2019-01-26", "2019-01-27", "2019-01-28", "2019-01-29", "2019-01-30", "2019-01-31", "2019-02-01"]
    console.log(_util.date.getDatesBetween('2019-01-25', '2019-02-01', 'YYYY-MM')); // ["2019-01", "2019-02"]
    

    浏览器判断方法


    _util.browser.type()
    console.log(_util.browser.type());
    
    _util.browser.isChrome()
    console.log(_util.browser.isChrome());
    
    _util.browser.isIE()
    console.log(_util.browser.isIE());
    
    _util.browser.isEdge()
    console.log(_util.browser.isEdge());
    
    _util.browser.isSafari()
    console.log(_util.browser.isSafari());
    
    _util.browser.isFirefox()
    console.log(_util.browser.isFirefox());
    
    _util.browser.isWechat()
    console.log(_util.browser.isWechat());
    
    _util.browser.isAndroid()
    console.log(_util.browser.isAndroid());
    
    _util.browser.isIOS()
    console.log(_util.browser.isIOS());
    
    _util.browser.isMobile()
    console.log(_util.browser.isMobile());
    

    表单验证方法


    _util.validate.positiveToFixed()
    var input = '12.345';
    
    console.log(_util.validate.positiveToFixed(input, 2));  // false
    console.log(_util.validate.positiveToFixed(input, 3));  // true
    
    注:其他方法直接调用即可

    下载

    npm i sg-utils -S
    

    GitHub地址(记得给星哦)

    https://github.com/shiguang0116/sg-utils


    系列文章

    JavaScript工具类(一):util.js创建及上传
    JavaScript工具类(二):cookie缓存
    JavaScript工具类(三):localStorage本地储存
    JavaScript工具类(四):数据类型
    JavaScript工具类(五):string字符串
    JavaScript工具类(六):number数字
    JavaScript工具类(七):array数组
    JavaScript工具类(八):object对象
    JavaScript工具类(九):date日期
    JavaScript工具类(十):base64编码、解码
    JavaScript工具类(十一):浏览器、移动端类型
    JavaScript工具类(十二):validate表单验证
    JavaScript工具类(十三):url路径处理
    JavaScript工具类(十四):json数据格式
    JavaScript工具类:util.js用法实例


    展开全文
  • cannot be cast to java.util.List

    千次阅读 2021-03-08 06:56:04
    java.lang.ClassCastException:... cannot be cast to java.util.List1. 使用人人安全框架,发现java.util.List报错信息### The error may involve io.renren.modules.job.dao.ScheduleJobDao.updateBatch### The er...
  • java.util

    千次阅读 2021-01-19 09:23:25
    1. java.util包概述 java.util包中放置了Java开发过程中常用的工具类,如日期时间类,日历类等等。 2. java.util包常用类 Date; Calendar及其子类; 集合接口以及实现类; 集合工具类; 数组工具类等等。 3. java...
  • 73)java.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:511) java.util.concurrent.FutureTask.run$$ capture(FutureTask.java:266)java.util.concurrent.FutureTask.run(FutureTask.java)java....
  • Java 8 新特性|java.util.stream.Collectors

    千次阅读 2020-06-02 22:57:55
    Java 8 流的新类 java.util.stream.Collectors 实现了 java.util.stream.Collector 接口,同时又提供了大量的方法对流 ( stream ) 的元素执行 map and reduce 操作,或者统计操作。 1、 Collectors.averagingDouble...
  • FAILED: Hive Internal Error: java.util.ConcurrentModificationException(null) java.util.ConcurrentModificationException at java.util.Hashtable$Enumerator.next(Hashtable.java:1383) at org.apache....
  • Md5Util.java

    热门讨论 2012-05-25 14:21:08
    Md5Util.java
  • 在WALT里面,一个task的util大小,涉及到下面几个参数: WALT窗口大小 cpu当前频率和cpu最高频率 task在一个窗口实际运行时间 task demand获取机制(比如最近窗口的数值,前五个窗口的最大数值等等) 在...
  • java.lang.IllegalStateException: No primary or single public constructor found for interface java.util.List - and no default constructor found either at org.springframework.beans.BeanUtils....
  • 常见问题之Java—— java.util.zip.ZipException: error in opening zip file 背景 日常我们开发时,会遇到各种各样的奇奇怪怪的问题(踩坑o(╯□╰)o),这个常见问题系列就是我日常遇到的一些问题的记录文章系列,...
  • at java.util.regex.Pattern$CharProperty.match(Pattern.java:3776) at java.util.regex.Pattern$Curly.match0(Pattern.java:4260) at java.util.regex.Pattern$Curly.match(Pattern.java:4234) at java.util....
  • java.util.Base64

    千次阅读 2021-03-15 19:10:52
    Base64 简单使用java.util.Base64package com.mozq.sb.jwt01.config;...import java.util.Base64;/*** Base64中的字符 + / = 在url中存在特殊意义,如果放在url中会被转义。*/public class Base64Test {public sta...
  • at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal....
  • Exception in thread "main" java.util.zip.ZipException: zip END header not found at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1573) at java.base/java.util.zip.ZipFile$Source.findEND...
  • 报错1:java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map和报错2:java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList的解决...
  • net.mindview.util包(Thinking in Java 4#)

    热门讨论 2013-05-29 16:36:11
    net.mindview.util包(Thinking in Java 4#)
  • Scanner类(java.util.Scanner)讲解

    千次阅读 多人点赞 2019-11-21 19:14:49
    Scanner类(java.util.Scanner) 需求:获取用户从键盘输入的年龄、姓名和成绩 解决方法:使用Scanner类 Scanner类的实现步骤 在有效代码的第一行,通过import关键字导入Scanner类,简言之,导包 例如: import ...
  • null)) 翻译:不能反序列化java.util类型的值从字符串"2022-06-21 18:00:01":不是一个有效的表示(错误:解析Date值’2022-06-21 18:00:01’失败:你能解析日期"2022-06-21 18:00:01":而它似乎是和格式’yyyy-MM-...
  • Java中import java.util.Scanner;语句的作用

    千次阅读 多人点赞 2021-05-16 21:34:22
    一java.util.Scanner 是 Java5 的新特征,我们可以通过 Scanner 类来获取用户的输入。 首先要导入包importjava.util.Scanner; Scanner类的创建对象:ScannerS=new Scanner(System.in); 方法基本格式 hasNextXxx...
  • iostat 中的 %util 指标说明

    千次阅读 2021-05-17 19:21:03
    判断磁盘极限性能误区:只通过iostat 中的 %util 指标确定磁盘是否达到带宽或iops极限背景:在判断磁盘是否达到极限性能时,总有人通过 iostat -x 中的 %util 指标来确认磁盘是否带宽带宽或IOPS瓶颈,其实这是不对的...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,122,805
精华内容 1,249,122
关键字:

util