是否可以将 docker-compose 文件“导入”或链接到另一个 docker-compose 文件中?
假设我有两个文件:
# docker-compose-1.yml
services:
A:
# config
B:
# config
Run Code Online (Sandbox Code Playgroud)
# docker-compose-2.yml
services:
C:
# config
import: docker-compose-1.yml
Run Code Online (Sandbox Code Playgroud)
通过运行docker-compose -f docker-compose-2.yml up
,我想启动容器 A、B(在导入的文件中指定)和 C。这可能-f
吗,而不必将两个文件与参数链接起来?
我有一堂课
public class A {
public String attr ="A attribute";
public void method() {
System.out.println(this+" , "+this.attr);
}
public String toString() {
return("Object A");
}
}
Run Code Online (Sandbox Code Playgroud)
还有另一个继承自它的类
public class B extends A{
public String attr = "B attribute";
public void method() {
super.method();
}
public String toString() {
return("Object B");
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,method()
of B
只是for method()
的包装A
。
当我运行以下代码
B b = new B();
b.method();
Run Code Online (Sandbox Code Playgroud)
我得到的意思Object B , A attribute
是输出,this
并this.attr
访问了不同的内容。为什么会这样?
不应该 …
假设我想在遇到特定异常时使用某个值进行恢复,否则返回带有异常的失败未来。我希望是这样的:
public static void main(String[] args) {
CompletableFuture
.supplyAsync(FuturesExample::fetchValue)
.exceptionally(throwable -> {
if (throwable instanceof RuntimeException) {
return "All good";
}
throw throwable; // does not compile
});
}
public static String fetchValue() {
// code that potentially throws an exception
return "value";
}
Run Code Online (Sandbox Code Playgroud)
如果fetchValue
函数会抛出一个已检查的异常,我想在链式方法中处理它。return throwable
和都试过了throw throwable
,但都没有编译。是否CompletableFuture
为这种情况提供了任何解决方案?我知道Function
作为exceptionally
方法参数的接口不会抛出任何异常 - 在这种情况下,我只想返回已经失败的未来。我想找到一个使用 Java 8 的解决方案。
我正在使用SpringData对查询执行使用基于QueryDSL的动态过滤器组件。因此,我Predicate
将从接收到的数据广告创建实例,并将其传递给QueryDslPredicateExecutor
。为了动态访问实体属性,我使用泛型PathBuilder
类型输入实体类。
考虑以下(简化)代码:
class Offer {
List<LanguageToName> names;
}
class LanguageToName {
String name;
String language;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试查询Offer
其集合name
元素中具有属性“ abc”的实体时,我仅按如下方式创建谓词:
pathBuilder.getCollection("names", LanguageToName.class).any().getString("name")
.like("%" + fieldData.getFieldValue() + "%");
Run Code Online (Sandbox Code Playgroud)
但是,我无法提出一种使用来通过包含对象的多个属性过滤集合的解决方案PathBuilder
。当我将上面的代码附加到.and()
并通过pathBuilder
变量再次访问集合时,我自然得到的结果等同于将sql query添加到AND EXISTS...
,这不是期望的结果。我也尝试使用getCollection().contains()
,但无法创建Expression<LanguageToName>
描述这种情况的。
有没有一种方法可以创建一个Predicate
将通过集合中元素的多个属性(即所查询实体的字段)过滤实体的实体?
我有一个 React 组件,一旦从服务器获取一些数据,它就会呈现 Cytoscape dagre 图。它似乎渲染了一个占据父级右半部分的画布<div id="cy" />
。调用cy.center()
并将cy.fit()
图形本身居中并适合父 div,但仅显示一半的可视化效果,因为包含的画布有一半位于屏幕之外。
设置以下 CSS:
position: absolute;
left: 0;
right: 0;
Run Code Online (Sandbox Code Playgroud)
与所有在线示例一样,在容器上,将使画布居中,但会破坏文档的流程。它还不能解决半尺寸问题。
JSX:
if (moduleStructure) {
return (
<div
id="cy-module-structure"
style={{
position: "absolute",
left: 0,
top: 0,
height: "500px",
width: "1500px",
display: "block",
}}
/>
);
}
Run Code Online (Sandbox Code Playgroud)
图形生成代码。获取数据后,React 钩子会调用此方法。
function generateGraph(nodes, edges) {
cytoscape.use(dagre);
const cy = cytoscape({
container: document.getElementById("cy-module-structure"),
boxSelectionEnabled: false,
autounselectify: true,
layout: {
name: "dagre",
nodeDimensionsIncludeLabels: true,
},
zoom: 1,
pan: { x: 0, y: …
Run Code Online (Sandbox Code Playgroud) 我有一个包含 json 记录的文件,并且想在将它们发送到 fluentd 输出之前从 json 记录中删除一些键。我可以使用“record_transformer Filter Plugin”来删除键,但它只从 json 中删除顶级键。如何使用嵌套键。
样本输入:
{
"key1": 1,
"key2": 2,
"key3": {
"nested_key1": 1,
"nested_key2": 1,
"nested_key3": 1,
"nested_key4": {
"double_nested_key1": 1,
"double_nested_key2": 2
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出样本:
{
"key1": 1,
"key2": 2,
"key3": {
"nested_key1": 1,
"nested_key2": 1,
"nested_key4": {
"double_nested_key2": 2
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码要编写。它采用一种枚举类型并返回其他枚举值。如何删除代码中太多(如果没有)条件并使其干净?
private static QuestionType parseQuestionType(QuestionTypeInfo questionTypeInfo) {
if (questionTypeInfo instanceof OpenEndedTextQuestionTypeInfo) {
return QuestionType.OPEN_ENDED;
} else if (questionTypeInfo instanceof MultiChoiceQuestionTypeInfo) {
return QuestionType.MULTI_CHOICE;
} else if (questionTypeInfo instanceof MatrixSinglePerRowQuestionTypeInfo) {
return QuestionType.MATRIX_SINGLE_PER_ROW;
} else if (questionTypeInfo instanceof OpenEndedTextQuestionTypeInfo) {
return QuestionType.OPEN_ENDED;
} else if (questionTypeInfo instanceof MatrixMultiPerRowQuestionTypeInfo) {
return QuestionType.MATRIX_MULTI_PER_ROW;
} else if (questionTypeInfo instanceof MatrixSideBySideQuestionTypeInfo) {
return QuestionType.MATRIX_SIDE_BY_SIDE;
} else if (questionTypeInfo instanceof MatrixSpreadSheetQuestionTypeInfo) {
return QuestionType.MATRIX_SPREAD_SHEET;
} else if (questionTypeInfo instanceof DataListQuestionTypeInfo) {
return QuestionType.DATA_LIST;
} else if …
Run Code Online (Sandbox Code Playgroud) 我最近将Ubuntu从14.04升级到16.04,并在运行任何mvn
命令(版本3.3.9)时开始出现以下错误:Error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar
。我的环境变量声明如下:
$JAVA_HOME: /usr/lib/jvm/java-8-oracle
$PATH: /usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$M2_HOME: /usr/share/maven
$M2: /usr/share/maven/bin
尝试找到解决方案时,我尝试按照各种线程上的建议删除M2和M2_HOME变量,这导致出现另一个错误:Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
。我也尝试过apt-get remove --purge maven
再次运行和安装它,以及下载.tar.gz档案,但是在两种情况下,都没有改变。
当查看/usr/share/maven/boot
文件夹时,有从指向的符号链接链plexus-classworlds-2.x.jar -> /usr/share/java/plexus-classworlds2-2.5.2.jar
。我缺少一些依赖吗?还是有没有被删除的旧配置文件--purge
?
编辑:当我以root身份执行mvn时,出现启动器错误,而不是plexus-classworlds-2.x。另外,我已经完全删除并重新安装了所有plexus库,但没有任何更改。
项目的限制要求我使用 aHashMap
作为我的数据源。我被要求使用以下方法
getAccountsWithMinimum
- 返回至少具有指定余额List
的Account
s
问题是 HashMap 没有索引。所以我不能使用 For 循环来完成它。
我尝试改编我在 Stack Overflow 和 GeeksForGeeks 上发现的类似问题的代码。这种方法不仅没有奏效,而且对我也没有多大好处,因为我不明白为什么它有效,即使它有效(它没有)。
我尝试从我在 GeeksForGeeks 上找到的代码中使用它。它什么也不打印。
public void getAccountsWithMinumum() {
Iterator entries = accounts.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Integer key = (Integer) entry.getKey();
Integer value = (Integer) entry.getValue();
System.out.println("Key = " + key + ", Value = " + value);
}
}
Run Code Online (Sandbox Code Playgroud)
帐户中的对象包含 (String)firstName、(String)lastName、(double)balance、(String)accountType 和 (String)AccountID 属性。
我想得到的是返回所需列表并将其打印到控制台的东西,以便我可以确认它。
我不需要有人为我做这件事,因为我怀疑这是我最后一次被要求做这件事或类似的事情。要么是一些非常沉重的手握提示,所以我可以填补空白,或者如果它更容易做到这一点,那么详细解释我为什么这样做将不胜感激。
ArrayList<Integer>[] paths = new ArrayList[N];
Run Code Online (Sandbox Code Playgroud)
这一行是我在作业中给我的代码的一部分,用作 Djikstra 算法的一部分。因为它是在作业中给我的,所以我认为它在语法上是正确的,但我认为我从未见过ArrayList
用括号声明数组的人。
这是一个ArrayList
还是一个数组?在这种情况下,括号是什么意思?
java ×6
java-8 ×2
code-cleanup ×1
css ×1
cytoscape.js ×1
docker ×1
exception ×1
fluentd ×1
hibernate ×1
inheritance ×1
javascript ×1
maven ×1
querydsl ×1
reactjs ×1
this ×1
ubuntu ×1