[Suiviobsmer-commits] r1297 - in trunk: wao-business/src/main/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/pages
Author: bleny Date: 2011-05-25 10:00:32 +0000 (Wed, 25 May 2011) New Revision: 1297 Log: sort substitutes boats with lenght compared to a reference boat Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-05-25 08:53:52 UTC (rev 1296) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-05-25 10:00:32 UTC (rev 1297) @@ -116,15 +116,15 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Comparator; import java.util.Date; -import java.util.GregorianCalendar; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; /** * ServiceContactImpl @@ -990,10 +990,10 @@ public ImportResults executeImportContactCsv(TopiaContext transaction, ConnectedUser user, InputStream input) - throws TopiaException, - IOException, - WaoBusinessException, - ParseException { + throws TopiaException, + IOException, + WaoBusinessException, + ParseException { ImportResults result = new ImportResultsImpl(); @@ -1564,7 +1564,9 @@ ContactFilter contactFilter = new ContactFilterImpl(); - GregorianCalendar initialFromDate = new GregorianCalendar(); + + Calendar initialFromDate = + DateUtil.getDefaultCalendar(context.getCurrentDate()); // in the firsts months of a new year go from now to 6 months before // in the rest of the year, just start at the beginning of the current year if (initialFromDate.get(Calendar.MONTH) < 3) { @@ -1588,7 +1590,7 @@ @Override protected ContactFilterValues executeGetPossibleValuesForFilter(TopiaContext transaction, ContactFilter filter) throws Exception { - // Dont use index + // Don't use index Integer startIndex = filter.getStartIndex(); Integer endIndex = filter.getEndIndex(); filter.setStartIndex(null); @@ -1607,7 +1609,8 @@ @Override protected Set<Boat> executeGetSubstitutesForBoat(TopiaContext transaction, Boat boat) throws Exception { BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction); - Set<Boat> substitutes = new HashSet<Boat>(); + Comparator<Boat> comparator = new BoatLengthComparator(boat); + Set<Boat> substitutes = new TreeSet<Boat>(comparator); if (boat.getFleet() != null) { // a substitute for a boat must be in the same fleet @@ -1629,4 +1632,54 @@ return substitutes; } + + /** + * This comparator order boats according to their difference of length to + * a given reference boat. The boats having a length close to the one + * of the reference boat must be in firsts positions, the boats with a + * length far from the one of the reference boats must be in lasts + * positions. + * + * For example, If reference boat has a length of 15 meters, + * and boats compared have length in {5; 12; 16; 20}, we must order those + * boats as such : [16; 12; 20; 5] (close to 15 to far from 15). + * + * If two boats are equally distant from the reference one, longest boat + * is in first. + */ + protected static class BoatLengthComparator implements Comparator<Boat> { + + protected int referenceBoatLength; + + public BoatLengthComparator(Boat referenceBoat) { + referenceBoatLength = referenceBoat.getBoatLength(); + } + + @Override + public int compare(Boat boat1, Boat boat2) { + // distance between the two boats length to the reference one + int lengthDiff1 = Math.abs( + referenceBoatLength - boat1.getBoatLength()); + int lengthDiff2 = Math.abs( + referenceBoatLength - boat2.getBoatLength()); + + // sorting according to those differences + if (lengthDiff1 < lengthDiff2) { + return -1; + } else if (lengthDiff1 > lengthDiff2) { + return 1; + } else { + // lengthDiff1 == lengthDiff2 + // boats length are equally distant from reference one, + if (boat1.getBoatLength() == boat2.getBoatLength()) { + return 0; + } else if (boat1.getBoatLength() > boat2.getBoatLength()) { + // we put longest boat first + return -1; + } else { + return 1; + } + } + } + } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java 2011-05-25 08:53:52 UTC (rev 1296) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java 2011-05-25 10:00:32 UTC (rev 1297) @@ -176,7 +176,8 @@ } } - // FIXME 20110502 bleny clicking on 'export' make the 'import' link still active but content is not showed/hidden + // FIXME 20110502 bleny clicking on 'export' make the 'import' link still + // active but content is not shown/hidden @Log public Object onActionFromShowImport() {
participants (1)
-
bleny@users.labs.libre-entreprise.org