构建器模式在创建不可变对象时很流行,但是创建构建器会产生一些编程开销.所以我想知道为什么不简单地使用配置对象.
构建器的用法如下所示:
Product p = Product.Builder.name("Vodka").alcohol(0.38).size(0.7).price(17.99).build();
Run Code Online (Sandbox Code Playgroud)
很明显,这是非常易读和简洁的,但您必须实现构建器:
public class Product {
public final String name;
public final float alcohol;
public final float size;
public final float price;
private Product(Builder builder) {
this.name = builder.name;
this.alcohol = builder.alcohol;
this.size = builder.size;
this.price = builder.price;
}
public static class Builder {
private String name;
private float alcohol;
private float size;
private float price;
// mandatory
public static Builder name(String name) {
Builder b = new Builder();
b.name = name;
return b;
} …
Run Code Online (Sandbox Code Playgroud) openssl 1.0.1c(我可以在www.openssl.org上找到的最新稳定版本)是否完全支持TLS 1.2?
我搜索了所有关于openssl的更改日志.不幸的是,我找不到诸如"完全支持TLS 1.2"之类的信息.它只是在"1.0.0h和1.0.1之间的变化"中提到了"初始TLS v1.2支持".
假设我有一个包含一些我希望根据正则表达式拆分的字符的向量.
更确切地说,我想基于逗号分隔字符串,然后是空格,然后是大写字母(根据我的理解,regex
命令看起来像这样:( /(, [A-Z])/g
当我在这里尝试它时工作正常)).
当我尝试实现这一点时r
,regex
似乎不起作用,例如:
x <- c("Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), Loans, Long-term original maturity (over 1 year or no stated maturity)",
"Non financial corporations, Financial corporations other than MFIs, insurance corporations, pension funds and non-MMF investment funds, Assets (Net Acquisition of), Loans, Short-term original maturity (up to 1 year)")
strsplit(x, "/(, [A-Z])/g")
[[1]]
[1] "Non MMF investment funds, Insurance corporations, Assets (Net Acquisition of), …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个试图匹配特定字符串的正则表达式,但忽略目标字符串中的所有数字 - 所以我的正则表达式可能是“MyDog”,但它应该匹配 MyDog,以及 My11Dog 和 MyDog1 等。我可以写一些类似的东西
M[^\d]*y[^\d]D[^\d]*o[^\d]g[^\d]*
Run Code Online (Sandbox Code Playgroud)
但这非常痛苦。有什么想法吗?我正在使用 Java,无法更改字符串中的内容,因为我需要按原样检索它。