ICU-10491 check in J samples
X-SVN-Rev: 34590
This commit is contained in:
parent
604f679894
commit
a2f8930fe9
7
.gitattributes
vendored
7
.gitattributes
vendored
@ -579,6 +579,13 @@ icu4j/manifest.stub -text
|
||||
icu4j/perf-tests/data/icuperf2report.xsl -text
|
||||
icu4j/samples/build.properties -text
|
||||
icu4j/samples/manifest.stub -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/es.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/res_index.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/root.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/es.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/mt.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/res_index.res -text
|
||||
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/root.res -text
|
||||
icu4j/tools/build/.settings/org.eclipse.core.resources.prefs -text
|
||||
icu4j/tools/build/icu4j28.api.gz -text
|
||||
icu4j/tools/build/icu4j30.api.gz -text
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -915,6 +915,8 @@ icu4j/main/tests/packaging/out
|
||||
icu4j/main/tests/translit/out
|
||||
icu4j/out
|
||||
icu4j/perf-tests/out
|
||||
icu4j/samples/build-local.properties
|
||||
icu4j/samples/out
|
||||
icu4j/tools/build/out
|
||||
icu4j/tools/misc/out
|
||||
tools/multi/c/Makefile.local
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!--
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011, International Business Machines Corporation and *
|
||||
* Copyright (C) 2011-2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
-->
|
||||
@ -28,4 +28,58 @@
|
||||
<target name="jar" depends="compile, copy, @jar" description="Create the project's jar file"/>
|
||||
|
||||
<target name="src-jar" depends="@src-jar" description="Create the project's source jar file"/>
|
||||
|
||||
<target name="rebuild-iuc-data" description="Rebuild IUC sample data">
|
||||
<!-- package to build into -->
|
||||
<property name="iuc.package" value="com/ibm/icu/samples/iuc" />
|
||||
<!-- output location -->
|
||||
<property name="iuc.dataoutdir" value="src/${iuc.package}/data" />
|
||||
<!-- tmp location -->
|
||||
<property name="iuc.tmp" value="out/tmp" />
|
||||
<!-- property for the root dir of our messages. -->
|
||||
<fail unless="iuc.res.src" message="Please set -Diuc.res.src=/path/ where /path/ is a checkout of http://source.icu-project.org/repos/icu/icuapps/trunk/icufacts/c" />
|
||||
<!-- properties for the two packages we will be building. -->
|
||||
<property name="iuc.res.reshello" value="reshello" />
|
||||
<property name="iuc.res.popmsg" value="popmsg" />
|
||||
<!-- paths for these two packages -->
|
||||
<property name="iuc.res.reshello.path" value="${iuc.res.src}/s30_reshello/${iuc.res.reshello}" />
|
||||
<property name="iuc.res.popmsg.path" value="${iuc.res.src}/s40_popmsg/${iuc.res.popmsg}" />
|
||||
<property name="iuc.bldicures" value="bldicures" />
|
||||
<!-- <available file="${iuc.bldicures}" type="file" property="iuc.bldicures.present" /> -->
|
||||
<fail unless="iuc.bldicures" message="Please set -Diuc.bldicures=/path/bldicures.py - which you can get from <http://source.icu-project.org/repos/icu/tools/trunk/scripts/bldicures.py>" />
|
||||
<mkdir dir="${iuc.tmp}" />
|
||||
<!-- make reshello -->
|
||||
<delete dir="${iuc.tmp}/${iuc.res.reshello}" /> <!-- clean up -->
|
||||
<exec executable="${iuc.bldicures}">
|
||||
<arg value="-v" />
|
||||
<arg value="--endian" />
|
||||
<arg value="big" />
|
||||
<arg value="--mode" />
|
||||
<arg value="files" />
|
||||
<arg value="--from" />
|
||||
<arg value="${iuc.res.reshello.path}" />
|
||||
<arg value="--dest" />
|
||||
<arg value="${iuc.tmp}/${iuc.res.reshello}" />
|
||||
<arg value="--name" />
|
||||
<arg value="${iuc.res.reshello}" />
|
||||
</exec>
|
||||
<move file="${iuc.tmp}/${iuc.res.reshello}/${iuc.res.reshello}" todir="${iuc.dataoutdir}/" />
|
||||
<!-- make popmsg -->
|
||||
<delete dir="${iuc.tmp}/${iuc.res.popmsg}" /> <!-- clean up -->
|
||||
<exec executable="${iuc.bldicures}">
|
||||
<arg value="-v" />
|
||||
<arg value="--endian" />
|
||||
<arg value="big" />
|
||||
<arg value="--mode" />
|
||||
<arg value="files" />
|
||||
<arg value="--from" />
|
||||
<arg value="${iuc.res.popmsg.path}" />
|
||||
<arg value="--dest" />
|
||||
<arg value="${iuc.tmp}/${iuc.res.popmsg}" />
|
||||
<arg value="--name" />
|
||||
<arg value="${iuc.res.popmsg}" />
|
||||
</exec>
|
||||
<move file="${iuc.tmp}/${iuc.res.popmsg}/${iuc.res.popmsg}" todir="${iuc.dataoutdir}/" />
|
||||
<delete dir="${iuc.tmp}" /> <!-- clean up -->
|
||||
</target>
|
||||
</project>
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.UResourceBundleIterator;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class PopulationData {
|
||||
/**
|
||||
* Entry in the population list
|
||||
*/
|
||||
public static class TerritoryEntry implements Comparable<TerritoryEntry> {
|
||||
private String territoryName;
|
||||
private double population;
|
||||
public TerritoryEntry(String displayCountry, double population) {
|
||||
this.territoryName = displayCountry;
|
||||
this.population = population;
|
||||
}
|
||||
public String territoryName() {
|
||||
return territoryName;
|
||||
}
|
||||
public double population() {
|
||||
return population;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
public int compareTo(TerritoryEntry o) {
|
||||
int rc = 0;
|
||||
if (rc==0) rc = territoryName.compareTo(o.territoryName());
|
||||
if (rc==0) rc = ((Double)population).compareTo(o.population());
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
public static Set<TerritoryEntry> getTerritoryEntries(ULocale loc, Set<TerritoryEntry> entries) {
|
||||
// Note: format of supplementalData is NOT STATIC and may change. It is internal to ICU!
|
||||
UResourceBundle suppData = SupplementalUtilities.getICUSupplementalData();
|
||||
UResourceBundle territoryInfo = suppData.get("territoryInfo");
|
||||
// int nTerr = territoryInfo.getSize();
|
||||
for(UResourceBundleIterator iter = territoryInfo.getIterator();iter.hasNext();) {
|
||||
UResourceBundle rawEntry= iter.next();
|
||||
UResourceBundle territoryF = rawEntry.get("territoryF");
|
||||
int vec[] = territoryF.getIntVector();
|
||||
|
||||
// now we have the entry
|
||||
// territoryF = { gdp, literacy, population }
|
||||
String terrID = rawEntry.getKey();
|
||||
ULocale territory = new ULocale("und", terrID);
|
||||
entries.add(new TerritoryEntry(territory.getDisplayCountry(loc), SupplementalUtilities.ldml2d(vec[2])));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
System.out.println("Loading population/territory data from CLDR");
|
||||
Set<TerritoryEntry> territoryEntries = getTerritoryEntries(ULocale.getDefault(), new HashSet<TerritoryEntry>());
|
||||
System.out.println(".. count="+ territoryEntries.size());
|
||||
for(TerritoryEntry te : territoryEntries) {
|
||||
System.out.println(" "+ te.territoryName() + " = " + te.population());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import com.ibm.icu.text.LocaleDisplayNames;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class Sample13_Hello {
|
||||
public static void main(String... args) {
|
||||
String world = LocaleDisplayNames
|
||||
.getInstance(ULocale.getDefault()).regionDisplayName("001");
|
||||
System.out.println("Hello, " + world + "\u2603");
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ibm.icu.text.LocaleDisplayNames;
|
||||
import com.ibm.icu.text.LocaleDisplayNames.DialectHandling;
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class Sample20_Message {
|
||||
public static void main(String... args) {
|
||||
ULocale defaultLocaleID = ULocale.getDefault();
|
||||
LocaleDisplayNames ldn = LocaleDisplayNames.getInstance(defaultLocaleID, DialectHandling.DIALECT_NAMES);
|
||||
String defaultLocaleName = ldn.localeDisplayName(defaultLocaleID);
|
||||
String world = ldn.regionDisplayName("001");
|
||||
MessageFormat fmt = new MessageFormat("A hello to {part, number, percent} of the {world}, in {mylocale}, on {today, date}!",
|
||||
defaultLocaleID);
|
||||
Map<String, Object> msgargs = new HashMap<String, Object>();
|
||||
msgargs.put("part", 1.00);
|
||||
msgargs.put("world", world);
|
||||
msgargs.put("mylocale", defaultLocaleName);
|
||||
msgargs.put("today", System.currentTimeMillis());
|
||||
System.out.println(fmt.format(msgargs, new StringBuffer(), null));
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class Sample30_ResHello {
|
||||
public static void main(String... args) {
|
||||
ULocale locale = ULocale.getDefault();
|
||||
UResourceBundle bundle =
|
||||
UResourceBundle.getBundleInstance(
|
||||
Sample30_ResHello.class.getPackage().getName().replace('.', '/')+"/data/reshello",
|
||||
locale,
|
||||
Sample30_ResHello.class.getClassLoader());
|
||||
System.out.println(bundle.getString("hello"));
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.samples.iuc.PopulationData.TerritoryEntry;
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class Sample40_PopMsg {
|
||||
public static void main(String... args) {
|
||||
// setup
|
||||
ULocale locale = ULocale.getDefault();
|
||||
Set<PopulationData.TerritoryEntry> territoryList;
|
||||
territoryList = PopulationData.getTerritoryEntries(locale,
|
||||
new HashSet<TerritoryEntry>());
|
||||
UResourceBundle resourceBundle =
|
||||
UResourceBundle.getBundleInstance(
|
||||
Sample40_PopMsg.class.getPackage().getName().replace('.', '/')+"/data/popmsg",
|
||||
locale,
|
||||
Sample40_PopMsg.class.getClassLoader());
|
||||
|
||||
// say hello
|
||||
String welcome = resourceBundle.getString("welcome");
|
||||
Map<String, Object> welcomeArgs = new HashMap<String, Object>();
|
||||
welcomeArgs.put("territoryCount", territoryList.size());
|
||||
System.out.println( MessageFormat.format(welcome, welcomeArgs) );
|
||||
|
||||
// Population roll call
|
||||
String info = resourceBundle.getString("info");
|
||||
Map<String, Object> infoArgs = new HashMap<String, Object>();
|
||||
for(PopulationData.TerritoryEntry entry : territoryList) {
|
||||
infoArgs.put("territory", entry.territoryName());
|
||||
infoArgs.put("population", entry.population());
|
||||
System.out.println(MessageFormat.format(info, infoArgs));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.ibm.icu.samples.iuc.PopulationData.TerritoryEntry;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class Sample50_PopSort {
|
||||
public static void main(String... args) {
|
||||
// setup
|
||||
final ULocale locale = ULocale.getDefault();
|
||||
Set<PopulationData.TerritoryEntry> territoryList;
|
||||
final Collator collator = Collator.getInstance(locale);
|
||||
territoryList = PopulationData.getTerritoryEntries(locale,
|
||||
new TreeSet<TerritoryEntry>(new Comparator<TerritoryEntry>(){
|
||||
public int compare(TerritoryEntry o1, TerritoryEntry o2) {
|
||||
return collator.compare(o1.territoryName(), o2.territoryName());
|
||||
}}));
|
||||
UResourceBundle resourceBundle =
|
||||
UResourceBundle.getBundleInstance(
|
||||
Sample40_PopMsg.class.getPackage().getName().replace('.', '/')+"/data/popmsg",
|
||||
locale,
|
||||
Sample40_PopMsg.class.getClassLoader());
|
||||
|
||||
// say hello
|
||||
String welcome = resourceBundle.getString("welcome");
|
||||
Map<String, Object> welcomeArgs = new HashMap<String, Object>();
|
||||
welcomeArgs.put("territoryCount", territoryList.size());
|
||||
System.out.println( MessageFormat.format(welcome, welcomeArgs) );
|
||||
|
||||
// Population roll call
|
||||
String info = resourceBundle.getString("info");
|
||||
Map<String, Object> infoArgs = new HashMap<String, Object>();
|
||||
for(PopulationData.TerritoryEntry entry : territoryList) {
|
||||
infoArgs.put("territory", entry.territoryName());
|
||||
infoArgs.put("population", entry.population());
|
||||
System.out.println(MessageFormat.format(info, infoArgs));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
*/
|
||||
public class SupplementalUtilities {
|
||||
/**
|
||||
* Convert LDML2ICUConverter format floating point (territoryF, etc)
|
||||
* into double.
|
||||
* See: SupplementalMapper.java
|
||||
* @param n input number, such as -48123456
|
||||
* @return double value, such as -123.456
|
||||
* @internal
|
||||
*/
|
||||
public static double ldml2d(int n) {
|
||||
if(n == 0) {
|
||||
return 0.;
|
||||
}
|
||||
boolean neg = false;
|
||||
if(n < 0) {
|
||||
n = -n;
|
||||
neg = true;
|
||||
}
|
||||
int exp = (n/1000000);
|
||||
n -= (exp * 1000000);
|
||||
int sexp = exp - 50; // signed exponent
|
||||
double d = n;
|
||||
d = d * Math.pow(10, (sexp-5)); // -5 because 50 isn't quite right..
|
||||
if(neg) {
|
||||
d = -d;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/** Test function */
|
||||
public static void main(String... args) {
|
||||
|
||||
System.out.println("Testingldml2d");
|
||||
int junk[] = {
|
||||
49990000, // 99%
|
||||
48680000, // 6.8%
|
||||
57344400, // ?
|
||||
52940000, // ?
|
||||
0,
|
||||
-48123456, // gets -0.012346 not -123.456
|
||||
-52123456, // this one gets -123.456
|
||||
46100000,
|
||||
63146600
|
||||
};
|
||||
|
||||
for(int i=0;i<junk.length;i++) {
|
||||
System.out.println(Integer.toString(junk[i]) + " -> " + Double.toString(ldml2d(junk[i])));
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Testing getICUSupplementalData");
|
||||
System.out.println("SupplementalData has " + getICUSupplementalData().getSize() + " size. (nonzero is good!)" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open ICU supplemental data
|
||||
* @return the bundle
|
||||
*/
|
||||
public static UResourceBundle getICUSupplementalData() {
|
||||
UResourceBundle suppData = UResourceBundle.getBundleInstance(
|
||||
ICUResourceBundle.ICU_BASE_NAME,
|
||||
"supplementalData",
|
||||
ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
return suppData;
|
||||
}
|
||||
}
|
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/es.res
Normal file
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/es.res
Normal file
Binary file not shown.
Binary file not shown.
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/root.res
Normal file
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/popmsg/root.res
Normal file
Binary file not shown.
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/es.res
Normal file
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/es.res
Normal file
Binary file not shown.
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/mt.res
Normal file
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/mt.res
Normal file
Binary file not shown.
Binary file not shown.
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/root.res
Normal file
BIN
icu4j/samples/src/com/ibm/icu/samples/iuc/data/reshello/root.res
Normal file
Binary file not shown.
13
icu4j/samples/src/com/ibm/icu/samples/iuc/package-info.java
Normal file
13
icu4j/samples/src/com/ibm/icu/samples/iuc/package-info.java
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
/**
|
||||
* @author srl
|
||||
*
|
||||
* This package contains samples for the IUC ICU workshops.
|
||||
*
|
||||
*/
|
||||
package com.ibm.icu.samples.iuc;
|
Loading…
Reference in New Issue
Block a user