From 6cf1b105e3df4ae0c4515ae608e15dcc07244141 Mon Sep 17 00:00:00 2001 From: MZC02-KIMCY Date: Mon, 16 Dec 2019 11:00:49 +0900 Subject: [PATCH 1/3] update code --- .DS_Store | Bin 0 -> 6148 bytes CODE_OF_CONDUCT.md | 4 + CONTRIBUTING.md | 61 +++++ LICENSE | 15 ++ pom.xml | 112 +++++++++ .../com/company/sample/application/App.java | 80 ++++++ .../application/CreateIllegalOrderThread.java | 36 +++ .../sample/application/CreateOrderThread.java | 72 ++++++ .../sample/application/ListOrderThread.java | 90 +++++++ .../com/company/sample/application/Order.java | 67 +++++ .../sample/application/ProductName.java | 46 ++++ .../sample/application/SalesSystem.java | 60 +++++ .../com/company/sample/application/Util.java | 233 ++++++++++++++++++ 13 files changed, 876 insertions(+) create mode 100644 .DS_Store create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 pom.xml create mode 100644 src/main/java/com/company/sample/application/App.java create mode 100644 src/main/java/com/company/sample/application/CreateIllegalOrderThread.java create mode 100644 src/main/java/com/company/sample/application/CreateOrderThread.java create mode 100644 src/main/java/com/company/sample/application/ListOrderThread.java create mode 100644 src/main/java/com/company/sample/application/Order.java create mode 100644 src/main/java/com/company/sample/application/ProductName.java create mode 100644 src/main/java/com/company/sample/application/SalesSystem.java create mode 100644 src/main/java/com/company/sample/application/Util.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + 4.0.0 + + com.amazon.SampleApplication + example + 1.0-SNAPSHOT + + example + + + UTF-8 + 1.8 + 1.8 + + + + + + codeguru-profiler + codeguru-profiler + https://d1osg35nybn3tt.cloudfront.net + + + + + + + software.amazon.awssdk + bom + 2.9.17 + pom + import + + + + + + + + com.amazonaws + codeguru-profiler-java-agent + 0.1.0 + + + + com.amazonaws + aws-java-sdk-s3 + 1.11.543 + + + + software.amazon.awssdk + auth + 2.9.17 + + + + com.google.guava + guava + 28.1-jre + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/src/main/java/com/company/sample/application/App.java b/src/main/java/com/company/sample/application/App.java new file mode 100644 index 0000000..e59fb6e --- /dev/null +++ b/src/main/java/com/company/sample/application/App.java @@ -0,0 +1,80 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; +import software.amazon.codeguruprofilerjavaagent.Profiler; + +public class App { + + public static void main(String[] args) { + // start the profiler + Profiler.builder().profilingGroupName("CodeGuru-Profiler-Sample") + .awsCredentialsProvider(DefaultCredentialsProvider.create()) + .build() + .start(); + + App app = new App(); + + while(true){ + app.load(); + app.load1(); + app.load2(); + } + } + + private void load() { + for (int i =0; i< 1 << 20; ++i){ + computeShort(); + } + } + + private void load1(){ + for (int i =0; i< 1 << 20; ++i){ + computeMedium(); + } + } + + private void load2(){ + for (int i =0; i< 1 << 20; ++i){ + computeLong(); + } + } + + private void computeShort(){ + long x = 0; + for (int i =0; i< 1 << 15; ++i){ + x += i; + } + } + + private void computeMedium(){ + long x = 0; + for (int i =0; i< 1 << 17; ++i){ + x += i; + } + } + + private void computeLong(){ + long x = 0; + for (int i =0; i< 1 << 18; ++i){ + x += i; + } + } +} + diff --git a/src/main/java/com/company/sample/application/CreateIllegalOrderThread.java b/src/main/java/com/company/sample/application/CreateIllegalOrderThread.java new file mode 100644 index 0000000..fe5099d --- /dev/null +++ b/src/main/java/com/company/sample/application/CreateIllegalOrderThread.java @@ -0,0 +1,36 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +public class CreateIllegalOrderThread extends CreateOrderThread{ + + private volatile boolean exit = false; + + public void run() { + while (!exit) { + //some illegal product names + createOrder("MANGO"); + createOrder("STRAWBERRY"); + createOrder("BANANA"); + createOrder("GRAPE"); + createOrder("CHERRY"); + } + + } +} + diff --git a/src/main/java/com/company/sample/application/CreateOrderThread.java b/src/main/java/com/company/sample/application/CreateOrderThread.java new file mode 100644 index 0000000..655a981 --- /dev/null +++ b/src/main/java/com/company/sample/application/CreateOrderThread.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import com.google.common.base.Optional; +import java.util.Date; +import java.util.Random; + +public class CreateOrderThread extends Thread{ + + static int id = 0; + + private volatile boolean exit = false; + + private static Random random = new Random(); + + public void run() { + while (!exit) { + createOrder("APPLE"); + createOrder("ORANGE"); + createOrder("PINEAPPLE"); + } + + } + + /** + * Create random orders + * @param productName + */ + public void createOrder(String productName){ + try { + Date orderDate = Util.getRandomDate(); + Optional optional = ProductName.getProductName(productName); + + if (!optional.isPresent()) { + return; + } + + ProductName enumProductName = optional.get(); + + Order order = new Order(enumProductName, orderDate, random.nextDouble() * 10000, id); + + if (SalesSystem.orders.size() > 10000) { + SalesSystem.orders.clear(); + id = 0; + } + + SalesSystem.orders.put(orderDate, order); + id++; + } catch (IllegalArgumentException e){ + //e.printStackTrace(); + //not showing exception stack trace here because it will wash away Profiler's running log + } + } + +} + diff --git a/src/main/java/com/company/sample/application/ListOrderThread.java b/src/main/java/com/company/sample/application/ListOrderThread.java new file mode 100644 index 0000000..ac4dd91 --- /dev/null +++ b/src/main/java/com/company/sample/application/ListOrderThread.java @@ -0,0 +1,90 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.text.DateFormat; +import java.text.DateFormatSymbols; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ListOrderThread extends Thread { + private volatile boolean exit = false; + + /** + * Resolution: uncomment the following line to see how this improves the profile. + */ +// private static DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(); +// private static DateFormat myFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", dateFormatSymbols); +// private static DateFormat todayFormat = new SimpleDateFormat("dd MMM yyyy", dateFormatSymbols); + /** + * Here DateFormatSymbols are not provided to the SimpleDateFormat + * constructor and it will look up on every call, comment the below two lines + */ + private static DateFormat myFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); + private static DateFormat todayFormat = new SimpleDateFormat("dd MMM yyyy"); + + private static String today = null; + + @Override + public void run() { + while (!exit) { + listOrders(); + + } + } + + /** + * List the same day orders + */ + private void listOrders(){ + ObjectMapper objectMapper = new ObjectMapper(); + + String productNames = ""; + + synchronized (SalesSystem.orders) { + for(Date orderDate: SalesSystem.orders.keySet()){ + try { + objectMapper.setDateFormat(myFormat); + Date todayDate = todayFormat.parse(this.today); + if(Util.isSameDay(orderDate, todayDate)) { + String orderAsString = objectMapper.writeValueAsString(SalesSystem.orders.get(orderDate)); + System.out.println(orderAsString); + + productNames += "," + SalesSystem.orders.get(orderDate).getProductName(); + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + productNames = productNames.substring(2); + System.out.println("Product Names : " + productNames); + + } + } + + public void setDate(String today){ + this.today = today; + } +} + diff --git a/src/main/java/com/company/sample/application/Order.java b/src/main/java/com/company/sample/application/Order.java new file mode 100644 index 0000000..507b3a0 --- /dev/null +++ b/src/main/java/com/company/sample/application/Order.java @@ -0,0 +1,67 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import java.util.Date; + +public class Order { + private ProductName productName; + private Date salesDate; + private double amount; + private int orderId; + + public Order(ProductName productName, Date salesDate, double amount, int orderId) { + this.productName = productName; + this.salesDate = salesDate; + this.amount = amount; + this.orderId = orderId; + } + + public ProductName getProductName() { + return productName; + } + + public void setProductName(ProductName productName) { + this.productName = productName; + } + + public Date getSalesDate() { + return salesDate; + } + + public void setSalesDate(Date salesDate) { + this.salesDate = salesDate; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } +} + diff --git a/src/main/java/com/company/sample/application/ProductName.java b/src/main/java/com/company/sample/application/ProductName.java new file mode 100644 index 0000000..9eb2695 --- /dev/null +++ b/src/main/java/com/company/sample/application/ProductName.java @@ -0,0 +1,46 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import com.google.common.base.Enums; + +import com.google.common.base.Optional; + +public enum ProductName{ + + APPLE, ORANGE, PINEAPPLE; + + /** + * Pick a random value of the ProductName enum. + * @return a random ProductName. + */ + public static Optional getProductName(String name) { + /** + * Here is attempting to parse a value in the enum, if the value is not found in the enum, + * it results in an exception being thrown, comment the below two lines to fix it and uncomment line 43 + */ + ProductName productName = ProductName.valueOf(name); + return Optional.of(productName); + + /** + * Resolution: uncomment the following line to see how this improves the profile. + */ +// return Enums.getIfPresent(ProductName.class, name); + } +} + diff --git a/src/main/java/com/company/sample/application/SalesSystem.java b/src/main/java/com/company/sample/application/SalesSystem.java new file mode 100644 index 0000000..a520f7c --- /dev/null +++ b/src/main/java/com/company/sample/application/SalesSystem.java @@ -0,0 +1,60 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; +import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; +import software.amazon.codeguruprofilerjavaagent.Profiler; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +import java.util.Date; +import java.util.concurrent.ConcurrentHashMap; + +public class SalesSystem { + + public static ConcurrentHashMap orders = new ConcurrentHashMap(); + + public static void main(String[] args) { + //Start the profiler + Profiler systemProfiler = + Profiler.builder().profilingGroupName("CodeGuru-Profiler-Sample") + .awsCredentialsProvider(ProfileCredentialsProvider.create("megazone")) + .build(); + + systemProfiler.start(); + + //Start create order thread + CreateOrderThread createOrderThread = new CreateOrderThread(); + createOrderThread.start(); + + //Start create Illegal order thread + CreateIllegalOrderThread createIllegalOrderThread = new CreateIllegalOrderThread(); + createIllegalOrderThread.start(); + + //Start list order thread + ListOrderThread listOrderThread = new ListOrderThread(); + + DateFormat currentDateFormat = new SimpleDateFormat("dd MMM yyyy"); + listOrderThread.setDate(currentDateFormat.format(new Date())); + + listOrderThread.start(); + } +} + diff --git a/src/main/java/com/company/sample/application/Util.java b/src/main/java/com/company/sample/application/Util.java new file mode 100644 index 0000000..c513a33 --- /dev/null +++ b/src/main/java/com/company/sample/application/Util.java @@ -0,0 +1,233 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT-0 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the "Software"), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.company.sample.application; + +import java.util.*; + +public class Util { + /** + * generate a random date in this year + * @return + */ + public static Date getRandomDate(){ + + GregorianCalendar gc = new GregorianCalendar(); + + int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR)); + + gc.set(gc.DAY_OF_YEAR, dayOfYear); + + return gc.getTime(); + } + + /** + * get a random number between start and end + * @param start + * @param end + * @return + */ + public static int randBetween(int start, int end) { + return start + (int)Math.round(Math.random() * (end - start)); + } + + /** + * Judge two dates are in the same day + * @param date1 + * @param date2 + * @return + */ + public static boolean isSameDay(Date date1, Date date2) { + if(date1 == null && date2 == null) { + throw new IllegalArgumentException("The date must not be null"); + } + //logic to compare the dates and return boolean. + Calendar cal1 = Calendar.getInstance(); + Calendar cal2 = Calendar.getInstance(); + cal1.setTime(date1); + cal2.setTime(date2); + return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR); + } + + public static int test(int len) { + int test = 0; + for(int i=0; i repo = new HashMap(); + if(repo.containsKey(ip)) { + return repo.get(ip); + } + return ""; + } +} + From f5735de125494cc69af77d85351539f2ffcabb58 Mon Sep 17 00:00:00 2001 From: Mark Wilson-Thomas Date: Tue, 31 Dec 2019 12:16:06 -0800 Subject: [PATCH 2/3] Adding TZ setter to see if comment goes away from CodeGuru --- .classpath | 44 ++++++++++++++++++ .project | 23 +++++++++ .settings/org.eclipse.core.resources.prefs | 3 ++ .settings/org.eclipse.jdt.apt.core.prefs | 2 + .settings/org.eclipse.jdt.core.prefs | 9 ++++ .settings/org.eclipse.m2e.core.prefs | 4 ++ .../sample/application/SalesSystem.java | 4 +- .../com/company/sample/application/App.class | Bin 0 -> 2228 bytes .../CreateIllegalOrderThread.class | Bin 0 -> 700 bytes .../application/CreateOrderThread.class | Bin 0 -> 2275 bytes .../sample/application/ListOrderThread.class | Bin 0 -> 3348 bytes .../company/sample/application/Order.class | Bin 0 -> 1472 bytes .../sample/application/ProductName.class | Bin 0 -> 1571 bytes .../sample/application/SalesSystem.class | Bin 0 -> 2698 bytes .../com/company/sample/application/Util.class | Bin 0 -> 3993 bytes 15 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.apt.core.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 target/classes/com/company/sample/application/App.class create mode 100644 target/classes/com/company/sample/application/CreateIllegalOrderThread.class create mode 100644 target/classes/com/company/sample/application/CreateOrderThread.class create mode 100644 target/classes/com/company/sample/application/ListOrderThread.class create mode 100644 target/classes/com/company/sample/application/Order.class create mode 100644 target/classes/com/company/sample/application/ProductName.class create mode 100644 target/classes/com/company/sample/application/SalesSystem.class create mode 100644 target/classes/com/company/sample/application/Util.class diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f0257c5 --- /dev/null +++ b/.classpath @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..d84eb44 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + example + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..e9441bb --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1b6e1ef --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/src/main/java/com/company/sample/application/SalesSystem.java b/src/main/java/com/company/sample/application/SalesSystem.java index a520f7c..a884969 100644 --- a/src/main/java/com/company/sample/application/SalesSystem.java +++ b/src/main/java/com/company/sample/application/SalesSystem.java @@ -23,8 +23,9 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; - +import java.time.ZoneId; import java.util.Date; +import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; public class SalesSystem { @@ -52,6 +53,7 @@ public static void main(String[] args) { ListOrderThread listOrderThread = new ListOrderThread(); DateFormat currentDateFormat = new SimpleDateFormat("dd MMM yyyy"); + currentDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); listOrderThread.setDate(currentDateFormat.format(new Date())); listOrderThread.start(); diff --git a/target/classes/com/company/sample/application/App.class b/target/classes/com/company/sample/application/App.class new file mode 100644 index 0000000000000000000000000000000000000000..1b92693c2b1919723b4f31307dffacee861b5e1c GIT binary patch literal 2228 zcmbuAUsD@Z7{;HIO;{2ZOGBHs0xfN64Io{hmD&a(5DEf;qH&mUyz!7MVcX4aX0zL> z7mgS8(ht!quDyYd&iDcRJnB^ypOdV`(PS8CGJ7`X-}`&t=e+O9uYdjY3xIq0R7XtU zM%k;GeCpEu+HA;L-LXtruRC^G2Day#3-!8=xIo_%`AnLQbgSm$ohMc~5a^nl_UwkhNbzJ( za-`Ix?FwYFUlfl$Dh0mnR&%4OP|ryOhnTRIJM$=a2n6BLezsKPUw>KeF#o6I4umI1w8Zlm?-t>%=fw+!6Id(08;Z$lRN zHv2yrI-wTYn#jFXUML?&4UA!2Akj=VftfbppPaD__dF&H+)?G0Xav#^QV>Y0X3D^{ z8jd@jtf+x|20m!6Qv*|K->L0i z@mbRl18 za)9gs-v1fm^Fx@$@k31Vxyxr}|L8X^*P4jiGzARMpFx@&;`v?WwKL4#O|~Qa-a?kO zpc%M)J-6gr_N{eg^i>Q94aa;nb+ zo_20E*1wu|IZ8YUEEEN14x8PBBb!64IJk%V0`p$BicF0_sn&TXKSaD@AckTSfkEXv&+xII@=!fny>aPJY=~2B2A&nej>g1hccSVu>0X8 z_SAEo3a$L_0Uo9FsB%Dq&neJKS4AsFo9iRa(c8;>z;1lyF)rbJ&TzIutEc4Gj|L$}??NtASYNK%X3Z+J&oZ)JQl?*ph`~v6V=l7JzAPKO^CP10q kDv8!eR6z;r^foAn84FCWD literal 0 HcmV?d00001 diff --git a/target/classes/com/company/sample/application/CreateOrderThread.class b/target/classes/com/company/sample/application/CreateOrderThread.class new file mode 100644 index 0000000000000000000000000000000000000000..400cf946d317b56557088dbfa5ebb683020c7838 GIT binary patch literal 2275 zcmb7FZBrXn6n<_JSV))G0s?}SLd#2O!;1wlAQcGN zDFKlXh*$@9!0nbmrEjAVLs8nUX4X8Ygj5@h@|0Ix#VFkurfMUuu2MfvPVhc zBL1pnOwTp*zE6~5bFa7ejNC3MMaUnp*%RfJ#0$bjC@h>6k4GEZR|OVydo0?y2_H3Q^s=hnUZP>48Bk836=_n$d@xy zTqNIH-kf5G*}^0fSSc6oRJkik@`z8fLpZN%&j}$R)8L&=;u2KZ7fCPgo7P=h&e@j# zd@628FX-Yx46{|jsFG8iyE}5|s^;Oy<}>JJQ0MqXfMvn?`s zjOG*EX~Nz8W7MAF-ekowzBs{`4ZZchphoRCB!t`zwpE;9YlC``$CNxlWa&tOSdWMN zHDFskBPxqARfQO18)6nC9D}3O7(+WIxSPan#Ib-WB)Cg*{B2_vk0_C)m@dR#%#c~| zXE3t}Hn0PecUE&gq+k)FcG`W5G~bP)54*6*jy?L2;1{&^sU=amg2+oWXmB))zr?tP YVGT2{Sn-esp~02QLs_{jl|%UMU-S($#Q*>R literal 0 HcmV?d00001 diff --git a/target/classes/com/company/sample/application/ListOrderThread.class b/target/classes/com/company/sample/application/ListOrderThread.class new file mode 100644 index 0000000000000000000000000000000000000000..c0bf5c11cbf12196ce0840e58955ba67e6181c45 GIT binary patch literal 3348 zcmb7G>30)V6#u<0nKYeJEu~l%4U5>7fZ~?cBGh6FU65d*?$czT1IbL7nLz7~DB`ZT z;=b4Ii$#OVQ8}P~@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$U{NWYjE# zrWxpv2BD!%!vT%sRilEK#-7>78v5h~>7M51g=r#Ol&u97v(U)!$)74?C(#h325#b7 uM)8%cvywle4tLRp-OB2QfT&=#tSnh!lJzq(m*I1K!Bsw%yQub;sQMc)*=1?~ literal 0 HcmV?d00001 diff --git a/target/classes/com/company/sample/application/Order.class b/target/classes/com/company/sample/application/Order.class new file mode 100644 index 0000000000000000000000000000000000000000..d4f32ac10f8695673c385ee20efc8a3fe19129be GIT binary patch literal 1472 zcmb7?-)<5?6vn^duWYw17HNgHTD7*z7TGr8LSsWD5|bvRHL2l#fKAq~0AovL37 zqz2Np2Q}%_(R5uEANr1KafY@Nvf~ZA)I`(-k{)B6wdw1OwoaX{<5vW##%)@Ld(_Sf z4T0EeuWf6H;;xQWYzRb+LL&u%dphDsaI~o-i8~zK*O7w8QC`OibbO0sxv!e&V?oeFQ0vE(;j2_g%`Fn@ z8dGddWesXoP!%@EstINyz!Z3b{h-z?NHz>ooD1?42lGI(VUS~Lcd`J4r^FLDgfRh$ zP&A&%))xw9CsLjZQh*s8uF#-))Cu#D>74F-R;?| zJl`*+?AW?lPi-eEVY0m2#@n#Z&3^DnlsQ=hV{QdNw~GwEvrrgq0TmF7B$||lwwoN zg&Wkva9OXL+-cjCRsEkB>0uhYnG$_mkZ~7rhTs7=+FJ1)L+0Gf7o!!0O=2mCMTS{H zp?}mYV;L(99*ffc*0f@6UsIjbMVjU_iOOP1e@vfYq}gXXQN=Bh2ByRlLs3z}IvxhG zL981{(rGzbL&hUKrpa;J<{i~)c4z|!``0UEdjQ=}6_Hc$C?y7vK2!ge!CS4=fK!jq zi2;>ZS0as6w%WF;z0d_$BLh5K5m*^E&$tZ9k<2QQ#7jRIUuIHl5kMy`kbBbZ0Ff!N zIb`9dT^fN*_LoS~;G-vy{R~!(j(U$Uc8GCTxaxC-m@7>9U12ith3vdtjF+pvE@I`X zzl+K8A*Mf45D%`?Q=$`?qJB-_hN~4{=r_tp?vah3u2qUlgus0~ zpi^{WgR}xxtc&UDD{u0onijS0c&CrCw$zV(ijw^*Ei5*(7b8h|1a2wH2-TCXVCVaJ N@RTe)*z8sH><2xPde8s> literal 0 HcmV?d00001 diff --git a/target/classes/com/company/sample/application/SalesSystem.class b/target/classes/com/company/sample/application/SalesSystem.class new file mode 100644 index 0000000000000000000000000000000000000000..0ad33659742e3b1b3b2030d62e559bb49493f0fd GIT binary patch literal 2698 zcmbtWZBr9h6n-uwE-YK45f!wpSP>K6f>uQcg-Q^l4KFsBinP^BvV_IWCf(g&>4*NO zPGb;;I}ND zorEWgW!p^1a@n?W(zi-ZA|q|n%j|f*S=0~`xUeO+Wx|$DA+fZ+W#)W=b0s%#x}HER z9sF7GEt`-|uHw3;<0n$@Zl6kTb3vAq0__>A;7GsXngXxS=r+-?ZbtfMGTkKhB^6h4 zlH0XS$jP=vt_=($!H(i;cC^5YGsXV?`y>_XcMaUbm+T?>pAw6}Z?O|J{ohuPPlZT+ zRNtr=9~gLuQGsyKi~GfLCNOEs^N)C^5YaFva4irk-~7c-WGtoCN(X04 zZc+Mem>1~C=X(|w7J7F0(J_l}m13m@E}zy`*)}Xv51+53bS&dL4bOO>>T0-R70s9I zcLN!$5V~OchbBt>X@Cv-e7KT@$l`^D?*%&RvDc$Eu!@%i_Zq>k9)JgfJfWlPU9Ssv|R z=-?)&aVuYJ_->&_GOrq+TF^#o8*Mr*9kdM4ram3}FjjYQ{tsOIosTWJ#9!qGLUjff z1;&AY;F#c5{TuGz#pUBJHv$)nS20p$ z=L}TwXdg*N^VPy&6_fjz;{D^rp(>{Lk>dT6@z6eISEEmN@y&R+I~-lu!%`K`yF=aK zeXMcCk5&9s#d>$B3bP*EBqH3jj|ALdCNbuCn}PN-up#tt^z`B`200W)@Bm{N#S9){ zk$11CczH|&Nln%Q#|8?->clf_!eUxIc!DjwA#;QDuu&w@W4w1zVzM)2v5cQtiWa!^ RYk>!!SH#X+eu7HgDuAuH7#wii7k9oHj0Py_PoeCaYa# zwQ}w7DiCO)P$Gj!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U z>&-hFTJTA?SR(ioPWv!P!ia8d*jd7->y4kOGH$?A_$)U@@HsqPHuevt-6ed!-uSs1 z<7ey6LX7=IOCbB(`_Z}`Rs`7J6~NtE#188pThCKCd~>us-Q zUuN%IWEowl!czPK5j7ix6lFNi;{_j7w6*|^d7z?dOZaAeE4)V7U(oJXRj{#I*a(-; z;rte`O&1CK-HUZ>e^1yy(C&{nhW#O4D#LnByva6piLgJqR0sPf!v2}Cf4MR2rLwZ( zq!Iqc|Z#<#?&THczt}}62 p5C Date: Tue, 31 Dec 2019 13:04:47 -0800 Subject: [PATCH 3/3] Removing needed setTimeZone call to provoke CG --- .../sample/application/SalesSystem.java | 3 ++- .../sample/application/SalesSystem.class | Bin 2698 -> 2534 bytes 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/company/sample/application/SalesSystem.java b/src/main/java/com/company/sample/application/SalesSystem.java index a884969..1204321 100644 --- a/src/main/java/com/company/sample/application/SalesSystem.java +++ b/src/main/java/com/company/sample/application/SalesSystem.java @@ -53,7 +53,8 @@ public static void main(String[] args) { ListOrderThread listOrderThread = new ListOrderThread(); DateFormat currentDateFormat = new SimpleDateFormat("dd MMM yyyy"); - currentDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + //remove the necessary line again to see if CG triggers again + //currentDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); listOrderThread.setDate(currentDateFormat.format(new Date())); listOrderThread.start(); diff --git a/target/classes/com/company/sample/application/SalesSystem.class b/target/classes/com/company/sample/application/SalesSystem.class index 0ad33659742e3b1b3b2030d62e559bb49493f0fd..887326aab1ad9d565de7f46786aba8712ba600ed 100644 GIT binary patch delta 252 zcmXAiy-osA6okKpWjA|6uwc~?8iTFLHZ-DGp;jm;h=@O2bw!AT#9WP?z3n~;FY0-|poU+}?a{RjF_EX*uHjZ@nqGxZrWEV0Y)Vpu&$24M& z3U*9)DmX=6ZiQU*>ji@fZ8kZfiZAZge}U+pD4$(UIm2Rw4bHic>>2@mG-=i;amkg8 Y)>!76kc{w~WMROqd?m?MiVX4o0O71J$^ZZW delta 380 zcmZvX&q@Mu5XV2O>#Cb1_=i}$6kQA!ym%;-E-7><(^5;Vbj!{BU%7hj+;tzIXOLiv zf*zm;33`Ms(Jvti>N3O3cRt^lc@5u0)t8UQXCTRBs!B@QM^3_BDsHIc+4WM82z88! zkr-R;UZU9Uo7LgK46sL0VyPIk!!lKB1iuXH0U8+grjnFT12pfhm4?gzj*KF{G3_^BR`-OqAJ}myX|m>d zqE@-*$l=)GM3WuNsTgz-7IB@Ro%biYtK?XtPKqXJA~R)X#~CeAMJRAi8;M1-bm$6R j7etRfZjp5c48;i