Fix string comparisons

This commit is contained in:
Graham Triggs 2017-09-18 18:31:09 +01:00
parent 351e363047
commit d594f8ac11
9 changed files with 16 additions and 12 deletions

View file

@ -191,7 +191,7 @@ public class DumpTestController extends FreemarkerHttpServlet {
} }
public String getName(String which) { public String getName(String which) {
return which == "first" ? firstName : lastName; return "first".equals(which) ? firstName : lastName;
} }
public String getMiddleName() { public String getMiddleName() {

View file

@ -17,6 +17,7 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -86,7 +87,7 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
for(Literal l: labels) { for(Literal l: labels) {
String languageTag = l.getLanguage(); String languageTag = l.getLanguage();
String languageName = ""; String languageName = "";
if(languageTag == "") { if(StringUtils.isEmpty(languageTag)) {
languageName = "untyped"; languageName = "untyped";
} }
else if(localeCodeToNameMap.containsKey(languageTag)) { else if(localeCodeToNameMap.containsKey(languageTag)) {
@ -95,7 +96,7 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
log.warn("This language tag " + languageTag + " does not have corresponding name in the system and was not processed"); log.warn("This language tag " + languageTag + " does not have corresponding name in the system and was not processed");
} }
if(languageName != "") { if(!StringUtils.isEmpty(languageName)) {
if(!labelsHash.containsKey(languageName)) { if(!labelsHash.containsKey(languageName)) {
labelsHash.put(languageName, new ArrayList<LabelInformation>()); labelsHash.put(languageName, new ArrayList<LabelInformation>());
} }

View file

@ -37,7 +37,7 @@ public class VClassGroupDaoFiltering extends BaseFiltering implements VClassGrou
public LinkedHashMap<String, VClassGroup> getClassGroupMap() { public LinkedHashMap<String, VClassGroup> getClassGroupMap() {
LinkedHashMap<String, VClassGroup> lhm = innerDao.getClassGroupMap(); LinkedHashMap<String, VClassGroup> lhm = innerDao.getClassGroupMap();
Set<String> keys = lhm.keySet(); Set<String> keys = lhm.keySet();
for( Object key : keys){ for( String key : keys){
VClassGroup vcg = (VClassGroup)lhm.get(key); VClassGroup vcg = (VClassGroup)lhm.get(key);
if( vcg == null || !filters.getVClassGroupFilter().fn(vcg) ){ if( vcg == null || !filters.getVClassGroupFilter().fn(vcg) ){
lhm.remove(key); lhm.remove(key);

View file

@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -291,7 +292,7 @@ public class RDFServiceGraph implements GraphWithPerform {
literalBuff.append("\""); literalBuff.append("\"");
if (node.getLiteralDatatypeURI() != null) { if (node.getLiteralDatatypeURI() != null) {
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
} else if (node.getLiteralLanguage() != null && node.getLiteralLanguage() != "") { } else if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
literalBuff.append("@").append(node.getLiteralLanguage()); literalBuff.append("@").append(node.getLiteralLanguage());
} }
return literalBuff.toString(); return literalBuff.toString();

View file

@ -8,6 +8,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.utils.http.HttpClientFactory; import edu.cornell.mannlib.vitro.webapp.utils.http.HttpClientFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -233,7 +234,7 @@ public class SparqlGraph implements GraphWithPerform {
literalBuff.append("\""); literalBuff.append("\"");
if (node.getLiteralDatatypeURI() != null) { if (node.getLiteralDatatypeURI() != null) {
literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">");
} else if (node.getLiteralLanguage() != null && node.getLiteralLanguage() != "") { } else if (!StringUtils.isEmpty(node.getLiteralLanguage())) {
literalBuff.append("@").append(node.getLiteralLanguage()); literalBuff.append("@").append(node.getLiteralLanguage());
} }
return literalBuff.toString(); return literalBuff.toString();

View file

@ -18,6 +18,7 @@ import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -251,7 +252,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
//for selection when creating a new label //for selection when creating a new label
//The assumption here is we don't want to allow the user to add a new label when a label //The assumption here is we don't want to allow the user to add a new label when a label
//already exists in that language //already exists in that language
if(languageName != "untyped" && !existingLabelsLanguageNames.contains(languageName)) { if(!"untyped".equals(languageName) && !existingLabelsLanguageNames.contains(languageName)) {
availableLocales.add(localeInfo); availableLocales.add(localeInfo);
} }
} }
@ -302,7 +303,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
for(Literal l: labels) { for(Literal l: labels) {
String languageTag = l.getLanguage(); String languageTag = l.getLanguage();
String languageName = ""; String languageName = "";
if(languageTag == "") { if(StringUtils.isEmpty(languageTag)) {
languageName = "untyped"; languageName = "untyped";
} }
else if(localeCodeToNameMap.containsKey(languageTag)) { else if(localeCodeToNameMap.containsKey(languageTag)) {
@ -311,7 +312,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
log.warn("This language tag " + languageTag + " does not have corresponding name in the system and was not processed"); log.warn("This language tag " + languageTag + " does not have corresponding name in the system and was not processed");
} }
if(languageName != "") { if(!StringUtils.isEmpty(languageName)) {
if(!labelsHash.containsKey(languageName)) { if(!labelsHash.containsKey(languageName)) {
labelsHash.put(languageName, new ArrayList<LabelInformation>()); labelsHash.put(languageName, new ArrayList<LabelInformation>());
} }

View file

@ -114,7 +114,7 @@ public class ManagePagePreprocessor extends
for(String uriName: uriKeys) { for(String uriName: uriKeys) {
//these values should never be overwritten or deleted //these values should never be overwritten or deleted
//if(uriName != "page" && uriName != "menuItem" && !uriName.startsWith("dataGetter")) { //if(uriName != "page" && uriName != "menuItem" && !uriName.startsWith("dataGetter")) {
if(uriName != "page") { if(!"page".equals(uriName)) {
boolean hasuv = submission.hasUriValue(uriName); boolean hasuv = submission.hasUriValue(uriName);
if(!submission.hasUriValue(uriName)) { if(!submission.hasUriValue(uriName)) {
submission.addUriToForm(editConfiguration, submission.addUriToForm(editConfiguration,

View file

@ -101,7 +101,7 @@ public class GadgetSpec {
if ('R' == req.getOwnerReq()) { if ('R' == req.getOwnerReq()) {
show &= isRegisteredTo(ownerId, ds); show &= isRegisteredTo(ownerId, ds);
} else if ('S' == req.getOwnerReq()) { } else if ('S' == req.getOwnerReq()) {
show &= (viewerId == ownerId); show &= (viewerId.equals(ownerId));
} }
} }
return show; return show;

View file

@ -1085,7 +1085,7 @@ public class DumpDirectiveTest {
} }
public String getName(String which) { public String getName(String which) {
return which == "first" ? firstName : lastName; return "first".equals(which) ? firstName : lastName;
} }
public String getMiddleName() { public String getMiddleName() {