001/* 002 * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and others. 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 * Contributors: 017 * Radu Darlea 018 * Florent Guillaume 019 */ 020 021package org.nuxeo.ecm.platform.tag; 022 023import org.apache.commons.lang.builder.EqualsBuilder; 024import org.apache.commons.lang.builder.HashCodeBuilder; 025 026import java.io.Serializable; 027import java.util.Comparator; 028 029/** 030 * Aggregates a tag with its weight. 031 * 032 * @deprecated since 9.3, as we don't use the weight anymore 033 */ 034@Deprecated 035public class Tag implements Serializable { 036 037 private static final long serialVersionUID = 1L; 038 039 /** 040 * The tag label. 041 */ 042 public final String label; 043 044 /** 045 * The weight of the tag. 046 */ 047 public long weight; 048 049 public Tag(String label, int weight) { 050 this.label = label; 051 this.weight = weight; 052 } 053 054 public String getLabel() { 055 return label; 056 } 057 058 public long getWeight() { 059 return weight; 060 } 061 062 public void setWeight(long weight) { 063 this.weight = weight; 064 } 065 066 @Override 067 public int hashCode() { 068 return HashCodeBuilder.reflectionHashCode(this); 069 } 070 071 @Override 072 public boolean equals(Object o) { 073 return EqualsBuilder.reflectionEquals(this, o); 074 } 075 076 @Override 077 public String toString() { 078 return getClass().getSimpleName() + '(' + label + ',' + weight + ')'; 079 } 080 081 protected static class TagLabelComparator implements Comparator<Tag> { 082 public int compare(Tag t1, Tag t2) { 083 return t1.label.compareToIgnoreCase(t2.label); 084 } 085 } 086 087 /** 088 * Compare tags by label, case insensitive. 089 */ 090 public static final Comparator<Tag> LABEL_COMPARATOR = new TagLabelComparator(); 091 092 protected static class TagWeightComparator implements Comparator<Tag> { 093 public int compare(Tag t1, Tag t2) { 094 return t2.weight < t1.weight ? -1 : (t2.weight == t1.weight ? 0 : 1); 095 } 096 } 097 098 /** 099 * Compare tags by weight, decreasing. 100 */ 101 public static final Comparator<Tag> WEIGHT_COMPARATOR = new TagWeightComparator(); 102 103}