1 /*
   2  * Copyright (c) 2016, 2019, 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.nio.file.FileSystems;
  36 import java.time.LocalDateTime;
  37 import java.time.ZoneId;
  38 import java.time.format.DateTimeFormatter;
  39 import java.util.stream.Stream;
  40 import java.util.logging.*;
  41 import java.util.Arrays;
  42 import java.util.Date;
  43 import java.util.List;
  44 import java.util.Locale;
  45 import java.text.DateFormat;
  46 
  47 import static java.util.stream.Collectors.*;
  48 
  49 /**
  50  * This class is used to generate a classlist during build. Intent
  51  * is to touch a reasonable amount of JDK classes that are commonly
  52  * loaded and used early.
  53  */
  54 public class HelloClasslist {
  55 
  56     private static final Logger LOGGER = Logger.getLogger("Hello");
  57 
  58     public static void main(String ... args) {
  59 
  60         FileSystems.getDefault();
  61 
  62         List<String> strings = Arrays.asList("Hello", "World!", "From: ",
  63               InetAddress.getLoopbackAddress().toString());
  64 
  65         String helloWorld = strings.parallelStream()
  66               .map(s -> s.toLowerCase(Locale.ROOT))
  67               .collect(joining(","));
  68 
  69         Stream.of(helloWorld.split(","))
  70               .forEach(System.out::println);
  71 
  72         // Common concatenation patterns
  73         String SS     = String.valueOf(args.length) + String.valueOf(args.length);
  74         String CS     = "string" + String.valueOf(args.length);
  75         String SC     = String.valueOf(args.length) + "string";
  76         String SCS    = String.valueOf(args.length) + "string" + String.valueOf(args.length);
  77         String CSS    = "string" + String.valueOf(args.length) + String.valueOf(args.length);
  78         String CSC    = "string" + String.valueOf(args.length) + "string";
  79         String SSC    = String.valueOf(args.length) + String.valueOf(args.length) + "string";
  80         String CSCS   = "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length);
  81         String SCSC   = String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string";
  82         String CSCSC  = "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string";
  83         String SCSCS  = String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length);
  84         String CI     = "string" + args.length;
  85         String IC     = args.length + "string";
  86         String CIC    = "string" + args.length + "string";
  87         String CICI   = "string" + args.length + "string" + args.length;
  88         String CJ     = "string" + System.currentTimeMillis();
  89         String JC     = System.currentTimeMillis() + "string";
  90         String CJC    = "string" + System.currentTimeMillis() + "string";
  91         String CJCJ   = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis();
  92         String CJCJC  = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis() + "string";
  93 
  94         String newDate = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
  95                 LocalDateTime.now(ZoneId.of("GMT")));
  96 
  97         String oldDate = String.format("%s%n",
  98                 DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ROOT)
  99                         .format(new Date()));
 100 
 101         LOGGER.log(Level.INFO, "New Date: " + newDate + " - old: " + oldDate);
 102     }
 103 
 104 }