package com.levelup.java.guava;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;

import com.google.common.base.Joiner;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

/**
 * This java example will demonstrate examples of 
 * Google Guava Joiner
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/'></a>
 * 
 */
public class JoinerExample {

	
	@Test
	public void join_a_list_of_strings () { 

		List<String> cloudGroups = Lists.newArrayList("Cirrus", "Alto", "Stratus", "Vertical Growth", "Special Clouds");  
		
		String cloudGroupsJoined = Joiner.on(",").join(cloudGroups);
		assertEquals("Cirrus,Alto,Stratus,Vertical Growth,Special Clouds", cloudGroupsJoined);
	}
	
	@Test
	public void join_a_list_of_strings_skipping_null () {
		List<String> cloudGroups = Lists.newArrayList("Cirrus", "Alto", null, null, "Stratus", "Vertical Growth", "Special Clouds", null);  

		String cloudGroupsJoined = Joiner.on(",").skipNulls().join(cloudGroups);
		assertEquals("Cirrus,Alto,Stratus,Vertical Growth,Special Clouds", cloudGroupsJoined);
	}

	@Test
	public void join_a_list_of_strings_replacing_null () {
		
		List<String> cloudGroups = Lists.newArrayList("Cirrus", "Alto", null, null, "Stratus", "Vertical Growth", "Special Clouds", null);
		
		String cloudGroupsJoined = Joiner.on(" and ").useForNull("[unknown]").join(cloudGroups);

		assertEquals("Cirrus and Alto and [unknown] and [unknown] and Stratus and Vertical Growth and Special Clouds and [unknown]", cloudGroupsJoined);
	}
	
	@Test
	public void join_key_values_map () {
		Multimap<String, String> coulds = ArrayListMultimap.create();
		
		coulds.put("Cirrus", "Cirrus");
		coulds.put("Cirrus", "Cirrostratus");
		coulds.put("Cirrus", "Cirrocumulus");
		
		coulds.put("Alto", "Altostratus");
		coulds.put("Alto", "Altocumulus");
		
		coulds.put("Stratus", "Stratus");
		coulds.put("Stratus", "Stratocumulus");
		coulds.put("Stratus", "Nimbostratus");
		
		coulds.put("Vertical Growth", "Cumulus");
		coulds.put("Vertical Growth", "Cumulonimbus");
		
		coulds.put("Special Clouds", "Mammatus");
		coulds.put("Special Clouds", "Lenticular");
		coulds.put("Special Clouds", "Fog");
		coulds.put("Special Clouds", "Contrails");
		
		String keysAndValuesJoined = Joiner.on(", ").withKeyValueSeparator(" has type ").join(coulds.entries());
		
		assertEquals("Cirrus has type Cirrus, Cirrus has type Cirrostratus, Cirrus has type Cirrocumulus, Vertical Growth has type Cumulus, Vertical Growth has type Cumulonimbus, Alto has type Altostratus, Alto has type Altocumulus, Stratus has type Stratus, Stratus has type Stratocumulus, Stratus has type Nimbostratus, Special Clouds has type Mammatus, Special Clouds has type Lenticular, Special Clouds has type Fog, Special Clouds has type Contrails", 
				keysAndValuesJoined);
	}
	
}

@@ -1712,19 +1712,19 @@
 tring%3E c
+l
 ou
-l
 ds = Arr
@@ -1746,35 +1746,35 @@
 create();%0A%09%09%0A%09%09c
+l
 ou
-l
 ds.put(%22Cirrus%22,
@@ -1780,35 +1780,35 @@
 , %22Cirrus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Cirrus%22,
@@ -1820,35 +1820,35 @@
 rostratus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Cirrus%22,
@@ -1863,35 +1863,35 @@
 umulus%22);%0A%09%09%0A%09%09c
+l
 ou
-l
 ds.put(%22Alto%22, %22
@@ -1900,35 +1900,35 @@
 tostratus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Alto%22, %22
@@ -1940,35 +1940,35 @@
 umulus%22);%0A%09%09%0A%09%09c
+l
 ou
-l
 ds.put(%22Stratus%22
@@ -1976,35 +1976,35 @@
  %22Stratus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Stratus%22
@@ -2018,35 +2018,35 @@
 tocumulus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Stratus%22
@@ -2062,35 +2062,35 @@
 tratus%22);%0A%09%09%0A%09%09c
+l
 ou
-l
 ds.put(%22Vertical
@@ -2106,35 +2106,35 @@
  %22Cumulus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Vertical
@@ -2162,27 +2162,27 @@
 us%22);%0A%09%09%0A%09%09c
+l
 ou
-l
 ds.put(%22Spec
@@ -2206,27 +2206,27 @@
 matus%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Spec
@@ -2252,27 +2252,27 @@
 cular%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22Spec
@@ -2295,19 +2295,19 @@
 g%22);%0A%09%09c
+l
 ou
-l
 ds.put(%22
@@ -2433,11 +2433,11 @@
 in(c
+l
 ou
-l
 ds.e

fix name