From 6d7b2b70e8143febbd17a3b174789f436f4e42f1 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 21 Sep 2019 22:54:50 +0200 Subject: [PATCH] Add util.Consumer and use it in StateDescriptorGraph --- .../smack/fsm/StateDescriptorGraph.java | 15 +++++------- .../org/jivesoftware/smack/util/Consumer.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/util/Consumer.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptorGraph.java b/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptorGraph.java index 661c35426..bc4fa7ca8 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptorGraph.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptorGraph.java @@ -31,6 +31,7 @@ import java.util.Set; import java.util.logging.Logger; import org.jivesoftware.smack.fsm.AbstractXmppStateMachineConnection.DisconnectedStateDescriptor; +import org.jivesoftware.smack.util.Consumer; import org.jivesoftware.smack.util.MultiMap; /** @@ -330,7 +331,8 @@ public class StateDescriptorGraph { return res; } - private static void dfsVisit(GraphVertex vertex, DfsFinishedVertex dfsFinishedVertex, DfsEdgeFound dfsEdgeFound) { + private static void dfsVisit(GraphVertex vertex, Consumer> dfsFinishedVertex, + DfsEdgeFound dfsEdgeFound) { vertex.color = GraphVertex.VertexColor.grey; final int totalEdgeCount = vertex.getOutgoingEdges().size(); @@ -349,11 +351,12 @@ public class StateDescriptorGraph { vertex.color = GraphVertex.VertexColor.black; if (dfsFinishedVertex != null) { - dfsFinishedVertex.onVertexFinished(vertex); + dfsFinishedVertex.accept(vertex); } } - private static void dfs(Collection> vertexes, DfsFinishedVertex dfsFinishedVertex, DfsEdgeFound dfsEdgeFound) { + private static void dfs(Collection> vertexes, Consumer> dfsFinishedVertex, + DfsEdgeFound dfsEdgeFound) { for (GraphVertex vertex : vertexes) { if (vertex.color == GraphVertex.VertexColor.white) { dfsVisit(vertex, dfsFinishedVertex, dfsEdgeFound); @@ -407,12 +410,6 @@ public class StateDescriptorGraph { dotOut.append("}\n"); } - // TODO: Replace with java.util.function.Consumer> once Smack's minimum Android SDK level is 24 or higher. - private interface DfsFinishedVertex { - void onVertexFinished(GraphVertex vertex); - } - - // TODO: Replace with java.util.function.Consumer> once Smack's minimum Android SDK level is 24 or higher. private interface DfsEdgeFound { void onEdgeFound(GraphVertex from, GraphVertex to, int edgeId, int totalEdgeCount); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/Consumer.java b/smack-core/src/main/java/org/jivesoftware/smack/util/Consumer.java new file mode 100644 index 000000000..eb1419bf6 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/Consumer.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2019 Florian Schmaus + * + * Licensed 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.jivesoftware.smack.util; + +// TODO: Replace with java.util.function.Consumer once Smack's minimum Android SDK level is 24 or higher. +public interface Consumer { + + void accept(T t); + +}