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 public final class Util {
24 public static <T> ListenableFuture<RpcResult<T>> resultRpcSuccessFor(final T output) {
25 return Futures.immediateFuture(RpcResultBuilder.success(output).build());
29 * Method filters qnames based on wildcard strings.
31 * @param list list of SchemaPaths
32 * @param pattern matching pattern
33 * @return list of filtered qnames
35 public static List<SchemaPath> expandQname(final List<SchemaPath> list, final Pattern pattern) {
36 final List<SchemaPath> matchingQnames = new ArrayList<>();
38 for (final SchemaPath notification : list) {
39 final String namespace = notification.getLastComponent().getNamespace().toString();
40 if (pattern.matcher(namespace).matches()) {
41 matchingQnames.add(notification);
44 return matchingQnames;
48 * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html.
50 public static String wildcardToRegex(final String wildcard) {
51 final StringBuilder s = new StringBuilder(wildcard.length());
53 for (final char c : wildcard.toCharArray()) {
61 // escape special regexp-characters