📄 listmaptemplaterepository.java
字号:
package com.esri.solutions.jitk.common.templates.map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Implementation of a Map Template Repository that uses a List of
* Map Template objects for the Repository. This implementation
* will allow a list of Map Template objects to be injected via
* {@link #setMapTemplates(List)}. This implementation will also
* build an index between the Map Template ID and the Map Template
* object in order to speed up the {@link #getMapTemplate(String)}
* operation.
*
* <p>
* This implementation is only to be used in deployments where
* there aren't many Map Templates.
* </p>
*/
public class ListMapTemplateRepository implements IMapTemplateRepository {
/**
* List of Map Templates.
*/
private final List<IMapTemplate> m_templates;
/**
* Index between a Map Template ID and the Map Template object.
*/
private final Map<String, IMapTemplate> m_idMap;
/**
* Constructs a new <code>ListMapTemplateRepository</code>.
*/
public ListMapTemplateRepository () {
m_templates = new ArrayList<IMapTemplate>();
m_idMap = new HashMap<String, IMapTemplate>();
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.common.templates.map.IMapTemplateRepository#getMapTemplate(java.lang.String)
*/
public IMapTemplate getMapTemplate(String id) {
//return m_idMap.get(id);
if (id == null) {
return null;
}
for (IMapTemplate template : m_templates) {
if (id.equals(template.getId())) {
return template;
}
}
return null;
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.common.templates.map.IMapTemplateRepository#getMapTemplateCount()
*/
public int getMapTemplateCount() {
return m_templates.size();
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.common.templates.map.IMapTemplateRepository#getMapTemplates()
*/
public List<IMapTemplate> getMapTemplates() {
//return new ArrayList<IMapTemplate>(m_templates);
return m_templates;
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.common.templates.map.IMapTemplateRepository#getMapTemplates(com.esri.solutions.jitk.common.templates.map.PageInfo)
*/
public List<IMapTemplate> getMapTemplates(PageInfo page) {
int pageIndex = page.getPage();
int pageSize = page.getPageSize();
int start = Math.max(0, pageIndex * pageSize);
int end = Math.max(m_templates.size() - 1, start + pageSize - 1);
return new ArrayList<IMapTemplate>(m_templates.subList(start, end));
}
/**
* Sets the List of Map Templates for this Repository. This method
* will store the references to the Map Templates as well as
* build an index between the Map Template ID and the Map Template
* object for easy retrieval.
*
* @param templates List of Map Templates, cannot be <code>null</code>.
* @throws NullPointerException Thrown if the templates argument
* is <code>null</code>.
*/
public void setMapTemplates (List<IMapTemplate> templates) {
if (templates == null) {
throw new NullPointerException ();
}
synchronized (m_templates) {
m_templates.clear();
m_templates.addAll(templates);
}
synchronized (m_idMap) {
for (IMapTemplate t : m_templates) {
t.setRepository(this);
m_idMap.put(t.getId(), t);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -