adapt to core StringUtils (#15781)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel
2023-10-21 12:03:26 +02:00
committed by GitHub
parent bf0cc2ba0f
commit 7d63504eee
3 changed files with 14 additions and 61 deletions

View File

@@ -1,47 +0,0 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.bluetooth.util;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* This is a n string utility class
*
* @author Leo Siepel - Initial contribution
*
*/
@NonNullByDefault
public class StringUtil {
public static String randomString(int length, String charset) {
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
int index = (int) (charset.length() * Math.random());
sb.append(charset.charAt(index));
}
return sb.toString();
}
public static String randomAlphabetic(int length) {
return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz");
}
public static String randomHex(int length) {
return StringUtil.randomString(length, "0123456789ABCDEF");
}
public static String randomAlphanummeric(int length) {
return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz");
}
}