Skip to content

Commit 855a6aa

Browse files
ImmutableDAG -> FixedDAG
1 parent 2a8c0ba commit 855a6aa

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

src/jdk.jpackage/share/classes/jdk/jpackage/internal/PackagingPipeline.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import jdk.jpackage.internal.model.Package;
4848
import jdk.jpackage.internal.model.PackagerException;
4949
import jdk.jpackage.internal.pipeline.DirectedEdge;
50-
import jdk.jpackage.internal.pipeline.ImmutableDAG;
50+
import jdk.jpackage.internal.pipeline.FixedDAG;
5151
import jdk.jpackage.internal.pipeline.TaskPipelineBuilder;
5252
import jdk.jpackage.internal.pipeline.TaskSpecBuilder;
5353
import jdk.jpackage.internal.util.function.ExceptionBox;
@@ -280,7 +280,7 @@ Builder appImageLayoutForPackaging(Function<Package, AppImageLayout> v) {
280280
return this;
281281
}
282282

283-
ImmutableDAG<TaskID> taskGraphSnapshot() {
283+
FixedDAG<TaskID> taskGraphSnapshot() {
284284
if (taskGraphSnapshot == null) {
285285
taskGraphSnapshot = taskGraphBuilder.create();
286286
}
@@ -303,13 +303,13 @@ PackagingPipeline create() {
303303
validatedAppImageLayoutForPackaging());
304304
}
305305

306-
private final ImmutableDAG.Builder<TaskID> taskGraphBuilder = ImmutableDAG.build();
306+
private final FixedDAG.Builder<TaskID> taskGraphBuilder = FixedDAG.build();
307307
private final List<Path> excludeCopyDirs = new ArrayList<>();
308308
private final Map<TaskID, TaskConfig> taskConfig = new HashMap<>();
309309
private UnaryOperator<TaskContext> appContextMapper;
310310
private UnaryOperator<TaskContext> pkgContextMapper;
311311
private Function<Package, AppImageLayout> appImageLayoutForPackaging;
312-
private ImmutableDAG<TaskID> taskGraphSnapshot;
312+
private FixedDAG<TaskID> taskGraphSnapshot;
313313
}
314314

315315
static Builder build() {
@@ -400,7 +400,7 @@ static void runPostAppImageUserScript(PackageBuildEnv<Package, AppImageLayout> e
400400
.run(env.env(), env.pkg().packageName());
401401
}
402402

403-
private PackagingPipeline(ImmutableDAG<TaskID> taskGraph, Map<TaskID, TaskConfig> taskConfig,
403+
private PackagingPipeline(FixedDAG<TaskID> taskGraph, Map<TaskID, TaskConfig> taskConfig,
404404
UnaryOperator<TaskContext> appContextMapper, UnaryOperator<TaskContext> pkgContextMapper,
405405
Function<Package, AppImageLayout> appImageLayoutForPackaging) {
406406
this.taskGraph = Objects.requireNonNull(taskGraph);
@@ -526,7 +526,7 @@ AppImageBuildEnv<Application, AppImageLayout> appImageBuildEnv() {
526526
}
527527
}
528528

529-
private record DefaultTaskContext(ImmutableDAG<TaskID> taskGraph, BuildEnv env, Application app,
529+
private record DefaultTaskContext(FixedDAG<TaskID> taskGraph, BuildEnv env, Application app,
530530
Optional<ApplicationLayout> appLayout, Optional<PackagingTaskContext> pkg) implements TaskContext {
531531

532532
DefaultTaskContext {
@@ -606,7 +606,7 @@ private static Callable<Void> createTask(TaskContext context, TaskID id, TaskCon
606606
};
607607
}
608608

609-
private final ImmutableDAG<TaskID> taskGraph;
609+
private final FixedDAG<TaskID> taskGraph;
610610
private final Map<TaskID, TaskConfig> taskConfig;
611611
private final Function<Package, AppImageLayout> appImageLayoutForPackaging;
612612
private final UnaryOperator<TaskContext> appContextMapper;

src/jdk.jpackage/share/classes/jdk/jpackage/internal/pipeline/ImmutableDAG.java renamed to src/jdk.jpackage/share/classes/jdk/jpackage/internal/pipeline/FixedDAG.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
import java.util.stream.StreamSupport;
4343

4444
/**
45-
* Immutable directed acyclic graph (DAG).
45+
* Fixed directed acyclic graph (DAG).
46+
* <p>
47+
* Number of nodes is fixed, links between nodes can be added or removed.
4648
*
4749
* @param edgeMatrix the edge matrix. [i,j] addresses an edge, where 'i' is the
4850
* index of the head node of the edge in the node container
4951
* and 'j' is the index of the tail node of the edge in the
5052
* node container
5153
* @param nodes the node container
5254
*/
53-
public record ImmutableDAG<T>(BinaryMatrix edgeMatrix, Nodes<T> nodes) {
55+
public record FixedDAG<T>(BinaryMatrix edgeMatrix, Nodes<T> nodes) {
5456

5557
public static <U> Builder<U> build() {
5658
return new Builder<>();
@@ -77,8 +79,8 @@ public Builder<U> addEdge(DirectedEdge<U> edge) {
7779
return this;
7880
}
7981

80-
public ImmutableDAG<U> create() {
81-
return ImmutableDAG.create(edges, nodes);
82+
public FixedDAG<U> create() {
83+
return FixedDAG.create(edges, nodes);
8284
}
8385

8486
private final List<U> nodes = new ArrayList<>();
@@ -121,7 +123,7 @@ public Iterator<V> iterator() {
121123
}
122124
}
123125

124-
public ImmutableDAG {
126+
public FixedDAG {
125127
Objects.requireNonNull(nodes);
126128

127129
Objects.requireNonNull(edgeMatrix);
@@ -134,11 +136,11 @@ public Iterator<V> iterator() {
134136
}
135137
}
136138

137-
public static <U> ImmutableDAG<U> create(Collection<DirectedEdge<U>> edges, List<U> nodes) {
139+
public static <U> FixedDAG<U> create(Collection<DirectedEdge<U>> edges, List<U> nodes) {
138140
return create(edges, Nodes.ofList(nodes));
139141
}
140142

141-
static <U> ImmutableDAG<U> create(Collection<DirectedEdge<U>> edges, Nodes<U> nodes) {
143+
static <U> FixedDAG<U> create(Collection<DirectedEdge<U>> edges, Nodes<U> nodes) {
142144
final var edgeMatrix = new BinaryMatrix(nodes.size());
143145
for (final var edge : edges) {
144146
final int row = nodes.indexOf(edge.tail());
@@ -150,7 +152,7 @@ static <U> ImmutableDAG<U> create(Collection<DirectedEdge<U>> edges, Nodes<U> no
150152
throw new UnsupportedOperationException("Cyclic edges not allowed");
151153
}
152154

153-
return new ImmutableDAG<>(edgeMatrix, nodes);
155+
return new FixedDAG<>(edgeMatrix, nodes);
154156
}
155157

156158
/**

src/jdk.jpackage/share/classes/jdk/jpackage/internal/pipeline/TaskPipelineBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
package jdk.jpackage.internal.pipeline;
2727

28-
import static jdk.jpackage.internal.pipeline.ImmutableDAG.getIncomingEdges;
29-
import static jdk.jpackage.internal.pipeline.ImmutableDAG.getNoOutgoingEdges;
28+
import static jdk.jpackage.internal.pipeline.FixedDAG.getIncomingEdges;
29+
import static jdk.jpackage.internal.pipeline.FixedDAG.getNoOutgoingEdges;
3030

3131
import java.util.Collection;
3232
import java.util.List;
@@ -134,7 +134,7 @@ public Void call() throws Exception {
134134

135135
}
136136

137-
private record ParallelWrapperTask(ImmutableDAG<Callable<Void>> taskGraph, Executor executor) implements Callable<Void> {
137+
private record ParallelWrapperTask(FixedDAG<Callable<Void>> taskGraph, Executor executor) implements Callable<Void> {
138138

139139
ParallelWrapperTask {
140140
Objects.requireNonNull(taskGraph);
@@ -206,6 +206,6 @@ private static Runnable toRunnable(Callable<Void> callable) {
206206

207207
}
208208

209-
private final ImmutableDAG.Builder<Callable<Void>> taskGraphBuilder = new ImmutableDAG.Builder<>();
209+
private final FixedDAG.Builder<Callable<Void>> taskGraphBuilder = new FixedDAG.Builder<>();
210210
private Executor executor;
211211
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
import org.junit.jupiter.params.ParameterizedTest;
3939
import org.junit.jupiter.params.provider.MethodSource;
4040

41-
final class ImmutableDAGTest {
41+
final class FixedDAGTest {
4242

4343
@Test
4444
public void testInvalidCtorArgs() {
4545
final var matrix1x2 = new BinaryMatrix(1, 2);
46-
final var nodes = ImmutableDAG.Nodes.<String>ofList(List.of(A, B));
46+
final var nodes = FixedDAG.Nodes.<String>ofList(List.of(A, B));
4747

48-
assertThrows(IllegalArgumentException.class, () -> new ImmutableDAG<>(matrix1x2, nodes));
48+
assertThrows(IllegalArgumentException.class, () -> new FixedDAG<>(matrix1x2, nodes));
4949

5050
final var matrix3x3 = new BinaryMatrix(3, 3);
51-
assertThrows(IllegalArgumentException.class, () -> new ImmutableDAG<>(matrix3x3, nodes));
51+
assertThrows(IllegalArgumentException.class, () -> new FixedDAG<>(matrix3x3, nodes));
5252
}
5353

5454
@Test
5555
public void testNodesToList() {
56-
final var nodes = ImmutableDAG.Nodes.<String>ofList(List.of(A, B));
56+
final var nodes = FixedDAG.Nodes.<String>ofList(List.of(A, B));
5757

5858
assertEquals(2, nodes.size());
5959

@@ -187,7 +187,7 @@ public void testSome() {
187187
// | | |
188188
// +----+------+
189189

190-
final var graphBuilder = ImmutableDAG.<String>build();
190+
final var graphBuilder = FixedDAG.<String>build();
191191

192192
graphBuilder.addEdge(edge(C, L));
193193
graphBuilder.addEdge(edge(D, B));
@@ -234,7 +234,7 @@ public void testSome2() {
234234
// +--- L ---+
235235
//
236236

237-
final var graphBuilder = ImmutableDAG.<String>build();
237+
final var graphBuilder = FixedDAG.<String>build();
238238

239239
graphBuilder.addEdge(edge(B, A));
240240
graphBuilder.addEdge(edge(C, A));
@@ -312,7 +312,7 @@ public void testTopologicalSort(List<DirectedEdge<Integer>> edges, int[] expecte
312312
return Stream.of(edge.tail(), edge.head());
313313
}).flatMap(x -> x).sorted().distinct().toList();
314314

315-
assertArrayEquals(expectedNodes, ImmutableDAG.create(edges, nodes).topologicalSort().stream().mapToInt(x -> x).toArray());
315+
assertArrayEquals(expectedNodes, FixedDAG.create(edges, nodes).topologicalSort().stream().mapToInt(x -> x).toArray());
316316
}
317317

318318
private static List<Object[]> testTopologicalSort() {
@@ -386,19 +386,19 @@ private static List<Object[]> testTopologicalSort() {
386386

387387
@Test
388388
public void testEmptyBuilder() {
389-
assertThrows(IllegalArgumentException.class, ImmutableDAG.<String>build()::create);
389+
assertThrows(IllegalArgumentException.class, FixedDAG.<String>build()::create);
390390
}
391391

392392
@Test
393393
public void testSingleNodeBuilder() {
394-
final var graphBuilder = ImmutableDAG.<String>build();
394+
final var graphBuilder = FixedDAG.<String>build();
395395
graphBuilder.addNode(A);
396396
assertNodesEquals(graphBuilder.create().nodes(), A);
397397
}
398398

399399
@Test
400400
public void testIsolatedNodesBuilder() {
401-
final var graphBuilder = ImmutableDAG.<String>build();
401+
final var graphBuilder = FixedDAG.<String>build();
402402
graphBuilder.addNode(A);
403403
graphBuilder.addNode(B);
404404
assertNodesEquals(graphBuilder.create().nodes(), A, B);
@@ -411,12 +411,12 @@ public void testIsolatedNodesBuilder() {
411411
assertEquals(graphBuilder.create().getNoIncomingEdges(), List.of(A, B));
412412
}
413413

414-
private static void assertNodesEquals(ImmutableDAG.Nodes<String> actual, String... expected) {
414+
private static void assertNodesEquals(FixedDAG.Nodes<String> actual, String... expected) {
415415
assertEquals(List.of(expected), StreamSupport.stream(actual.spliterator(), false).toList());
416416
}
417417

418-
private static ImmutableDAG<String> create(Collection<DirectedEdge<String>> edges) {
419-
final var graphBuilder = ImmutableDAG.<String>build();
418+
private static FixedDAG<String> create(Collection<DirectedEdge<String>> edges) {
419+
final var graphBuilder = FixedDAG.<String>build();
420420
edges.forEach(graphBuilder::addEdge);
421421
return graphBuilder.create();
422422
}

0 commit comments

Comments
 (0)