org.maxur.ldoc.model.Domain Maven / Gradle / Ivy
The newest version!
package org.maxur.ldoc.model;
import com.sun.javadoc.RootDoc;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* The type Domain.
*
* @author Maxim Yunusov
* @version 1.0
* @since 8/29/2016
*/
public class Domain {
@Getter
@NotNull
private final Collection subDomains;
@Getter
@NotNull
private final Set links;
/**
* Instantiates a new Domain.
*
* @param root the root
*/
public Domain(final RootDoc root) {
subDomains = collectDomainModels(root);
links = collectLinks(subDomains);
}
@NotNull
private Set collectDomainModels(final RootDoc root) {
final Set result = Arrays.stream(root.specifiedPackages())
.map(SubDomain::makeBy)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toSet());
result.forEach(
sd -> {
Arrays.stream(root.specifiedPackages()).forEach(
sd::add
);
}
);
return result;
}
@NotNull
private Set collectLinks(final Collection domains) {
final Map result = new HashMap<>();
for (SubDomain domain : domains) {
for (SubDomain.LinkModel link : domain.getLinks()) {
final BiLink newLink = new BiLink(domain.getId(), link.getRelated(), link.getLabel());
final BiLink oldLink = result.get(newLink);
if (oldLink != null) {
final BiLink value = oldLink.mergeWith(newLink);
result.remove(oldLink);
result.put(value, value);
} else {
result.put(newLink, newLink);
}
}
}
return result.keySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy