1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 02:27:58 +01:00

Make StringEncoder generic

This commit is contained in:
Florian Schmaus 2018-08-21 09:16:11 +02:00
parent e91a8336f6
commit 7374caefef
7 changed files with 22 additions and 22 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import org.jivesoftware.smack.util.stringencoder.StringEncoder;
import android.util.Base64;
public final class AndroidBase64UrlSafeEncoder implements StringEncoder {
public final class AndroidBase64UrlSafeEncoder implements StringEncoder<String> {
private static AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();

View file

@ -34,7 +34,7 @@ import org.jivesoftware.smack.util.StringUtils;
*/
public class Base32 {
private static final StringEncoder base32Stringencoder = new StringEncoder() {
private static final StringEncoder<String> base32Stringencoder = new StringEncoder<String>() {
@Override
public String encode(String string) {
@ -49,7 +49,7 @@ public class Base32 {
};
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678";
public static StringEncoder getStringEncoder() {
public static StringEncoder<String> getStringEncoder() {
return base32Stringencoder;
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2015 Florian Schmaus
* Copyright © 2014-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,14 +20,14 @@ import org.jivesoftware.smack.util.Objects;
public class Base64UrlSafeEncoder {
private static StringEncoder base64UrlSafeEncoder;
private static StringEncoder<String> base64UrlSafeEncoder;
public static void setEncoder(StringEncoder encoder) {
public static void setEncoder(StringEncoder<String> encoder) {
Objects.requireNonNull(encoder, "encoder must no be null");
base64UrlSafeEncoder = encoder;
}
public static StringEncoder getStringEncoder() {
public static StringEncoder<String> getStringEncoder() {
return base64UrlSafeEncoder;
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Florian Schmaus
* Copyright 2013-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,20 +21,20 @@ package org.jivesoftware.smack.util.stringencoder;
*
* @author Florian Schmaus
*/
public interface StringEncoder {
public interface StringEncoder<O> {
/**
* Encodes an string to another representation.
* Encodes an object to another representation.
*
* @param string
* @param object the object to encode.
* @return the encoded String
*/
String encode(String string);
String encode(O object);
/**
* Decodes an string back to it's initial representation.
* Decodes a string back to it's initial representation.
*
* @param string
* @return the decoded String
* @param string the string to decode.
* @return the decoded object
*/
String decode(String string);
O decode(String string);
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2011-2014 Florian Schmaus
* Copyright © 2011-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
private static final Logger LOGGER = Logger.getLogger(SimpleDirectoryPersistentCache.class.getName());
private final File cacheDir;
private final StringEncoder filenameEncoder;
private final StringEncoder<String> filenameEncoder;
/**
* Creates a new SimpleDirectoryPersistentCache Object. Make sure that the
@ -69,7 +69,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
* @param cacheDir The directory where the cache will be stored.
* @param filenameEncoder Encodes the node string into a filename.
*/
public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder filenameEncoder) {
public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder<String> filenameEncoder) {
if (!cacheDir.exists())
throw new IllegalStateException("Cache directory \"" + cacheDir + "\" does not exist");
if (!cacheDir.isDirectory())

View file

@ -75,7 +75,7 @@ public class EntityCapsManagerTest extends InitExtensions {
assertTrue(di.containsDuplicateIdentities());
}
private static void testSimpleDirectoryCache(StringEncoder stringEncoder) throws IOException {
private static void testSimpleDirectoryCache(StringEncoder<String> stringEncoder) throws IOException {
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory());
EntityCapsManager.setPersistentCache(cache);

View file

@ -33,7 +33,7 @@ import org.jivesoftware.smack.util.stringencoder.StringEncoder;
*
* @author Robin Collier
*/
public final class Java7Base64UrlSafeEncoder implements StringEncoder {
public final class Java7Base64UrlSafeEncoder implements StringEncoder<String> {
private static final Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();