List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:eu.cassandra.sim.Simulation.java
License:Apache License
public static ProbabilityDistribution json2dist(DBObject distribution) throws Exception { String distType = (String) distribution.get("distrType"); switch (distType) { case ("Normal Distribution"): BasicDBList normalList = (BasicDBList) distribution.get("parameters"); DBObject normalDoc = (DBObject) normalList.get(0); double mean = Double.parseDouble(normalDoc.get("mean").toString()); double std = Double.parseDouble(normalDoc.get("std").toString()); Gaussian normal = new Gaussian(mean, std); normal.precompute(0, 1439, 1440); return normal; case ("Uniform Distribution"): BasicDBList unifList = (BasicDBList) distribution.get("parameters"); DBObject unifDoc = (DBObject) unifList.get(0); double from = Double.parseDouble(unifDoc.get("start").toString()); double to = Double.parseDouble(unifDoc.get("end").toString()); Uniform uniform = new Uniform(from, to); uniform.precompute(from, to, (int) to + 1); return uniform; case ("Gaussian Mixture Models"): BasicDBList mixList = (BasicDBList) distribution.get("parameters"); int length = mixList.size(); double[] w = new double[length]; double[] means = new double[length]; double[] stds = new double[length]; for (int i = 0; i < mixList.size(); i++) { DBObject tuple = (DBObject) mixList.get(i); w[i] = Double.parseDouble(tuple.get("w").toString()); means[i] = Double.parseDouble(tuple.get("mean").toString()); stds[i] = Double.parseDouble(tuple.get("std").toString()); }/*from ww w . ja va 2s . c o m*/ GaussianMixtureModels gmm = new GaussianMixtureModels(length, w, means, stds); gmm.precompute(0, 1439, 1440); return gmm; case ("Histogram"): BasicDBList hList = (BasicDBList) distribution.get("values"); int l = hList.size(); double[] v = new double[l]; for (int i = 0; i < l; i++) { v[i] = Double.parseDouble(hList.get(i).toString()); } Histogram h = new Histogram(v); return h; default: throw new Exception("Non existing distribution type. Problem in setting up the simulation."); } }
From source file:eu.cassandra.sim.utilities.Utils.java
License:Apache License
public static double[] dblist2doubleArr(BasicDBList list) { double[] arr = new double[list.size()]; for (int i = 0; i < list.size(); i++) { arr[i] = Double.parseDouble(list.get(i).toString()); }// w w w . jav a 2s . c o m return arr; }
From source file:eu.cassandra.sim.utilities.Utils.java
License:Apache License
public static float[] dblist2floatArr(BasicDBList list) { float[] arr = new float[list.size()]; for (int i = 0; i < list.size(); i++) { arr[i] = ((Float) list.get(i)).floatValue(); }//from w w w . ja va 2s . c o m return arr; }
From source file:eu.cassandra.sim.utilities.Utils.java
License:Apache License
public static int[] dblist2intArr(BasicDBList list) { int[] arr = new int[list.size()]; for (int i = 0; i < list.size(); i++) { arr[i] = ((Integer) list.get(i)).intValue(); }//from w w w . j a va2s . c o m return arr; }
From source file:eu.cassandra.training.consumption.ActiveConsumptionModel.java
License:Apache License
/** * This is the main function that create the triplets of the pattern * //from w w w . jav a 2s.co m * @param modelObjactive * The active activeOnly consumption model JSON schema as DBObject. * */ public void init(DBObject modelObj) { outerN = ((Integer) modelObj.get("n")).intValue(); BasicDBList patternsObj = (BasicDBList) modelObj.get("params"); patternN = patternsObj.size(); patterns = new ArrayList[patternN]; n = new int[patternN]; patternDuration = new int[patternN]; for (int i = 0; i < patternN; i++) { n[i] = ((Integer) ((DBObject) patternsObj.get(i)).get("n")).intValue(); BasicDBList values = ((BasicDBList) ((DBObject) patternsObj.get(i)).get("values")); int tripplets = values.size(); patterns[i] = new ArrayList<TripletPower>(tripplets); for (int j = 0; j < tripplets; j++) { TripletPower t = new TripletPower(); try { t.p = ((Double) ((DBObject) values.get(j)).get("p")).doubleValue(); } catch (ClassCastException e) { t.p = (double) ((Integer) ((DBObject) values.get(j)).get("p")).intValue(); } t.d = ((Integer) ((DBObject) values.get(j)).get("d")).intValue(); patternDuration[i] += t.d; totalDuration += (n[i] * t.d); try { t.s = ((Double) ((DBObject) values.get(j)).get("s")).doubleValue(); } catch (ClassCastException e) { t.s = (double) ((Integer) ((DBObject) values.get(j)).get("s")).intValue(); } patterns[i].add(t); } } }
From source file:eu.cassandra.training.consumption.ReactiveConsumptionModel.java
License:Apache License
/** * This is the main function that create the triplets of the pattern * /*from w ww. j a v a 2 s . c o m*/ * @param modelObjactive * The reactive activeOnly consumption model JSON schema as DBObject. * */ public void init(DBObject modelObj) { outerN = ((Integer) modelObj.get("n")).intValue(); BasicDBList patternsObj = (BasicDBList) modelObj.get("params"); patternN = patternsObj.size(); patterns = new ArrayList[patternN]; n = new int[patternN]; patternDuration = new int[patternN]; for (int i = 0; i < patternN; i++) { n[i] = ((Integer) ((DBObject) patternsObj.get(i)).get("n")).intValue(); BasicDBList values = ((BasicDBList) ((DBObject) patternsObj.get(i)).get("values")); int tripplets = values.size(); patterns[i] = new ArrayList<TripletReactive>(tripplets); for (int j = 0; j < tripplets; j++) { TripletReactive t = new TripletReactive(); try { t.q = ((Double) ((DBObject) values.get(j)).get("q")).doubleValue(); } catch (ClassCastException e) { t.q = (double) ((Integer) ((DBObject) values.get(j)).get("q")).intValue(); } t.d = ((Integer) ((DBObject) values.get(j)).get("d")).intValue(); patternDuration[i] += t.d; totalDuration += (n[i] * t.d); try { t.s = ((Double) ((DBObject) values.get(j)).get("s")).doubleValue(); } catch (ClassCastException e) { t.s = (double) ((Integer) ((DBObject) values.get(j)).get("s")).intValue(); } patterns[i].add(t); } } }
From source file:eu.cassandra.training.utils.APIUtilities.java
License:Apache License
/** * This function is used to send the user's credentials to the Cassandra * Server./* www . ja va 2 s . co m*/ * * @param username * The username of the user in the server. * @param password * The password of the user in the server. * @return true if connected, else false. * @throws Exception */ public static boolean sendUserCredentials(String username, char[] password) throws Exception { String pass = String.valueOf(password); try { UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, pass); char SEP = File.separatorChar; File dir = new File(System.getProperty("java.home") + SEP + "lib" + SEP + "security"); File file = new File(dir, "jssecacerts"); if (file.isFile() == false) { InstallCert.createCertificate("160.40.50.233", 8443); JFrame success = new JFrame(); JOptionPane.showMessageDialog(success, "Certificate was created for user " + username + ". Now the connection will start", "Response Model Exported", JOptionPane.INFORMATION_MESSAGE); } try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, null); sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception e1) { } Scheme scheme = new Scheme("https", 8443, sf); httpclient.getConnectionManager().getSchemeRegistry().register(scheme); HttpGet httpget = new HttpGet(url + "/usr"); httpget.addHeader(new BasicScheme().authenticate(usernamePasswordCredentials, httpget, localcontext)); System.out.println("executing request: " + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget, localcontext); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); System.out.println(responseString); DBObject dbo = (DBObject) JSON.parse(responseString); if (dbo.get("success").toString().equalsIgnoreCase("true")) { BasicDBList dataObj = (BasicDBList) dbo.get("data"); DBObject dbo2 = (DBObject) dataObj.get(0); userID = dbo2.get("usr_id").toString(); System.out.println("userId: " + userID); return true; } else { System.out.println(false); return false; } } finally { } }
From source file:eu.eubrazilcc.lvl.storage.dao.LeishmaniaDAO.java
License:EUPL
@Override public List<Leishmania> getNear(final Point point, final double maxDistance) { final List<Leishmania> leishmanias = newArrayList(); final BasicDBList list = MONGODB_CONN.geoNear(COLLECTION, point.getCoordinates().getLongitude(), point.getCoordinates().getLatitude(), maxDistance); for (int i = 0; i < list.size(); i++) { leishmanias.add(parseObject(list.get(i))); }// www . j ava 2 s .c o m return leishmanias; }
From source file:eu.eubrazilcc.lvl.storage.dao.LvlInstanceDAO.java
License:EUPL
@Override public List<LvlInstance> getNear(final Point point, final double maxDistance) { final List<LvlInstance> instances = newArrayList(); final BasicDBList list = MONGODB_CONN.geoNear(COLLECTION, point.getCoordinates().getLongitude(), point.getCoordinates().getLatitude(), maxDistance); for (int i = 0; i < list.size(); i++) { instances.add(parseObject(list.get(i))); }// www .j a va 2s . c o m return instances; }
From source file:eu.eubrazilcc.lvl.storage.dao.SandflyDAO.java
License:EUPL
@Override public List<Sandfly> getNear(final Point point, final double maxDistance) { final List<Sandfly> sandflies = newArrayList(); final BasicDBList list = MONGODB_CONN.geoNear(COLLECTION, point.getCoordinates().getLongitude(), point.getCoordinates().getLatitude(), maxDistance); for (int i = 0; i < list.size(); i++) { sandflies.add(parseObject(list.get(i))); }/* w ww .j a v a2 s .c o m*/ return sandflies; }