BaseContact
BaseContactEntryCollection verwendet jetzt intern ein TreeSet, damit die Einträge in der angegebenen Reihenfolge angezeigt werden. Funktioniert erstaunlicherweise im ersten Versuch. Jetzt muß das gleiche nur noch für die Ausgabe auf den Webseiten gemacht werden. git-svn-id: https://svn.libreccm.org/ccm/trunk@219 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
061ef166d1
commit
d0f493d2bf
|
|
@ -10,6 +10,9 @@ package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.domain.DomainCollection;
|
import com.arsdigita.domain.DomainCollection;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,6 +21,11 @@ import com.arsdigita.persistence.DataCollection;
|
||||||
*/
|
*/
|
||||||
public class BaseContactEntryCollection extends DomainCollection {
|
public class BaseContactEntryCollection extends DomainCollection {
|
||||||
|
|
||||||
|
private TreeSet m_sortedCollection = new TreeSet(new BaseContactEntryComparator());
|
||||||
|
private Iterator m_iterator;
|
||||||
|
private boolean m_firstElem;
|
||||||
|
private BaseContactEntry m_currentBaseContactEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of BaseContactEntryCollection
|
* Creates a new instance of BaseContactEntryCollection
|
||||||
*/
|
*/
|
||||||
|
|
@ -27,6 +35,54 @@ public class BaseContactEntryCollection extends DomainCollection {
|
||||||
|
|
||||||
public BaseContactEntryCollection(DataCollection dataCollection) {
|
public BaseContactEntryCollection(DataCollection dataCollection) {
|
||||||
super(dataCollection);
|
super(dataCollection);
|
||||||
|
|
||||||
|
// Now copy all objects from m_dataCollection to the sorting TreeSet
|
||||||
|
this.sortCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean next() {
|
||||||
|
boolean retVal = m_iterator.hasNext();
|
||||||
|
if(retVal) {
|
||||||
|
m_currentBaseContactEntry = (BaseContactEntry)m_iterator.next();
|
||||||
|
m_firstElem = false;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBeforeFirst() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAfterLast() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFirst() {
|
||||||
|
return m_firstElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLast() {
|
||||||
|
return !m_iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return m_sortedCollection.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long size() {
|
||||||
|
return m_sortedCollection.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
super.reset();
|
||||||
|
m_iterator = null;
|
||||||
|
m_currentBaseContactEntry = null;
|
||||||
|
m_sortedCollection = new TreeSet(new BaseContactEntryComparator());
|
||||||
|
this.sortCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rewind() {
|
||||||
|
m_iterator = m_sortedCollection.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getKey() {
|
public final String getKey() {
|
||||||
|
|
@ -42,7 +98,37 @@ public class BaseContactEntryCollection extends DomainCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseContactEntry getBaseContactEntry() {
|
public BaseContactEntry getBaseContactEntry() {
|
||||||
return new BaseContactEntry(m_dataCollection.getDataObject());
|
// return new BaseContactEntry(m_dataCollection.getDataObject());
|
||||||
|
return m_currentBaseContactEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void sortCollection() {
|
||||||
|
|
||||||
|
m_dataCollection.rewind();
|
||||||
|
|
||||||
|
while(m_dataCollection.next()) {
|
||||||
|
m_sortedCollection.add(new BaseContactEntry(m_dataCollection.getDataObject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_iterator = m_sortedCollection.iterator();
|
||||||
|
m_firstElem = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class BaseContactEntryComparator implements Comparator {
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
int retVal = 0;
|
||||||
|
if(o1 instanceof BaseContactEntry && o2 instanceof BaseContactEntry) {
|
||||||
|
BaseContactEntry bc1 = (BaseContactEntry)o1;
|
||||||
|
BaseContactEntry bc2 = (BaseContactEntry)o2;
|
||||||
|
retVal = BaseContact.getConfig().getKeyIndex(bc1.getKey()) -
|
||||||
|
BaseContact.getConfig().getKeyIndex(bc2.getKey());
|
||||||
|
if(retVal == 0) {
|
||||||
|
retVal=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue