Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructure adapters to avoid unnecessary casts
Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch-si.com>
- Loading branch information
Showing
64 changed files
with
994 additions
and
686 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
177 changes: 0 additions & 177 deletions
177
...ocol-adapter/src/main/java/org/eclipse/ditto/protocoladapter/AbstractAdapterResolver.java
This file was deleted.
Oops, something went wrong.
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
65 changes: 65 additions & 0 deletions
65
protocol-adapter/src/main/java/org/eclipse/ditto/protocoladapter/DefaultPathMatcher.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,65 @@ | ||
/* | ||
* Copyright (c) 2019 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.protocoladapter; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.eclipse.ditto.json.JsonPointer; | ||
|
||
/** | ||
* Utility class for matching {@link Payload} path. | ||
* TODO test | ||
*/ | ||
public final class DefaultPathMatcher implements PathMatcher { | ||
|
||
private final Map<String, Pattern> patterns; | ||
|
||
private DefaultPathMatcher(final Map<String, Pattern> patterns) { | ||
this.patterns = patterns; | ||
} | ||
|
||
public static PathMatcher from(final Map<String, Pattern> patterns) { | ||
return new DefaultPathMatcher(patterns); | ||
} | ||
|
||
public static PathMatcher empty() { | ||
return new DefaultPathMatcher(Collections.emptyMap()); | ||
} | ||
|
||
/** | ||
* Matches a given {@code path} against known schemes and returns the corresponding entity name. | ||
* | ||
* @param path the path to match. | ||
* @return the entity name which matched. | ||
* @throws UnknownPathException if {@code path} matched no known scheme. | ||
*/ | ||
@Override | ||
public String match(final JsonPointer path) { | ||
final Predicate<Map.Entry<String, Pattern>> pathMatchesPattern = entry -> { | ||
final Pattern pattern = entry.getValue(); | ||
final Matcher matcher = pattern.matcher(path); | ||
return matcher.matches(); | ||
}; | ||
|
||
return patterns.entrySet() | ||
.stream() | ||
.filter(pathMatchesPattern) | ||
.findFirst() | ||
.map(Map.Entry::getKey) | ||
.orElseThrow(() -> UnknownPathException.newBuilder(path).build()); | ||
} | ||
} |
Oops, something went wrong.