Error en que los numeros de boletas eran comparados segun sus valor ascii y no de forma natural

Se agrego una clase de otra persona que hace el trabajo, gracias buen hombre <3
This commit is contained in:
Daniel Cortes
2019-01-12 18:11:22 -03:00
parent 06b2de9f65
commit 3b6baf3bed
4 changed files with 283 additions and 57 deletions

180
.idea/workspace.xml generated
View File

@@ -7,18 +7,13 @@
</component>
<component name="BookmarkManager">
<bookmark url="file://$PROJECT_DIR$/src/danielcortes/xyz/controllers/ArqueoController.java" line="55" />
<bookmark url="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java" line="149" mnemonic="0" />
</component>
<component name="ChangeListManager">
<list default="true" id="a633d35a-56a6-4479-b4c4-f97198052fb7" name="Default Changelist" comment="Corregido error en la generacion del informe, mucho se tuvo que cambiar del mismo para que voliera a funcionar&#10;Presentaba errores al intentar conseguir los numeros de las distintos numeros de boleta">
<change beforePath="$PROJECT_DIR$/.idea/dataSources.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.xml" afterDir="false" />
<list default="true" id="a633d35a-56a6-4479-b4c4-f97198052fb7" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/danielcortes/xyz/utils/NaturalOrderComparator.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dist/caja.jar" beforeDir="false" afterPath="$PROJECT_DIR$/dist/caja.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dist/conf.properties" beforeDir="false" afterPath="$PROJECT_DIR$/dist/conf.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dist/database.sqlite" beforeDir="false" afterPath="$PROJECT_DIR$/dist/database.sqlite" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/danielcortes/xyz/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/danielcortes/xyz/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/danielcortes/xyz/informes/InformeMensual.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/danielcortes/xyz/informes/InformeMensual.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContent.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContent.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContentDAO.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContentDAO.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/target/" />
@@ -74,7 +69,56 @@
<favorites_list name="caja" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300" />
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="163">
<caret line="229" column="38" selection-start-line="229" selection-start-column="38" selection-end-line="229" selection-end-column="38" />
<folding>
<element signature="method#getInformeMensual#0;class#SQLiteInformeMensualContentDAO#0" />
<element signature="method#fillTotalesFromResultSet#0;class#SQLiteInformeMensualContentDAO#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/utils/NaturalOrderComparator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="276">
<caret line="12" column="20" selection-start-line="12" selection-start-column="20" selection-end-line="12" selection-end-column="20" />
<folding>
<element signature="method#compareRight#0;class#NaturalOrderComparator#0" />
<element signature="e#1327#1386#0" />
<element signature="e#1595#2232#1" />
<element signature="e#1738#1782#1" />
<element signature="e#1823#1865#1" />
<element signature="e#1906#1948#1" />
<element signature="e#1985#2029#1" />
<element signature="e#2058#2222#1" />
<element signature="e#2089#2139#1" />
<element signature="e#2158#2208#1" />
<element signature="method#compare#0;class#NaturalOrderComparator#0" />
<element signature="e#2457#3956#1" />
<element signature="e#2740#2979#1" />
<element signature="e#2773#2819#1" />
<element signature="e#2825#2926#1" />
<element signature="e#3040#3279#1" />
<element signature="e#3073#3119#1" />
<element signature="e#3125#3226#1" />
<element signature="e#3382#3556#1" />
<element signature="e#3490#3542#1" />
<element signature="e#3594#3773#1" />
<element signature="e#3612#3663#0" />
<element signature="e#3799#3841#1" />
<element signature="e#3867#3909#1" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
@@ -87,7 +131,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>from efectivo</find>
<find>caj</find>
<find>remove</find>
<find>error</find>
@@ -117,6 +160,7 @@
<find>get</find>
<find>System.out.println(.+)</find>
<find>System.out</find>
<find>this.comparator</find>
</findStrings>
<replaceStrings>
<replace>2018 Daniel Cortes</replace>
@@ -126,6 +170,7 @@
<replace>text</replace>
<replace>integer primary key</replace>
<replace>Copyright (c) 2018-2019 Daniel Cortes</replace>
<replace>comparator</replace>
</replaceStrings>
<dirStrings>
<dir>$PROJECT_DIR$/src</dir>
@@ -138,7 +183,6 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/danielcortes/xyz/data/SQLiteConnectionHolder.java" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/models/caja/Caja.java" />
<option value="$PROJECT_DIR$/database/mysql.sql" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/models/ingreso/Ingreso.java" />
@@ -188,6 +232,7 @@
<option value="$PROJECT_DIR$/src/danielcortes/xyz/Main.java" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContent.java" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/informes/InformeMensual.java" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/utils/NaturalOrderComparator.java" />
<option value="$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java" />
</list>
</option>
@@ -258,6 +303,21 @@
<item name="xyz" type="462c0819:PsiDirectoryNode" />
<item name="models" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="caja" type="b2602c69:ProjectViewProjectNode" />
<item name="caja" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="xyz" type="462c0819:PsiDirectoryNode" />
<item name="models" type="462c0819:PsiDirectoryNode" />
<item name="informe" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="caja" type="b2602c69:ProjectViewProjectNode" />
<item name="caja" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="xyz" type="462c0819:PsiDirectoryNode" />
<item name="utils" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="caja" type="b2602c69:ProjectViewProjectNode" />
<item name="caja" type="462c0819:PsiDirectoryNode" />
@@ -286,7 +346,7 @@
<property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.STATE" value="ToolWindow" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1547325445022" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1547326684094" />
<property name="com.intellij.ide.scratch.LRUPopupBuilder$1/Change SQL Dialect" value="SQLite" />
<property name="database.console.LAST_STATE" value="false" />
<property name="database.data.extractors.current.id" value="Tab-separated (TSV)_id" />
@@ -504,7 +564,8 @@
<workItem from="1547267080995" duration="827000" />
<workItem from="1547315193858" duration="5374000" />
<workItem from="1547322244451" duration="1427000" />
<workItem from="1547324215778" duration="1060000" />
<workItem from="1547324215778" duration="2265000" />
<workItem from="1547326945767" duration="480000" />
</task>
<task id="LOCAL-00001" summary="First!! :3 Existe una pequeña base de proyecto por ahora">
<created>1545280618093</created>
@@ -800,11 +861,18 @@
<option name="project" value="LOCAL" />
<updated>1547082730641</updated>
</task>
<option name="localTasksCounter" value="43" />
<task id="LOCAL-00043" summary="Corregido error en la generacion del informe, mucho se tuvo que cambiar del mismo para que voliera a funcionar&#10;Presentaba errores al intentar conseguir los numeros de las distintos numeros de boleta dado a la query que se estaba realizando, se corrige creando 2 querys separadas y se comprueba que los numeros de boleta sean minimos o maimos en el codigo">
<created>1547325551265</created>
<option name="number" value="00043" />
<option name="presentableId" value="LOCAL-00043" />
<option name="project" value="LOCAL" />
<updated>1547325551265</updated>
</task>
<option name="localTasksCounter" value="44" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="291801000" />
<option name="totallyTimeSpent" value="293486000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@@ -818,7 +886,7 @@
<component name="ToolWindowManager">
<frame x="0" y="-18" width="1366" height="765" extended-state="6" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.49438202" visible="true" weight="0.2283105" />
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49438202" weight="0.23211567" />
<window_info id="Image Layers" order="1" />
<window_info id="Designer" order="2" />
<window_info x="458" y="95" width="450" height="453" id="UI Designer" order="3" weight="0.20243531" />
@@ -845,7 +913,7 @@
<window_info anchor="right" id="Maven" order="5" show_stripe_button="false" weight="0.32876712" />
<window_info anchor="right" id="Capture Analysis" order="6" />
<window_info anchor="right" id="Palette&#9;" order="7" />
<window_info anchor="right" x="4" y="0" width="902" height="488" id="Run" order="8" sideWeight="0.4975923" visible="true" weight="0.40182647" />
<window_info active="true" anchor="right" x="4" y="0" width="902" height="488" id="Run" order="8" sideWeight="0.4975923" visible="true" weight="0.40182647" />
<window_info anchor="right" id="Database" order="9" sideWeight="0.4988067" weight="0.32115677" />
<window_info anchor="right" id="Version Control" order="10" weight="0.7435312" />
<window_info anchor="right" id="Structure" order="11" sideWeight="0.5008026" weight="0.2283105" />
@@ -909,7 +977,6 @@
<component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" />
<MESSAGE value="Agregadas clases para compatibilidad con sqlite" />
<MESSAGE value="Corregido problemas .w." />
<MESSAGE value="Separando un poco las clases de los modelos" />
<MESSAGE value="Creando documentacion basica" />
@@ -934,20 +1001,14 @@
<MESSAGE value="Mensaje de confirmacion al generarse el informe" />
<MESSAGE value="Solucionado bug que no generaba el ultimo dia del mes :3" />
<MESSAGE value="Informes mejorados, pensado para transcribirlo a un informe de ventas" />
<option name="LAST_COMMIT_MESSAGE" value="Informes mejorados, pensado para transcribirlo a un informe de ventas" />
<MESSAGE value="Corregido error en la generacion del informe, mucho se tuvo que cambiar del mismo para que voliera a funcionar&#10;Presentaba errores al intentar conseguir los numeros de las distintos numeros de boleta dado a la query que se estaba realizando, se corrige creando 2 querys separadas y se comprueba que los numeros de boleta sean minimos o maimos en el codigo" />
<option name="LAST_COMMIT_MESSAGE" value="Corregido error en la generacion del informe, mucho se tuvo que cambiar del mismo para que voliera a funcionar&#10;Presentaba errores al intentar conseguir los numeros de las distintos numeros de boleta dado a la query que se estaba realizando, se corrige creando 2 querys separadas y se comprueba que los numeros de boleta sean minimos o maimos en el codigo" />
</component>
<component name="antWorkspaceConfiguration">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
<option name="FILTER_TARGETS" value="false" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="439">
<caret line="236" column="5" selection-start-line="236" selection-start-column="5" selection-end-line="236" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/Downloads/TimesheetDemo.java" />
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informes/Informe.java" />
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java">
@@ -1457,24 +1518,12 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContent.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="370">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
<folding>
<element signature="e#2440#2519#0" />
<element signature="e#6257#7465#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/informes/InformeMensual.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="112" selection-start-line="112" selection-end-line="112" />
<state relative-caret-position="-149">
<caret line="90" column="30" selection-start-line="90" selection-start-column="30" selection-end-line="90" selection-end-column="30" />
<folding>
<element signature="method#InformeMensual#0;class#InformeMensual#0" />
<element signature="n#!!block;n#sortInforme#0;n#InformeMensual#0" />
<element signature="method#fillHeaders#0;class#InformeMensual#0" />
<element signature="method#fillTotales#0;class#InformeMensual#0" />
<element signature="method#joinCells#0;class#InformeMensual#0" />
@@ -1486,10 +1535,57 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informe/InformeMensualContent.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="221" column="29" selection-start-line="221" selection-start-column="29" selection-end-line="221" selection-end-column="29" />
<folding>
<element signature="e#5399#6607#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/models/informe/SQLiteInformeMensualContentDAO.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="390">
<caret line="147" selection-start-line="147" selection-end-line="147" />
<state relative-caret-position="163">
<caret line="229" column="38" selection-start-line="229" selection-start-column="38" selection-end-line="229" selection-end-column="38" />
<folding>
<element signature="method#getInformeMensual#0;class#SQLiteInformeMensualContentDAO#0" />
<element signature="method#fillTotalesFromResultSet#0;class#SQLiteInformeMensualContentDAO#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/danielcortes/xyz/utils/NaturalOrderComparator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="276">
<caret line="12" column="20" selection-start-line="12" selection-start-column="20" selection-end-line="12" selection-end-column="20" />
<folding>
<element signature="method#compareRight#0;class#NaturalOrderComparator#0" />
<element signature="e#1327#1386#0" />
<element signature="e#1595#2232#1" />
<element signature="e#1738#1782#1" />
<element signature="e#1823#1865#1" />
<element signature="e#1906#1948#1" />
<element signature="e#1985#2029#1" />
<element signature="e#2058#2222#1" />
<element signature="e#2089#2139#1" />
<element signature="e#2158#2208#1" />
<element signature="method#compare#0;class#NaturalOrderComparator#0" />
<element signature="e#2457#3956#1" />
<element signature="e#2740#2979#1" />
<element signature="e#2773#2819#1" />
<element signature="e#2825#2926#1" />
<element signature="e#3040#3279#1" />
<element signature="e#3073#3119#1" />
<element signature="e#3125#3226#1" />
<element signature="e#3382#3556#1" />
<element signature="e#3490#3542#1" />
<element signature="e#3594#3773#1" />
<element signature="e#3612#3663#0" />
<element signature="e#3799#3841#1" />
<element signature="e#3867#3909#1" />
</folding>
</state>
</provider>
</entry>

BIN
dist/caja.jar vendored

Binary file not shown.

View File

@@ -25,6 +25,7 @@
package danielcortes.xyz.models.informe;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.utils.NaturalOrderComparator;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -34,9 +35,9 @@ import java.time.LocalDate;
import java.util.*;
public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
HashMap<Integer, InformeMensualContent> map;
private HashMap<Integer, InformeMensualContent> map;
public SQLiteInformeMensualContentDAO(){
public SQLiteInformeMensualContentDAO() {
this.map = new HashMap<>();
}
@@ -109,7 +110,8 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
}
}
private void fillBoletasFromResultSet(ResultSet rs) throws SQLException{
private void fillBoletasFromResultSet(ResultSet rs) throws SQLException {
Comparator<String> comparator = new NaturalOrderComparator();
while (rs.next()) {
InformeMensualContent informe = map.get(rs.getInt("caja"));
int tipoIngreso = rs.getInt("tipo_ingreso");
@@ -121,7 +123,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
String fiscalesZFinal = rs.getString("z_final");
if (informe.getFiscalesInicial() != null) {
if (fiscalesInicial.compareTo(informe.getFiscalesInicial()) < 0) {
if (comparator.compare(fiscalesInicial, informe.getFiscalesInicial()) < 0) {
informe.setFiscalesInicial(fiscalesInicial);
}
} else {
@@ -129,7 +131,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
}
if (informe.getFiscalesFinal() != null) {
if (fiscalesFinal.compareTo(informe.getFiscalesFinal()) > 0) {
if (comparator.compare(fiscalesFinal, informe.getFiscalesFinal()) > 0) {
informe.setFiscalesFinal(fiscalesFinal);
}
} else {
@@ -137,7 +139,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
}
if (informe.getFiscalesZInicial() != null) {
if (fiscalesZInicial.compareTo(informe.getFiscalesZInicial()) < 0) {
if (comparator.compare(fiscalesZInicial, informe.getFiscalesZInicial()) < 0) {
informe.setFiscalesZInicial(fiscalesZInicial);
}
} else {
@@ -145,7 +147,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
}
if (informe.getFiscalesZFinal() != null) {
if (fiscalesZFinal.compareTo(informe.getFiscalesZFinal()) > 0) {
if (comparator.compare(fiscalesZFinal, informe.getFiscalesZFinal()) > 0) {
informe.setFiscalesZFinal(fiscalesZFinal);
}
} else {
@@ -158,7 +160,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
String manualesFinal = rs.getString("final");
if (informe.getManualesInicial() != null) {
if (manualesInicial.compareTo(informe.getManualesInicial()) < 0) {
if (comparator.compare(manualesInicial, informe.getManualesInicial()) < 0) {
informe.setManualesInicial(manualesInicial);
}
} else {
@@ -166,7 +168,7 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
}
if (informe.getManualesFinal() != null) {
if (manualesFinal.compareTo(informe.getManualesFinal()) > 0) {
if (comparator.compare(manualesFinal, informe.getManualesFinal()) > 0) {
informe.setManualesFinal(manualesFinal);
}
} else {
@@ -179,14 +181,14 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
String facturasFinal = rs.getString("final");
if (informe.getFacturasInicial() != null) {
if (facturasInicial.compareTo(informe.getFacturasInicial()) < 0) {
if (comparator.compare(facturasInicial, informe.getFacturasInicial()) < 0) {
informe.setFacturasInicial(facturasInicial);
}
} else {
informe.setFacturasInicial(facturasInicial);
}
if (informe.getFacturasFinal() != null) {
if (facturasFinal.compareTo(informe.getFacturasFinal()) > 0) {
if (comparator.compare(facturasFinal, informe.getFacturasFinal()) > 0) {
informe.setFacturasFinal(facturasFinal);
}
} else {
@@ -199,14 +201,14 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
String guiasFinal = rs.getString("final");
if (informe.getGuiasInicial() != null) {
if (guiasInicial.compareTo(informe.getGuiasInicial()) < 0) {
if (comparator.compare(guiasInicial, informe.getGuiasInicial()) < 0) {
informe.setGuiasInicial(guiasInicial);
}
} else {
informe.setGuiasInicial(guiasInicial);
}
if (informe.getGuiasFinal() != null) {
if (guiasFinal.compareTo(informe.getGuiasFinal()) > 0) {
if (comparator.compare(guiasFinal, informe.getGuiasFinal()) > 0) {
informe.setGuiasFinal(guiasFinal);
}
} else {
@@ -218,14 +220,14 @@ public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO {
String exentasFinal = rs.getString("final");
if (informe.getExentasInicial() != null) {
if (exentasInicial.compareTo(informe.getExentasInicial()) < 0) {
if (comparator.compare(exentasInicial, informe.getExentasInicial()) < 0) {
informe.setExentasInicial(exentasInicial);
}
} else {
informe.setExentasInicial(exentasInicial);
}
if (informe.getExentasFinal() != null) {
if (exentasFinal.compareTo(informe.getExentasFinal()) > 0) {
if (comparator.compare(exentasFinal, informe.getExentasFinal()) > 0) {
informe.setExentasFinal(exentasFinal);
}
} else {

View File

@@ -0,0 +1,128 @@
/*
NaturalOrderComparator.java -- Perform 'natural order' comparisons of strings in Java.
Copyright (C) 2003 by Pierre-Luc Paour <natorder@paour.com>
Based on the C version by Martin Pool, of which this is more or less a straight conversion.
Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
This class was sightly modified by Daniel Cortes, removing the main method that it had
*/
package danielcortes.xyz.utils;
import java.util.*;
public class NaturalOrderComparator implements Comparator {
int compareRight(String a, String b) {
int bias = 0, ia = 0, ib = 0;
// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
// both numbers to know that they have the same magnitude, so we
// remember it in BIAS.
for (; ; ia++, ib++) {
char ca = charAt(a, ia);
char cb = charAt(b, ib);
if (!Character.isDigit(ca) && !Character.isDigit(cb)) {
return bias;
}
if (!Character.isDigit(ca)) {
return -1;
}
if (!Character.isDigit(cb)) {
return +1;
}
if (ca == 0 && cb == 0) {
return bias;
}
if (bias == 0) {
if (ca < cb) {
bias = -1;
} else if (ca > cb) {
bias = +1;
}
}
}
}
public int compare(Object o1, Object o2) {
String a = o1.toString();
String b = o2.toString();
int ia = 0, ib = 0;
int nza = 0, nzb = 0;
char ca, cb;
while (true) {
// Only count the number of zeroes leading the last number compared
nza = nzb = 0;
ca = charAt(a, ia);
cb = charAt(b, ib);
// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0') {
if (ca == '0') {
nza++;
} else {
// Only count consecutive zeroes
nza = 0;
}
ca = charAt(a, ++ia);
}
while (Character.isSpaceChar(cb) || cb == '0') {
if (cb == '0') {
nzb++;
} else {
// Only count consecutive zeroes
nzb = 0;
}
cb = charAt(b, ++ib);
}
// Process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb)) {
int bias = compareRight(a.substring(ia), b.substring(ib));
if (bias != 0) {
return bias;
}
}
if (ca == 0 && cb == 0) {
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
return nza - nzb;
}
if (ca < cb) {
return -1;
}
if (ca > cb) {
return +1;
}
++ia;
++ib;
}
}
static char charAt(String s, int i) {
return i >= s.length() ? 0 : s.charAt(i);
}
}