Range
|
Meaning
|
---|---|
1.0 |
"Soft" requirement on 1.0 (just a recommendation - helps select the correct version if it matches all ranges)
|
(,1.0] |
x <= 1.0
|
(,1.0],[1.2,) |
x <= 1.0 or x >= 1.2. Multiple sets are comma-separated
|
(,1.1),(1.1,) |
This excludes 1.1 if it is known not to work in combination with this library
|
[1.0,2.0) |
1.0 <= x < 2.0
|
[1.0] |
Hard requirement on 1.0
|
[1.2,1.3] |
1.2 <= x <= 1.3
|
[1.5,) |
x >= 1.5
|
2015년 10월 28일 수요일
Maven에서 Dependency Version Range
2015년 7월 9일 목요일
Java MVC model
Observer
Model
Controller
View
Main Method
public interface Observer { public void update(int data); }
Model
public class CalculatorModel { private int data; private ArrayList list = new ArrayList(); public void addTwoNumber(int firstNumber, int secondNumber){ data = firstNumber + secondNumber; notifyObservers(); } public void registerObserver(Observer o){ list.add(o); } public void notifyObservers() { for(Observer o : list){ o.update(data); } } }
Controller
public class CalculatorController implements ActionListener{ private CalculatorModel model; private CalculatorView view; public CalculatorController(CalculatorModel model, CalculatorView view) { this.model = model; this.view = view; this.view.setCalculatorListener(this); } @Override public void actionPerformed(ActionEvent arg0) { try { int firstNumber = view.getFirstNumber(); int secondNumber = view.getSecondNumber(); model.addTwoNumber(firstNumber, secondNumber); } catch (RuntimeException e) { e.printStackTrace(); } } }
View
public class CalculatorView extends JFrame implements Observer{ private JTextField firstNumber = new JTextField(10); private JLabel additionLabel = new JLabel("+"); private JTextField secondNumber = new JTextField(10); private JButton calculateButton = new JButton("계산"); private JTextField calcSolution = new JTextField(10); private JPanel calcPanel = new JPanel(); public CalculatorView() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(600, 200); setLayout(new BorderLayout()); calcPanel.add(firstNumber); calcPanel.add(additionLabel); calcPanel.add(secondNumber); calcPanel.add(calculateButton); calcPanel.add(calcSolution); add(calcPanel, BorderLayout.CENTER); } public int getFirstNumber() { return Integer.parseInt(firstNumber.getText()); } public int getSecondNumber() { return Integer.parseInt(secondNumber.getText()); } public void setCalcSolution(int result) { calcSolution.setText(result +""); } public void setCalculatorListener(ActionListener listener){ calculateButton.addActionListener(listener); } @Override public void update(int data) { setCalcSolution(data); } }
Main Method
public class MVCTest { public static void main(String[] args) { CalculatorView view = new CalculatorView(); CalculatorModel model = new CalculatorModel(); model.registerObserver(view); @SuppressWarnings("unused") CalculatorController controller = new CalculatorController(model, view); view.setVisible(true); } }
2015년 5월 13일 수요일
Java code에서 java 파일 생성 후 컴파일 하기
package junit_sample; public class JavaCompileTest { @SuppressWarnings("resource") public static void main(String[] args) throws Exception { // Prepare source somehow. String source = "package test; public class Test { " + "static { System.out.println(\"hello\"); } " + "public Test() { System.out.println(\"world\"); } }"; // Save source in .java file. File root = new File("/java"); // On Windows running on C:\, this is C:\java. File sourceFile = new File(root, "test/Test.java"); sourceFile.getParentFile().mkdirs(); System.out.println("path: " + sourceFile.getParentFile()); new FileWriter(sourceFile).append(source).close(); // Compile source file. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, null, sourceFile.getPath()); // Load and instantiate compiled class. URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() }); Class<?> cls = Class.forName("test.Test", true, classLoader); // Should print "hello". Object instance = cls.newInstance(); // Should print "world". System.out.println(instance); // Should print "test.Test@hashcode". } }
2015년 4월 27일 월요일
Junit testcase 순서별 실행
import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; //Running test cases in order of method names in ascending order @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class OrderedTestCasesExecution { @Test public void secondTest() { System.out.println("Executing second test"); } @Test public void firstTest() { System.out.println("Executing first test"); } @Test public void thirdTest() { System.out.println("Executing third test"); } }
output:
Excuting first test
Excuting second test
Excuting third test
2015년 1월 20일 화요일
maven build 시 integration test 추가하기
4.0.0 MavenIntegrationTest MavenIntegrationTest 0.0.1-SNAPSHOT UTF-8 UTF-8 org.codehaus.mojo build-helper-maven-plugin 1.9.1 add-it-source pre-integration-test add-test-source src/it/java org.apache.maven.plugins maven-resources-plugin 2.7 add-it-resources pre-integration-test copy-resources ${project.build.directory}/it-classes src/it/resources org.apache.maven.plugins maven-compiler-plugin 3.2 1.7 1.7 compile-integration-test pre-integration-test testCompile **/*IT.java ${project.build.directory}/it-classes org.apache.maven.plugins maven-surefire-plugin 2.15 org.apache.maven.plugins maven-failsafe-plugin 2.15 src/it/java ${project.build.directory}/it-classes integration-test integration-test verify verify junit junit 4.11 org.apache.maven.surefire surefire-junit47 2.12
2015년 1월 6일 화요일
클래스 이름으로 instance 생성하기
String className = "mocktest.Calculator"; Class<?> myClass = Class.forName(className); Constructor constructor = myClass.getConstructor(); Calculator cal = (Calculator) constructor.newInstance(); System.out.println(cal.add(1, 1));
피드 구독하기:
글 (Atom)