package com.siebel.api.server.config.rest;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* @Author Tim
* @Date 2020/6/10 16:11
*/
public class Test {
public static void main(String[] args) {
List<String> list = Lists.newArrayList();
Set<String> set = Sets.newHashSet();
Map<String,Object> map2 = Maps.newHashMap();
Map<String,Object> map = Maps.newConcurrentMap();
ImmutableList<String> immutableList = ImmutableList.of("1", "2", "3");// 不可变集合
//字符串判空操作:
String s = ""; Boolean isEmpty = StringUtils.isEmpty(s);
//判断集合是否为空:
Boolean isNotEmpty = CollectionUtils.isNotEmpty(list);
//list直接转string拼接起来,可以指定拼接符号
List<String> list2 = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
String result = Joiner.on(">").join(list2);
String result2 = Joiner.on("").join(list2);
System.out.println("result="+result);
System.out.println("result2="+result2);
// 连接字符串,当然也可以使用重载的方法,加上一些前缀,后缀和中间分隔符
String strEmp = list.stream().map(emp -> emp.getName()).collect(Collectors.joining());
String strEmp1 = list.stream().map(emp -> emp.getName()).collect(Collectors.joining("-中间的分隔符-"));
String strEmp2 = list.stream().map(emp -> emp.getName()).collect(Collectors.joining("-中间的分隔符-", "前缀*", "&后缀"));
// 小名小红小蓝小灰小黄小白
// 小名-中间的分隔符-小红-中间的分隔符-小蓝-中间的分隔符-小灰-中间的分隔符-小黄-中间的分隔符-小白
// 前缀*小名-中间的分隔符-小红-中间的分隔符-小蓝-中间的分隔符-小灰-中间的分隔符-小黄-中间的分隔符-小白&后缀
//求交集、并集、差集等
Set<Integer> set1 = Sets.newHashSet(1, 2, 3, 4, 5, 6);
Set<Integer> set2 = Sets.newHashSet(1,2,3,4);
Sets.SetView<Integer> intersection = Sets.intersection(set1, set2);
System.out.println("交集="+intersection);
//一个post或者get请求
User user = new User();
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpMethod method = HttpMethod.POST;
// 以表单的方式提交 将请求头部和参数合成一个请求
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<User> requestEntity = new HttpEntity<>(user, headers);
String ssoUrl = "http://10.95.33.81:8181/customer/v1.0.0/members/membersUpser";
ResponseEntity<User> responseEntity = client.exchange(ssoUrl , method, requestEntity, User.class);
System.out.println("http返回数据:"+responseEntity); } }