diff options
author | 2019-06-24 10:19:53 -0400 | |
---|---|---|
committer | 2019-06-24 10:19:53 -0400 | |
commit | 775e76368b8826ec74b17196b5079c7a06a035ed (patch) | |
tree | 03d4b1e0fe200a4a029e2c960ef2310a2538e4a3 /Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java | |
parent | Implement linear regressor using Weka3 (diff) | |
download | VIATRA-Generator-775e76368b8826ec74b17196b5079c7a06a035ed.tar.gz VIATRA-Generator-775e76368b8826ec74b17196b5079c7a06a035ed.tar.zst VIATRA-Generator-775e76368b8826ec74b17196b5079c7a06a035ed.zip |
add sample domain for measuring realistic metrics
Diffstat (limited to 'Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java')
-rw-r--r-- | Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java new file mode 100644 index 00000000..3ebede25 --- /dev/null +++ b/Metrics/Metrics-Calculation/SocialNetwork_plugin/src/ca/mcgill/ecse/socialnetwork/runner/Persisitence.java | |||
@@ -0,0 +1,63 @@ | |||
1 | package ca.mcgill.ecse.socialnetwork.runner; | ||
2 | import java.io.IOException; | ||
3 | import java.util.Collections; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.emf.common.util.URI; | ||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | import org.eclipse.emf.ecore.resource.Resource; | ||
9 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
10 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
11 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
12 | |||
13 | public class Persisitence<G extends EObject> { | ||
14 | private String uri; | ||
15 | |||
16 | public Persisitence (String suffix, String uri){ | ||
17 | //prepare to save | ||
18 | Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; | ||
19 | Map<String, Object> m = reg.getExtensionToFactoryMap(); | ||
20 | m.put(suffix, new XMIResourceFactoryImpl()); | ||
21 | this.uri = uri; | ||
22 | } | ||
23 | |||
24 | |||
25 | /** | ||
26 | * Save the model | ||
27 | * @return whether the model has saved successfully | ||
28 | */ | ||
29 | public boolean save(G model) { | ||
30 | //create resource | ||
31 | ResourceSet resSet = new ResourceSetImpl(); | ||
32 | Resource resource = resSet.createResource(URI.createURI(uri)); | ||
33 | resource.getContents().add(model); | ||
34 | try { | ||
35 | resource.save(Collections.EMPTY_MAP); | ||
36 | return true; | ||
37 | }catch(IOException e) { | ||
38 | e.printStackTrace(); | ||
39 | return false; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * load the model from persistent | ||
45 | * @return: the model loaded | ||
46 | */ | ||
47 | @SuppressWarnings("unchecked") | ||
48 | public G load() { | ||
49 | G model = null; | ||
50 | // try { | ||
51 | ResourceSet resSet = new ResourceSetImpl(); | ||
52 | Resource resource = resSet.getResource(URI.createURI(uri), true); | ||
53 | model = (G) resource.getContents().get(0); | ||
54 | // }catch (org.eclipse.emf.common.util.WrappedException e) { | ||
55 | // // if the file cannot be found then return null | ||
56 | // if(e.getCause().getClass() == java.io.FileNotFoundException.class) { | ||
57 | // return null; | ||
58 | // } | ||
59 | // } | ||
60 | |||
61 | return model; | ||
62 | } | ||
63 | } | ||