|
| 1 | +/* |
| 2 | + * Copyright © 2024 XDEV Software (https://xdev.software) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package software.xdev.vaadin.utl; |
| 17 | + |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Comparator; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import software.xdev.vaadin.model.ChipBadge; |
| 23 | +import software.xdev.vaadin.model.ChipBadgeExtension; |
| 24 | +import software.xdev.vaadin.model.FilterCondition; |
| 25 | + |
| 26 | + |
| 27 | +public final class FilterComponentUtl<T> |
| 28 | +{ |
| 29 | + public FilterComponentUtl() |
| 30 | + { |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Check if the lists contains the same chip badges objects |
| 35 | + * |
| 36 | + * @param one List one |
| 37 | + * @param two List two |
| 38 | + * @return True if the lists contains the same objects |
| 39 | + */ |
| 40 | + public boolean equalLists( |
| 41 | + final List<ChipBadgeExtension<FilterCondition<T, ?>>> one, |
| 42 | + final List<ChipBadgeExtension<FilterCondition<T, ?>>> two) |
| 43 | + { |
| 44 | + if(one == null && two == null) |
| 45 | + { |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + if(one == null || two == null || one.size() != two.size()) |
| 50 | + { |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + // to avoid messing the order of the lists we will use a copy |
| 55 | + final List<ChipBadgeExtension<FilterCondition<T, ?>>> oneCopy = new ArrayList<>(one); |
| 56 | + final List<ChipBadgeExtension<FilterCondition<T, ?>>> twoCopy = new ArrayList<>(two); |
| 57 | + |
| 58 | + oneCopy.sort(Comparator.comparing(ChipBadge::getBadgeId)); |
| 59 | + twoCopy.sort(Comparator.comparing(ChipBadge::getBadgeId)); |
| 60 | + return one.equals(two); |
| 61 | + } |
| 62 | +} |
0 commit comments