Java tutorial
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.ocsoft.olivia.models.project; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import org.frows.genericfile.v0_3_2.GenericFile; import org.ocsoft.olivia.DefaultValues; import org.ocsoft.olivia.models.association.AssociationList; import org.ocsoft.olivia.models.contents.config.OliviaConfig; import org.ocsoft.olivia.models.contents.config.def.BasicProjectConfigDef; import org.ocsoft.olivia.models.file.OliviaFile; import com.fasterxml.jackson.core.type.TypeReference; /** * * @author tohhy * */ public class ProjectConfig { /** * */ private final OliviaProject project; /** * */ private final OliviaConfig config; /** * ????????. */ private String dirNodeBindedFileName = "_dir.txt"; /** * ????. */ private String newNodePrefix = "node"; /** * ????. */ private String basicExt = "txt"; /** * ???. */ @Nonnull private final AssociationList association; /** * */ private List<String> excludeFilePatterns = new ArrayList<>(); /** * * @param project * @param projectDir */ public ProjectConfig(OliviaProject project, OliviaFile projectDir) { this.project = project; GenericFile configFile = new GenericFile(project.getProjectDataDir().getOrigin(), DefaultValues.PROJECT_CONFIG_FILENAME); this.config = new OliviaConfig(OliviaFile.create(configFile)); this.excludeFilePatterns.addAll(DefaultValues.PROJECT_DEFAULT_EXCLUDE_FILES); this.association = new AssociationList(); } /** * OliviaProject???????.<br> * ?Olivia???. */ void load() { // Map<String, Integer> indexes = config.getAsType(BasicProjectConfigDef.ProjectNodeIndexes, new TypeReference<Map<String, Integer>>() { }); project.sortTreeByIndexMap(indexes); List<String> expandedNodes = config.getAsType(BasicProjectConfigDef.ProjectExpandedNodes, new TypeReference<List<String>>() { }); project.setExpandState(expandedNodes); } /** * */ void store() { config.set(BasicProjectConfigDef.ProjectNodeIndexes, project.createNodePositionMap()); config.set(BasicProjectConfigDef.ProjectExpandedNodes, project.createExpandedNodePathStringList()); try { config.storeContent(); } catch (IOException e) { e.printStackTrace(); } } /** * * @param newNodePrefix */ public void setNewNodePrefix(String newNodePrefix) { this.newNodePrefix = newNodePrefix; } /** * * @param newNodeExt */ public void setNewNodeExt(String newNodeExt) { this.basicExt = newNodeExt; } /** * * @return */ public String getDirNodeBindedFileName() { return dirNodeBindedFileName; } /** * * @param dirNodeBindedFileName */ public void setDirNodeBindedFileName(String dirNodeBindedFileName) { this.dirNodeBindedFileName = dirNodeBindedFileName; } /** * * @return */ public String getNewNodePrefix() { return newNodePrefix; } /** * * @return */ public String getBasicExt() { return basicExt; } /** * * @return */ public List<String> getExcludeFilePatterns() { return excludeFilePatterns; } /** * * @param excludeFilePatterns */ public void setExcludeFilePatterns(List<String> excludeFilePatterns) { this.excludeFilePatterns = excludeFilePatterns; } /** * ???????. * @return ????? */ @Nonnull public AssociationList getAssociation() { return association; } /** * * @return */ public OliviaConfig getConfig() { return config; } }