Remove dependency on Google Guava

This commit is contained in:
Jochen Schalanda 2016-02-18 16:00:27 +01:00
parent 8c06992d00
commit 8852380e46
4 changed files with 37 additions and 17 deletions

View File

@ -73,11 +73,6 @@
<version>1.6</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>

View File

@ -1,12 +1,12 @@
package org.graylog2.syslog4j.impl.message.structured;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.graylog2.syslog4j.SyslogConstants;
import org.graylog2.syslog4j.impl.message.AbstractSyslogMessage;
import org.graylog2.syslog4j.util.Preconditions;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -121,7 +121,7 @@ public class StructuredSyslogMessage extends AbstractSyslogMessage implements St
end=stringMessage.indexOf(SyslogConstants.STRUCTURED_DATA_EMPTY_VALUE)+4;
} else {
final Map<String, Map<String, String>> structuredDataMap = Maps.newHashMap();
final Map<String, Map<String, String>> structuredDataMap = new HashMap<String, Map<String, String>>();
while(start < stringMessage.length() && matchChar(stringMessage, start, '[') == start) {
Preconditions.checkArgument(stringMessage.charAt(start) == '[', "Invalid structured data in syslog message '%s'", stringMessage);
@ -129,7 +129,7 @@ public class StructuredSyslogMessage extends AbstractSyslogMessage implements St
Preconditions.checkArgument(end != -1 && stringMessage.charAt(end) == ']', "Invalid structured data in syslog message '%s'", stringMessage);
String key = null;
Map<String, String> keyMap = Maps.newHashMap();
Map<String, String> keyMap = new HashMap<String, String>();
while (start < end) {
if (key == null) {
final int keyEnd = matchChar(stringMessage, ++start, ']', ' '); // Key can be terminated by a space (then more fields to follow) or a ]
@ -138,7 +138,6 @@ public class StructuredSyslogMessage extends AbstractSyslogMessage implements St
} else {
Preconditions.checkArgument(start < stringMessage.length() && stringMessage.charAt(start) == ' ', "Invalid structured data in syslog message '%s'", stringMessage);
start = start + 1; // Start points at the space behind either the key or the previous value
Preconditions.checkArgument(key != null, "Invalid structured data in syslog message '%s'", stringMessage);
final int equalsIndex = stringMessage.indexOf('=', start); // Equals terminates the field name.
Preconditions.checkArgument(equalsIndex != -1, "Invalid structured data in syslog message '%s'", stringMessage);
Preconditions.checkArgument(stringMessage.charAt(equalsIndex + 1) == '"', "Invalid structured data in syslog message '%s'", stringMessage);

View File

@ -0,0 +1,26 @@
package org.graylog2.syslog4j.util;
public final class Preconditions {
private Preconditions() {
}
public static void checkArgument(boolean expression) {
if (!expression) {
throw new IllegalArgumentException();
}
}
public static void checkArgument(boolean expression, Object errorMessage) {
if (!expression) {
throw new IllegalArgumentException(String.valueOf(errorMessage));
}
}
public static void checkArgument(boolean expression,
String errorMessageTemplate,
Object... errorMessageArgs) {
if (!expression) {
throw new IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));
}
}
}

View File

@ -48,13 +48,13 @@ package org.graylog2.syslog4j.test.message.structured;
// Date: Jul 15, 2009
// ---------------------
import com.google.common.collect.Maps;
import junit.framework.TestCase;
import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessage;
import org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent;
import org.junit.Assert;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
public class StructuredSyslogMessageTest extends TestCase
@ -123,7 +123,7 @@ public class StructuredSyslogMessageTest extends TestCase
fail();
} catch (IllegalArgumentException iae) {
//
assertEquals("Invalid structured data in syslog message 'msgId1 [invalid SD] my message!!'", iae.getMessage());
}
}
@ -136,7 +136,7 @@ public class StructuredSyslogMessageTest extends TestCase
fail();
} catch (IllegalArgumentException iae) {
//
assertEquals("Invalid structured data in syslog message 'msgId1 [data1 a=b] my message!!'", iae.getMessage());
}
}
@ -149,7 +149,7 @@ public class StructuredSyslogMessageTest extends TestCase
fail();
} catch (IllegalArgumentException iae) {
//
assertEquals("Invalid structured data in syslog message 'msgId1 [data1 a=\"b] my message!!'", iae.getMessage());
}
}
@ -162,7 +162,7 @@ public class StructuredSyslogMessageTest extends TestCase
fail();
} catch (IllegalArgumentException iae) {
//
assertEquals("Invalid structured data in syslog message 'msgId1 [data1 a=b\"] my message!!'", iae.getMessage());
}
}
@ -214,13 +214,13 @@ public class StructuredSyslogMessageTest extends TestCase
public void testCreateMessage3()
{
final StructuredSyslogMessage message =
new StructuredSyslogMessage("msgId", null, Maps.<String, Map<String, String>>newHashMap(), "my message");
new StructuredSyslogMessage("msgId", null, new HashMap<String, Map<String, String>>(), "my message");
assertEquals("msgId [0@0] my message", message.createMessage());
}
public void testCreateMessage4()
{
final Map<String, Map<String, String>> map = Maps.newHashMap();
final Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
final StructuredSyslogMessage message =
new StructuredSyslogMessage("msgId", null, map, "my message");
assertEquals("msgId [0@0] my message", message.createMessage());