<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>DefaultSiteFinder.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">NorthernWind :: Core :: Default Implementation</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.core.impl.model</a> > <span class="el_source">DefaultSiteFinder.java</span></div><h1>DefaultSiteFinder.java</h1><pre class="source lang-java linenums">/*
* #%L
* *********************************************************************************************************************
*
* NorthernWind - lightweight CMS
* http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
* %%
* Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.northernwind.core.impl.model;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.spi.HierarchicFinderSupport;
import it.tidalwave.northernwind.core.model.SiteFinder;
import it.tidalwave.northernwind.core.impl.util.RegexTreeMap;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L51">@Immutable @RequiredArgsConstructor(access = AccessLevel.PRIVATE)</span>
<span class="fc" id="L52">@ToString(callSuper = true, exclude = {"mapByRelativePath", "mapByRelativeUri" })</span>
public class DefaultSiteFinder<T> extends HierarchicFinderSupport<T, SiteFinder<T>> implements SiteFinder<T>
{
private static final long serialVersionUID = 3242345356779345L;
/* package */
@Nonnull final transient Map<String, T> mapByRelativePath;
/* package */
@Nullable final transient RegexTreeMap<T> mapByRelativeUri;
@Nullable
private final String relativePath;
@Nullable
private final String relativeUri;
/*******************************************************************************************************************
*
* Constructor used to create an instance with the given data.
*
* @param finderName the name (for debugging)
* @param mapByRelativePath the map of resources by relative path
* @param mapByRelativeUri the map of resources by relative uri
*
******************************************************************************************************************/
public DefaultSiteFinder (@Nonnull final String finderName,
@CheckForNull final Map<String, T> mapByRelativePath,
@CheckForNull final RegexTreeMap<T> mapByRelativeUri)
{
<span class="fc" id="L82"> super(finderName);</span>
<span class="fc" id="L83"> this.mapByRelativePath = mapByRelativePath;</span>
<span class="fc" id="L84"> this.mapByRelativeUri = mapByRelativeUri;</span>
<span class="fc" id="L85"> this.relativePath = null;</span>
<span class="fc" id="L86"> this.relativeUri = null;</span>
<span class="fc" id="L87"> }</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Nonnull
private static <T> DefaultSiteFinder<T> fields (@CheckForNull final Map<String, T> mapByRelativePath,
@CheckForNull final RegexTreeMap<T> mapByRelativeUri,
@CheckForNull final String relativePath,
@CheckForNull final String relativeUri)
{
<span class="fc" id="L100"> Objects.requireNonNull(mapByRelativePath, "Searching for a relativePath, but no map");</span>
<span class="fc" id="L101"> return new DefaultSiteFinder<>(mapByRelativePath, mapByRelativeUri, relativePath, relativeUri);</span>
}
/*******************************************************************************************************************
*
* Clone constructor. See documentation of {@link HierarchicFinderSupport} for more information.
*
* @param other the {@code Finder} to clone
* @param override the override object
*
******************************************************************************************************************/
// FIXME: should be protected