Skip to content

Commit

Permalink
#118 replace commons-lang with guava
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Jun 18, 2014
1 parent 094d8ba commit 97d727b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
4 changes: 0 additions & 4 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@
<groupId>com.buschmais.xo</groupId>
<artifactId>xo.spi</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.buschmais.xo.impl.reflection;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.*;

import com.buschmais.xo.api.XOException;
import com.buschmais.xo.spi.reflection.AnnotatedMethod;
import com.buschmais.xo.spi.reflection.GetPropertyMethod;
import com.buschmais.xo.spi.reflection.SetPropertyMethod;
import com.buschmais.xo.spi.reflection.UserMethod;
import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.*;
import com.google.common.base.CaseFormat;

public final class BeanMethodProvider {

Expand All @@ -34,15 +34,15 @@ public Collection<AnnotatedMethod> getMethods(Class<?> type) {
Class<?>[] parameterTypes = method.getParameterTypes();
Type[] genericParameterTypes = method.getGenericParameterTypes();
if (methodName.startsWith("get") && parameterTypes.length == 0 && !void.class.equals(returnType)) {
String name = StringUtils.uncapitalize(methodName.substring(3));
String name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, methodName.substring(3));
getters.put(name, method);
addType(type, name, returnType, genericReturnType);
} else if (methodName.startsWith("is") && parameterTypes.length == 0 && !void.class.equals(returnType)) {
String name = StringUtils.uncapitalize(methodName.substring(2));
String name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, methodName.substring(2));
getters.put(name, method);
addType(type, name, returnType, genericReturnType);
} else if (methodName.startsWith("set") && parameterTypes.length == 1 && void.class.equals(returnType) && methodName.startsWith("set")) {
String name = StringUtils.uncapitalize(methodName.substring(3));
String name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, methodName.substring(3));
setters.put(name, method);
addType(type, name, parameterTypes[0], genericParameterTypes[0]);
} else {
Expand Down Expand Up @@ -78,11 +78,13 @@ public Collection<AnnotatedMethod> getMethods(Class<?> type) {
private void addType(Class<?> declaringType, String name, Class<?> type, Type genericType) {
Class<?> existingType = types.put(name, type);
if (existingType != null && !existingType.equals(type)) {
throw new XOException("Get and set methods for property '" + name + "' of type '" + declaringType.getName() + "' do not declare the same type: " + existingType.getName() + " <> " + type.getName());
throw new XOException("Get and set methods for property '" + name + "' of type '" + declaringType.getName() + "' do not declare the same type: "
+ existingType.getName() + " <> " + type.getName());
}
Type existingGenericType = genericTypes.put(name, genericType);
if (existingGenericType != null && !existingGenericType.equals(genericType)) {
throw new XOException("Get and set methods for property '" + name + "' of type '" + declaringType.getName() + "' do not declare the same generic type: " + existingGenericType + " <> " + type.getName());
throw new XOException("Get and set methods for property '" + name + "' of type '" + declaringType.getName()
+ "' do not declare the same generic type: " + existingGenericType + " <> " + type.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public Option[] createConfiguration() {
mavenBundle("com.buschmais.xo", "xo.api").versionAsInProject(), //
mavenBundle("com.buschmais.xo", "xo.spi").versionAsInProject(), //
mavenBundle("javax.validation", "validation-api", "1.1.0.Final"), //
mavenBundle("commons-lang", "commons-lang", "2.6"), //
mavenBundle("org.osgi", "org.osgi.compendium", "4.3.1"), //
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.6.0").start(true), //
mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.6.2"), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.buschmais.xo.spi.reflection.AnnotatedMethod;
import com.buschmais.xo.spi.reflection.AnnotatedType;
import com.buschmais.xo.spi.reflection.PropertyMethod;
import com.google.common.base.CaseFormat;
import org.apache.commons.lang.StringUtils;
import org.neo4j.graphdb.DynamicLabel;
import org.neo4j.graphdb.DynamicRelationshipType;
Expand Down Expand Up @@ -87,7 +88,7 @@ public RelationshipMetadata createRelationMetadata(AnnotatedElement<?> annotated
}
}
if (name == null) {
name = StringUtils.capitalize(annotatedElement.getName());
name = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, annotatedElement.getName());
}
RelationshipType relationshipType = new RelationshipType(DynamicRelationshipType.withName(name));
return new RelationshipMetadata(relationshipType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface Group {
@ResultOf
MemberByName getMemberByName(@Parameter("name") String name);

@Cypher("match (g:Group)-[:Members]->(p:Person) where id(g)={this} and p.name={name} return p as member")
@Cypher("match (g:Group)-[:MEMBERS]->(p:Person) where id(g)={this} and p.name={name} return p as member")
public interface MemberByName {
Person getMember();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void oneToOne() {
xoManager.currentTransaction().begin();
assertThat(a.getOneToOne(), equalTo(b1));
assertThat(b1.getOneToOne(), equalTo(a));
assertThat(executeQuery("MATCH (a:A)-[:ImplicitOneToOne]->(b:B) RETURN b").getColumn("b"), hasItem(b1));
assertThat(executeQuery("MATCH (a:A)-[:IMPLICIT_ONE_TO_ONE]->(b:B) RETURN b").getColumn("b"), hasItem(b1));
B b2 = xoManager.create(B.class);
a.setOneToOne(b2);
xoManager.currentTransaction().commit();
xoManager.currentTransaction().begin();
assertThat(a.getOneToOne(), equalTo(b2));
assertThat(b2.getOneToOne(), equalTo(a));
assertThat(b1.getOneToOne(), equalTo(null));
assertThat(executeQuery("MATCH (a:A)-[:ImplicitOneToOne]->(b:B) RETURN b").getColumn("b"), hasItem(b2));
assertThat(executeQuery("MATCH (a:A)-[:IMPLICIT_ONE_TO_ONE]->(b:B) RETURN b").getColumn("b"), hasItem(b2));
a.setOneToOne(null);
xoManager.currentTransaction().commit();
xoManager.currentTransaction().begin();
Expand Down
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down

0 comments on commit 97d727b

Please sign in to comment.