public void whenReverseList_thenReversed() {
    List<String> names = Lists.newArrayList("John", "Adam", "Jane");
 
    List<String> reversed = Lists.reverse(names);
    assertThat(reversed, contains("Jane", "Adam", "John"));
}

        

class ListUtils
{
	// Java program to creates a mutable ArrayList instance using 
	// Guava's Lists.newArrayList() method
	public static void main(String[] args)
	{
		// 1. create an empty mutable ArrayList
		List<Integer> emptyList = Lists.newArrayList();
		System.out.println(emptyList);

		// 2. create a mutable ArrayList from elements of the given array
		Integer[] ints = { 1, 2, 3 };
		List<Integer> list = Lists.newArrayList(ints);
		System.out.println(list);

		// 3. create a mutable ArrayList from elements of the given iterable
		Iterable<Integer> iterable = Arrays.asList(1, 2, 3, 4);
		List<Integer> collection = Lists.newArrayList(iterable);
		System.out.println(collection);
		
		// 4. create a mutable ArrayList from given Iterator
		Iterator<Integer> itr = Arrays.asList(1, 2, 3, 4, 5).iterator();
		List<Integer> mutableList = Lists.newArrayList(itr);
		System.out.println(mutableList);
	}
}

        

public void staticFactoryMethodsOfCollections() {
	// Generic collections without Guava
	List<Integer> list1 = new ArrayList<Integer>();
	Set<String> set1 = new HashSet<String>();
	Map<Integer, String> map1 = new HashMap<Integer, String>();

	// Generic collections with Guava
	List<Integer> list2 = newArrayList();
	Set<String> set2 = newHashSet();
	Map<Integer, String> map2 = newHashMap();
	// Don't need to retype the generic anymore

	// Prepopulated collections without Guava
	List<Integer> ints1 = new ArrayList<Integer>(Arrays.asList(1, 2, 3));

	// Prepopulated collections with Guava
	List<Integer> ints2 = newArrayList(1, 2, 3);

	// Immutable collections without Guava
	List<String> strs1 =
			unmodifiableList(new ArrayList<String>(Arrays.asList("A", "B", "C")));
	@SuppressWarnings("serial")
	Map<Integer, String> int2Str1 =
	unmodifiableMap(new HashMap<Integer, String>() {

		{
			put(1, "a");
			put(2, "b");
			put(3, "c");
		}
	});

	// Immutable collections with Guava
	List<String> strs2 = ImmutableList.of("A", "B", "C");
	Map<Integer, String> int2Str2 = ImmutableMap.of(1, "a", 2, "b", 3, "c");
}

        

public void makeNewCollectionsInline() {
	{
		// Don't need to specify generic types on right hand side
		List<String> names = Lists.newArrayList();
		names.add("Joe");
	}

	{
		// Empty immutable list
		List<String> names = ImmutableList.of();
	}

	{
		// Immutable list built in one line of code
		List<String> names = ImmutableList.of("Joe", "Tom");
	}

	{
		// Convenient map creation
		Map<Integer, String> people = ImmutableMap.of(1, "Joe",
				2, "Tom");
	}
}

        

public class InitializeCollectionEx {

    public static void main(String[] args) {

        Map items = ImmutableMap.of("coin", 3, "glass", 4, "pencil", 1);

        items.entrySet()
                .stream()
                .forEach(System.out::println);
        
        List<String> fruits = Lists.newArrayList("orange", "banana", "kiwi", 
                "mandarin", "date", "quince");
        
        for (String fruit: fruits) {
            System.out.println(fruit);
        }
    }
}

        

static void rollForwardByApplyingLogs(
    RemoteEditLogManifest manifest,
    FSImage dstImage,
    FSNamesystem dstNamesystem) throws IOException {
  NNStorage dstStorage = dstImage.getStorage();

  List<EditLogInputStream> editsStreams = Lists.newArrayList();    
  for (RemoteEditLog log : manifest.getLogs()) {
    if (log.getEndTxId() > dstImage.getLastAppliedTxId()) {
      File f = dstStorage.findFinalizedEditsFile(
          log.getStartTxId(), log.getEndTxId());
      editsStreams.add(new EditLogFileInputStream(f, log.getStartTxId(), 
                                                  log.getEndTxId(), true));
    }
  }
  LOG.info("Checkpointer about to load edits from " +
      editsStreams.size() + " stream(s).");
  dstImage.loadEdits(editsStreams, dstNamesystem);
}

        

public void testDate_Part() throws Exception {
  final String query = "select date_part('year', date '2008-2-23') as col \n" +
      "from cp.`tpch/region.parquet` \n" +
      "limit 0";

  List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList();
  MajorType majorType = Types.required(MinorType.BIGINT);
  expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType));

  testBuilder()
      .sqlQuery(query)
      .schemaBaseLine(expectedSchema)
      .build()
      .run();
}

        

public ServerResponse getOrderCartProduct(Integer userId) {
    OrderProductVo orderProductVo = new OrderProductVo();

    List<Cart> cartList = cartMapper.selectCheckedCartByUserId(userId);
    ServerResponse serverResponse = this.getCartOrderItem(userId, cartList);

    if (!serverResponse.isSuccess()) {
        return serverResponse;
    }
    List<OrderItem> orderItemList = (List<OrderItem>) serverResponse.getData();

    List<OrderItemVo> orderItemVoList = Lists.newArrayList();

    BigDecimal payment = new BigDecimal("0");
    for (OrderItem orderItem : orderItemList) {
        payment = BigDecimalUtil.add(payment.doubleValue(), orderItem.getTotalPrice().doubleValue());
        orderItemVoList.add(assembleOrderItemVo(orderItem));
    }
    orderProductVo.setProductTotalPrice(payment);
    orderProductVo.setOrderItemVoList(orderItemVoList);
    orderProductVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix"));

    return ServerResponse.createBySuccess(orderProductVo);
}

        

public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
{
    if (args.length == 1)
    {
        Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
        List<String> list = Lists.<String>newArrayList();

        for (ScoreObjective scoreobjective : scoreboard.getScoreObjectives())
        {
            if (scoreobjective.getCriteria() == IScoreObjectiveCriteria.TRIGGER)
            {
                list.add(scoreobjective.getName());
            }
        }

        return getListOfStringsMatchingLastWord(args, (String[])list.toArray(new String[list.size()]));
    }
    else
    {
        return args.length == 2 ? getListOfStringsMatchingLastWord(args, new String[] {"add", "set"}): null;
    }
}

        

public List<Object> deserialize(ByteBuffer ser) {
    // If this flag is true, return null.
    if (returnNull) {
        return null;
    }

    // Probably a better way to do this juggling.
    if (ser == null) {
        return null;
    }
    ser.rewind();
    byte[] bytes = new byte[ser.remaining()];
    ser.get(bytes, 0, bytes.length);

    return Lists.newArrayList(new String(bytes, Charsets.UTF_8));
}        
main