Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Use Guava, not commons-lang3
This allows API classes to be used in GWT without danger of bringing
in commons-lang3, which is not automatically compiled for GWT.
  • Loading branch information
seanf committed Jul 27, 2016
1 parent 6de8f1e commit d97306b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 41 deletions.
27 changes: 15 additions & 12 deletions zanata-common-api/pom.xml
Expand Up @@ -42,6 +42,21 @@

<plugins>

<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<bannedDependencies>
<excludes combine.children="append">
<!-- For GWT compatibility, stick to guava -->
<exclude>commons-lang:commons-lang</exclude>
<exclude>org.apache.commons:commons-lang3</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</plugin>

<!--
This config is used when running mvn enunciate:docs.
Docs will be generated in target/enunciate/build/docs/rest-api-docs.
Expand Down Expand Up @@ -305,12 +320,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

<dependency>
<!-- we still need this because the annotation must present in the
interface/dto otherwise RESTEasy server implementation won't work-->
Expand Down Expand Up @@ -361,15 +370,9 @@
<artifactId>spock-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
Expand Up @@ -22,7 +22,6 @@

import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;
import static org.apache.commons.lang3.StringUtils.isBlank;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -90,7 +89,7 @@ private static Set<String> buildExtensionsList(boolean source) {
}

public static @Nullable DocumentType getByName(@Nullable String name) {
if (isBlank(name)) {
if (name == null || name.isEmpty()) {
return null;
}
try {
Expand Down
Expand Up @@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.List;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.zanata.common.DocumentType.*;

@XmlType(name = "projectTypeType")
Expand All @@ -42,7 +41,7 @@ public enum ProjectType {
*/
public static ProjectType getValueOf(String projectType) throws Exception {
// TODO change all values to upper case and use ProjectType.valueOf(projectType)
if (isBlank(projectType)) {
if (projectType == null || projectType.isEmpty()) {
throw new Exception("No project type specified");
}
for (ProjectType pt : ProjectType.values()) {
Expand Down
9 changes: 5 additions & 4 deletions zanata-common-api/src/main/java/org/zanata/rest/ElemSet.java
@@ -1,12 +1,13 @@
package org.zanata.rest;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

// NB don't add state in subclasses, or you will break the equals method
public abstract class ElemSet<T> implements Set<T> {

Expand All @@ -17,7 +18,7 @@ public abstract class ElemSet<T> implements Set<T> {
public ElemSet(String values) {
impl = new HashSet<T>();
if (values != null) {
String[] splitValues = StringUtils.split(values, ';');
Iterable<String> splitValues = Splitter.on(';').split(values);
for (String val : splitValues) {
T elem = valueOfElem(val);
add(elem);
Expand Down Expand Up @@ -92,7 +93,7 @@ public <T> T[] toArray(T[] a) {

@Override
public String toString() {
return StringUtils.join(this, ";");
return Joiner.on(';').join(this);
}

// method is final because equals is final
Expand Down
@@ -1,13 +1,13 @@
package org.zanata.rest.dto.extensions.gettext;

import java.io.Serializable;
import java.util.Objects;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;

import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonPropertyOrder;
import org.zanata.rest.dto.DTOUtil;

Expand Down Expand Up @@ -68,8 +68,8 @@ public boolean equals(Object obj) {
return false;

HeaderEntry other = (HeaderEntry) obj;
return StringUtils.equals(this.key, other.key)
&& StringUtils.equals(this.value, other.value);
return Objects.equals(this.key, other.key)
&& Objects.equals(this.value, other.value);
}

@Override
Expand Down
Expand Up @@ -6,16 +6,16 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.zanata.rest.dto.DTOUtil;
import org.zanata.rest.dto.ExtensionValue;

import javax.annotation.Nonnull;

public class ExtensionSet<T extends ExtensionValue> extends
AbstractCollection<T> implements Serializable {

private static final long serialVersionUID = 1L;
private Map<Class<?>, T> extensions = new LinkedHashMap<Class<?>, T>();
private @Nonnull Map<Class<?>, T> extensions = new LinkedHashMap<>();

@Override
public Iterator<T> iterator() {
Expand Down Expand Up @@ -57,27 +57,20 @@ public <E extends T> E findOrAddByType(Class<E> clz) {
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
} else if (!(obj instanceof ExtensionSet)) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || !(o instanceof ExtensionSet)) {
return false;
} else {
@SuppressWarnings("rawtypes")
ExtensionSet other = (ExtensionSet) obj;

return new EqualsBuilder()
.append(this.extensions, other.extensions).isEquals();
}
ExtensionSet<?> that = (ExtensionSet<?>) o;
return extensions.equals(that.extensions);
}

@Override
public int hashCode() {
HashCodeBuilder hcBuilder = new HashCodeBuilder(15, 67);
for (T t : this) {
hcBuilder.append(t);
}
return hcBuilder.toHashCode();
return extensions.hashCode();
}

}

0 comments on commit d97306b

Please sign in to comment.