1 /*
   2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * This application is meant to be run to create a classlist file representing
  28  * common use.
  29  *
  30  * The classlist is produced by adding -XX:DumpLoadedClassList=classlist
  31  */
  32 package build.tools.classlist;
  33 
  34 import java.net.InetAddress;
  35 import java.time.LocalDateTime;
  36 import java.time.ZoneId;
  37 import java.time.format.DateTimeFormatter;
  38 import java.util.stream.Stream;
  39 import java.util.logging.*;
  40 import java.util.Arrays;
  41 import java.util.Date;
  42 import java.util.List;
  43 import java.util.Locale;
  44 import java.text.DateFormat;
  45 
  46 import static java.util.stream.Collectors.*;
  47 
  48 /**
  49  * This class is used to generate a classlist during build. Intent
  50  * is to touch a reasonable amount of JDK classes that are commonly
  51  * loaded and used early.
  52  */
  53 public class HelloClasslist {
  54 
  55     private static final Logger LOGGER = Logger.getLogger("Hello");
  56 
  57     public static void main(String ... args) {
  58 
  59         List<String> strings = Arrays.asList("Hello", "World!", "From: ",
  60               InetAddress.getLoopbackAddress().toString());
  61 
  62         String helloWorld = "";
  63         /*
  64         strings.parallelStream()
  65               .map(s -> s.toLowerCase(Locale.ROOT))
  66               .collect(joining(","));
  67         */
  68 
  69         Stream.of(helloWorld.split(","))
  70               .forEach(System.out::println);
  71 
  72         // Common concatenation patterns
  73         String const_I = "string" + args.length;
  74         String const_S = "string" + String.valueOf(args.length);
  75         String S_const = String.valueOf(args.length) + "string";
  76         String S_S     = String.valueOf(args.length) + String.valueOf(args.length);
  77         String const_J = "string" + System.currentTimeMillis();
  78         String I_const = args.length + "string";
  79         String J_const = System.currentTimeMillis() + "string";
  80 
  81         String newDate = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
  82                 LocalDateTime.now(ZoneId.of("GMT")));
  83 
  84         String oldDate = String.format("%s%n",
  85                 DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ROOT)
  86                         .format(new Date()));
  87 
  88         LOGGER.log(Level.INFO, "New Date: " + newDate + " - old: " + oldDate);
  89     }
  90 
  91 }