001/*
002 *  Copyright 2018 Anyware Services
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 */
016package org.ametys.runtime.model;
017
018import java.util.Comparator;
019
020import org.ametys.runtime.i18n.I18nizableText;
021
022/**
023 * Comparator of model items. Compare the model items' by their labels using the given {@link Comparator} of {@link I18nizableText}
024 */
025public class I18nizableTextModelItemComparator implements Comparator<ModelItem>
026{
027    private final Comparator<I18nizableText> _labelComparator;
028
029    /**
030     * Constructor
031     * @param labelComparator a {@link Comparator} of {@link I18nizableText}
032     */
033    public I18nizableTextModelItemComparator(Comparator<I18nizableText> labelComparator)
034    {
035        this._labelComparator = labelComparator;
036    }
037
038    public int compare(ModelItem item1, ModelItem item2)
039    {
040        return _labelComparator.compare(item1.getLabel(), item2.getLabel());
041    }
042}