📄 groupallocatablesstrategy.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Gereon Fassbender, Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.plugin.abstractcalendar;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.rapla.components.calendarview.AbstractGroupStrategy;
import org.rapla.entities.NamedComparator;
import org.rapla.entities.domain.Allocatable;
/** Tries to put reservations that allocate the same Ressources in the same column.*/
public class GroupAllocatablesStrategy extends AbstractGroupStrategy {
Comparator allocatableComparator;
Collection allocatables = new ArrayList();
public GroupAllocatablesStrategy(Locale locale) {
allocatableComparator = new NamedComparator( locale );
}
public void setAllocationGroups( Collection allocatables) {
this.allocatables = allocatables;
}
protected Collection group(List list) {
HashMap groups = new HashMap();
for (Iterator it = allocatables.iterator();it.hasNext(); ) {
groups.put( it.next(), new ArrayList() );
}
Collection noAllocatablesGroup = null;
for (Iterator it = list.iterator();it.hasNext();) {
AbstractRaplaBlock block = (AbstractRaplaBlock) it.next();
Allocatable allocatable = ((RaplaBuilder.RaplaBlockContext)block.getContext()).getGroupAllocatable();
if (allocatable == null) {
if (noAllocatablesGroup == null)
noAllocatablesGroup = new ArrayList();
noAllocatablesGroup.add(block);
continue;
}
List col = (List) groups.get( allocatable );
if (col == null) {
col = new ArrayList();
groups.put( allocatable, col );
}
col.add(block);
}
ArrayList sortedAllocatables = new ArrayList(groups.keySet());
Collections.sort(sortedAllocatables, allocatableComparator);
ArrayList sortedList = new ArrayList();
for (Iterator it = sortedAllocatables.iterator();it.hasNext();) {
sortedList.add( groups.get(it.next()) );
}
if (noAllocatablesGroup != null)
sortedList.add(noAllocatablesGroup);
return sortedList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -