001package org.apache.archiva.model; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.lang.StringUtils; 023 024/** 025 * Keys - utility methods for converting common objects into string keys. 026 * 027 * 028 */ 029public class Keys 030{ 031 public static String toKey( String groupId, String artifactId, String version, String classifier, String type ) 032 { 033 StringBuilder key = new StringBuilder(); 034 035 key.append( groupId ).append( ":" ); 036 key.append( artifactId ).append( ":" ); 037 key.append( version ).append( ":" ); 038 key.append( StringUtils.defaultString( classifier ) ).append( ":" ); 039 key.append( type ); 040 041 return key.toString(); 042 } 043 044 public static String toKey( ArtifactReference ref ) 045 { 046 return toKey( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref.getClassifier(), ref.getType() ); 047 } 048 049 public static String toKey( ProjectReference ref ) 050 { 051 StringBuilder key = new StringBuilder(); 052 053 key.append( ref.getGroupId() ).append( ":" ); 054 key.append( ref.getArtifactId() ); 055 056 return key.toString(); 057 } 058 059 public static String toKey( String groupId, String artifactId, String version ) 060 { 061 StringBuilder key = new StringBuilder(); 062 063 key.append( groupId ).append( ":" ); 064 key.append( artifactId ).append( ":" ); 065 key.append( version ); 066 067 return key.toString(); 068 } 069 070 public static String toKey( VersionedReference ref ) 071 { 072 return toKey( ref.getGroupId(), ref.getArtifactId(), ref.getVersion() ); 073 } 074}