2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.network.navigation;
7 import eu.svjatoslav.commons.string.GlobMatcher;
9 import java.util.ArrayList;
10 import java.util.List;
12 public class NavigationItem {
14 private final ArrayList<NavigationItem> children = new ArrayList<>();
15 private final String url;
16 private String pattern;
18 private boolean isDefault;
20 public NavigationItem(final String url, String pattern, String title ) {
22 this.pattern = pattern;
26 public NavigationItem setDefault(){
31 public boolean isDefault(){
35 public void add(final NavigationItem navigationItem) {
36 children.add(navigationItem);
39 public String getUrl() {
43 NavigationItem getMatch(final String requestPath) {
44 if (matchesUrl(requestPath))
47 for (final NavigationItem childNavigationItem : children) {
48 final NavigationItem match = childNavigationItem.getMatch(requestPath);
56 public List<NavigationItem> getChildren() {
60 public String getTitle() {
64 public boolean matchesUrl(final String url) {
65 return GlobMatcher.match(url, pattern);
68 public NavigationItem getDefaultNavigationItem() {
69 for (NavigationItem child : children)
70 if (child.isDefault())