-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from computer-engineering-uniovi/development
Development
- Loading branch information
Showing
11 changed files
with
304 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,57 @@ | ||
/* | ||
* This source file is part of the Swift open source project. | ||
* | ||
* Copyright (c) 2017 Guillermo Facundo Colunga and the Swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package Foundation; | ||
|
||
/** | ||
* | ||
* A value that identifies the location of a resource, such as an item on a | ||
* remote server or the path to a local file. | ||
* | ||
* @author Guillermo Facundo Colunga | ||
* @version 201802032056 | ||
*/ | ||
public class URL { | ||
|
||
private String _fileURLWithPath = ""; | ||
|
||
|
||
public URL(String fileURLWithPath) { | ||
this._fileURLWithPath = fileURLWithPath; | ||
} | ||
|
||
public String getFileURL() { | ||
return this._fileURLWithPath; | ||
} | ||
|
||
private String _fileURLWithPath = ""; | ||
private String _user, _password; | ||
private int _port; | ||
|
||
public URL( String fileURLWithPath ) { | ||
this._fileURLWithPath = fileURLWithPath; | ||
} | ||
|
||
public String getFileURL() { | ||
return this._fileURLWithPath; | ||
} | ||
|
||
public String getUser() { | ||
return this._user; | ||
} | ||
|
||
public void setUser( String user ) { | ||
_user = user; | ||
} | ||
|
||
public String getPassword() { | ||
return this._password; | ||
} | ||
|
||
public void setPassword( String password ) { | ||
_password = password; | ||
} | ||
|
||
public int getPort() { | ||
return _port; | ||
} | ||
|
||
public void setPort( int port ) { | ||
_port = port; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package Foundation; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class XMLWriter { | ||
|
||
/** | ||
* Write an XML based on the objects received. You have to specify the root name | ||
* of the document and it´s name. | ||
* | ||
* @param objects | ||
* the List objects received | ||
* @param root | ||
* the root of the document | ||
*/ | ||
public <T> String save(List<T> objects, String root) { | ||
String xml = getHeadborard(); | ||
xml += openElement(root); | ||
for (Object o : objects) { | ||
Class<?> clazz = o.getClass(); | ||
String objectName = o.getClass().getSimpleName(); | ||
xml += openElement(objectName); | ||
|
||
for (Field field : clazz.getDeclaredFields()) { | ||
String fieldName = field.getName(); | ||
xml += openElement(fieldName); | ||
xml += getValue(field, clazz, o); | ||
xml += closeElement(fieldName); | ||
} | ||
xml += closeElement(objectName); | ||
} | ||
xml += closeElement(root); | ||
return xml; | ||
} | ||
|
||
/** | ||
* Returns the value of a generic attribute. You need to specify the class where | ||
* the attribute is located to search the correct method that returns it´s | ||
* value. The object is needed too because you have to invoke that method with | ||
* it. | ||
* | ||
* @param field | ||
* the | ||
* @param clazz | ||
* @param o | ||
* @return | ||
*/ | ||
private String getValue(Field field, Class<?> clazz, Object o) { | ||
String fieldName = field.getName(); | ||
for (Method method : clazz.getMethods()) { | ||
if (method.getName().toLowerCase().endsWith("get" + fieldName.toLowerCase())) { | ||
try { | ||
return String.valueOf(method.invoke(o)); | ||
} catch (IllegalAccessException e) { | ||
System.out.println("Could not determine method: " + method.getName()); | ||
} catch (InvocationTargetException e) { | ||
System.out.println("Could not determine method: " + method.getName()); | ||
} | ||
} | ||
} | ||
return "error"; | ||
} | ||
|
||
/** | ||
* Returns true if the Class that receives inherit from Collection | ||
* | ||
* @param c | ||
* @return | ||
*/ | ||
public boolean isClassCollection(Class<?> c) { | ||
return Collection.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c) || c.isArray(); | ||
} | ||
|
||
private String openElement(String element) { | ||
return "<" + element + ">"; | ||
} | ||
|
||
private String closeElement(String element) { | ||
return "</" + element + ">"; | ||
} | ||
|
||
private String getHeadborard() { | ||
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of AcceptanceTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface AcceptanceTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of DBTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface DBTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of IntegrationTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface IntegrationTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of RegressionTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface RegressionTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of SmokeTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface SmokeTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* This source file is part of the swift open source project. | ||
* | ||
* Copyright (c) 2018 willy and the swift project authors. | ||
* Licensed under GNU General Public License v3.0. | ||
* | ||
* See /LICENSE for license information. | ||
* | ||
*/ | ||
package TestKit; | ||
|
||
/** | ||
* Instance of UnitTest.java | ||
* | ||
* @author | ||
* @version | ||
*/ | ||
public interface UnitTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import org.junit.Test; | ||
|
||
public class CSVFileTest { | ||
|
||
private CSVFile file; | ||
|
||
@Before public void setUp() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Foundation; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.awt.Point; | ||
import java.util.ArrayList; | ||
|
||
import org.junit.Test; | ||
|
||
public class XMLWriterTest { | ||
|
||
@Test | ||
public void test() { | ||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | ||
+"<Points><Point><x>2.0</x><y>3.0</y><serialVersionUID>" | ||
+"error</serialVersionUID></Point><Point><x>4.0</x><y>3.0" | ||
+"</y><serialVersionUID>error</serialVersionUID></Point><Point>" | ||
+"<x>6.0</x><y>9.0</y><serialVersionUID>error</serialVersionUID>"+ | ||
"</Point><Point><x>5.0</x><y>7.0</y><serialVersionUID>error</serialVersionUID>" | ||
+"</Point><Point><x>1.0</x><y>2.0</y><serialVersionUID>error</serialVersionUID>" | ||
+"</Point></Points>"; | ||
|
||
|
||
ArrayList<Point> p1 = new ArrayList<Point>(); | ||
p1.add(new Point(2, 3)); | ||
p1.add(new Point(4, 3)); | ||
p1.add(new Point(6, 9)); | ||
p1.add(new Point(5, 7)); | ||
p1.add(new Point(1, 2)); | ||
|
||
assertEquals(expected, new XMLWriter().save(p1, "Points")); | ||
|
||
} | ||
|
||
} |