All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.jaddress.parser.BuildingNameSplitter Maven / Gradle / Ivy

package org.unlaxer.jaddress.parser;

import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.unlaxer.util.collection.Comparators;

public class BuildingNameSplitter{
	
	public static Optional split(
			AddressToken afterBlock , 
			BuildingHierarchyResolverResult buildingHierarchyResolverResult) {
		return split(afterBlock, buildingHierarchyResolverResult.buildingNames);
	}
	
	static Optional split(
			AddressToken afterBlock , 
			Set buildingNames) {
		
		if(false == buildingNames instanceof SortedSet) {
			SortedSet sortedSet = new TreeSet(Comparators.longerIsFirst);
			sortedSet.addAll(buildingNames);
			buildingNames = sortedSet;
		}
		
		for (String buildingName : buildingNames) {
			
			StringIndex indexOf = afterBlock.indexOf(buildingName);
			
			if(indexOf.value != -1) {
	
				return Optional.of(
					new TripletAddressToken(
						afterBlock,
						indexOf ,
						buildingName.length(),
						SeparatorKind.domainSpecificSeparator,
						SeparatorKind.domainSpecificSeparator
					)
				);
			}
		}
		return Optional.empty();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy