List of usage examples for java.text ChoiceFormat ChoiceFormat
public ChoiceFormat(double[] limits, String[] formats)
From source file:Main.java
public static void main(String args[]) { double limits[] = { 0.0, 0.1, 0.3, 0.7 }; String labels[] = { "very low", "low", "moderate", "high" }; ChoiceFormat format = new ChoiceFormat(limits, labels); double r = Math.random(); System.out.println(format.format(r) + " (" + r + ")."); }
From source file:ChoiceFormatDemo.java
static void displayMessages(Locale currentLocale) { System.out.println("currentLocale = " + currentLocale.toString()); System.out.println();/* w w w . j a va 2 s. c om*/ ResourceBundle bundle = ResourceBundle.getBundle("ChoiceBundle", currentLocale); MessageFormat messageForm = new MessageFormat(""); messageForm.setLocale(currentLocale); double[] fileLimits = { 0, 1, 2 }; String[] fileStrings = { bundle.getString("noFiles"), bundle.getString("oneFile"), bundle.getString("multipleFiles") }; ChoiceFormat choiceForm = new ChoiceFormat(fileLimits, fileStrings); String pattern = bundle.getString("pattern"); Format[] formats = { choiceForm, null, NumberFormat.getInstance() }; messageForm.applyPattern(pattern); messageForm.setFormats(formats); Object[] messageArguments = { null, "XDisk", null }; for (int numFiles = 0; numFiles < 4; numFiles++) { messageArguments[0] = new Integer(numFiles); messageArguments[2] = new Integer(numFiles); String result = messageForm.format(messageArguments); System.out.println(result); } }
From source file:org.springframework.cloud.deployer.resource.maven.MavenArtifactResolver.java
/** * Resolve an artifact and return its location in the local repository. Aether performs the normal * Maven resolution process ensuring that the latest update is cached to the local repository. * In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>, * the POM is also resolved and cached./*from w ww. j a v a 2s .co m*/ * @param resource the {@link MavenResource} representing the artifact * @return a {@link FileSystemResource} representing the resolved artifact in the local repository * @throws IllegalStateException if the artifact does not exist or the resolution fails */ Resource resolve(MavenResource resource) { Assert.notNull(resource, "MavenResource must not be null"); validateCoordinates(resource); RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository()); ArtifactResult resolvedArtifact; try { List<ArtifactRequest> artifactRequests = new ArrayList<>(2); if (properties.isResolvePom()) { artifactRequests.add( new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); } artifactRequests .add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests); resolvedArtifact = results.get(results.size() - 1); } catch (ArtifactResolutionException e) { ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " }); MessageFormat messageFormat = new MessageFormat( "Failed to resolve MavenResource: {0}. Configured remote {1}: {2}"); messageFormat.setFormat(1, pluralizer); String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]"); throw new IllegalStateException(messageFormat .format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e); } return toResource(resolvedArtifact); }