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

de.otto.edison.navigation.NavBar Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
package de.otto.edison.navigation;

import net.jcip.annotations.ThreadSafe;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Comparator.comparing;

/**
 * The navigation of Edison-Microservices on /internal pages.
 * 

* The NavBar can be extended by more items. In order to do this, just {@link #register} *

* @since 1.0.0 */ @ThreadSafe public class NavBar { private volatile List items; private NavBar(final List items) { updateAndSortItems(new ArrayList<>(items)); } public static NavBar emptyNavBar() { return new NavBar(emptyList()); } public static NavBar navBar(final List items) { return new NavBar(items); } /** * Registers another item in this NavBar. *

* The item is positioned in the navigation by {@link NavBarItem#getPosition()}, * then by {@link NavBarItem#getTitle()}. *

* @param item New NavBarItem. */ public void register(final NavBarItem item) { updateAndSortItems(new ArrayList(items) {{ add(item); }}); } /** * Returns the list of all {@link NavBarItem items}. *

* The list is sorted by {@link NavBarItem#getPosition()}, then by {@link NavBarItem#getTitle()}. *

* @return Unmodifiable list of navbar items. */ public List getItems() { return unmodifiableList(items); } private void updateAndSortItems(final List items) { items.sort( comparing(NavBarItem::getPosition) .thenComparing(NavBarItem::getTitle)); this.items = unmodifiableList(items); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy