Guava

聊聊carrera的GroovyScriptAction

佐手、 提交于 2020-02-27 23:03:09
序 本文主要研究一下carrera的GroovyScriptAction Action DDMQ/carrera-consumer/src/main/java/com/xiaojukeji/carrera/cproxy/actions/Action.java public interface Action { enum Status { FAIL, CONTINUE, FINISH, ASYNCHRONIZED } class UnsupportedDataType extends RuntimeException { } default Status act(UpstreamJob job) { Object data = job.getData(); if (data instanceof byte[]) { return act(job, (byte[]) data); } else if (data instanceof JSONObject) { return act(job, (JSONObject) data); } else { throw new UnsupportedDataType(); } } default Status act(UpstreamJob job, byte[] bytes) { throw new UnsupportedDataType()

检查字符串是否不为空且不为空

做~自己de王妃 提交于 2020-02-25 23:15:34
如何检查字符串是否不为null也不为空? public void doStuff(String str) { if (str != null && str != "**here I want to check the 'str' is empty or not**") { /* handle empty string */ } /* ... */ } #1楼 添加到@BJorn和@SeanPatrickFloyd Guava的方法是: Strings.nullToEmpty(str).isEmpty(); // or Strings.isNullOrEmpty(str); Commons Lang有时更具可读性,但我一直在慢慢地更多地依赖Guava,有时在谈到 isBlank() 时,Commons Lang有时会造成混乱(例如是否有空格)。 Guava的Commons Lang isBlank 版本为: Strings.nullToEmpty(str).trim().isEmpty() 我会说不允许使用 "" (空) 和 null 是可疑的,并且有潜在的bug,因为它可能无法处理不允许使用 null 所有情况(尽管对于SQL,我可以理解为SQL / HQL对 '' )很奇怪。 #2楼 只需在此处添加Android: import android.text.TextUtils;

模拟jar包冲突

最后都变了- 提交于 2020-02-25 22:27:06
jar包冲突原因 前段时间,因为经历了项目重构,引入很多包,加上管理不善,出现了很多jar包冲突问题。当时项目想用spring管理hbase实例,引入了org.springframework.data,spring-data-hadoop,2.5.0.RELEASE jar包,出现了guava包的冲突,tomcat对servlet-api加载冲突问题。在最近的开发中也遇到了curator-client包冲突问题。借着这次机会,顺便学习写博客。 其实在java开发中,jar hell是一个很常见的问题,主要是因为jvm在加载的过程中,项目的加载的顺序问题。同一个类(全限定名相同)在jvm中只会加载一次,这里面涉及到类加载和maven依赖管理的知识点。当然,maven已经给我们提供了很多解决的方法。 冲突原因 造成jar包冲突的原因主要有两种 1. 第一种是一个项目,依赖了同一个项目的两个版本。 2. 第二种冲突原因是不同项目中,出现了相同的类。何为相同的类,即类的全限定名相同。 1 2 3 一般的错误有: 找不到方法:java.lang.NoSuchMethodError 找不到类:Exception in thread "main" java.lang.NoClassDefFoundError 找不到变量:Exception in thread "main" java.lang

如何熟悉一个系统?(内含知识大图)

眉间皱痕 提交于 2020-02-25 22:12:05
作者 | 唐志龙(鲲龙) 阿里巴巴高级开发工程师 导读 :本文总结了熟悉系统主要分三部分:业务学习、技术学习、实战。每部分会梳理一些在学习过程中需要解答的问题,这些问题随着经验的积累需要逐步补充完善。 前言 开发人员经常会面临下面一些场景: 新人入职,需要学习已有系统,作为 landing 的一部分,如何学习? 被拉过去参与一个陌生系统的迭代开发或者系统维护(bugfix),如何快速上手? 同事离职或转岗,需要把系统交接给你,怎么去接? 内心 os:这是一口锅吗? 这样的场景多了,就需要去梳理常见问题以及应对方法,方便后续遇到类似场景可以快速应对。本文总结熟悉系统主要分三部分:业务学习、技术学习、实战。每部分会梳理一些在学习过程中需要解答的问题,这些问题随着经验的积累需要逐步补充完善。 业务学习 业务学习就是从业务角度去学习系统,我们需要了解系统的客户是谁、使用人是谁、带来了什么价值,系统提供了哪些功能等。不清楚业务,就等于不知道系统在干什么。技术是为业务落地而服务,清楚了业务才知道怎样用技术更好地服务业务,所以业务学习是熟悉一个系统的首要任务。这块主要的学习方式有跟产品、运营、开发沟通,学习产品设计文档文档、PRD、自己使用系统,还有一些常见图,如产品功能架构图、业务流程图、功能树,用例图等。 常见问题: 系统所在行业的情况是怎样? 系统的目标用户是谁?比如是给公司高层做决策用

Java 8 collector for Guava ImmutableTable using HashBasedTable as accumulator gives IllegalAccessError

∥☆過路亽.° 提交于 2020-02-23 05:57:32
问题 Process list of string via method which returns ImmutableTable<R,C,V> . For instance ImmutableTable<Integer,String,Boolean> process(String item) { /*...*/} . Collect the result i.e, merge all results (individual table may contain duplicates) and return ImmutableTable . My current implementation works when there are no duplicates: final ImmutableTable<Integer, String, Boolean> result = itemsToProcess.parallelStream() .map(item -> ProcessorInstanceProvider.get() .buildTable(item)) .collect

Java 8 collector for Guava ImmutableTable using HashBasedTable as accumulator gives IllegalAccessError

隐身守侯 提交于 2020-02-23 05:57:07
问题 Process list of string via method which returns ImmutableTable<R,C,V> . For instance ImmutableTable<Integer,String,Boolean> process(String item) { /*...*/} . Collect the result i.e, merge all results (individual table may contain duplicates) and return ImmutableTable . My current implementation works when there are no duplicates: final ImmutableTable<Integer, String, Boolean> result = itemsToProcess.parallelStream() .map(item -> ProcessorInstanceProvider.get() .buildTable(item)) .collect

Apache Spark — using spark-submit throws a NoSuchMethodError

浪子不回头ぞ 提交于 2020-02-20 04:47:20
问题 To submit a Spark application to a cluster, their documentation notes: To do this, create an assembly jar (or “uber” jar) containing your code and its dependencies. Both sbt and Maven have assembly plugins. When creating assembly jars, list Spark and Hadoop as provided dependencies; these need not be bundled since they are provided by the cluster manager at runtime. -- http://spark.apache.org/docs/latest/submitting-applications.html So, I added the Apache Maven Shade Plugin to my pom.xml file

Apache Spark — using spark-submit throws a NoSuchMethodError

本小妞迷上赌 提交于 2020-02-20 04:44:33
问题 To submit a Spark application to a cluster, their documentation notes: To do this, create an assembly jar (or “uber” jar) containing your code and its dependencies. Both sbt and Maven have assembly plugins. When creating assembly jars, list Spark and Hadoop as provided dependencies; these need not be bundled since they are provided by the cluster manager at runtime. -- http://spark.apache.org/docs/latest/submitting-applications.html So, I added the Apache Maven Shade Plugin to my pom.xml file

Guava table to CSV

折月煮酒 提交于 2020-02-02 04:42:07
问题 I am attempting to export a Guava table to CSV. The code below works, but it skips the first column which I want to see in the output as well. Can you suggest anything? EDIT: obviously using values() and keySet() separately works. final RowSortedTable<String, String, Double> graph = TreeBasedTable.create(); graph.put("A", "0", 0.0); graph.put("A", "1", 1.0); graph.put("B", "0", 0.1); graph.put("B", "1", 1.1); final Appendable out = new StringBuilder(); try { final CSVPrinter printer =

org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList; with Selenium 3.5.3 Chrome 76

随声附和 提交于 2020-01-28 10:56:32
问题 I'm writing Selenium Junit tests with IntelliJ. The tests run ok if I trigger from test directly. However, if I trigger tests from TestRunnerSuite with JunitCore, I encountered following weird error that I did not find a solution after researching on google. Similar questions on DriverService$builder, but not my error type. [main] ERROR sire.responseOrg.TestIncidents - java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common