Commit ddc374f4 authored by Michelle Avomo's avatar Michelle Avomo Committed by mavomo

TP - clean code init

parent cfad6b27
/target/
/.idea/
/cleancode.iml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.soat</groupId>
<artifactId>cleancode</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cleancode</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package io.soat.names.disinformation.game;
import java.util.ArrayList;
import java.util.List;
public class Example1 {
private List<int[]> theList;
public List<int[]> getThem(){
List<int[]> list1 = new ArrayList<>();
for(int[] x : theList)
if (x[0] == 4)
list1.add(x);
return list1;
}
}
package io.soat.names.disinformation.game;
import java.util.ArrayList;
import java.util.List;
public class Example1Clean {
private static final int STATUS_VALUE = 0;
private static final int FLAGGED = 4;
private List<int[]> gameBoard;
public List<int[]> getFlaggedCells() {
List<int[]> flaggedCells = new ArrayList<>();
for (int[] cell : gameBoard)
if (cell[STATUS_VALUE] == FLAGGED)
flaggedCells.add(cell);
return flaggedCells;
}
}
package io.soat.names.disinformation.game.best;
public class Cell {
private boolean flagged;
public boolean isFlagged() {
return flagged ;
}
}
package io.soat.names.disinformation.game.best;
import java.util.ArrayList;
import java.util.List;
public class Example1Better {
private List<Cell> gameBoard;
public List<Cell> getFlaggedCells() {
List<Cell> flaggedCells = new ArrayList<>();
for (Cell cell : gameBoard)
if (cell.isFlagged())
flaggedCells.add(cell);
return flaggedCells;
}
}
package io.soat.names.disinformation.spam;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.List;
public class DataGenerator {
private static String GenerateXML()
{
StringBuilder data = new StringBuilder();
data.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
data.append("<mailings>");
data.append("<mailing nom=\"TestXMLLoad\">");
data.append("<summary>Test du XML Load</summary>");
data.append("<location>Salle OQP</location>");
data.append("<description>Xml de test générè à la volé</description>");
data.append("<days>");
data.append("<day>0</day>");
data.append("</days>");
data.append("<startHour>10</startHour>");
data.append("<duration>15</duration>");
data.append("<attendees>");
data.append("<emails>");
data.append("<email>");
data.append("<value>testEmail@soat.fr</value>");
data.append("<name>Prenom Nom</name>");
data.append("<dir>INT</dir>");
data.append("<dispos>");
data.append("<day>0</day>");
data.append("<day>2</day>");
data.append("<day>4</day>");
data.append("</dispos>");
data.append("</email>");
data.append("<email>");
data.append("<value>testEmail2@soat.fr</value>");
data.append("<name>Prenom2 Nom2</name>");
data.append("<dir>DSI</dir>");
data.append("<dispos>");
data.append("<day>0</day>");
data.append("<day>1</day>");
data.append("<day>2</day>");
data.append("<day>3</day>");
data.append("<day>4</day>");
data.append("</dispos>");
data.append("</email>");
data.append("</emails>");
data.append("</attendees>");
data.append("<type>Week</type>");
data.append("</mailing>");
data.append("</mailings>");
return data.toString();
}
public static XMLLoad GenerateXMLLoad(String matchString, String changeString)
{
String fileName = "FichierDeTest.xml";
Path path = Paths.get(fileName);
try (BufferedWriter writer = Files.newBufferedWriter(path))
{
writer.write(GenerateXML().replace(matchString, changeString));
} catch (IOException e) {
e.printStackTrace();
}
XMLLoad xml = new XMLLoad(fileName);
return xml;
}
public static Memory GenerateMemory(LocalDate date)
{
Memory result = new Memory();
List<String> email = Arrays.asList("testEmail@soat.fr", "testEmail2@soat.fr");
LastMailingSendInfo lmsi = new LastMailingSendInfo("TestXMLLoad", email, date);
result.myMemoryMailingValue(lmsi.getName(), lmsi);
return result;
}
public static LocalDate GenerateFirstMonthDayBeforToday()
{
LocalDate date1 = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
LocalDate date2 = LocalDate.now().minusDays(1);
LocalDate result = LocalDate.now().isEqual(date1) ? date2 : LocalDate.now();
result = LocalDate.of(result.getYear(), result.getMonth(), 1);
return result;
}
}
package io.soat.names.disinformation.spam;
import java.time.LocalDate;
import java.util.List;
public class LastMailingSendInfo {
private LocalDate date;
private List<String> email;
private String name;
public LastMailingSendInfo(String name,List<String> email, LocalDate date) {
this.date = date;
this.email = email;
this.name = name;
}
public LocalDate getDate() {
return date;
}
public List<String> getEmail() {
return email;
}
public String getName() {
return name;
}
}
package io.soat.names.disinformation.spam;
import java.util.ArrayList;
import java.util.List;
public class Memory {
private LastMailingSendInfo info;
private String name;
private static List<Memory> values = new ArrayList<>();
public Memory() {}
public Memory(String name, LastMailingSendInfo info) {
this.name = name;
this.info = info;
}
public static void myMemoryMailingValue(String name, LastMailingSendInfo info) {
values.add(new Memory(name, info));
}
}
package io.soat.names.disinformation.spam;
public class XMLLoad {
private String filename;
public XMLLoad(String filename) {
this.filename = filename;
}
}
package io.soat.names.distinction;
public class Utils {
//Avoid
public static void copyChars(char a1[], char a2[]) {
for (int i = 0; i < a1.length; i++) {
a2[i] = a1[i];
}
}
/*
public static void copyChars(char source[], char destination[]) {
for (int i = 0; i < source.length; i++) {
destination[i] = source[i];
}
}*/
}
package io.soat.names.pronounceable;
import java.util.Date;
public class DtaRcrd102 {
private Date genymdhms;
private Date modymdhms;
private final String pszqint = "102";
}
package io.soat.names.pronounceable.good;
import java.util.Date;
public class Customer {
private Date generationTimestamp;
private Date modificationTimestamp;
private final String recordId = "102";
}
package io.soat.names.searchable;
public class Example {
private static int s;
private static int t[];
public static void main(String[] args) {
for (int j = 0; j < 34; j++) {
s += (t[j] * 4) / 5;
}
}
}
package io.soat.names.searchable.better;
public class Example {
private static final int NUMBER_OF_TASKS = 5;
private static int realDaysPerIdealDay = 4;
private final int WORK_DAYS_PER_WEEK = 5;
public void sum(int[] taskEstimate, int realdays) {
int sum = 0;
for (int j = 0; j < NUMBER_OF_TASKS; j++) {
int realTaskDays = taskEstimate[j] * realDaysPerIdealDay;
int realTaskWeeks = (realdays / WORK_DAYS_PER_WEEK);
sum += realTaskWeeks;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment