2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.messagebus.app.util;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.regex.Pattern;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 @Deprecated(forRemoval = true)
21 public final class Util {
25 public static <T> ListenableFuture<RpcResult<T>> resultRpcSuccessFor(final T output) {
26 return Futures.immediateFuture(RpcResultBuilder.success(output).build());
30 * Method filters qnames based on wildcard strings.
32 * @param list list of SchemaPaths
33 * @param pattern matching pattern
34 * @return list of filtered qnames
36 public static List<SchemaPath> expandQname(final List<SchemaPath> list, final Pattern pattern) {
37 final List<SchemaPath> matchingQnames = new ArrayList<>();
39 for (final SchemaPath notification : list) {
40 final String namespace = notification.getLastComponent().getNamespace().toString();
41 if (pattern.matcher(namespace).matches()) {
42 matchingQnames.add(notification);
45 return matchingQnames;
49 * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html.
51 public static String wildcardToRegex(final String wildcard) {
52 final StringBuilder s = new StringBuilder(wildcard.length());
54 for (final char c : wildcard.toCharArray()) {
62 // escape special regexp-characters