001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.util.common.form; 018 019import java.io.Serializable; 020import java.util.HashMap; 021import java.util.HashSet; 022import java.util.Map; 023import java.util.Set; 024 025public class TransferProperties 026 implements Serializable { 027 028 private Map<Class, Set<String>> classesAndProperties = new HashMap<>(); 029 private Map<Class, String> collectionFilters = new HashMap<>(); 030 031 public TransferProperties addClassAndProperty(Class clazz, String property) { 032 Set<String> properties = classesAndProperties.get(clazz); 033 034 if(properties == null) { 035 properties = new HashSet<>(); 036 037 classesAndProperties.put(clazz, properties); 038 } 039 040 if(property != null) { 041 properties.add(property); 042 } 043 044 return this; 045 } 046 047 public TransferProperties addClassAndProperties(Class clazz, String... properties) { 048 for(var property : properties) { 049 addClassAndProperty(clazz, property); 050 } 051 052 return this; 053 } 054 055 public TransferProperties addCollectionFilter(Class clazz, String expression) { 056 collectionFilters.put(clazz, expression); 057 058 return this; 059 } 060 061 public Set<String> getProperties(Class clazz) { 062 return classesAndProperties.get(clazz); 063 } 064 065 public String getExpression(Class clazz) { 066 return collectionFilters.get(clazz); 067 } 068 069}