package siprp.database.cayenne.objects; import java.util.Arrays; import java.util.Collections; import java.util.List; import siprp.database.cayenne.objects.auto._Estabelecimentos; public class Estabelecimentos extends _Estabelecimentos implements Comparable { private static final long serialVersionUID = 1L; private String name = null; private String convertedName = null; @Override public String getNome() { String currentName = super.getNome(); if( name == null || !name.equals( currentName ) ) { name = currentName; convertedName = null; } return convertName(); } @Override public void setNome( String nome ) { super.setNome( parseToUnicode( name ) ); getNome(); } private String convertName() { if( name == null ) { convertedName = null; } else { convertedName = parseFromUnicode( name ); } return convertedName; } @Override public String toString() { return getNome(); } @Override public List getTrabalhadoresArray() { List result = super.getTrabalhadoresArray(); for(int i = 0; i < result.size(); ++i) { Trabalhadores current = result.get(i); if( current == null || "y".equals(current.getInactivo())) { result.remove( i ); --i; } } Collections.sort( result ); return result; } @Override public int compareTo( Estabelecimentos estabelecimento ) { if( estabelecimento == null) { return 1; } if( this.getNomePlain() == null ) { return (estabelecimento.getNomePlain() != null) ? -1 : 0; } return (-1) * estabelecimento.getNomePlain().compareTo( getNomePlain() ); } }