<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.designer.util;

import java.util.ArrayList;

import org.eclipse.birt.report.designer.nls.Messages;

import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.util.Currency;
import com.ibm.icu.util.ULocale;

/**
 * A pattern class serves for getting and setting pattern string for a currency.
 */
public class FormatCurrencyNumPattern extends FormatNumberPattern
{

	private int decPlaces = 0;
	private boolean useSep = false;
	private boolean useSpace = false;
	private boolean useBracket = false;
	private String symbol = ""; //$NON-NLS-1$
	private String symPos = ""; //$NON-NLS-1$

	public static String[] BUILT_IN_SYMBOLS;

	static
	{
		java.util.List<String> list = new ArrayList<String>( );
		list.add( Messages.getString( "FormatNumberPage.currency.symbol.none" ) ); //$NON-NLS-1$
		list.add( "\u00A5" ); //$NON-NLS-1$
		list.add( "$" ); //$NON-NLS-1$
		list.add( "\u20ac" ); //$NON-NLS-1$
		list.add( "\u00A3" ); //$NON-NLS-1$
		//list.add( "\u20A9" ); //$NON-NLS-1$
		list.add( "DKK" ); //$NON-NLS-1$

		String defaultSymbol = Currency.getInstance( ULocale.getDefault( ) )
				.getSymbol( );
		/*
		 * bug 233779, the localSymbol doesn't allow to be null in IBM JDK List
		 * but in Sun JDK, it's option and ArrayList allows to be null.
		 */
		if ( defaultSymbol != null && !list.contains( defaultSymbol ) )
		{
			list.add( 1, defaultSymbol );
		}
		BUILT_IN_SYMBOLS = list.toArray( new String[list.size( )] );
	}

	/**
	 * Returns the default currency symbol position for given locale. Returns
	 * <code>null</code> if no symbol needed by default.
	 * 
	 * @param locale
	 * @return
	 */
	public static String getDefaultSymbolPosition( ULocale locale )
	{
		if ( locale == null )
		{
			locale = ULocale.getDefault( );
		}

		Currency currency = Currency.getInstance( locale );
		if ( currency != null )
		{
			String symbol = currency.getSymbol( );<commit_msg>- Bugzilla Bug (s) Resolved: 314123 - Description: handle the case when retrieve default currency symbol while coutry is not set in current locale setting<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.designer.util;

import java.util.ArrayList;

import org.eclipse.birt.report.designer.nls.Messages;

import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.util.Currency;
import com.ibm.icu.util.ULocale;

/**
 * A pattern class serves for getting and setting pattern string for a currency.
 */
public class FormatCurrencyNumPattern extends FormatNumberPattern
{

	private int decPlaces = 0;
	private boolean useSep = false;
	private boolean useSpace = false;
	private boolean useBracket = false;
	private String symbol = ""; //$NON-NLS-1$
	private String symPos = ""; //$NON-NLS-1$

	public static String[] BUILT_IN_SYMBOLS;

	static
	{
		java.util.List<String> list = new ArrayList<String>( );
		list.add( Messages.getString( "FormatNumberPage.currency.symbol.none" ) ); //$NON-NLS-1$
		list.add( "\u00A5" ); //$NON-NLS-1$
		list.add( "$" ); //$NON-NLS-1$
		list.add( "\u20ac" ); //$NON-NLS-1$
		list.add( "\u00A3" ); //$NON-NLS-1$
		//list.add( "\u20A9" ); //$NON-NLS-1$
		list.add( "DKK" ); //$NON-NLS-1$

		String defaultSymbol = null;
		Currency defaultCurrency = Currency.getInstance( ULocale.getDefault( ) );
		if ( defaultCurrency != null )
		{
			// the default currency could be null if country is not set properly
			// in locale settings.
			defaultSymbol = defaultCurrency.getSymbol( );
		}

		/*
		 * bug 233779, the localSymbol doesn't allow to be null in IBM JDK List
		 * but in Sun JDK, it's option and ArrayList allows to be null.
		 */
		if ( defaultSymbol != null && !list.contains( defaultSymbol ) )
		{
			list.add( 1, defaultSymbol );
		}
		BUILT_IN_SYMBOLS = list.toArray( new String[list.size( )] );
	}

	/**
	 * Returns the default currency symbol position for given locale. Returns
	 * <code>null</code> if no symbol needed by default.
	 * 
	 * @param locale
	 * @return
	 */
	public static String getDefaultSymbolPosition( ULocale locale )
	{
		if ( locale == null )
		{
			locale = ULocale.getDefault( );
		}

		Currency currency = Currency.getInstance( locale );
		if ( currency != null )
		{
			String symbol = currency.getSymbol( );
{'fraction_non_alphanumeric': 0.18029704831735288, 'fraction_numerical': 0.014664410603496898, 'mean_word_length': 3.7627573858549686, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7493637', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1627, 'n_words': 469}