Skip to content

Commit

Permalink
Revert TRUNK-2663 Include guava library in core
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jul 28, 2014
1 parent 64e8142 commit de8bf13
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 132 deletions.
4 changes: 0 additions & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.azeckoski</groupId>
<artifactId>reflectutils</artifactId>
Expand Down
7 changes: 4 additions & 3 deletions api/src/main/java/org/openmrs/BaseOpenmrsObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import java.util.UUID;

import com.google.common.base.Objects;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* This is the base implementation of the {@link OpenmrsObject} interface.<br/>
Expand Down Expand Up @@ -99,7 +100,7 @@ public boolean equals(Object obj) {
*/
@Override
public String toString() {
return Objects.toStringHelper(this).add("hashCode", Integer.toHexString(hashCode())).add("uuid", getUuid())
.omitNullValues().toString();
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("hashCode",
Integer.toHexString(hashCode())).append("uuid", getUuid()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
import org.openmrs.util.ConceptMapTypeComparator;
import org.openmrs.util.OpenmrsConstants;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**
* The Hibernate class for Concepts, Drugs, and related classes. <br/>
* <br/>
Expand All @@ -94,14 +90,6 @@ public class HibernateConceptDAO implements ConceptDAO {

private SessionFactory sessionFactory;

private final Function<ConceptName, Concept> transformNameToConcept = new Function<ConceptName, Concept>() {

@Override
public Concept apply(ConceptName name) {
return name.getConcept();
}
};

/**
* Sets the session factory
*
Expand Down Expand Up @@ -596,7 +584,17 @@ public List<Concept> getConcepts(final String name, final Locale loc, final bool

List<ConceptName> names = conceptNameQuery.list();

final List<Concept> concepts = Lists.transform(names, transformNameToConcept);
List<Concept> concepts = transformNamesToConcepts(names);

return concepts;
}

private List<Concept> transformNamesToConcepts(List<ConceptName> names) {
List<Concept> concepts = new ArrayList<Concept>();

for (ConceptName name : names) {
concepts.add(name.getConcept());
}

return concepts;
}
Expand Down Expand Up @@ -1351,14 +1349,11 @@ public List<ConceptSearchResult> getConcepts(final String phrase, final List<Loc

ListPart<ConceptName> names = query.listPart(start, size);

List<ConceptSearchResult> results = Lists.transform(names.getList(),
new Function<ConceptName, ConceptSearchResult>() {

@Override
public ConceptSearchResult apply(ConceptName conceptName) {
return new ConceptSearchResult(phrase, conceptName.getConcept(), conceptName);
}
});
List<ConceptSearchResult> results = new ArrayList<ConceptSearchResult>();

for (ConceptName name : names.getList()) {
results.add(new ConceptSearchResult(phrase, name.getConcept(), name));
}

return results;
}
Expand All @@ -1385,9 +1380,9 @@ private LuceneQuery<ConceptName> newConceptNameLuceneQuery(final String phrase,
final Set<Locale> searchLocales;

if (locales == null) {
searchLocales = Sets.newHashSet(Context.getLocale());
searchLocales = new HashSet<Locale>(Arrays.asList(Context.getLocale()));
} else {
searchLocales = Sets.newHashSet(locales);
searchLocales = new HashSet<Locale>(locales);
}

query.append(newConceptNameQuery(phrase, searchKeywords, searchLocales, searchExactLocale));
Expand Down Expand Up @@ -1717,7 +1712,7 @@ public List<Concept> getConceptsByName(final String name, final Locale locale, f

List<ConceptName> names = conceptNameQuery.list();

final List<Concept> concepts = Lists.transform(names, transformNameToConcept);
final List<Concept> concepts = transformNamesToConcepts(names);

return concepts;
}
Expand Down Expand Up @@ -1752,7 +1747,7 @@ public Concept getConceptByName(final String name) {
} else {
log.warn("Multiple concepts found for '" + name + "'");

List<Concept> concepts = Lists.transform(list, transformNameToConcept);
List<Concept> concepts = transformNamesToConcepts(list);
for (Concept concept : concepts) {
for (ConceptName conceptName : concept.getNames(locale)) {
if (conceptName.getName().equalsIgnoreCase(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.hibernate.search.query.dsl.QueryBuilder;
import org.openmrs.collection.ListPart;

import com.google.common.collect.Sets;

/**
* Performs Lucene queries.
*
Expand Down Expand Up @@ -226,7 +224,7 @@ public LuceneQuery<T> skipSame(String field) {

List<Object> documents = listProjection(idPropertyName, field);

Set<Object> uniqueFieldValues = Sets.newHashSet();
Set<Object> uniqueFieldValues = new HashSet<Object>();
TermsFilter termsFilter = new TermsFilter();
for (Object document : documents) {
Object[] row = (Object[]) document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
*/
package org.openmrs.api.db.hibernate.search;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.List;

import org.apache.commons.lang.Validate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.openmrs.collection.ListPart;
Expand All @@ -33,8 +32,8 @@ public abstract class SearchQuery<T> {
private final Session session;

public SearchQuery(Session session, Class<T> type) {
checkNotNull(session);
checkNotNull(type);
Validate.notNull(session);
Validate.notNull(type);

this.session = session;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/
package org.openmrs.api.handler;

import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.openmrs.Encounter;
Expand All @@ -29,18 +30,14 @@
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.OpenmrsUtil;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
* This handler assigns an encounter to an existing visit, where appropriate, or creates a new one.
*
* @see EncounterVisitHandler
*/
public class ExistingOrNewVisitAssignmentHandler extends ExistingVisitAssignmentHandler implements GlobalPropertyListener {

private static volatile LoadingCache<EncounterType, VisitType> encounterVisitMapping = null;
private static volatile Map<EncounterType, VisitType> encounterVisitMapping;

/**
* @see org.openmrs.api.handler.ExistingVisitAssignmentHandler#getDisplayName(java.util.Locale)
Expand All @@ -51,10 +48,6 @@ public String getDisplayName(Locale locale) {
locale);
}

public static void setEncounterVisitMapping(LoadingCache<EncounterType, VisitType> encounterVisitMapping) {
ExistingOrNewVisitAssignmentHandler.encounterVisitMapping = encounterVisitMapping;
}

/**
* @see org.openmrs.api.handler.ExistingVisitAssignmentHandler#beforeCreateEncounter(org.openmrs.Encounter)
* @should assign existing visit if match found
Expand All @@ -77,27 +70,23 @@ public void beforeCreateEncounter(Encounter encounter) {
visit.setLocation(encounter.getLocation());
visit.setPatient(encounter.getPatient());

try {
if (encounterVisitMapping == null) {
//initial one-time setup
encounterVisitMapping = new HashMap<EncounterType, VisitType>();
Context.getAdministrationService().addGlobalPropertyListener(this);
}

VisitType visitType = encounterVisitMapping.get(encounter.getEncounterType());
if (visitType == null) {
visitType = loadVisitType(encounter.getEncounterType());

if (encounterVisitMapping == null) {
// Create cache of mappings encounter type - visit type
LoadingCache<EncounterType, VisitType> temp = CacheBuilder.newBuilder().build(
new CacheLoader<EncounterType, VisitType>() {

public VisitType load(EncounterType key) throws APIException {
return loadVisitType(key);
}
});
setEncounterVisitMapping(temp);
Context.getAdministrationService().addGlobalPropertyListener(this);
}
//replace reference instead of synchronizing
Map<EncounterType, VisitType> newMap = new HashMap<EncounterType, VisitType>(encounterVisitMapping);
newMap.put(encounter.getEncounterType(), visitType);

VisitType visitType = encounterVisitMapping.get(encounter.getEncounterType());
visit.setVisitType(visitType);
}
catch (ExecutionException e) {
throw new APIException("Error getting mapping encounter type - visit type from cache", e);
encounterVisitMapping = newMap;
}
visit.setVisitType(visitType);

//set stop date time to last millisecond of the encounter day.
visit.setStopDatetime(OpenmrsUtil.getLastMomentOfDay(encounter.getEncounterDatetime()));
Expand Down Expand Up @@ -161,12 +150,12 @@ public boolean supportsPropertyName(String propertyName) {

@Override
public void globalPropertyChanged(GlobalProperty newValue) {
encounterVisitMapping.invalidateAll();
encounterVisitMapping = new HashMap<EncounterType, VisitType>();
}

@Override
public void globalPropertyDeleted(String propertyName) {
encounterVisitMapping.invalidateAll();
encounterVisitMapping = new HashMap<EncounterType, VisitType>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -70,8 +71,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.google.common.collect.Lists;

/**
* Default Implementation of ConceptService service layer classes
*
Expand Down Expand Up @@ -1565,7 +1564,7 @@ private ConceptName cloneConceptName(ConceptName conceptName) {
@Transactional(readOnly = true)
public List<ConceptSearchResult> findConceptAnswers(String phrase, Locale locale, Concept concept) throws APIException {

List<ConceptSearchResult> concepts = getConcepts(phrase, Lists.newArrayList(locale), false, null, null, null, null,
List<ConceptSearchResult> concepts = getConcepts(phrase, Arrays.asList(locale), false, null, null, null, null,
concept, null, null);

return concepts;
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/openmrs/collection/CollectionPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.Collection;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.Validate;

/**
* It is a wrapper for a partial collection, which stores additional info about the current part and
Expand All @@ -35,7 +35,7 @@ public abstract class CollectionPart<E> {

public CollectionPart(Collection<E> collection, Long firstElement, Long maxElements, Long totalElements,
Boolean totalElementsExact) {
Preconditions.checkNotNull(collection);
Validate.notNull(collection);

if (firstElement == null) {
this.firstElement = 0L;
Expand Down
5 changes: 2 additions & 3 deletions api/src/main/java/org/openmrs/logic/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.openmrs.Concept;
import org.openmrs.ConceptDatatype;
import org.openmrs.Obs;
import org.openmrs.api.context.Context;
import org.openmrs.logic.LogicException;

import com.google.common.base.Objects;

/**
* A result from the logic service. A result can be 0-to-n date-values pairs. You can treat the
* result as a list or easily coerce it into a simple value as needed. <br/>
Expand Down Expand Up @@ -843,7 +842,7 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
if (isSingleResult()) {
return Objects.hashCode(datatype);
return new HashCodeBuilder().append(datatype).hashCode();
} else {
return super.hashCode();
}
Expand Down
7 changes: 2 additions & 5 deletions api/src/main/java/org/openmrs/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
import java.util.Set;
import java.util.Vector;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.GlobalProperty;
import org.openmrs.Privilege;
import org.w3c.dom.Document;

import com.google.common.base.Objects;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashCodes;

/**
* Generic module class that openmrs manipulates
*
Expand Down Expand Up @@ -150,7 +147,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return Objects.hashCode(getModuleId());
return new HashCodeBuilder().append(getModuleId()).toHashCode();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/openmrs/util/DoubleRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package org.openmrs.util;

import com.google.common.base.Objects;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* Represents a bounded or unbounded numeric range. By default the range is closed (ake inclusive)
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(low, high);
return new HashCodeBuilder().append(low).append(high).build();
}

}
7 changes: 4 additions & 3 deletions api/src/test/java/org/openmrs/BaseOpenmrsObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public void shouldNotBeEqualWhenFirstIsNull() throws Exception {
public void toString_shouldIncludeUuidIfNotNull() throws Exception {
BaseOpenmrsObject o = new BaseOpenmrsObjectMock();

assertEquals("BaseOpenmrsObjectMock{hashCode=" + Integer.toHexString(o.hashCode()) + ", uuid=" + o.getUuid() + "}",
o.toString());
assertEquals("BaseOpenmrsObjectTest.BaseOpenmrsObjectMock[hashCode=" + Integer.toHexString(o.hashCode()) + ",uuid="
+ o.getUuid() + "]", o.toString());
}

/**
Expand All @@ -186,6 +186,7 @@ public void toString_shouldIncludeHashCodeIfUuidIsNull() throws Exception {

//when
//then
assertEquals("BaseOpenmrsObjectMock{hashCode=" + Integer.toHexString(o.hashCode()) + "}", o.toString());
assertEquals("BaseOpenmrsObjectTest.BaseOpenmrsObjectMock[hashCode=" + Integer.toHexString(o.hashCode())
+ ",uuid=<null>]", o.toString());
}
}

0 comments on commit de8bf13

Please sign in to comment.