zoukankan      html  css  js  c++  java
  • YAML中重复的KEY的判断

    package com.test.util;
    
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    
    public class CheckYaml {
    
    	public void checkYaml(String fileName) {
    		BufferedReader read = null;
    		try {
    			read = new BufferedReader(new InputStreamReader(new FileInputStream("locator/" + fileName)));
    			String temp = read.readLine();
    			List<String> list = new ArrayList<String>();
    			while(temp != null){
    				if(!temp.startsWith(" ") && !temp.trim().startsWith("#")){
    					String key = temp.substring(0, temp.length()-1);
    					if(list.contains(key)){
    						System.out.println("duplicate key: "+key);
    					}else{
    						list.add(key);
    					}
    				}
    				temp = read.readLine();
    			}
    		} catch (FileNotFoundException e) {			
    			e.printStackTrace();
    		} catch (IOException e) {			
    			e.printStackTrace();
    		}finally{			
    			try {
    				if(read != null){
    				read.close();
    				}
    			} catch (IOException e) {				
    				e.printStackTrace();
    			}
    		}		
    	}
    
    	public static void main(String[] args) {
    		CheckYaml cy = new CheckYaml();
    		cy.checkYaml("TestBaidu.yaml");
    	}
    
    }
    
  • 相关阅读:
    1022.游船出租
    1021.统计字符
    1020.最小长方形
    1017.还是畅通工程
    1019.简单计算器
    1015.还是A+B
    1014.排名
    1013.开门人和关门人
    1011.最大连续子序列
    1009.二叉搜索树
  • 原文地址:https://www.cnblogs.com/zhangfei/p/4505714.html
Copyright © 2011-2022 走看看