Repository: curator Updated Branches: refs/heads/CURATOR-397 e8c68188d -> dd390b6e1
doc Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/dd390b6e Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/dd390b6e Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/dd390b6e Branch: refs/heads/CURATOR-397 Commit: dd390b6e1b100add85dd9d340dfbae9873b84bd0 Parents: e8c6818 Author: randgalt <[email protected]> Authored: Sat Apr 8 22:35:51 2017 -0500 Committer: randgalt <[email protected]> Committed: Sat Apr 8 22:35:51 2017 -0500 ---------------------------------------------------------------------- .../details/recipes/ModeledCachedNodeImpl.java | 108 +++++++++++++++++++ 1 file changed, 108 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/dd390b6e/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/recipes/ModeledCachedNodeImpl.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/recipes/ModeledCachedNodeImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/recipes/ModeledCachedNodeImpl.java new file mode 100644 index 0000000..cdf967d --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/recipes/ModeledCachedNodeImpl.java @@ -0,0 +1,108 @@ +/** + * 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.details.recipes; + +import org.apache.curator.x.async.modeled.ZPath; +import org.apache.curator.x.async.modeled.recipes.ModeledCachedNode; +import org.apache.zookeeper.data.Stat; +import java.util.Objects; +import java.util.Optional; + +public class ModeledCachedNodeImpl<T> implements ModeledCachedNode<T> +{ + private final ZPath path; + private final Stat stat; + private final Optional<T> data; + + public ModeledCachedNodeImpl(ZPath path) + { + this(path, null, new Stat()); + } + + public ModeledCachedNodeImpl(ZPath path, T data) + { + this(path, data, new Stat()); + } + + public ModeledCachedNodeImpl(ZPath path, T data, Stat stat) + { + this.path = Objects.requireNonNull(path, "path cannot be null"); + this.data = Optional.ofNullable(data); + this.stat = Objects.requireNonNull(stat, "stat cannot be null"); + } + + @Override + public ZPath getPath() + { + return path; + } + + @Override + public Stat getStat() + { + return stat; + } + + @Override + public Optional<T> getData() + { + return data; + } + + @Override + public boolean equals(Object o) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + ModeledCachedNodeImpl<?> that = (ModeledCachedNodeImpl<?>)o; + + if ( !path.equals(that.path) ) + { + return false; + } + //noinspection SimplifiableIfStatement + if ( !stat.equals(that.stat) ) + { + return false; + } + return data.equals(that.data); + } + + @Override + public int hashCode() + { + int result = path.hashCode(); + result = 31 * result + stat.hashCode(); + result = 31 * result + data.hashCode(); + return result; + } + + @Override + public String toString() + { + return "ModeledCachedNode{" + "stat=" + stat + ", data=" + data + '}'; + } +}
