Minor code improvements

This commit is contained in:
Graham Triggs 2017-09-18 13:47:04 +01:00
parent 9e411253c4
commit 0cff29fa2a
34 changed files with 76 additions and 76 deletions

View file

@ -182,7 +182,7 @@ public class BaseEditController extends VitroHttpServlet {
} }
Collections.sort(bodyVal, new ListComparator(vreq.getCollator())); bodyVal.sort(new ListComparator(vreq.getCollator()));
for (String aBodyVal : bodyVal) { for (String aBodyVal : bodyVal) {
options.add(hashMap.get(aBodyVal)); options.add(hashMap.get(aBodyVal));
} }

View file

@ -267,7 +267,7 @@ public class FormUtils {
} }
} }
Collections.sort(options, (o1, o2) -> o1.getBody().compareTo(o2.getBody())); options.sort((o1, o2) -> o1.getBody().compareTo(o2.getBody()));
return options; return options;
} }

View file

@ -308,7 +308,7 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
protected void sortPropertiesForDisplay( ){ protected void sortPropertiesForDisplay( ){
//here we sort the Property objects //here we sort the Property objects
Collections.sort(getObjectPropertyList(), new ObjectProperty.DisplayComparator()); getObjectPropertyList().sort(new ObjectProperty.DisplayComparator());
} }
public JsonNode toJSON() { public JsonNode toJSON() {

View file

@ -463,7 +463,7 @@ public class ObjectProperty extends Property implements Comparable<ObjectPropert
} }
}; };
try { try {
Collections.sort(objPropStmtsList, fieldComp); objPropStmtsList.sort(fieldComp);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception sorting object property statements for object property "+prop.getURI()); log.error("Exception sorting object property statements for object property "+prop.getURI());
} }
@ -562,7 +562,7 @@ public class ObjectProperty extends Property implements Comparable<ObjectPropert
} }
}; };
try { try {
Collections.sort(objPropStmtsList, dpComp); objPropStmtsList.sort(dpComp);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception sorting object property statements " + log.error("Exception sorting object property statements " +
"for object property " + prop.getURI(), e); "for object property " + prop.getURI(), e);

View file

@ -35,7 +35,7 @@ public class VClassList extends VClass {
} }
public void sort(){ public void sort(){
Collections.sort(getEntities(), getCompare() ); getEntities().sort(getCompare());
} }
public int getSize(){ public int getSize(){

View file

@ -157,7 +157,7 @@ public class DashboardPropertyListController extends VitroHttpServlet {
if (mergedPropertyList!=null) { if (mergedPropertyList!=null) {
try { try {
Collections.sort(mergedPropertyList,new PropertyRanker(vreq)); mergedPropertyList.sort(new PropertyRanker(vreq));
} catch (Exception ex) { } catch (Exception ex) {
log.error("Exception sorting merged property list: " + ex.getMessage()); log.error("Exception sorting merged property list: " + ex.getMessage());
} }
@ -276,7 +276,7 @@ public class DashboardPropertyListController extends VitroHttpServlet {
} }
if (pg.getPropertyList().size()>1) { if (pg.getPropertyList().size()>1) {
try { try {
Collections.sort(pg.getPropertyList(),new Property.DisplayComparatorIgnoringPropertyGroup()); pg.getPropertyList().sort(new Property.DisplayComparatorIgnoringPropertyGroup());
} catch (Exception ex) { } catch (Exception ex) {
log.error("Exception sorting property group "+pg.getName()+" property list: "+ex.getMessage()); log.error("Exception sorting property group "+pg.getName()+" property list: "+ex.getMessage());
} }

View file

@ -205,7 +205,7 @@ public class VitroHttpServlet extends HttpServlet implements MultipartRequestWra
protected void sortForPickList(List<? extends ResourceBean> beans, protected void sortForPickList(List<? extends ResourceBean> beans,
VitroRequest vreq) { VitroRequest vreq) {
Collections.sort(beans, new PickListSorter(vreq)); beans.sort(new PickListSorter(vreq));
} }
protected class PickListSorter implements Comparator<ResourceBean> { protected class PickListSorter implements Comparator<ResourceBean> {

View file

@ -60,12 +60,12 @@ public abstract class UserAccountsPage extends AbstractPageHandler {
} }
} }
Collections.sort(list, new Comparator<PermissionSet>() { list.sort(new Comparator<PermissionSet>() {
@Override @Override
public int compare(PermissionSet ps1, PermissionSet ps2) { public int compare(PermissionSet ps1, PermissionSet ps2) {
return ps1.getUri().compareTo(ps2.getUri()); return ps1.getUri().compareTo(ps2.getUri());
} }
}); });
return list; return list;
} }

View file

@ -244,8 +244,7 @@ public class FauxPropertyRetryController extends BaseEditController {
private List<Option> createClassGroupOptionList() { private List<Option> createClassGroupOptionList() {
List<Option> groupOptList = getGroupOptList(beanForEditing List<Option> groupOptList = getGroupOptList(beanForEditing
.getGroupURI()); .getGroupURI());
Collections.sort(groupOptList, groupOptList.sort(new OptionsBodyComparator(req.getCollator()));
new OptionsBodyComparator(req.getCollator()));
groupOptList.add(0, new Option("", "none")); groupOptList.add(0, new Option("", "none"));
return groupOptList; return groupOptList;
} }
@ -322,12 +321,12 @@ public class FauxPropertyRetryController extends BaseEditController {
list.add(option); list.add(option);
} }
} }
Collections.sort(list, new Comparator<Option>() { list.sort(new Comparator<Option>() {
@Override @Override
public int compare(Option o1, Option o2) { public int compare(Option o1, Option o2) {
return o1.getBody().compareTo(o2.getBody()); return o1.getBody().compareTo(o2.getBody());
} }
}); });
} }
private static class OptionsBodyComparator implements private static class OptionsBodyComparator implements

View file

@ -74,7 +74,7 @@ public class PropertyGroupsListingController extends BaseEditController {
results.add("XX"); results.add("XX");
List<Property> propertyList = pg.getPropertyList(); List<Property> propertyList = pg.getPropertyList();
if (propertyList != null && propertyList.size() > 0) { if (propertyList != null && propertyList.size() > 0) {
Collections.sort(propertyList, comparator); propertyList.sort(comparator);
results.add("+"); results.add("+");
results.add("XX"); results.add("XX");
results.add("property"); results.add("property");

View file

@ -102,7 +102,7 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
} else { } else {
roots = opDao.getRootObjectProperties(); roots = opDao.getRootObjectProperties();
if (roots!=null){ if (roots!=null){
Collections.sort(roots, new ObjectPropertyAlphaComparator(vreq)); // sorts by domain public roots.sort(new ObjectPropertyAlphaComparator(vreq)); // sorts by domain public
} }
} }

View file

@ -114,7 +114,7 @@ public class ViewLabelsServlet extends FreemarkerHttpServlet{
LabelInformationComparator lic = new LabelInformationComparator(); LabelInformationComparator lic = new LabelInformationComparator();
for(String languageName: labelsHash.keySet()) { for(String languageName: labelsHash.keySet()) {
List<LabelInformation> labelInfo = labelsHash.get(languageName); List<LabelInformation> labelInfo = labelsHash.get(languageName);
Collections.sort(labelInfo, lic); labelInfo.sort(lic);
} }
return labelsHash; return labelsHash;

View file

@ -202,9 +202,9 @@ public class VClassDaoFiltering extends BaseFiltering implements VClassDao{
vcg.setLocalName("0"); vcg.setLocalName("0");
vcg.setPublicName("Browse Categories"); vcg.setPublicName("Browse Categories");
vcg.addAll( this.getAllVclasses() ); vcg.addAll( this.getAllVclasses() );
java.util.Collections.sort(vcg.getVitroClassList(),new Comparator(){ vcg.getVitroClassList().sort(new Comparator() {
public int compare(Object o1, Object o2){ public int compare(Object o1, Object o2) {
return ((VClass)o1).getName().compareTo(((VClass)o2).getName()); return ((VClass) o1).getName().compareTo(((VClass) o2).getName());
} }
}); });
groups.add(vcg); groups.add(vcg);

View file

@ -63,7 +63,7 @@ public class VitroFilterUtils {
@Override @Override
public List<Individual> fn(List<Individual> individuals) { public List<Individual> fn(List<Individual> individuals) {
Collections.sort(individuals,comparator); individuals.sort(comparator);
return individuals; return individuals;
} }

View file

@ -164,7 +164,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
} }
List<DataProperty> dataprops = new ArrayList<DataProperty>(hash.values()); List<DataProperty> dataprops = new ArrayList<DataProperty>(hash.values());
Collections.sort(dataprops, new DataPropertyRanker()); dataprops.sort(new DataPropertyRanker());
return dataprops; return dataprops;
} }

View file

@ -602,7 +602,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
} }
}; };
try { try {
Collections.sort(getObjectPropertyStatements(), comp); getObjectPropertyStatements().sort(comp);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception sorting object property statements for object property "+this.getURI()); log.error("Exception sorting object property statements for object property "+this.getURI());
} }

View file

@ -1038,7 +1038,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
}; };
try { try {
Collections.sort(getObjectPropertyStatements(), comp); getObjectPropertyStatements().sort(comp);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception sorting object property statements for object property "+this.getURI()); log.error("Exception sorting object property statements for object property "+this.getURI());
} }

View file

@ -896,18 +896,18 @@ public class JenaBaseDao extends JenaBaseDaoCon {
} }
// Sort by lexical value to guarantee consistent results // Sort by lexical value to guarantee consistent results
Collections.sort(labels, new Comparator<RDFNode>() { labels.sort(new Comparator<RDFNode>() {
public int compare(RDFNode left, RDFNode right) { public int compare(RDFNode left, RDFNode right) {
if (left == null) { if (left == null) {
return (right == null) ? 0 : -1; return (right == null) ? 0 : -1;
} }
if ( left.isLiteral() && right.isLiteral()) { if (left.isLiteral() && right.isLiteral()) {
return ((Literal) left).getLexicalForm().compareTo(((Literal) right).getLexicalForm()); return ((Literal) left).getLexicalForm().compareTo(((Literal) right).getLexicalForm());
} }
// Can't sort meaningfully if both are not literals // Can't sort meaningfully if both are not literals
return 0; return 0;
} }
}); });
for (String lang : PREFERRED_LANGUAGES) { for (String lang : PREFERRED_LANGUAGES) {
label = getLabel(lang,labels); label = getLabel(lang,labels);

View file

@ -121,7 +121,7 @@ public class PropertyInstanceDaoJena extends PropertyDaoJena implements
propInsts.add(propInst); propInsts.add(propInst);
} }
} }
Collections.sort(propInsts, new PropInstSorter()); propInsts.sort(new PropInstSorter());
return propInsts; return propInsts;
} }

View file

@ -76,7 +76,7 @@ public class SparqlGraphMultilingual extends SparqlGraph implements GraphWithPer
return WrappedIterator.create(tripList.iterator()); return WrappedIterator.create(tripList.iterator());
} }
if (subject.isConcrete() && predicate.isConcrete() && !object.isConcrete()) { if (subject.isConcrete() && predicate.isConcrete() && !object.isConcrete()) {
Collections.sort(tripList, new TripleSortByLang()); tripList.sort(new TripleSortByLang());
LinkedList<Triple> tripl = new LinkedList<Triple>(); LinkedList<Triple> tripl = new LinkedList<Triple>();
if (!tripList.get(0).getObject().isLiteral()) { if (!tripList.get(0).getObject().isLiteral()) {
tripl.addAll(tripList); tripl.addAll(tripList);

View file

@ -450,7 +450,7 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
getOntModel().leaveCriticalSection(); getOntModel().leaveCriticalSection();
} }
Collections.sort(list, new PermissionSetsByUri()); list.sort(new PermissionSetsByUri());
return list; return list;
} }

View file

@ -251,11 +251,11 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
} }
public void sortGroupList(List<VClassGroup> groupList) { public void sortGroupList(List<VClassGroup> groupList) {
Collections.sort(groupList, new Comparator<VClassGroup>() { groupList.sort(new Comparator<VClassGroup>() {
public int compare(VClassGroup first, VClassGroup second) { public int compare(VClassGroup first, VClassGroup second) {
if (first!=null) { if (first != null) {
if (second!=null) { if (second != null) {
return (first.getDisplayRank()-second.getDisplayRank()); return (first.getDisplayRank() - second.getDisplayRank());
} else { } else {
log.error("error--2nd VClassGroup is null in VClassGroupDao.getGroupList().compare()"); log.error("error--2nd VClassGroup is null in VClassGroupDao.getGroupList().compare()");
} }

View file

@ -75,7 +75,7 @@ public class SelectListGeneratorVTwo {
comparator = new MapPairsComparator(vreq); comparator = new MapPairsComparator(vreq);
} }
Collections.sort(objectsToSort, comparator); objectsToSort.sort(comparator);
HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size()); HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size());
for (String[] pair:objectsToSort) { for (String[] pair:objectsToSort) {

View file

@ -256,13 +256,13 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
} }
} }
//Sort list by language label and return //Sort list by language label and return
Collections.sort(availableLocales, new Comparator<HashMap<String, String>>() { availableLocales.sort(new Comparator<HashMap<String, String>>() {
public int compare(HashMap<String, String> h1, HashMap<String, String> h2) { public int compare(HashMap<String, String> h1, HashMap<String, String> h2) {
String languageName1 = (String) h1.get("label"); String languageName1 = (String) h1.get("label");
String languageName2 = (String) h2.get("label"); String languageName2 = (String) h2.get("label");
return languageName1.compareTo(languageName2); return languageName1.compareTo(languageName2);
} }
}); });
return availableLocales; return availableLocales;
} }
@ -330,7 +330,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
LabelInformationComparator lic = new LabelInformationComparator(); LabelInformationComparator lic = new LabelInformationComparator();
for(String languageName: labelsHash.keySet()) { for(String languageName: labelsHash.keySet()) {
List<LabelInformation> labelInfo = labelsHash.get(languageName); List<LabelInformation> labelInfo = labelsHash.get(languageName);
Collections.sort(labelInfo, lic); labelInfo.sort(lic);
} }
return labelsHash; return labelsHash;

View file

@ -119,7 +119,7 @@ public class LanguageFilteringRDFService implements RDFService {
if (candidatesForRemoval.size() == 1) { if (candidatesForRemoval.size() == 1) {
continue; continue;
} }
Collections.sort(candidatesForRemoval, new StatementSortByLang()); candidatesForRemoval.sort(new StatementSortByLang());
log.debug("sorted statements: " + showSortedStatements(candidatesForRemoval)); log.debug("sorted statements: " + showSortedStatements(candidatesForRemoval));
Iterator<Statement> candIt = candidatesForRemoval.iterator(); Iterator<Statement> candIt = candidatesForRemoval.iterator();
String langRegister = null; String langRegister = null;
@ -197,7 +197,7 @@ public class LanguageFilteringRDFService implements RDFService {
if (candidatesForRemoval.size() == 1) { if (candidatesForRemoval.size() == 1) {
continue; continue;
} }
Collections.sort(candidatesForRemoval, new RowIndexedLiteralSortByLang()); candidatesForRemoval.sort(new RowIndexedLiteralSortByLang());
log.debug("sorted RowIndexedLiterals: " + showSortedRILs(candidatesForRemoval)); log.debug("sorted RowIndexedLiterals: " + showSortedRILs(candidatesForRemoval));
Iterator<RowIndexedLiteral> candIt = candidatesForRemoval.iterator(); Iterator<RowIndexedLiteral> candIt = candidatesForRemoval.iterator();
String langRegister = null; String langRegister = null;
@ -290,7 +290,7 @@ public class LanguageFilteringRDFService implements RDFService {
if (candidatesForRemoval.size() == 1) { if (candidatesForRemoval.size() == 1) {
continue; continue;
} }
Collections.sort(candidatesForRemoval, new RowIndexedLiteralSortByLang()); candidatesForRemoval.sort(new RowIndexedLiteralSortByLang());
log.debug("sorted RowIndexedLiterals: " + showSortedRILs(candidatesForRemoval)); log.debug("sorted RowIndexedLiterals: " + showSortedRILs(candidatesForRemoval));
Iterator<RowIndexedLiteral> candIt = candidatesForRemoval.iterator(); Iterator<RowIndexedLiteral> candIt = candidatesForRemoval.iterator();
String langRegister = null; String langRegister = null;

View file

@ -416,10 +416,11 @@ public class PagedSearchController extends FreemarkerHttpServlet {
} }
Collections.sort(classes, new Comparator<VClass>(){ classes.sort(new Comparator<VClass>() {
public int compare(VClass o1, VClass o2) { public int compare(VClass o1, VClass o2) {
return o1.compareTo(o2); return o1.compareTo(o2);
}}); }
});
List<VClassSearchLink> vClassLinks = new ArrayList<VClassSearchLink>(classes.size()); List<VClassSearchLink> vClassLinks = new ArrayList<VClassSearchLink>(classes.size());
for (VClass vc : classes) { for (VClass vc : classes) {

View file

@ -88,7 +88,7 @@ public class ThemeInfoSetup implements ServletContextListener {
} }
} }
Collections.sort(themeNames, String.CASE_INSENSITIVE_ORDER); themeNames.sort(String.CASE_INSENSITIVE_ORDER);
return themeNames; return themeNames;
} }

View file

@ -73,7 +73,7 @@ public class GetAllPrefix extends BaseEditController {
respo.append("<options>"); respo.append("<options>");
List<String> prefixList = new ArrayList<String>(); List<String> prefixList = new ArrayList<String>();
prefixList.addAll(prefixMap.keySet()); prefixList.addAll(prefixMap.keySet());
Collections.sort(prefixList, vreq.getCollator()); prefixList.sort(vreq.getCollator());
for (String prefix : prefixList) { for (String prefix : prefixList) {
respo.append(makeOption(prefix, prefixMap.get(prefix))); respo.append(makeOption(prefix, prefixMap.get(prefix)));
} }

View file

@ -87,7 +87,7 @@ public class OptionsForPropertyTag extends TagSupport {
if( stmts == null ) throw new Exception("object properties for subject were null"); if( stmts == null ) throw new Exception("object properties for subject were null");
individuals = removeIndividualsAlreadyInRange(individuals,stmts); individuals = removeIndividualsAlreadyInRange(individuals,stmts);
Collections.sort(individuals,new compareEnts()); individuals.sort(new compareEnts());
JspWriter out = pageContext.getOut(); JspWriter out = pageContext.getOut();

View file

@ -622,7 +622,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
x[1] = hmap.get(key); x[1] = hmap.get(key);
objectsToSort.add(x); objectsToSort.add(x);
} }
Collections.sort(objectsToSort, new MapComparator()); objectsToSort.sort(new MapComparator());
HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size()); HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size());
for (String[] pair:objectsToSort) { for (String[] pair:objectsToSort) {

View file

@ -167,7 +167,7 @@ public class CollatedObjectPropertyTemplateModel extends
filteredList.add(outerMap); filteredList.add(outerMap);
} else { } else {
//Subclass variable should already reflect most specifick types but there may be more than one most specific type //Subclass variable should already reflect most specifick types but there may be more than one most specific type
Collections.sort(dataForThisObject, new DataComparatorBySubclass()); dataForThisObject.sort(new DataComparatorBySubclass());
filteredList.add(dataForThisObject.get(0)); filteredList.add(dataForThisObject.get(0));
} }
} }

View file

@ -219,7 +219,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
protected void sort(List<Property> propertyList) { protected void sort(List<Property> propertyList) {
try { try {
Collections.sort(propertyList, new PropertyRanker(vreq)); propertyList.sort(new PropertyRanker(vreq));
} catch (Exception ex) { } catch (Exception ex) {
log.error("Exception sorting merged property list: " log.error("Exception sorting merged property list: "
+ ex.getMessage()); + ex.getMessage());

View file

@ -225,7 +225,7 @@ public class LanguageFilteringRDFServiceTest extends AbstractTestClass {
log.debug("before sorting: " log.debug("before sorting: "
+ languagesFromLiterals(listOfRowIndexedLiterals)); + languagesFromLiterals(listOfRowIndexedLiterals));
Comparator<Object> comparator = buildRowIndexedLiteralSortByLang(); Comparator<Object> comparator = buildRowIndexedLiteralSortByLang();
Collections.sort(listOfRowIndexedLiterals, comparator); listOfRowIndexedLiterals.sort(comparator);
} }
private void assertLanguageOrder(String message) { private void assertLanguageOrder(String message) {

View file

@ -94,8 +94,8 @@ public class StringResultsMappingTest extends AbstractTestClass {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private <T> void assertEquivalentUnorderedLists(List<T> list1, List<T> list2) { private <T> void assertEquivalentUnorderedLists(List<T> list1, List<T> list2) {
Collections.sort(list1, new ArbitraryOrder<>()); list1.sort(new ArbitraryOrder<>());
Collections.sort(list2, new ArbitraryOrder<>()); list2.sort(new ArbitraryOrder<>());
assertEquals(list1, list2); assertEquals(list1, list2);
} }