Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2d1dd7
commit 9d45a9a
Showing
3 changed files
with
73 additions
and
29 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
47 changes: 47 additions & 0 deletions
47
...re-ide-app/src/main/java/org/eclipse/che/ide/statepersistance/StateComponentRegistry.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.statepersistance; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import org.eclipse.che.ide.api.statepersistance.StateComponent; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import static java.util.Comparator.comparingInt; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
@Singleton | ||
class StateComponentRegistry { | ||
|
||
private final Set<StateComponent> persistenceComponents; | ||
|
||
@Inject | ||
StateComponentRegistry(Set<StateComponent> persistenceComponents) { | ||
this.persistenceComponents = persistenceComponents; | ||
} | ||
|
||
/** Returns list of persistence state components sorted by execution priority. */ | ||
List<StateComponent> getComponents() { | ||
return persistenceComponents.stream() | ||
.sorted(comparingInt(StateComponent::getPriority).reversed()) | ||
.collect(toList()); | ||
} | ||
|
||
Optional<StateComponent> getComponentById(String id) { | ||
return persistenceComponents.stream() | ||
.filter(component -> component.getId().equals(id)) | ||
.findAny(); | ||
} | ||
} |
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