All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vandmo.dependencylock.maven.Artifacts Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package se.vandmo.dependencylock.maven;

import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

public final class Artifacts {

  public final List artifacts;

  Artifacts(List artifacts) {
    ArrayList copy = new ArrayList<>(artifacts);
    sort(copy);
    this.artifacts = unmodifiableList(copy);
  }

  public static Artifacts from(Set artifacts) {
    return new Artifacts(artifacts.stream().map(Artifact::from).collect(toList()));
  }

  public Optional by(ArtifactIdentifier identifier) {
    for (Artifact artifact : artifacts) {
      if (identifier.equals(artifact.identifier)) {
        return Optional.of(artifact);
      }
    }
    return Optional.empty();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy