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.impl;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.UUID;
14 import java.util.concurrent.Future;
15 import java.util.regex.Pattern;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import com.google.common.util.concurrent.Futures;
24 public final class Util {
26 public static String getUUIDIdent(){
27 UUID uuid = UUID.randomUUID();
28 return uuid.toString();
31 public static <T> Future<RpcResult<T>> resultRpcSuccessFor(final T output) {
32 final RpcResult<T> result = RpcResultBuilder.success(output).build();
33 return Futures.immediateFuture(result);
37 * Method filters qnames based on wildcard strings
40 * @param patterh matching pattern
41 * @return list of filtered qnames
43 public static List<SchemaPath> expandQname(final List<SchemaPath> list, final Pattern pattern) {
44 final List<SchemaPath> matchingQnames = new ArrayList<>();
46 for (final SchemaPath notification : list) {
47 final String namespace = notification.getLastComponent().getNamespace().toString();
48 if (pattern.matcher(namespace).matches()) {
49 matchingQnames.add(notification);
52 return matchingQnames;
56 * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html
60 public static String wildcardToRegex(final String wildcard){
61 final StringBuffer s = new StringBuffer(wildcard.length());
63 for (final char c : wildcard.toCharArray()) {
71 // escape special regexp-characters