-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Placeholder pipeline: Replace Option<String> by dedicated PipelineEle…
…ment. Reason: To add another pipeline function fn:delete that should delete the entire string containing the pipeline, which is not evaluated yet. Signed-off-by: Yufei Cai <yufei.cai@bosch-si.com>
- Loading branch information
Showing
32 changed files
with
703 additions
and
246 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
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
94 changes: 94 additions & 0 deletions
94
...s/src/main/java/org/eclipse/ditto/model/placeholders/ImmutablePipelineElementVisitor.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,94 @@ | ||
/* | ||
* 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.model.placeholders; | ||
|
||
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; | ||
|
||
import java.util.function.Function; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Package-private implementation of {@code PipelineElementVisitor}. | ||
* | ||
* @param <T> type of visitor result. | ||
*/ | ||
final class ImmutablePipelineElementVisitor<T> implements PipelineElementVisitor<T> { | ||
|
||
private final Function<String, T> onResolution; | ||
private final T onIrresolution; | ||
private final T onDeletion; | ||
|
||
private ImmutablePipelineElementVisitor( | ||
final Function<String, T> onResolution, | ||
final T onIrresolution, | ||
final T onDeletion) { | ||
this.onResolution = onResolution; | ||
this.onIrresolution = onIrresolution; | ||
this.onDeletion = onDeletion; | ||
} | ||
|
||
static <T> PipelineElementVisitor.Builder<T> newBuilder() { | ||
return new Builder<>(); | ||
} | ||
|
||
@Override | ||
public T resolved(final String resolved) { | ||
return onResolution.apply(resolved); | ||
} | ||
|
||
@Override | ||
public T unresolved() { | ||
return onIrresolution; | ||
} | ||
|
||
@Override | ||
public T deleted() { | ||
return onDeletion; | ||
} | ||
|
||
private static final class Builder<T> implements PipelineElementVisitor.Builder<T> { | ||
|
||
@Nullable private Function<String, T> onResolution; | ||
@Nullable private T onIrresolution; | ||
@Nullable private T onDeletion; | ||
|
||
private Builder() {} | ||
|
||
@Override | ||
public PipelineElementVisitor<T> build() { | ||
return new ImmutablePipelineElementVisitor<>( | ||
checkNotNull(onResolution, "onResolution"), | ||
checkNotNull(onIrresolution, "onIrresolution"), | ||
checkNotNull(onDeletion, "onDeletion")); | ||
} | ||
|
||
@Override | ||
public PipelineElementVisitor.Builder<T> resolved(final Function<String, T> onResolution) { | ||
this.onResolution = onResolution; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PipelineElementVisitor.Builder<T> unresolved(final T onIrresolution) { | ||
this.onIrresolution = onIrresolution; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PipelineElementVisitor.Builder<T> deleted(final T onDeletion) { | ||
this.onDeletion = onDeletion; | ||
return this; | ||
} | ||
} | ||
} |
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
103 changes: 103 additions & 0 deletions
103
model/placeholders/src/main/java/org/eclipse/ditto/model/placeholders/PipelineElement.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,103 @@ | ||
/* | ||
* 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.model.placeholders; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* An element going through some pipeline of functions. | ||
*/ | ||
public interface PipelineElement extends Iterable<String> { | ||
|
||
/** | ||
* Advance a resolved value to the next stage. Other elements are unchanged. | ||
* | ||
* @param stringProcessor What to do for resolved values. | ||
* @return the pipeline element at the next pipeline stage. | ||
*/ | ||
PipelineElement onResolved(Function<String, PipelineElement> stringProcessor); | ||
|
||
/** | ||
* Advance an unresolved value to the next stage. Other elements are unchanged. | ||
* | ||
* @param nextPipelineElement supplier of the next pipeline element. | ||
* @return the pipeline element at the next pipeline stage. | ||
*/ | ||
PipelineElement onUnresolved(Supplier<PipelineElement> nextPipelineElement); | ||
|
||
/** | ||
* Advance a deleted value to the next stage. Other elements are unchanged. | ||
* | ||
* @param nextPipelineElement supplier of the next pipeline element. | ||
* @return the pipeline element at the next pipeline stage. | ||
*/ | ||
PipelineElement onDeleted(Supplier<PipelineElement> nextPipelineElement); | ||
|
||
/** | ||
* Evaluate this pipeline element by a visitor. | ||
* | ||
* @param visitor the visitor. | ||
* @param <T> the type of results. | ||
* @return the evaluation result. | ||
*/ | ||
<T> T accept(PipelineElementVisitor<T> visitor); | ||
|
||
/** | ||
* Convert a resolved value into another resolved value and leave other elements untouched. | ||
* | ||
* @param mapper what to do about the resolved value. | ||
* @return the mapped resolved value. | ||
*/ | ||
default PipelineElement map(Function<String, String> mapper) { | ||
return onResolved(mapper.andThen(PipelineElement::resolved)); | ||
} | ||
|
||
/** | ||
* Create a builder of a visitor to evaluate pipeline elements. | ||
* | ||
* @param <T> the type of results. | ||
* @return the visitor builder. | ||
*/ | ||
static <T> PipelineElementVisitor.Builder<T> newVisitorBuilder() { | ||
return ImmutablePipelineElementVisitor.newBuilder(); | ||
} | ||
|
||
/** | ||
* Creat a pipeline element containing a resolved value. | ||
* | ||
* @param value the resolved value. | ||
* @return the pipeline element. | ||
*/ | ||
static PipelineElement resolved(final String value) { | ||
return PipelineElementResolved.of(value); | ||
} | ||
|
||
/** | ||
* Get the unique pipeline element signifying deletion of the whole string containing the pipeline. | ||
* | ||
* @return the deleted element. | ||
*/ | ||
static PipelineElement deleted() { | ||
return PipelineElementDeleted.INSTANCE; | ||
} | ||
|
||
/** | ||
* Get the unique pipeline element signifying failed resolution. | ||
* | ||
* @return the unresolved element. | ||
*/ | ||
static PipelineElement unresolved() { | ||
return PipelineElementUnresolved.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.