Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.helger.masterdata.vehiclesigns.VehicleSigns Maven / Gradle / Ivy
/**
* Copyright (C) 2014-2017 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.masterdata.vehiclesigns;
import java.util.Locale;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import com.helger.collection.multimap.MultiHashMapLinkedHashSetBased;
import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.collection.impl.CommonsLinkedHashSet;
import com.helger.commons.collection.impl.ICommonsMap;
import com.helger.commons.collection.impl.ICommonsOrderedSet;
import com.helger.commons.exception.InitializationException;
import com.helger.commons.locale.country.CountryCache;
/**
* Source: http://www.unece.org/fileadmin/DAM/trans/conventn/Distsigns.pdf Old
* Source: http://www.unece.org/trans/main/wp1/wp1fdoc/disting-signs-5-2001.pdf
*
* @author Philip Helger
*/
@Immutable
public final class VehicleSigns
{
private static MultiHashMapLinkedHashSetBased s_aCountryToSign = new MultiHashMapLinkedHashSetBased <> ();
private static MultiHashMapLinkedHashSetBased s_aSignToCountry = new MultiHashMapLinkedHashSetBased <> ();
static
{
_add ("AL", "AL");
_add ("DZ", "DZ");
_add ("AD", "AND");
_add ("AR", "RA");
_add ("AM", "AM");
_add ("AU", "AUS");
_add ("AT", "A");
_add ("AZ", "AZ");
_add ("BS", "BS");
_add ("BH", "BRN");
_add ("BD", "BD");
_add ("BB", "BDS");
// old: _add ("BY", "SU");
_add ("BY", "BY");
_add ("BE", "B");
_add ("BZ", "BH");
_add ("BJ", "DY");
_add ("BA", "BIH");
// old: _add ("BW", "RB");
_add ("BW", "BW");
_add ("BR", "BR");
_add ("BN", "BRU");
_add ("BG", "BG");
// old: _add ("KH", "K");
_add ("KH", "KH");
_add ("CA", "CDN");
_add ("CF", "RCA");
_add ("CL", "RCH");
_add ("CN", "RC");
_add ("CG", "RCB");
_add ("CR", "CR");
_add ("CI", "CI");
_add ("HR", "HR");
_add ("CU", "CU");
_add ("CY", "CY");
_add ("CZ", "CZ");
_add ("CD", "ZRE");
_add ("DK", "DK");
_add ("FO", "FO");
_add ("DO", "DOM");
_add ("EC", "EC");
_add ("EG", "ET");
_add ("EE", "EST");
_add ("FJ", "FJI");
_add ("FI", "FIN");
_add ("FR", "F");
_add ("GM", "WAG");
_add ("GE", "GE");
_add ("DE", "D");
_add ("GH", "GH");
// deleted: _add ("GI", "GBZ");
_add ("GR", "GR");
_add ("GD", "WG");
_add ("GT", "GCA");
_add ("GY", "GUY");
_add ("HT", "RH");
_add ("VA", "V");
_add ("HU", "H");
_add ("IS", "IS");
_add ("IN", "IND");
_add ("ID", "RI");
_add ("IR", "IR");
_add ("IE", "IRL");
_add ("IL", "IL");
_add ("IT", "I");
_add ("JM", "JA");
_add ("JP", "J");
_add ("JO", "HKJ");
_add ("KZ", "KZ");
_add ("KE", "EAK");
_add ("KE", "E.A.K.");
_add ("KW", "KWT");
_add ("KG", "KS");
_add ("LA", "LAO");
_add ("LV", "LV");
_add ("LB", "RL");
_add ("LS", "LS");
_add ("LT", "LT");
_add ("LU", "L");
_add ("MG", "RM");
_add ("MW", "MW");
_add ("MY", "MAL");
_add ("ML", "RMM");
_add ("MT", "M");
_add ("MU", "MS");
_add ("MX", "MEX");
_add ("MD", "MD");
_add ("MC", "MC");
_add ("MN", "MGL");
_add ("ME", "MNE");
_add ("MA", "MA");
_add ("MM", "BUR");
_add ("NA", "NAM");
_add ("NL", "NL");
_add ("AN", "NA");
_add ("NZ", "NZ");
_add ("NI", "NIC");
_add ("NE", "RN");
_add ("NG", "WAN");
_add ("NO", "N");
_add ("PK", "PK");
_add ("PG", "PNG");
_add ("PY", "PY");
_add ("PE", "PE");
_add ("PH", "RP");
_add ("PL", "PL");
_add ("PT", "P");
_add ("KP", "ROK");
_add ("KR", "ROK");
_add ("RU", "RUS");
_add ("RW", "RWA");
_add ("LC", "WL");
_add ("VC", "WV");
_add ("WS", "WS");
_add ("SM", "RSM");
_add ("SN", "SN");
_add ("RS", "SRB");
_add ("SC", "SY");
_add ("SL", "WAL");
_add ("SG", "SGP");
_add ("SK", "SK");
_add ("SI", "SLO");
_add ("ZA", "ZA");
_add ("ES", "E");
_add ("LK", "CL");
_add ("SR", "SME");
_add ("SZ", "SD");
_add ("SE", "S");
_add ("CH", "CH");
_add ("SY", "SYR");
_add ("TJ", "TJ");
_add ("TH", "T");
_add ("MK", "MK");
_add ("TG", "TG");
_add ("TT", "TT");
_add ("TN", "TN");
_add ("TR", "TR");
_add ("TM", "TM");
_add ("UG", "EAU");
_add ("UA", "UA");
_add ("GB", "GB");
// Alderney
_add ("GB", "GBA");
_add ("GG", "GBG");
_add ("IM", "GBM");
_add ("JE", "GBJ");
// Tanganyika
_add ("TZ", "EAT");
// Zanzibar
_add ("TZ", "EAZ");
_add ("US", "USA");
_add ("UY", "ROU");
_add ("UZ", "UZ");
_add ("VE", "YV");
// deleted: _add ("YE", "YAR");
_add ("ZM", "RNR");
_add ("ZW", "ZW");
}
private static void _add (@Nonnull final String sCountryCode, @Nonnull final String sSign)
{
final Locale aCountry = CountryCache.getInstance ().getCountry (sCountryCode);
if (s_aCountryToSign.putSingle (aCountry, sSign).isUnchanged ())
throw new InitializationException ("Locale " + aCountry + " already contains sign '" + sSign + "'");
if (s_aSignToCountry.putSingle (sSign, aCountry).isUnchanged ())
throw new InitializationException ("Sign '" + sSign + "' already contains country " + aCountry);
}
private VehicleSigns ()
{}
@Nonnull
@ReturnsMutableCopy
public static ICommonsOrderedSet getAllVehicleSigns (@Nullable final String sCountry)
{
final Locale aRealCountry = CountryCache.getInstance ().getCountry (sCountry);
final ICommonsOrderedSet aSigns = s_aCountryToSign.get (aRealCountry);
return new CommonsLinkedHashSet <> (aSigns);
}
@Nonnull
@ReturnsMutableCopy
public static ICommonsOrderedSet getAllVehicleSigns (@Nullable final Locale aCountry)
{
return getAllVehicleSigns (aCountry == null ? null : aCountry.getCountry ());
}
@Nullable
public static String getSingleVehicleSign (@Nullable final String sCountry)
{
final Locale aRealCountry = CountryCache.getInstance ().getCountry (sCountry);
final ICommonsOrderedSet aSigns = s_aCountryToSign.get (aRealCountry);
if (aSigns != null)
{
if (aSigns.size () == 1)
return aSigns.getFirst ();
throw new IllegalArgumentException ("Multiple vehicle signs are assigned to the country locale '" +
sCountry +
"': " +
aSigns);
}
return null;
}
@Nullable
public static String getSingleVehicleSign (@Nullable final Locale aCountry)
{
return getSingleVehicleSign (aCountry == null ? null : aCountry.getCountry ());
}
/**
* @return The complete map from country locale to all vehicle signs. Never
* null
nor empty.
*/
@Nonnull
@ReturnsMutableCopy
public static ICommonsMap > getCountryToVehicleSignMap ()
{
return s_aCountryToSign.getClone ();
}
@Nonnull
@ReturnsMutableCopy
public static ICommonsOrderedSet getAllCountriesFromVehicleSign (@Nullable final String sSign)
{
final ICommonsOrderedSet aCountries = s_aSignToCountry.get (sSign);
return new CommonsLinkedHashSet <> (aCountries);
}
@Nullable
public static Locale getSingleCountryFromVehicleSign (@Nullable final String sSign)
{
final ICommonsOrderedSet aCountries = s_aSignToCountry.get (sSign);
if (aCountries != null)
{
if (aCountries.size () == 1)
return aCountries.getFirst ();
throw new IllegalArgumentException ("Multiple country locales are assigned to the vehicle sign '" +
sSign +
"': " +
aCountries);
}
return null;
}
/**
* @return A copy of the full map from vehicle sign to country locales. Never
* null
.
* @since 5.0.6
*/
@Nonnull
@ReturnsMutableCopy
public static ICommonsMap > getVehicleSignToCountryMap ()
{
return s_aSignToCountry.getClone ();
}
}