-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
111 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 25 additions & 15 deletions
40
modules/core/core-api/src/main/java/com/enonic/xp/site/SiteConfigs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,92 @@ | ||
package com.enonic.xp.site; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Function; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
import com.enonic.xp.app.ApplicationKey; | ||
import com.enonic.xp.support.AbstractImmutableEntityList; | ||
|
||
@PublicApi | ||
public class SiteConfigs | ||
public final class SiteConfigs | ||
extends AbstractImmutableEntityList<SiteConfig> | ||
{ | ||
private final ImmutableMap<ApplicationKey, SiteConfig> applicationsByName; | ||
private static final SiteConfigs EMPTY = new SiteConfigs( ImmutableList.of() ); | ||
|
||
private SiteConfigs( final ImmutableList<SiteConfig> list ) | ||
{ | ||
super( list ); | ||
this.applicationsByName = | ||
list.stream().collect( ImmutableMap.toImmutableMap( SiteConfig::getApplicationKey, Function.identity() ) ); | ||
} | ||
|
||
public SiteConfig get( final ApplicationKey applicationKey ) | ||
{ | ||
return this.applicationsByName.get( applicationKey ); | ||
return list.stream().filter( sc -> applicationKey.equals( sc.getApplicationKey() ) ).findAny().orElse( null ); | ||
} | ||
|
||
@Deprecated | ||
public SiteConfig get( final String applicationKey ) | ||
{ | ||
return get( ApplicationKey.from( applicationKey ) ); | ||
} | ||
|
||
@Deprecated | ||
public ImmutableSet<ApplicationKey> getApplicationKeys() | ||
{ | ||
return applicationsByName.keySet(); | ||
return list.stream().map( SiteConfig::getApplicationKey ).collect( ImmutableSet.toImmutableSet() ); | ||
} | ||
|
||
public static SiteConfigs empty() | ||
{ | ||
return new SiteConfigs( ImmutableList.of() ); | ||
return EMPTY; | ||
} | ||
|
||
public static SiteConfigs from( final SiteConfig... siteConfigs ) | ||
{ | ||
return new SiteConfigs( ImmutableList.copyOf( siteConfigs ) ); | ||
return fromInternal( ImmutableList.copyOf( siteConfigs ) ); | ||
} | ||
|
||
public static SiteConfigs from( final Iterable<? extends SiteConfig> siteConfigs ) | ||
{ | ||
return new SiteConfigs( ImmutableList.copyOf( siteConfigs ) ); | ||
return fromInternal( ImmutableList.copyOf( siteConfigs ) ); | ||
} | ||
|
||
public static SiteConfigs from( final Collection<? extends SiteConfig> siteConfigs ) | ||
{ | ||
return new SiteConfigs( ImmutableList.copyOf( siteConfigs ) ); | ||
return fromInternal( ImmutableList.copyOf( siteConfigs ) ); | ||
} | ||
|
||
private static SiteConfigs fromInternal( final ImmutableList<SiteConfig> siteConfigs ) | ||
{ | ||
if ( siteConfigs.isEmpty() ) | ||
{ | ||
return EMPTY; | ||
} | ||
else | ||
{ | ||
return new SiteConfigs( siteConfigs ); | ||
} | ||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder | ||
public static final class Builder | ||
{ | ||
private final ImmutableList.Builder<SiteConfig> builder = ImmutableList.builder(); | ||
|
||
public Builder add( SiteConfig siteConfig ) | ||
public Builder add( final SiteConfig siteConfig ) | ||
{ | ||
builder.add( siteConfig ); | ||
return this; | ||
} | ||
|
||
public SiteConfigs build() | ||
{ | ||
return new SiteConfigs( builder.build() ); | ||
return fromInternal( builder.build() ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.