Java tutorial
/* * Copyright 1998-2012 Linux.org.ru * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ru.org.linux.section; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import java.util.List; @Service public class SectionService { private ImmutableList<Section> sectionList; @Autowired SectionDao sectionDao; /** * ? ?? ? . * ?? ? ? ? ?? . */ @PostConstruct private void initializeSectionList() { Builder<Section> sectionListBuilder = ImmutableList.builder(); List<Section> sections = sectionDao.getAllSections(); sectionListBuilder.addAll(sections); sectionList = sectionListBuilder.build(); } /** * ? . * * @param SectionName ? * @return ? * @throws SectionNotFoundException ? ?? */ public int getSectionIdByName(String SectionName) throws SectionNotFoundException { if (sectionList == null) { initializeSectionList(); } for (Section section : sectionList) { if (section.getName().equals(SectionName)) { return section.getId(); } } throw new SectionNotFoundException(); } /** * ? ?. * * @param sectionId ? * @return ? * @throws SectionNotFoundException ? ?? */ public Section getSection(int sectionId) throws SectionNotFoundException { for (Section section : sectionList) { if (section.getId() == sectionId) { return section; } } throw new SectionNotFoundException(sectionId); } /** * ?? ?. * * @return ?? ? */ public ImmutableList<Section> getSectionList() { return sectionList; } /** * ? ? ?. * * @param id ? * @return ?? ? ? */ public String getAddInfo(int id) { return sectionDao.getAddInfo(id); } /** * "??" ?. * * @param sectionId ? * @return "??" ? * @throws SectionNotFoundException */ public SectionScrollModeEnum getScrollMode(int sectionId) throws SectionNotFoundException { Section section = getSection(sectionId); return section.getScrollMode(); } }