001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.common.util.property;
017
018import java.util.Comparator;
019import java.util.List;
020
021import org.kuali.common.util.Assert;
022import org.springframework.util.CollectionUtils;
023
024/**
025 * @deprecated
026 */
027@Deprecated
028public class ProjectPropertiesComparator implements Comparator<ProjectProperties> {
029
030        List<String> order;
031
032        @Override
033        public int compare(ProjectProperties one, ProjectProperties two) {
034
035                Assert.isFalse(CollectionUtils.isEmpty(order), "order is empty");
036
037                String id1 = getIdString(one);
038                String id2 = getIdString(two);
039
040                Integer index1 = order.indexOf(id1);
041                Integer index2 = order.indexOf(id2);
042
043                if (index1 == -1) {
044                        throw new IllegalStateException("Could not find an index for " + id1);
045                }
046                if (index1 == -2) {
047                        throw new IllegalStateException("Could not find an index for " + id2);
048                }
049
050                return index1.compareTo(index2);
051        }
052
053        protected String getIdString(ProjectProperties pp) {
054                org.kuali.common.util.Project p = pp.getProject();
055                StringBuilder sb = new StringBuilder();
056                sb.append(p.getGroupId());
057                sb.append(":");
058                sb.append(p.getArtifactId());
059                return sb.toString();
060        }
061
062        public List<String> getOrder() {
063                return order;
064        }
065
066        public void setOrder(List<String> order) {
067                this.order = order;
068        }
069
070}