Skip to content

Commit

Permalink
Move DependencyTree* API to the API module
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Nov 24, 2023
1 parent ddcb237 commit 6477fc6
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.devtools.messagewriter.MessageWriter;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.aether.artifact.Artifact;

abstract class BaseDependencyTreeProcessScheduler<E> implements DependencyTreeVisitScheduler {
Expand Down Expand Up @@ -138,63 +137,4 @@ protected String getResolvedTreeMessage(Artifact a) {
@formatter:on */
return sb.append(a.getVersion()).toString();
}

public static void main(String[] args) throws Exception {

double[] x1 = { 2, 3, 4, 5, 6, 7, 8, 9 };
double[] y1 = { 4, 8, 16, 32, 64, 128, 256, 512 };
double[] x2 = { 10 };

for (int i = 0; i < x2.length; i++) {
System.out.println("Value: " + x2[i] + " => extrapolation: " + extraPolate(x1, y1, x2[i]));
}

var e = new Extrapolator();
e.pushSample(2);
e.pushSample(4);
e.pushSample(8);
e.pushSample(16);
e.pushSample(32);
e.pushSample(64);
e.pushSample(128);
e.pushSample(256);
e.pushSample(512);

System.out.println(e.extrapolate());
}

static double extraPolate(double[] x, double[] y, double x2) {
var lowIndex = 2;
return y[y.length - 1] + (x2 - x[x.length - lowIndex]) / (x[x.length - 1] - x[x.length - lowIndex])
* (y[y.length - 1] - y[y.length - lowIndex]);
}

private static class Extrapolator {

private static final int MAX_SAMPLES = 6;
private static final int LOW_INDEX = 1;
private final AtomicLong[] samples = new AtomicLong[MAX_SAMPLES];
private final AtomicInteger sampleCounter = new AtomicInteger(-1);

public Extrapolator() {
for (int i = 0; i < MAX_SAMPLES; ++i) {
samples[i] = new AtomicLong();
}
}

public void pushSample(long sample) {
var sampleIndex = sampleCounter.incrementAndGet();
samples[sampleIndex % MAX_SAMPLES].set(sample);
}

public long extrapolate() {
var sampleCounter = this.sampleCounter.get();
var sampleIndex = sampleCounter % MAX_SAMPLES;
var lastSample = samples[sampleIndex].get();
var lowSample = samples[(MAX_SAMPLES + sampleIndex - LOW_INDEX) % MAX_SAMPLES].get();
return lastSample
+ (sampleCounter + 1 - (sampleCounter - LOW_INDEX)) / (sampleCounter - (sampleCounter - LOW_INDEX))
* (lastSample - lowSample);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.devtools.messagewriter.MessageWriter;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package io.quarkus.domino.cli;
package io.quarkus.domino.tree;

import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.domino.cli.repo.DependencyTreeBuilder;
import io.quarkus.domino.cli.repo.DependencyTreeRoot;
import io.quarkus.domino.cli.repo.DependencyTreeVisitScheduler;
import io.quarkus.domino.cli.repo.DependencyTreeVisitor;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.domino.processor.ExecutionContext;
Expand Down Expand Up @@ -47,7 +47,7 @@ static <E> DependencyTreeVisitScheduler parallel(DependencyTreeBuilder treeBuild
MessageWriter log,
int treesTotal) {

return new BaseDependencyTreeProcessScheduler<E>(processor, log, treesTotal) {
return new BaseDependencyTreeProcessScheduler<>(processor, log, treesTotal) {

final ParallelTreeProcessor<String, DependencyTreeRoot, DependencyNode> treeProcessor = ParallelTreeProcessor
.with(new NodeProcessor<>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.devtools.messagewriter.MessageWriter;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import org.eclipse.aether.collection.DependencyCollectionException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.domino.cli.repo;
package io.quarkus.domino.tree;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import org.eclipse.aether.graph.DependencyNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.domino.ArtifactSet;
import io.quarkus.domino.cli.repo.DependencyTreeVisitor;
import io.quarkus.domino.tree.DependencyTreeProcessor;
import io.quarkus.domino.tree.DependencyTreeVisitor;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.util.GlobUtil;
import java.io.BufferedWriter;
Expand Down

0 comments on commit 6477fc6

Please sign in to comment.