Repository: curator Updated Branches: refs/heads/CURATOR-397 523f0c809 -> 55df07e6a
Added '0' versions of Typed classes as a convenience so that the same idiom can be used even if there are no real type arguments Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/f32a5fb4 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/f32a5fb4 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/f32a5fb4 Branch: refs/heads/CURATOR-397 Commit: f32a5fb4eeb63251ad769f54f7fee255c2bee61e Parents: 523f0c8 Author: randgalt <[email protected]> Authored: Fri Jun 9 23:54:51 2017 -0500 Committer: randgalt <[email protected]> Committed: Fri Jun 9 23:54:51 2017 -0500 ---------------------------------------------------------------------- .../x/async/modeled/typed/TypedModelSpec0.java | 61 +++++++++++++++++++ .../modeled/typed/TypedModeledFramework0.java | 63 ++++++++++++++++++++ .../x/async/modeled/typed/TypedZPath0.java | 52 ++++++++++++++++ 3 files changed, 176 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java new file mode 100644 index 0000000..dee3506 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.curator.x.async.modeled.typed; + +import org.apache.curator.x.async.modeled.ModelSpec; +import org.apache.curator.x.async.modeled.ModelSpecBuilder; + +/** + * Same as {@link TypedModelSpec}, but with 0 parameters + */ +@FunctionalInterface +public interface TypedModelSpec0<M> +{ + ModelSpec<M> resolved(); + + /** + * Return a new TypedModelSpec using the given model spec builder and typed path. When + * {@link #resolved()} is called the actual model spec is generated with the + * resolved path + * + * @param builder model spec builder + * @param path typed path + * @return new TypedModelSpec + */ + static <M> TypedModelSpec0<M> from(ModelSpecBuilder<M> builder, TypedZPath0 path) + { + return () -> builder.withPath(path.resolved()).build(); + } + + /** + * Return a new TypedModelSpec using the given model spec builder and path. A TypedZPath + * is created from the given full path and When + * {@link #resolved()} is called the actual model spec is generated with the + * resolved path + * + * @param builder model spec builder + * @param pathWithIds typed path + * @return new TypedModelSpec + */ + static <M> TypedModelSpec0<M> from(ModelSpecBuilder<M> builder, String pathWithIds) + { + TypedZPath0 zPath = TypedZPath0.from(pathWithIds); + return () -> builder.withPath(zPath.resolved()).build(); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java new file mode 100644 index 0000000..8c9de04 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.curator.x.async.modeled.typed; + +import org.apache.curator.x.async.AsyncCuratorFramework; +import org.apache.curator.x.async.modeled.ModelSpecBuilder; +import org.apache.curator.x.async.modeled.ModeledFramework; +import org.apache.curator.x.async.modeled.ModeledFrameworkBuilder; + +/** + * Same as {@link TypedModeledFramework}, but with 0 parameters + */ +@FunctionalInterface +public interface TypedModeledFramework0<M> +{ + ModeledFramework<M> resolved(AsyncCuratorFramework client); + + /** + * Return a new TypedModeledFramework using the given modeled framework builder and typed model spec. + * When {@link #resolved(org.apache.curator.x.async.AsyncCuratorFramework)} is called the actual ModeledFramework is generated with the + * resolved model spec + * + * @param frameworkBuilder ModeledFrameworkBuilder + * @param modelSpec TypedModelSpec + * @return new TypedModeledFramework + */ + static <M> TypedModeledFramework0<M> from(ModeledFrameworkBuilder<M> frameworkBuilder, TypedModelSpec0<M> modelSpec) + { + return (client) -> frameworkBuilder.withClient(client).withModelSpec(modelSpec.resolved()).build(); + } + + /** + * Return a new TypedModeledFramework using the given modeled framework builder, model spec builder and a path with ids. + * When {@link #resolved(org.apache.curator.x.async.AsyncCuratorFramework)} is called the actual ModeledFramework is generated with the + * resolved model spec and resolved path + * + * @param frameworkBuilder ModeledFrameworkBuilder + * @param modelSpecBuilder model spec builder + * @param pathWithIds path with {XXXX} parameters + * @return new TypedModeledFramework + */ + static <M> TypedModeledFramework0<M> from(ModeledFrameworkBuilder<M> frameworkBuilder, ModelSpecBuilder<M> modelSpecBuilder, String pathWithIds) + { + TypedModelSpec0<M> typedModelSpec = TypedModelSpec0.from(modelSpecBuilder, pathWithIds); + return (client) -> frameworkBuilder.withClient(client).withModelSpec(typedModelSpec.resolved()).build(); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java new file mode 100644 index 0000000..60576b2 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.curator.x.async.modeled.typed; + +import org.apache.curator.x.async.modeled.ZPath; + +/** + * Same as {@link TypedZPath}, but with 0 parameters. + */ +@FunctionalInterface +public interface TypedZPath0 +{ + ZPath resolved(); + + /** + * Return a TypedZPath using {@link org.apache.curator.x.async.modeled.ZPath#parseWithIds} + * + * @param pathWithIds path to pass to {@link org.apache.curator.x.async.modeled.ZPath#parseWithIds} + * @return TypedZPath + */ + static TypedZPath0 from(String pathWithIds) + { + return from(ZPath.parseWithIds(pathWithIds)); + } + + /** + * Return a TypedZPath + * + * @param path path to use + * @return TypedZPath + */ + static TypedZPath0 from(ZPath path) + { + return path::resolved; + } +}
