List of usage examples for java.lang NullPointerException printStackTrace
public void printStackTrace()
From source file:com.optimusinfo.elasticpath.cortex.common.Utils.java
/** * Utility method to check network availability * /* w w w . java2 s . co m*/ * @return boolean value indicating the presence of network availability */ public static boolean isNetworkAvailable(Context argActivity) { if (argActivity == null) { return false; } ConnectivityManager connectivityManager; NetworkInfo activeNetworkInfo = null; try { connectivityManager = (ConnectivityManager) argActivity.getSystemService(Context.CONNECTIVITY_SERVICE); activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); } catch (NullPointerException e) { e.printStackTrace(); } return activeNetworkInfo != null; }
From source file:com.cws.esolutions.security.listeners.SecurityServiceInitializer.java
/** * Initializes the security service in a standalone mode - used for applications outside of a container or when * run as a standalone jar./*from w w w .j a v a 2 s . c om*/ * * @param configFile - The security configuration file to utilize * @param logConfig - The logging configuration file to utilize * @param startConnections - Configure, load and start repository connections * @throws SecurityServiceException @{link com.cws.esolutions.security.exception.SecurityServiceException} * if an exception occurs during initialization */ public static void initializeService(final String configFile, final String logConfig, final boolean startConnections) throws SecurityServiceException { URL xmlURL = null; JAXBContext context = null; Unmarshaller marshaller = null; SecurityConfigurationData configData = null; final ClassLoader classLoader = SecurityServiceInitializer.class.getClassLoader(); final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("configFileFile") : configFile; final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("secLogConfig") : logConfig; try { try { DOMConfigurator.configure(Loader.getResource(loggingConfig)); } catch (NullPointerException npx) { try { DOMConfigurator.configure(FileUtils.getFile(loggingConfig).toURI().toURL()); } catch (NullPointerException npx1) { System.err.println("Unable to load logging configuration. No logging enabled!"); System.err.println(""); npx1.printStackTrace(); } } xmlURL = classLoader.getResource(serviceConfig); if (xmlURL == null) { // try loading from the filesystem xmlURL = FileUtils.getFile(serviceConfig).toURI().toURL(); } context = JAXBContext.newInstance(SecurityConfigurationData.class); marshaller = context.createUnmarshaller(); configData = (SecurityConfigurationData) marshaller.unmarshal(xmlURL); SecurityServiceInitializer.svcBean.setConfigData(configData); if (startConnections) { DAOInitializer.configureAndCreateAuthConnection( new FileInputStream(FileUtils.getFile(configData.getSecurityConfig().getAuthConfig())), false, SecurityServiceInitializer.svcBean); Map<String, DataSource> dsMap = SecurityServiceInitializer.svcBean.getDataSources(); if (DEBUG) { DEBUGGER.debug("dsMap: {}", dsMap); } if (configData.getResourceConfig() != null) { if (dsMap == null) { dsMap = new HashMap<String, DataSource>(); } for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) { if (!(dsMap.containsKey(mgr.getDsName()))) { StringBuilder sBuilder = new StringBuilder() .append("connectTimeout=" + mgr.getConnectTimeout() + ";") .append("socketTimeout=" + mgr.getConnectTimeout() + ";") .append("autoReconnect=" + mgr.getAutoReconnect() + ";") .append("zeroDateTimeBehavior=convertToNull"); if (DEBUG) { DEBUGGER.debug("StringBuilder: {}", sBuilder); } BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(mgr.getDriver()); dataSource.setUrl(mgr.getDataSource()); dataSource.setUsername(mgr.getDsUser()); dataSource.setConnectionProperties(sBuilder.toString()); dataSource.setPassword(PasswordUtils.decryptText(mgr.getDsPass(), mgr.getDsSalt(), configData.getSecurityConfig().getSecretAlgorithm(), configData.getSecurityConfig().getIterations(), configData.getSecurityConfig().getKeyBits(), configData.getSecurityConfig().getEncryptionAlgorithm(), configData.getSecurityConfig().getEncryptionInstance(), configData.getSystemConfig().getEncoding())); if (DEBUG) { DEBUGGER.debug("BasicDataSource: {}", dataSource); } dsMap.put(mgr.getDsName(), dataSource); } } if (DEBUG) { DEBUGGER.debug("dsMap: {}", dsMap); } SecurityServiceInitializer.svcBean.setDataSources(dsMap); } } } catch (JAXBException jx) { jx.printStackTrace(); throw new SecurityServiceException(jx.getMessage(), jx); } catch (FileNotFoundException fnfx) { fnfx.printStackTrace(); throw new SecurityServiceException(fnfx.getMessage(), fnfx); } catch (MalformedURLException mux) { mux.printStackTrace(); throw new SecurityServiceException(mux.getMessage(), mux); } catch (SecurityException sx) { sx.printStackTrace(); throw new SecurityServiceException(sx.getMessage(), sx); } }
From source file:com.optimusinfo.elasticpath.cortex.common.Utils.java
/** * Get data from the given Cortex URL// w ww .j av a 2 s .co m * * @param url * URL of the API * @param accessToken * the access token to authenticate the request * @param contentType * the content type of the request * @param contentTypeString * @param authorizationString * @param accessTokenInitializer * the string to be used before the access token as per the * guidelines * @return the JSON data returned by this navigation task */ public static String getJSONFromCortexUrl(String url, String accessToken, String contentType, String contentTypeString, String authorizationString, String accessTokenInitializer) { try { // Input stream InputStream objInputStream; // JSON String String responseJSON; // Making HTTP request DefaultHttpClient httpClient = new DefaultHttpClient(); Log.i("GET REQUEST", url); HttpGet httpGet = new HttpGet(url); httpGet.setHeader(contentTypeString, contentType); httpGet.setHeader(authorizationString, accessTokenInitializer + " " + accessToken); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); switch (httpResponse.getStatusLine().getStatusCode()) { case Constants.ApiResponseCode.REQUEST_SUCCESSFUL_CREATED: case Constants.ApiResponseCode.REQUEST_SUCCESSFUL_UPDATED: objInputStream = httpEntity.getContent(); break; case Constants.ApiResponseCode.UNAUTHORIZED_ACCESS: return Integer.toString((Constants.ApiResponseCode.UNAUTHORIZED_ACCESS)); default: return Integer.toString(httpResponse.getStatusLine().getStatusCode()); } ; // Parse the response to String BufferedReader objReader = new BufferedReader(new InputStreamReader(objInputStream, "iso-8859-1"), 8); StringBuilder objSb = new StringBuilder(); String line = null; while ((line = objReader.readLine()) != null) { objSb.append(line + "\n"); } objInputStream.close(); // Instantiate the String before setting it to the result // string responseJSON = new String(); responseJSON = objSb.toString(); return responseJSON; } catch (NullPointerException e) { e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
From source file:org.semanticscience.narf.graphs.lib.cycles.CycleHelper.java
/** * Make a Double representation of a Cycle<Nucleotide, InteractionEdge> * // w w w .j a va 2s . c o m * @param ac * a cycle * @param basepaironly * if set to true glycosidic bond orientation and nucleobase * edge-edge interactions will be ignored * @return a string representation of the cycle that includes the following * features: Nucleotides, backbones and base pairs only */ public static BigDecimal normalizeCycle(Cycle<Nucleotide, InteractionEdge> ac, boolean basepaironly) { List<Nucleotide> verts = ac.getVertexList(); LinkedList<Integer> tmpints = new LinkedList<Integer>(); for (Nucleotide aNuc : verts) { try { int nn = aNuc.getNormalizedNucleotide(); tmpints.add(nn); } catch (NullPointerException e) { System.out.println("offending nucleotide: " + aNuc); e.printStackTrace(); System.exit(1); } InteractionEdge ie = ac.getNextEdge(aNuc); Set<NucleotideInteraction> nis = ie.getInteractions(); for (NucleotideInteraction aNi : nis) { if (aNi instanceof BasePair) { try { if (basepaironly == false) { int bp = ((BasePair) aNi).getNormalizedBasePairClass(); tmpints.add(bp); } else { int bp = 1; tmpints.add(bp); } } catch (NullPointerException e) { e.printStackTrace(); } } if (aNi instanceof PhosphodiesterBond) { int pdb = ((PhosphodiesterBond) aNi).getNormalizedBackBone(); tmpints.add(pdb); } // break; } } String intStr = ""; for (Integer anInt : tmpints) { intStr += anInt; } BigDecimal d = null; try { d = new BigDecimal(intStr); } catch (NumberFormatException e) { e.printStackTrace(); } return d; }
From source file:swift.selenium.Automation.java
public static void setUp() throws Exception { if (driver != null) { WebHelper.wait = null;/*www . j ava 2 s . c o m*/ driver.quit(); } // 03-Jun-16:SS No need to check if Process is running, we can directly go for Kill operation String extn = ""; String osName = System.getProperty("os.name"); if (osName.contains("Mac") || osName.contains("Linux")) { extn = ""; } else { extn = ".exe"; } CalendarSnippet.killProcess("IEDriverServer" + extn); CalendarSnippet.killProcess("chromedriver" + extn); CalendarSnippet.killProcess("node" + extn); try { if (!StringUtils.equalsIgnoreCase("none", configHashMap.get("BROWSERTYPE").toString())) { Automation.browser = Automation.configHashMap.get("BROWSERTYPE").toString(); } browserType = browserTypeEnum.valueOf(browser); switch (browserType) { case AppiumDriver: AppiumDriverLocalService service = null; File classPathRoot = new File(System.getProperty("user.dir")); // Read Appium Config and set the desired capabilities String Appium_Path = appiumConfigMap.get("APPIUM_PATH").toString(); String Appium_REMOTE_URL = appiumConfigMap.get("REMOTE_URL").toString(); int Appium_REMOTE_PORT = Integer.parseInt(appiumConfigMap.get("REMOTE_PORT").toString()); DesiredCapabilities capabilities = new DesiredCapabilities(); String platformname = appiumConfigMap.get("PLATFORMNAME").toString(); capabilities.setCapability("platformName", platformname); String deviceName = appiumConfigMap.get("DEVICENAME").toString(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName); String udid = appiumConfigMap.get("UDID").toString(); if (!udid.equalsIgnoreCase("NA")) { capabilities.setCapability(MobileCapabilityType.UDID, udid); } String browserName = appiumConfigMap.get("BROWSERNAME").toString(); if (browserName.equalsIgnoreCase("NA")) { capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); } else { capabilities.setCapability(CapabilityType.BROWSER_NAME, browserName); } String platform = appiumConfigMap.get("PLATFORM").toString(); capabilities.setCapability(CapabilityType.PLATFORM, platform); String appPakcage = appiumConfigMap.get("APP_PACKAGE").toString(); if (!appPakcage.equalsIgnoreCase("NA")) { capabilities.setCapability("appPackage", appPakcage); } String appPath = appiumConfigMap.get("APP_PATH").toString(); if (!appPath.equalsIgnoreCase("NA")) { capabilities.setCapability("app", appPath); } String appActivity = appiumConfigMap.get("APP_ACTIVITY").toString(); if (!appActivity.equalsIgnoreCase("NA")) { capabilities.setCapability("appActivity", appActivity); } String service_url = ""; // Start the Appium Service based on OS if (osName.contains("Windows")) { try { service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withAppiumJS(new File(Appium_Path + "\\node_modules\\appium\\bin\\Appium.js")) .usingDriverExecutable(new File(Appium_Path + "\\node.exe")) .withArgument(GeneralServerFlag.LOG_LEVEL, "info").withIPAddress(Appium_REMOTE_URL) .usingPort(Appium_REMOTE_PORT) .withLogFile(new File(new File(classPathRoot, File.separator), "Appium.log"))); service.start(); Thread.sleep(5000); service_url = service.getUrl().toString(); } catch (Exception e) { e.printStackTrace(); } } else if (osName.contains("Mac")) { try { service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withAppiumJS( new File(Appium_Path + "//lib//node_modules//appium//build//lib//main.js")) .usingDriverExecutable(new File(Appium_Path + "//Cellar//node//6.2.0//bin//node")) .withArgument(GeneralServerFlag.LOG_LEVEL, "info").withIPAddress(Appium_REMOTE_URL) .usingPort(Appium_REMOTE_PORT) .withLogFile(new File(new File(classPathRoot, File.separator), "Appium.log"))); service.start(); Thread.sleep(5000); service_url = service.getUrl().toString(); } catch (Exception e) { e.printStackTrace(); } } else if (osName.contains("Linux")) { try { service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder() .withAppiumJS(new File( "/home/rushikesh/.linuxbrew/lib/node_modules/appium/bin/appium.js")) .usingDriverExecutable( new File(Appium_Path + "//usr//local//n//versions//node//6.0.0//bin//node")) .withArgument(GeneralServerFlag.LOG_LEVEL, "info").withIPAddress(Appium_REMOTE_URL) .usingPort(Appium_REMOTE_PORT) .withLogFile(new File(new File(classPathRoot, File.separator), "Appium.log"))); service.start(); Thread.sleep(5000); service_url = service.getUrl().toString(); } catch (Exception e) { e.printStackTrace(); } } else { TransactionMapping .pauseFun("Mobile Automation Support for this OS " + osName + " is yet to be added"); } // Initiate the driver based on Mobile OS if (platformname.contains("iOS")) { driver = new IOSDriver(new URL(service_url), capabilities); } else if (platformname.contains("Android")) { driver = new AndroidDriver(new URL(service_url), capabilities); } break; case InternetExplorer: driver = getIEDriverInstance(); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); break; case FireFox: driver = getFFDriverInstance(); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); break; case Chrome: driver = getChromeDriverInstance(); driver.manage().deleteAllCookies(); break; // TM-20/01/2015-Case added for Safari case Safari: driver = getSafariDriverInstance(); driver.manage().window().maximize(); break; case None: System.out.println("The browser setup need to be done in Input file..."); break; } if (driver != null) { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); WebHelper.wait = new WebDriverWait(Automation.driver, Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString())); } //if (!StringUtils.equalsIgnoreCase("none", configHashMap.get("BROWSERTYPE").toString())){ //WebHelper.wait = new WebDriverWait(Automation.driver,Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString())); //} } catch (NullPointerException npe) { npe.printStackTrace(); TransactionMapping.pauseFun("Null Values Found in Automation.SetUp Function"); } catch (Exception e) { e.printStackTrace(); TransactionMapping.pauseFun("Error from Automation.Setup " + e.getMessage()); } }
From source file:org.apache.streams.urls.LinkResolver.java
/** * Removes the protocol, if it exists, from the front and * removes any random encoding characters * Extend this to do other url cleaning/pre-processing * * @param url - The String URL to normalize * @return normalizedUrl - The String URL that has no junk or surprises *///from ww w . java 2 s .c om public static String normalizeURL(String url) { // Decode URL to remove any %20 type stuff String normalizedUrl = url; try { // Replaced URLDecode with commons-codec b/c of failing tests URLCodec codec = new URLCodec(); normalizedUrl = codec.decode(url); // Remove the protocol, http:// ftp:// or similar from the front if (normalizedUrl.contains("://")) normalizedUrl = normalizedUrl.split(":/{2}")[1]; } catch (NullPointerException npe) { System.err.println("NPE Decoding URL. Decoding skipped."); npe.printStackTrace(); } catch (Throwable e) { System.err.println("Misc error Decoding URL. Decoding skipped."); e.printStackTrace(); } // Room here to do more pre-processing return normalizedUrl; }
From source file:com.mattprecious.telescope.FileProvider.java
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) *///from www.ja v a2 s . co m private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException { final SimplePathStrategy strat = new SimplePathStrategy(authority); final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority, PackageManager.GET_META_DATA); final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS); if (in == null) { throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data"); } int type; while ((type = in.next()) != END_DOCUMENT) { if (type == START_TAG) { final String tag = in.getName(); final String name = in.getAttributeValue(null, ATTR_NAME); String path = in.getAttributeValue(null, ATTR_PATH); File target = null; if (TAG_ROOT_PATH.equals(tag)) { target = buildPath(DEVICE_ROOT, path); } else if (TAG_FILES_PATH.equals(tag)) { target = buildPath(context.getFilesDir(), path); } else if (TAG_CACHE_PATH.equals(tag)) { target = buildPath(context.getCacheDir(), path); } else if (TAG_EXTERNAL.equals(tag)) { target = buildPath(Environment.getExternalStorageDirectory(), path); } else if (TAG_EXTERNAL_APP.equals(tag)) { try { // This sometimes causes an exception on API level 19 // Just avoid this specific file provider, so we can try to keep going target = buildPath(context.getExternalFilesDir(null), path); } catch (NullPointerException npe) { npe.printStackTrace(); } } if (target != null) { strat.addRoot(name, target); } } } return strat; }
From source file:org.scantegrity.scanner.Scanner.java
/** * Get and set up the configuration file data. * /*from w ww .ja v a 2 s . com*/ * This file configures the election. * * @param p_configPath - The path. * @return */ private static ScannerConfig getConfiguration(String p_configPath) { ScannerConfig l_config = new ScannerConfig(); File c_loc = null; try { if (p_configPath == null) { c_loc = new FindFile(ScannerConstants.DEFAULT_CONFIG_NAME).find(); } else { c_loc = new File(p_configPath); } if (!c_loc.isFile()) { c_loc = new FindFile(ScannerConstants.DEFAULT_CONFIG_NAME).find(); System.err.println("Could not open file."); } } catch (NullPointerException e_npe) { System.err.println("Could not open file. File does not exist."); e_npe.printStackTrace(); criticalExit(5); } //TODO: make sure the file is found and is readable if (c_loc == null) { System.err.println("Critical Error: Could not open configuration " + "file. System Exiting."); criticalExit(10); } XMLDecoder e; try { e = new XMLDecoder(new BufferedInputStream(new FileInputStream(c_loc))); l_config = (ScannerConfig) e.readObject(); e.close(); } catch (Exception e_e) { System.err.println("Could not parse Configuration File!"); e_e.printStackTrace(); criticalExit(20); } return l_config; }
From source file:edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty.java
/** * Sorts the object property statements taking into account the sort order. *//*from w w w. j a v a 2 s .co m*/ public static List<ObjectPropertyStatement> sortObjectPropertyStatementsForDisplay(ObjectProperty prop, List objPropStmtsList) { if (objPropStmtsList == null) { log.error("incoming object property statement list is null; " + "returning null"); return null; } if (objPropStmtsList.size() < 2) { // no need to sort return objPropStmtsList; } String tmpDirection = prop.getDomainEntitySortDirection(); // Valid values are "desc" and "asc"; // anything else will default to ascending. final boolean ascending = !"desc".equalsIgnoreCase(tmpDirection); String objIndivSortPropURI = prop.getObjectIndividualSortPropertyURI(); if (prop.getObjectIndividualSortPropertyURI() == null || prop.getObjectIndividualSortPropertyURI().length() == 0) { log.debug("objectIndividualSortPropertyURI is null or blank " + "so sorting by name "); Comparator fieldComp = new Comparator() { public final int compare(Object o1, Object o2) { ObjectPropertyStatement e2e1 = (ObjectPropertyStatement) o1, e2e2 = (ObjectPropertyStatement) o2; Individual e1, e2; e1 = e2e1 != null ? e2e1.getObject() : null; e2 = e2e2 != null ? e2e2.getObject() : null; Object val1 = null, val2 = null; if (e1 != null) { val1 = e1.getName(); } else { log.debug("PropertyWebapp.sortObjectPropertiesForDisplay() " + "passed object property statement with no range entity."); } if (e2 != null) { val2 = e2.getName(); } else { log.debug("PropertyWebapp.sortObjectPropertyStatementsForDisplay " + "passed object property statement with no range entity."); } int rv = 0; try { if (val1 instanceof String) { if (val2 == null) { rv = -1; } else { Collator collator = Collator.getInstance(); rv = collator.compare(((String) val1), ((String) val2)); } } else if (val1 instanceof Date) { DateTime dt1 = new DateTime((Date) val1); DateTime dt2 = new DateTime((Date) val2); rv = dt1.compareTo(dt2); } else { rv = 0; } } catch (NullPointerException e) { e.printStackTrace(); } if (ascending) { return rv; } else { return rv * -1; } } }; try { Collections.sort(objPropStmtsList, fieldComp); } catch (Exception e) { log.error("Exception sorting object property statements for object property " + prop.getURI()); } } else { // sort by specified range entity data property value instead of a property having a get() method in Individual.java log.debug("using data property " + prop.getObjectIndividualSortPropertyURI() + " to sort related entities"); final String objIndSortPropURI = prop.getObjectIndividualSortPropertyURI(); Comparator dpComp = new Comparator() { final String cDatapropURI = objIndSortPropURI; public final int compare(Object o1, Object o2) { ObjectPropertyStatement e2e1 = (ObjectPropertyStatement) o1, e2e2 = (ObjectPropertyStatement) o2; Individual e1, e2; e1 = e2e1 != null ? e2e1.getObject() : null; e2 = e2e2 != null ? e2e2.getObject() : null; Object val1 = null, val2 = null; if (e1 != null) { try { List<DataPropertyStatement> dataPropertyStatements = e1.getDataPropertyStatements(); for (DataPropertyStatement dps : dataPropertyStatements) { if (cDatapropURI.equals(dps.getDatapropURI())) { if (dps.getData() != null && dps.getData().trim().length() > 0) { if (XSDDatatype.XSDint.getURI().equals(dps.getDatatypeURI()) || XSDDatatype.XSDinteger.getURI().equals(dps.getDatatypeURI())) { val1 = Integer.parseInt(dps.getData()); } else { val1 = dps.getData(); } } } } } catch (Exception e) { e.printStackTrace(); } } else log.debug( "PropertyWebapp.sortObjectPropertiesForDisplay passed object property statement with no range entity."); if (e2 != null) { try { List<DataPropertyStatement> dataPropertyStatements = e2.getDataPropertyStatements(); for (DataPropertyStatement dps : dataPropertyStatements) { if (cDatapropURI.equals(dps.getDatapropURI())) { if (dps.getData() != null && dps.getData().trim().length() > 0) { if (XSDDatatype.XSDint.getURI().equals(dps.getDatatypeURI()) || XSDDatatype.XSDinteger.getURI().equals(dps.getDatatypeURI())) { val2 = Integer.parseInt(dps.getData()); } else { val2 = dps.getData(); } } } } } catch (Exception e) { e.printStackTrace(); } } else { log.debug( "PropertyWebapp.sortObjectPropertyStatementsForDisplay passed object property statement with no range entity."); } int rv = 0; try { if (val1 == null && val2 == null) { rv = 0; } else if (val1 == null) { rv = 1; } else if (val2 == null) { rv = -1; } else { if (val1 instanceof String) { Collator collator = Collator.getInstance(); rv = collator.compare(((String) val1), ((String) val2)); //was rv = ((String)val1).compareTo((String)val2); } else if (val1 instanceof Date) { DateTime dt1 = new DateTime((Date) val1); DateTime dt2 = new DateTime((Date) val2); rv = dt1.compareTo(dt2); } else if (val1 instanceof Integer) { rv = ((Integer) val1) - ((Integer) val2); } else { rv = 0; } } } catch (NullPointerException e) { e.printStackTrace(); } if (!ascending) { rv = rv * -1; } // sort alphabetically by name if have same dataproperty value if (rv == 0) { String nameValue1 = (e1.getName() != null) ? e1.getName() : ""; String nameValue2 = (e2.getName() != null) ? e2.getName() : ""; rv = Collator.getInstance().compare(nameValue1, nameValue2); } return rv; } }; try { Collections.sort(objPropStmtsList, dpComp); } catch (Exception e) { log.error("Exception sorting object property statements " + "for object property " + prop.getURI(), e); } } return objPropStmtsList; }
From source file:org.ubicompforall.BusTUC.Speech.Calc.java
public DummyObj parse(String jsonString) { DummyObj dummy = new DummyObj(); JSONObject json_obj;//from w w w . ja v a2 s. c o m try { json_obj = new JSONObject(jsonString); dummy.setAnswer(json_obj.getString("theAnswer")); dummy.setSoundInfo(json_obj.getString("soundInfo")); } catch (JSONException e) { e.printStackTrace(); } catch (NullPointerException ex) { ex.printStackTrace(); } return dummy; }