Skip to content

Commit

Permalink
gchq#2914 Issue: Remove redundant constants class
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrijesh committed Mar 12, 2023
1 parent ca465ec commit 43b9968
Show file tree
Hide file tree
Showing 54 changed files with 186 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.user.User;

import java.nio.charset.StandardCharsets;
import java.util.List;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void canBeJsonSerialisedAndDeserialised() throws Exception {
assertEquals("{" +
"\"class\":\"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," +
"\"userPredicate\":{\"class\":\"uk.gov.gchq.gaffer.access.predicate.user.DefaultUserPredicate\",\"creatingUserId\":\"TestUser\",\"auths\":[\"auth1\",\"auth2\"]}" +
"}", new String(bytes, CommonConstants.UTF_8));
"}", new String(bytes, StandardCharsets.UTF_8));
assertEquals(predicate, JSONSerialiser.deserialise(bytes, AccessPredicate.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.user.User;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

Expand All @@ -40,7 +41,7 @@ public void canBeJsonSerialisedAndDeserialised() throws Exception {
final byte[] bytes = JSONSerialiser.serialise(predicate);
assertEquals("{" +
"\"class\":\"uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate\"" +
"}", new String(bytes, CommonConstants.UTF_8));
"}", new String(bytes, StandardCharsets.UTF_8));
assertEquals(predicate, JSONSerialiser.deserialise(bytes, NoAccessPredicate.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.user.User;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -40,7 +41,7 @@ public void canBeJsonSerialisedAndDeserialised() throws Exception {
final byte[] bytes = JSONSerialiser.serialise(predicate);
assertEquals("{" +
"\"class\":\"uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate\"" +
"}", new String(bytes, CommonConstants.UTF_8));
"}", new String(bytes, StandardCharsets.UTF_8));
assertEquals(predicate, JSONSerialiser.deserialise(bytes, UnrestrictedAccessPredicate.class));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import uk.gov.gchq.koryphe.serialisation.json.SimpleClassNameIdResolver;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -44,11 +44,7 @@ private StringUtil() {
* @return the resulting string
*/
public static String toString(final byte[] bytes) {
try {
return new String(bytes, CommonConstants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException("Unable to convert bytes to string", e);
}
return new String(bytes, StandardCharsets.UTF_8);
}

/**
Expand All @@ -61,11 +57,7 @@ public static byte[] toBytes(final String string) {
if (null == string) {
return new byte[0];
}
try {
return string.getBytes(CommonConstants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException("Unable to convert bytes to string", e);
}
return string.getBytes(StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import uk.gov.gchq.gaffer.access.ResourceType;
import uk.gov.gchq.gaffer.access.predicate.AccessPredicate;
import uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.StringUtil;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate;
Expand All @@ -40,6 +39,7 @@

import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -54,7 +54,7 @@
@JsonDeserialize(builder = NamedViewDetail.Builder.class)
public class NamedViewDetail implements AccessControlledResource, Serializable {
private static final long serialVersionUID = -8354836093398004122L;
private static final String CHARSET_NAME = CommonConstants.UTF_8;
private static final String CHARSET_NAME = String.valueOf(StandardCharsets.UTF_8);
private String name;
private String view;
private String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.data.elementdefinition.ElementDefinitions;
import uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException;
import uk.gov.gchq.koryphe.serialisation.json.JsonSimpleClassName;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -100,13 +99,9 @@ public byte[] toCompactJson() throws SchemaException {

@Override
public String toString() {
try {
return new ToStringBuilder(this)
.append(new String(toJson(true), CommonConstants.UTF_8))
.build();
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new ToStringBuilder(this)
.append(new String(toJson(true), StandardCharsets.UTF_8))
.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import uk.gov.gchq.gaffer.access.predicate.AccessPredicate;
import uk.gov.gchq.gaffer.access.predicate.DefaultAccessPredicateTest;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.user.User;

import java.nio.charset.StandardCharsets;
import java.util.List;

import static java.util.Arrays.asList;
Expand All @@ -44,7 +44,7 @@ public void canBeJsonSerialisedAndDeserialised() throws Exception {
"\"creatingUserId\":\"TestUser\"," +
"\"auths\":[\"auth1\",\"auth2\"]" +
"}" +
"}", new String(bytes, CommonConstants.UTF_8));
"}", new String(bytes, StandardCharsets.UTF_8));
assertEquals(predicate, JSONSerialiser.deserialise(bytes, NamedViewWriteAccessPredicate.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.slf4j.LoggerFactory;

import uk.gov.gchq.gaffer.commonutil.CollectionUtil;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.iterable.AlwaysValid;
import uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable;
import uk.gov.gchq.gaffer.commonutil.iterable.TransformIterable;
Expand All @@ -42,7 +41,7 @@
import uk.gov.gchq.koryphe.impl.predicate.AreIn;
import uk.gov.gchq.koryphe.serialisation.json.SimpleClassNameIdResolver;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -167,11 +166,7 @@ protected Object transform(final Element edge) {
try {
return JSONSerialiser.deserialise(resultBytes, resultClass);
} catch (final SerialisationException e) {
try {
LOGGER.error("Unable to deserialise result: {}", new String(resultBytes, CommonConstants.UTF_8), e);
} catch (final UnsupportedEncodingException e1) {
throw new RuntimeException(e);
}
LOGGER.error("Unable to deserialise result: {}", new String(resultBytes, StandardCharsets.UTF_8), e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.operation.OperationChain;
import uk.gov.gchq.gaffer.user.User;

import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
* POJO containing details of a Gaffer job.
*/
public class JobDetail implements Serializable {
private static final long serialVersionUID = -1677432285205724269L;
private static final String CHARSET_NAME = CommonConstants.UTF_8;
private static final String CHARSET_NAME = String.valueOf(StandardCharsets.UTF_8);
private String parentJobId;
private Repeat repeat;
private String jobId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.commons.lang3.StringUtils;

import uk.gov.gchq.gaffer.access.predicate.AccessPredicate;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.Required;
import uk.gov.gchq.gaffer.exception.SerialisationException;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
Expand All @@ -37,6 +36,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class AddNamedOperation implements Operation, Operations<Operation> {
private AccessPredicate readAccessPredicate;
private AccessPredicate writeAccessPredicate;

private static final String CHARSET_NAME = CommonConstants.UTF_8;
private static final String CHARSET_NAME = String.valueOf(StandardCharsets.UTF_8);

public boolean isOverwriteFlag() {
return overwriteFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import uk.gov.gchq.gaffer.access.AccessControlledResource;
import uk.gov.gchq.gaffer.access.ResourceType;
import uk.gov.gchq.gaffer.access.predicate.AccessPredicate;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.exception.SerialisationException;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
Expand All @@ -39,6 +38,7 @@
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -51,7 +51,7 @@
public class NamedOperationDetail implements AccessControlledResource, Serializable {

private static final long serialVersionUID = -8831783492657131469L;
private static final String CHARSET_NAME = CommonConstants.UTF_8;
private static final String CHARSET_NAME = String.valueOf(StandardCharsets.UTF_8);
private String operationName;
private List<String> labels;
private String inputType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.commons.lang3.exception.CloneFailedException;

import uk.gov.gchq.gaffer.access.predicate.AccessPredicate;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.Required;
import uk.gov.gchq.gaffer.data.elementdefinition.view.View;
import uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail;
Expand All @@ -38,6 +37,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -51,7 +51,7 @@
@Since("1.3.0")
@Summary("Adds a new named view")
public class AddNamedView implements Operation {
private static final String CHARSET_NAME = CommonConstants.UTF_8;
private static final String CHARSET_NAME = String.valueOf(StandardCharsets.UTF_8);
@Required
private String name;
@Required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package uk.gov.gchq.gaffer.serialisation;

import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.exception.SerialisationException;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
Expand All @@ -30,7 +30,7 @@ public class DateSerialiser extends ToBytesViaStringDeserialiser<Date> {
private static final long serialVersionUID = 5647756843689779437L;

public DateSerialiser() {
super(CommonConstants.ISO_8859_1_ENCODING);
super(String.valueOf(StandardCharsets.ISO_8859_1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package uk.gov.gchq.gaffer.serialisation;


import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.exception.SerialisationException;

import java.nio.charset.StandardCharsets;

/**
* @deprecated this is not very efficient and should only be used for compatibility
* reasons. For new properties use {@link uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser}
Expand All @@ -29,7 +30,7 @@ public class DoubleSerialiser extends ToBytesViaStringDeserialiser<Double> {
private static final long serialVersionUID = 5647756843689779437L;

public DoubleSerialiser() {
super(CommonConstants.ISO_8859_1_ENCODING);
super(String.valueOf(StandardCharsets.ISO_8859_1));
}

@Override
Expand Down
Loading

0 comments on commit 43b9968

Please sign in to comment.