Pessoal, estou tentando desenvocver uma classe que me organize os meses em ordem ascendente. Tenho um código que eu fiz algumas transformações, porem ele está com erro na parte em separado, o codigo completo está logo abaixo. Quem puder me explicar o que está acontecendo eu agradeço muito.
obs: essa parte está no código de baixo é é o local do erro.
if (m_asc) {
// faz a escolha em ordem acendente
if (month0.getMonth() > month1.getMonth()) {
return 1;
}
if (month0.getMonth() < month1.getMonth()) {
return -1;
}
} else {
// faz a escolha em ordem descendente
if (month0.getMonth() > month1.getMonth()) {
return -1;
}
if (month0.getMonth() < month1.getMonth()) {
return 1;
}
}
obs2; este é o código completo.
package org.opencms.file.collectors;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsException;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CmsAttributeResourceComparator implements Comparator {
/** The name of the date property to read. */
public static final String PROPERTY_DATE = "collector.date";
/** The date sort order. */
private boolean m_asc;
/** The current OpenCms user context. */
private CmsObject m_cms;
/** The interal map of comparator month. */
private Map m_month;
/** The date of this comparator key.
private long m_date;*/
/** The priority of this comparator attribute. */
private int m_attribute;
/**
* Creates a new instance of this comparator key.<p>
*
* @param cms the current OpenCms user context
* @param asc if true, the date sort order is ascending, otherwise descending
*/
public CmsAttributeResourceComparator(CmsObject cms, boolean asc) {
m_cms = cms;
m_asc = asc;
m_month = new HashMap();
}
/**
* Creates a new instance of this comparator key.<p>
*
* @param resource the resource to create the key for
* @param cms the current OpenCms user context
*
* @return a new instance of this comparatoy key
*/
private static CmsAttributeResourceComparator create(CmsResource resource, CmsObject cms) {
CmsAttributeResourceComparator result = new CmsAttributeResourceComparator(null, false);
result.init(resource, cms);
return result;
}
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object arg0, Object arg1) {
if ((arg0 == arg1) || !(arg0 instanceof CmsResource) || !(arg1 instanceof CmsResource)) {
return 0;
}
CmsResource res0 = (CmsResource)arg0;
CmsResource res1 = (CmsResource)arg1;
/** faz a comparação dos meses */
CmsAttributeResourceComparator month0 = (CmsAttributeResourceComparator)m_month.get(res0.getStructureId());
CmsAttributeResourceComparator month1 = (CmsAttributeResourceComparator)m_month.get(res1.getStructureId());
if (month0 == null) {
// inicializa se não preencher o mes
month0 = CmsAttributeResourceComparator.create(res0, m_cms);
m_month.put(res0.getStructureId(), month0);
}
if (month1 == null) {
// inicializa se não preencher o mes
month1 = CmsAttributeResourceComparator.create(res1, m_cms);
m_month.put(res1.getStructureId(), month1);
}
if (m_asc) {
// faz a escolha em ordem acendente
if (month0.getMonth() > month1.getMonth()) {
return 1;
}
if (month0.getMonth() < month1.getMonth()) {
return -1;
}
} else {
// faz a escolha em ordem descendente
if (month0.getMonth() > month1.getMonth()) {
return -1;
}
if (month0.getMonth() < month1.getMonth()) {
return 1;
}
}
return 0;
}
/**
* Retorna o codigo do comparador month.
* @return the date of this resource comparator month
*/
public Map getMonth() {
return m_month;
}
/**
* Initializes the comparator month based on the member variables.<p>
*
* @param resource the resource to use
* @param cms the current OpenCms user contxt
*/
private void init(CmsResource resource, CmsObject cms) {
List properties;
try {
properties = cms.readPropertyObjects(resource, false);
} catch (CmsException e) {
m_attribute = 0;
return;
}
try {
m_attribute = Integer.parseInt(CmsProperty.get("Data_inicio", properties).getValue());
} catch (NumberFormatException e) {
m_attribute = 0;
e.printStackTrace();
}
}
}
galera se possível urgente.
[color=“red”][/color]