001package com.thetransactioncompany.util; 002 003 004import java.util.Properties; 005 006 007/** 008 * Property filtering utilities. 009 * 010 * @author Vladimir Dzhuvinov 011 */ 012public class PropertyFilter { 013 014 015 016 /** 017 * Filters properties with the specified name prefix. 018 * 019 * @param prefix The property name prefix to filter matching 020 * properties. Must not be {@code null}. 021 * @param props The properties to filter, {@code null} 022 * 023 * @return The filtered properties, empty if no matches were found or 024 * the original properties are empty or {@code null}. 025 */ 026 public static Properties filterWithPrefix(final String prefix, final Properties props) { 027 028 Properties filteredProps = new Properties(); 029 030 if (props == null || props.isEmpty()) { 031 return filteredProps; 032 } 033 034 for (String key: props.stringPropertyNames()) { 035 036 if (key.startsWith(prefix)) { 037 filteredProps.put(key, props.getProperty(key)); 038 } 039 } 040 041 return filteredProps; 042 } 043}