Commit 3f83a233 authored by jcechace's avatar jcechace
Browse files

Initial project assignment

parents
# Created by .ignore support plugin (hsz.mobi)
### Java template
*.class
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
### NetBeans template
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
# Vim
*.un~
# OS X .DS_Store
.DS_Store
image: maven:3-jdk-11
build:
script:
- mvn clean install -B -Dcheckstyle.fail=true
tags:
- shared-fi
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<!--<property name="fileExtensions" value="java, xml, properties"/>-->
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="scope" value="public"/>
<property name="checkFirstSentence" value="false"/>
</module>
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength">
<property name="max" value="50"/>
<property name="countEmpty" value="false"/>
</module>
<module name="ParameterNumber"/>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifier.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly">
<property name="option" value="eol"/>
</module>
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="false"/>
</module>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
</module>
</module>
package cz.muni.fi.pb162.hw03.app;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.List;
import java.util.Optional;
/**
* Library of chemical elements
*/
public interface ElementLibrary {
/**
* Finds element by atomic number
*
* @param num atomic number
* @return element with given atomic number or empty {@link Optional}
*/
Optional<Element> findByAtomicNumber(int num);
/**
* Finds element by symbol
*
* @param symbol element's symbol
* @return element with given symbol or empty {@link Optional}
*/
Optional<Element> findBySymbol(String symbol);
/**
* Finds element by name
*
* @param name element's name
* @return element with given name or empty {@link Optional}
*/
Optional<Element> findByName(String name);
/**
* Finds elements discovered in given year
*
* @param year year of discovery
* @return list of elements discovered in given year
*/
List<Element> findByYear(int year);
}
package cz.muni.fi.pb162.hw03.app.cmd;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
/**
* Command Line Interface
*/
public final class CommandLine {
private final JCommander commander;
/**
* Constructs new CLI instance
*
* @param application application object to be populated with arguments
*/
public CommandLine(Object application) {
commander = JCommander.newBuilder()
.addObject(application)
.build();
commander.setProgramName(application.getClass().getSimpleName());
}
/**
* Parses command line arguments (terminates on error)
*
* @param args command line arguments of the application
*/
public void parseArguments(String[] args) {
try {
commander.parse(args);
} catch (ParameterException ex) {
System.err.println("Error: " + ex.getMessage());
showUsage();
}
}
/**
* Shows usage of the application and terminates
*/
public void showUsage() {
commander.usage();
}
}
package cz.muni.fi.pb162.hw03.app.impl;
import com.beust.jcommander.Parameter;
import cz.muni.fi.pb162.hw03.app.cmd.CommandLine;
import java.io.IOException;
/**
* Application CLI
*/
@SuppressWarnings("FieldMayBeFinal")
public final class Application {
@Parameter(names = "--help", help = true)
private boolean showUsage = false;
/**
* Application entry point
*
* @param args command line arguments of the application
* @throws IOException on unrecoverable IO error
*/
public static void main(String[] args) throws IOException {
Application app = new Application();
CommandLine cli = new CommandLine(app);
cli.parseArguments(args);
if (app.showUsage) {
cli.showUsage();
} else {
app.run(cli);
}
}
/**
* Application runtime logic
*
* @param cli command line interface
*/
private void run(CommandLine cli) {
throw new UnsupportedOperationException("Implement this method!");
}
}
package cz.muni.fi.pb162.hw03.app.impl;
/**
* Representation of element
*/
public final class Element {
private final int atomicNumber;
private final String symbol;
private final String name;
private final String standardState;
private final String groupBlock;
private final int yearDiscovered;
/**
* Constructs element instance
*
* @param atomicNumber Atomic number
* @param symbol Symbol
* @param name Name
* @param standardState Standard state of occurrence
* @param groupBlock Group block in periodic table
* @param yearDiscovered Year of discovery
*/
public Element(
int atomicNumber, String symbol, String name,
String standardState, String groupBlock, int yearDiscovered
) {
this.atomicNumber = atomicNumber;
this.symbol = symbol;
this.name = name;
this.standardState = standardState;
this.groupBlock = groupBlock;
this.yearDiscovered = yearDiscovered;
}
public int getAtomicNumber() {
return this.atomicNumber;
}
public String getSymbol() {
return this.symbol;
}
public String getName() {
return this.name;
}
public String getStandardState() {
return this.standardState;
}
public String getGroupBlock() {
return this.groupBlock;
}
public int getYearDiscovered() {
return this.yearDiscovered;
}
}
\ No newline at end of file
package cz.muni.fi.pb162.hw03.app.output;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.Collection;
/**
* Formatting of Element instances as string
*/
public interface ElementFormatter {
/**
* Formats element as string
*
* @param element formatted element
* @return String representation of given element
*/
String format(Element element);
/**
* Formats collection of elements as string
*
* @param elements formatted elements
* @return String representation of given elements
*/
String format(Collection<Element> elements);
}
package cz.muni.fi.pb162.hw03.app.output;
/**
* Error message constants
*/
public final class Messages {
public static final String SINGLE_FILTER_REQUIRED = "Single filter is required!";
public static final String NO_ELEMENT_FOUND = "No matching element found!";
private Messages() { }
}
package cz.muni.fi.pb162.hw03.app.output;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
/**
* Formatting of {@link Element} instances as ASCI table
*/
public class TableFormatter implements ElementFormatter {
private static final String ROW_SEPARATOR = "-------------------------------------------------" +
"------------------------------------------------------";
private static final String HEAD_SEPARATOR = "=================================================" +
"======================================================";
@Override
public String format(Element element) {
return lines(head(), row(element), ROW_SEPARATOR);
}
@Override
public String format(Collection<Element> elements) {
List<String> rows = elements.stream().map(this::row).collect(toList());
return lines(head(), lines(rows), ROW_SEPARATOR);
}
private String head() {
String row = row("#", "Symbol", "Name", "Standard State", "Group Block", "Year");
return lines(ROW_SEPARATOR, row, HEAD_SEPARATOR);
}
private String row(Element element) {
return row(
String.valueOf(element.getAtomicNumber()),
element.getSymbol(),
element.getName(),
element.getStandardState(),
element.getGroupBlock(),
String.valueOf(element.getYearDiscovered())
);
}
private String row(String... data) {
if (data.length != 6) {
throw new IllegalArgumentException("Incorrect number of values");
}
return "|" +
String.format("%10s", data[0]) + "|" +
String.format("%10s", data[1]) + "|" +
String.format("%20s", data[2]) + "|" +
String.format("%20s", data[3]) + "|" +
String.format("%25s", data[4]) + "|" +
String.format("%10s", data[5]) +
"|";
}
private String lines(String... lines) {
return lines(Arrays.asList(lines));
}
private String lines(Collection<String> lines) {
return lines.stream()
.collect(joining(System.lineSeparator()));
}
}
atomicNumber, symbol, name, standardState, groupBlock, yearDiscovered
1, H , Hydrogen,gas,nonmetal,1766
2, He , Helium,gas,noble gas,1868
3, Li , Lithium,solid,alkali metal,1817
4, Be , Beryllium,solid,alkaline earth metal,1798
5, B , Boron,solid,metalloid,1807
6, C , Carbon,solid,nonmetal,-1
7, N , Nitrogen,gas,nonmetal,1772
8, O , Oxygen,gas,nonmetal,1774
9, F , Fluorine,gas,halogen,1670
10, Ne , Neon,gas,noble gas,1898
11, Na , Sodium,solid,alkali metal,1807
12, Mg , Magnesium,solid,alkaline earth metal,1808
13, Al , Aluminum,solid,metal,-1
14, Si , Silicon,solid,metalloid,1854
15, P , Phosphorus,solid,nonmetal,1669
16, S , Sulfur,solid,nonmetal,-1
17, Cl , Chlorine,gas,halogen,1774
18, Ar , Argon,gas,noble gas,1894
19, K , Potassium,solid,alkali metal,1807
20, Ca , Calcium,solid,alkaline earth metal,-1
21, Sc , Scandium,solid,transition metal,1876
22, Ti , Titanium,solid,transition metal,1791
23, V , Vanadium,solid,transition metal,1803
24, Cr , Chromium,solid,transition metal,-1
25, Mn , Manganese,solid,transition metal,1774
26, Fe , Iron,solid,transition metal,-1
27, Co , Cobalt,solid,transition metal,-1
28, Ni , Nickel,solid,transition metal,1751
29, Cu , Copper,solid,transition metal,-1
30, Zn , Zinc,solid,transition metal,1746
31, Ga , Gallium,solid,metal,1875
32, Ge , Germanium,solid,metalloid,1886
33, As , Arsenic,solid,metalloid,-1
34, Se , Selenium,solid,nonmetal,1817
35, Br , Bromine,liquid,halogen,1826
36, Kr , Krypton,gas,noble gas,1898
37, Rb , Rubidium,solid,alkali metal,1861
38, Sr , Strontium,solid,alkaline earth metal,1790
39, Y , Yttrium,solid,transition metal,1794
40, Zr , Zirconium,solid,transition metal,1789
41, Nb , Niobium,solid,transition metal,1801
42, Mo , Molybdenum,solid,transition metal,1778
43, Tc , Technetium,solid,transition metal,1937
44, Ru , Ruthenium,solid,transition metal,1827
45, Rh , Rhodium,solid,transition metal,1803
46, Pd , Palladium,solid,transition metal,1803
47, Ag , Silver,solid,transition metal,-1
48, Cd , Cadmium,solid,transition metal,1817
49, In , Indium,solid,metal,1863
50, Sn , Tin,solid,metal,-1
51, Sb , Antimony,solid,metalloid,-1
52, Te , Tellurium,solid,metalloid,1782
53, I , Iodine,solid,halogen,1811
54, Xe , Xenon,gas,noble gas,1898
55, Cs , Cesium,solid,alkali metal,1860
56, Ba , Barium,solid,alkaline earth metal,1808
57, La , Lanthanum,solid,lanthanoid,1839
58, Ce , Cerium,solid,lanthanoid,1803
59, Pr , Praseodymium,solid,lanthanoid,1885
60, Nd , Neodymium,solid,lanthanoid,1885
61, Pm , Promethium,solid,lanthanoid,1947
62, Sm , Samarium,solid,lanthanoid,1853
63, Eu , Europium,solid,lanthanoid,1901
64, Gd , Gadolinium,solid,lanthanoid,1880
65, Tb , Terbium,solid,lanthanoid,1843
66, Dy , Dysprosium,solid,lanthanoid,1886
67, Ho , Holmium,solid,lanthanoid,1878
68, Er , Erbium,solid,lanthanoid,1842
69, Tm , Thulium,solid,lanthanoid,1879
70, Yb , Ytterbium,solid,lanthanoid,1878
71, Lu , Lutetium,solid,lanthanoid,1907
72, Hf , Hafnium,solid,transition metal,1923
73, Ta , Tantalum,solid,transition metal,1802
74, W , Tungsten,solid,transition metal,1783
75, Re , Rhenium,solid,transition metal,1925
76, Os , Osmium,solid,transition metal,1803
77, Ir , Iridium,solid,transition metal,1803
78, Pt , Platinum,solid,transition metal,-1
79, Au , Gold,solid,transition metal,-1
80, Hg , Mercury,liquid,transition metal,-1
81, Tl , Thallium,solid,metal,1861
82, Pb , Lead,solid,metal,-1
83, Bi , Bismuth,solid,metal,-1
84, Po , Polonium,solid,metalloid,1898
85, At , Astatine,solid,halogen,1940
86, Rn , Radon,gas,noble gas,1900
87, Fr , Francium,solid,alkali metal,1939
88, Ra , Radium,solid,alkaline earth metal,1898
89, Ac , Actinium,solid,actinoid,1899
90, Th , Thorium,solid,actinoid,1828
91, Pa , Protactinium,solid,actinoid,1913
92, U , Uranium,solid,actinoid,1789
93, Np , Neptunium,solid,actinoid,1940
94, Pu , Plutonium,solid,actinoid,1940
95, Am , Americium,solid,actinoid,1944
96, Cm , Curium,solid,actinoid,1944
97, Bk , Berkelium,solid,actinoid,1949
98, Cf , Californium,solid,actinoid,1950
99, Es , Einsteinium,solid,actinoid,1952
100, Fm , Fermium,,actinoid,1952
101, Md , Mendelevium,,actinoid,1955
102, No , Nobelium,,actinoid,1957
103, Lr , Lawrencium,,transition metal,1961
104, Rf , Rutherfordium,,transition metal,1969
105, Db , Dubnium,,transition metal,1967
106, Sg , Seaborgium,,transition metal,1974
107, Bh , Bohrium,,transition metal,1976
108, Hs , Hassium,,transition metal,1984
109, Mt , Meitnerium,,transition metal,1982
110, Ds , Darmstadtium,,transition metal,1994
111, Rg , Roentgenium,,transition metal,1994
112, Cn , Copernicium,,transition metal,1996
113, Nh , Nihonium,,post-transition metal,2003
114, Fl , Flerovium,,post-transition metal,1998
115, Mc , Moscovium,,post-transition metal,2003
116, Lv , Livermorium,,post-transition metal,2000
117, Ts , Tennessine,,post-transition metal,2010
118, Og , Oganesson,,noble gas,2002
package cz.muni.fi.pb162.hw03;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TestUtils {
private TestUtils() {
}
public static Path resourcePath(String path) throws URISyntaxException {
return Paths.get(TestUtils.class.getResource(path).toURI());
}
}
\ No newline at end of file