List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:ffx.potential.bonded.BondedUtils.java
public static Atom buildHydrogenAtom(MSGroup residue, String atomName, Atom ia, double bond, Atom ib, double angle1, Atom ic, double angle2, int chiral, AtomType atomType, ForceField forceField, ArrayList<Bond> bondList) { if (atomType == null) { return null; }/*from w w w .j av a 2 s .com*/ Atom atom = (Atom) residue.getAtomNode(atomName); // It may be a Deuterium if (atom == null) { String dAtomName = atomName.replaceFirst("H", "D"); atom = (Atom) residue.getAtomNode(dAtomName); } // Basic checking for unspecified H atoms attached to waters. if (residue instanceof Molecule && atom == null) { Molecule molec = (Molecule) residue; String molName = molec.getName().toUpperCase(); if (molName.startsWith("HOH") || molName.startsWith("WAT") || molName.startsWith("TIP3")) { atom = (Atom) molec.getAtomNode("H"); if (atom == null) { atom = (Atom) molec.getAtomNode("D"); } if (atom != null) { atom.setName(atomName); } } } if (atom == null) { String resName = ia.getResidueName(); int resSeq = ia.getResidueNumber(); Character chainID = ia.getChainID(); Character altLoc = ia.getAltLoc(); String segID = ia.getSegID(); double occupancy = ia.getOccupancy(); double tempFactor = ia.getTempFactor(); atom = new Atom(0, atomName, altLoc, new double[3], resName, resSeq, chainID, occupancy, tempFactor, segID, true); residue.addMSNode(atom); intxyz(atom, ia, bond, ib, angle1, ic, angle2, chiral); } atom.setAtomType(atomType); buildBond(ia, atom, forceField, bondList); return atom; }
From source file:co.mcme.animations.animations.commands.AnimationFactory.java
public static void listAvailableSounds(Player p) { p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "---------------------------"); p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Available Sound constants:"); p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "---------------------------"); String sounds = ""; for (Sound s : Sound.values()) { sounds += ", " + s.toString(); }// w ww .ja v a 2 s .c o m sounds.replaceFirst(", ", ""); p.sendMessage(ChatColor.AQUA + sounds); }
From source file:com.qmetry.qaf.automation.ui.selenium.AssertionService.java
private static Boolean handleRegex(String prefix, String expectedPattern, String actual, int flags) { if (expectedPattern.startsWith(prefix)) { String expectedRegEx = expectedPattern.replaceFirst(prefix, ".*") + ".*"; Pattern p = Pattern.compile(expectedRegEx, flags); if (!p.matcher(actual).matches()) { System.out.println("expected " + actual + " to match regexp " + expectedPattern); return Boolean.FALSE; }//from ww w .j a v a 2s . c o m return Boolean.TRUE; } return null; }
From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java
private static void setupRunStatsProfile(Connection conn, Backend backend, String dphName, String dsName, String rphName, String rsName, String lstrName, int bucketSizeDPH, int bucketSizeRPH, String schema) { if (backend == Backend.postgresql) { String dbRunStatsSql = Sqls.getSqls(backend).getSql("dphRphRunStats"); dbRunStatsSql = dbRunStatsSql.replaceFirst("%s", schema); dbRunStatsSql = dbRunStatsSql.replaceFirst("%t", dphName); SQLExecutor.executeCall(conn, dbRunStatsSql); }//from w w w . ja v a 2 s . c o m if (backend == Backend.db2) { String dbRunStatsSql = Sqls.getSqls(backend).getSql("dphRphRunStats"); dbRunStatsSql = dbRunStatsSql.replaceFirst("%s", schema); StringBuffer dphBuf = new StringBuffer(); int i = 0; for (; (i < bucketSizeDPH - 1); i++) { dphBuf.append(" prop" + i + ","); } dphBuf.append(" prop" + i); // now rph StringBuffer rphBuf = new StringBuffer(); for (i = 0; (i < bucketSizeRPH - 1); i++) { rphBuf.append(" prop" + i + ","); } rphBuf.append(" prop" + i); String table = dphName; // DPH String dph = dbRunStatsSql.replaceFirst("%t", table); dph = dph.replaceFirst("%c", dphBuf.toString()); SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", dph); // RPH table = rphName; String rph = dbRunStatsSql.replaceFirst("%t", table); rph = rph.replaceFirst("%c", rphBuf.toString()); SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", rph); // DS dbRunStatsSql = Sqls.getSqls(backend).getSql("dsRsLsRunStats"); dbRunStatsSql = dbRunStatsSql.replaceFirst("%s", schema); table = dsName; SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", dbRunStatsSql.replaceFirst("%t", table)); // RS table = rsName; SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", dbRunStatsSql.replaceFirst("%t", table)); // LSTR table = lstrName; SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", dbRunStatsSql.replaceFirst("%t", table)); // TURN ON AUTORUNSTATS SQLExecutor.executeCall(conn, "CALL ADMIN_CMD(?)", Sqls.getSqls(backend).getSql("setAutoStats")); } }
From source file:eionet.util.SecurityUtil.java
/** * * @param request/* ww w .ja v a 2 s . c o m*/ * @return */ public static String getLogoutURL(HttpServletRequest request) { // The default result used when the application is configured to not use Central Authentication Service (CAS). String result = "index.jsp"; if (Props.isUseCentralAuthenticationService()) { CASFilterConfig casFilterConfig = CASFilterConfig.getInstance(); if (casFilterConfig != null) { String casLoginUrl = casFilterConfig.getInitParameter(CASFilter.LOGIN_INIT_PARAM); if (casLoginUrl != null) { String casServerName = casFilterConfig.getInitParameter(CASFilter.SERVERNAME_INIT_PARAM); if (casServerName == null) { throw new DDRuntimeException("If " + CASFilter.LOGIN_INIT_PARAM + " context parameter has been specified, so must be " + CASFilter.SERVERNAME_INIT_PARAM); } try { result = casLoginUrl.replaceFirst("/login", "/logout") + "?url=" + URLEncoder.encode( request.getScheme() + "://" + casServerName + request.getContextPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new DDRuntimeException(e.toString(), e); } } } } return result; }
From source file:org.openmrs.module.webservices.rest.web.RestUtil.java
/** * Gets a list of classes in a given package. Note that interfaces are not returned. * /* w ww . ja v a 2 s . c o m*/ * @param pkgname the package name. * @param suffix the ending text on name. eg "Resource.class" * @return the list of classes. */ public static ArrayList<Class<?>> getClassesForPackage(String pkgname, String suffix) throws IOException { ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); //Get a File object for the package File directory = null; String relPath = pkgname.replace('.', '/'); Enumeration<URL> resources = OpenmrsClassLoader.getInstance().getResources(relPath); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); if (resource == null) { throw new RuntimeException("No resource for " + relPath); } try { directory = new File(resource.toURI()); } catch (URISyntaxException e) { throw new RuntimeException(pkgname + " (" + resource + ") does not appear to be a valid URL / URI. Strange, since we got it from the system...", e); } catch (IllegalArgumentException ex) { //ex.printStackTrace(); } //If folder exists, look for all resource class files in it. if (directory != null && directory.exists()) { //Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { //We are only interested in Resource.class files if (files[i].endsWith(suffix)) { //Remove the .class extension String className = pkgname + '.' + files[i].substring(0, files[i].length() - 6); try { Class<?> cls = Class.forName(className); if (!cls.isInterface()) classes.add(cls); } catch (ClassNotFoundException e) { throw new RuntimeException("ClassNotFoundException loading " + className); } } } } else { //Directory does not exist, look in jar file. try { String fullPath = resource.getFile(); String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); JarFile jarFile = new JarFile(jarPath); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String entryName = entry.getName(); if (!entryName.endsWith(suffix)) continue; if (entryName.startsWith(relPath) && entryName.length() > (relPath.length() + "/".length())) { String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); try { Class<?> cls = Class.forName(className); if (!cls.isInterface()) classes.add(cls); } catch (ClassNotFoundException e) { throw new RuntimeException("ClassNotFoundException loading " + className); } } } } catch (IOException e) { throw new RuntimeException( pkgname + " (" + directory + ") does not appear to be a valid package", e); } } } return classes; }
From source file:jp.co.golorp.emarf.model.Models.java
/** * ?????sql??//from w ww . ja v a2 s . c om * * @param sql * sql * @param params * * @return ???sql */ private static String getRawSql(final String sql, final Object... params) { String query = sql; for (Object param : params) { query = query.replaceFirst("\\?", "'" + String.valueOf(param).replaceAll("\\\\", "\\\\\\\\") + "'"); } return query; }
From source file:jp.co.golorp.emarf.model.Models.java
/** * ??????????/*from w w w . j av a 2s.co m*/ * * @param <T> * * @param bean * ??bean */ private static <T> void cp2org(final T bean) { Class<?> clazz = bean.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.getName().startsWith(BeanGenerator.ORG_PREFIX)) { try { String orgName = field.getName(); String propertyName = orgName.replaceFirst(BeanGenerator.ORG_PREFIX, ""); Field property = clazz.getDeclaredField(propertyName); field.setAccessible(true); property.setAccessible(true); Object value = property.get(bean); field.set(bean, value); } catch (Exception e) { throw new SystemError(e); } } } }
From source file:free.yhc.feeder.model.Utils.java
public static String removeLeadingTrailingWhiteSpace(String s) { s = s.replaceFirst("^\\s+", ""); return s.replaceFirst("\\s+$", ""); }
From source file:org.biopax.validator.Main.java
public static Collection<Resource> getResourcesToValidate(String input) throws IOException { Set<Resource> setRes = new HashSet<Resource>(); File fileOrDir = new File(input); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".owl")); }/*from www. j av a 2 s. c o m*/ }; for (String s : fileOrDir.list(filter)) { String uri = "file:" + fileOrDir.getCanonicalPath() + File.separator + s; setRes.add(ctx.getResource(uri)); } } else if (input.startsWith("list:")) { // consider it's a file that contains a list of (pseudo-)URLs String batchFile = input.replaceFirst("list:", "file:"); Reader isr = new InputStreamReader(ctx.getResource(batchFile).getInputStream()); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null && !"".equals(line.trim())) { // check the source URL if (!ResourceUtils.isUrl(line)) { log.error("Invalid URL: " + line + ". A resource must be either a " + "pseudo URL (classpath: or file:) or standard URL!"); continue; } setRes.add(ctx.getResource(line)); } reader.close(); } else { // a single local OWL file or remote data Resource resource = null; if (!ResourceUtils.isUrl(input)) input = "file:" + input; resource = ctx.getResource(input); setRes.add(resource); } return setRes; }