Java Code Examples for com.google.common.collect.ImmutableSortedSet.Builder

The following are top voted examples for showing how to use com.google.common.collect.ImmutableSortedSet.Builder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: google-cloud-eclipse   File: ArtifactRetriever.java   View source code 5 votes vote down vote up
@Override
public NavigableSet<ArtifactVersion> load(String coordinates) throws Exception {
  Document document = getMetadataDocument(coordinates);
  XPath xpath = XPathFactory.newInstance().newXPath();
  NodeList versionNodes = (NodeList) xpath.evaluate(
      "/metadata/versioning/versions/version",
      document,
      XPathConstants.NODESET);
  Builder<ArtifactVersion> versions = ImmutableSortedSet.naturalOrder();
  for (int i = 0; i < versionNodes.getLength(); i++) {
    String versionString = versionNodes.item(i).getTextContent();
    versions.add(new DefaultArtifactVersion(versionString));
  }
  return versions.build();
}
 
Example 2
Project: sdh-vocabulary   File: LanguagePack.java   View source code 5 votes vote down vote up
Set<String> tagUris(final String tag) {
	final Optional<Integer> langId = tagLanguage(tag);
	if(!langId.isPresent()) {
		return Collections.emptySet();
	}
	final Set<Part> tagParts = tagParts(tag);
	if(tagParts.isEmpty()) {
		throw new CorruptedLanguagePackException("Missing parts for tag '"+tag+"'");
	}
	final Builder<String> builder = ImmutableSortedSet.<String>naturalOrder();
	for(final Tag.Part part:tagParts) {
		builder.add(getProperty(languagePartUriProperty(langId.get(), part),"Coult not find uri for tag '"+tag+"' of ISO 639-"+part));
	}
	return builder.build();
}
 
Example 3
Project: sdh-vocabulary   File: LanguagePack.java   View source code 5 votes vote down vote up
Set<Tag.Part> tagParts(final String tag) {
	final String property = this.properties.getProperty(tagPartsProperty(tag));
	if(property==null) {
		return Collections.emptySet();
	}
	final Builder<Tag.Part> builder = ImmutableSortedSet.<Tag.Part>naturalOrder();
	for(final String rawPart:Splitter.on(',').splitToList(property)) {
		builder.add(part(rawPart));
	}
	return builder.build();
}
 
Example 4
Project: sdh-vocabulary   File: LanguagePack.java   View source code 5 votes vote down vote up
Set<Tag.Part> languageParts(final int langId) {
	final String property = this.properties.getProperty(languagePartsProperty(langId));
	if(property==null) {
		return Collections.emptySet();
	}
	final Builder<Tag.Part> builder = ImmutableSortedSet.<Tag.Part>naturalOrder();
	for(final String rawPart:Splitter.on(',').splitToList(property)) {
		builder.add(part(rawPart));
	}
	return builder.build();
}
 
Example 5
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T> Collector<T, ?, ImmutableList<T>> toImmutableList() {

		return Collector.of(
				ImmutableList.Builder<T>::new, 
				ImmutableList.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableList.Builder<T>::build);
	}
 
Example 6
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T> Collector<T, ?, ImmutableSet<T>> toImmutableSet() {

		return Collector.of(
				ImmutableSet.Builder<T>::new, 
				ImmutableSet.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableSet.Builder<T>::build);
	}
 
Example 7
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T> Collector<T, ?, ImmutableMultiset<T>> toImmutableMultiset() {

		return Collector.of(
				ImmutableMultiset.Builder<T>::new, 
				ImmutableMultiset.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableMultiset.Builder<T>::build);
	}
 
Example 8
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T extends Comparable<?>> Collector<T, ImmutableSortedSet.Builder<T>, ImmutableSortedSet<T>> toImmutableSortedSet() {		

		return Collector.of(
				ImmutableSortedSet::<T> naturalOrder,
				ImmutableSortedSet.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableSortedSet.Builder<T>::build );
	}
 
Example 9
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T extends Comparable<?>> Collector<T, ImmutableSortedSet.Builder<T>, ImmutableSortedSet<T>> toImmutableSortedSetReversed() {		

		return Collector.of(
				ImmutableSortedSet::<T> reverseOrder,
				ImmutableSortedSet.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableSortedSet.Builder<T>::build,
				Characteristics.UNORDERED);
	}
 
Example 10
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T> Collector<T, ?, ImmutableSortedSet<T>> toImmutableSortedSet( final Supplier<Builder<T>> supplier ){

		return Collector.of(
				supplier,
				ImmutableSortedSet.Builder<T>::add,
				(l, r) -> l.addAll(r.build()), 
				ImmutableSortedSet.Builder<T>::build,
				Characteristics.UNORDERED);
	}
 
Example 11
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T> Collector<T, ?, ImmutableSortedSet<T>> toImmutableSortedSet( final Comparator<T> supplier ){;

	return Collector.of(
			() -> ImmutableSortedSet.orderedBy( supplier ),
			ImmutableSortedSet.Builder<T>::add,
			(l, r) -> l.addAll(r.build()), 
			ImmutableSortedSet.Builder<T>::build,
			Characteristics.UNORDERED);	
	}
 
Example 12
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T, K, V> Collector<T,?,ImmutableMap<K,V>> toImmutableMap(
		final Function<T,K> keyFunction,
		final Function<T,V> valueFunction ){

	return Collector.of( 
			ImmutableMap::<K,V>builder, 
			( builder, value ) -> builder.put( keyFunction.apply( value ), valueFunction.apply( value )),
			(l, r) -> l.putAll( r.build() ),
			ImmutableMap.Builder<K,V>::build);
}
 
Example 13
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T, K, V> Collector<T,?,ImmutableBiMap<K,V>> toImmutableBiMap(
		final Function<T,K> keyFunction,
		final Function<T,V> valueFunction ){

	return Collector.of( 
			ImmutableBiMap::<K,V> builder,
			(builder, value) -> builder.put( keyFunction.apply( value ), valueFunction.apply( value )),
			(l, r) -> l.putAll( r.build() ),
			ImmutableBiMap.Builder<K,V>::build);

}
 
Example 14
Project: guava-collectors   File: GuavaCollectors.java   View source code 5 votes vote down vote up
public static <T, R, C, V> Collector<T,?,ImmutableTable<R,C,V>> toImmutableTable( 
		final Function<T,R> rowFunction,
		final Function<T,C> columnFunction,
		final Function<T,V> valueFunction ){

	return Collector.of( 
			ImmutableTable::<R,C,V> builder,
			(builder, value ) -> builder.put( rowFunction.apply( value ), columnFunction.apply( value ), valueFunction.apply( value )),
			(l, r) -> l.putAll( r.build() ),
			ImmutableTable.Builder<R,C,V>::build);		
}