List of usage examples for org.apache.commons.lang StringUtils countMatches
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
From source file:org.gradle.api.internal.plugins.StartScriptTemplateBindingFactory.java
String createJoinedAppHomeRelativePath(String scriptRelPath) { int depth = StringUtils.countMatches(scriptRelPath, "/"); if (depth == 0) { return ""; }/*from w w w . jav a2s . c o m*/ List<String> appHomeRelativePath = new ArrayList<String>(depth); for (int i = 0; i < depth; i++) { appHomeRelativePath.add(".."); } return Joiner.on(windows ? "\\" : "/").join(appHomeRelativePath); }
From source file:org.hupo.psi.mi.psicquic.ws.IndexBasedPsicquicRestServiceTest.java
@Test public void testGetByQuery_biopax() throws Exception { ResponseImpl response = (ResponseImpl) service.getByQuery("FANCD1", "biopax", "0", "5", "n"); final String output = ((GenericEntity<String>) response.getEntity()).getEntity(); Assert.assertEquals(5, StringUtils.countMatches(output, "<j.0:MolecularInteraction ")); }
From source file:org.intermine.api.lucene.KeywordSearch.java
@SuppressWarnings("unchecked") private static synchronized void parseProperties(ObjectStore os) { if (properties != null) { return;/*from w ww. j a va 2s.co m*/ } specialReferences = new HashMap<Class<? extends InterMineObject>, String[]>(); ignoredClasses = new HashSet<Class<? extends InterMineObject>>(); classBoost = new HashMap<ClassDescriptor, Float>(); ignoredFields = new HashMap<Class<? extends InterMineObject>, Set<String>>(); facets = new Vector<KeywordSearchFacetData>(); debugOutput = true; // load config file to figure out special classes String configFileName = "keyword_search.properties"; ClassLoader classLoader = KeywordSearch.class.getClassLoader(); InputStream configStream = classLoader.getResourceAsStream(configFileName); if (configStream != null) { properties = new Properties(); try { properties.load(configStream); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = ((String) entry.getValue()).trim(); if ("index.ignore".equals(key) && !StringUtils.isBlank(value)) { String[] ignoreClassNames = value.split("\\s+"); for (String className : ignoreClassNames) { ClassDescriptor cld = os.getModel().getClassDescriptorByName(className); if (cld == null) { LOG.error("Unknown class in config file: " + className); } else { addCldToIgnored(ignoredClasses, cld); } } } else if ("index.ignore.fields".equals(key) && !StringUtils.isBlank(value)) { String[] ignoredPaths = value.split("\\s+"); for (String ignoredPath : ignoredPaths) { if (StringUtils.countMatches(ignoredPath, ".") != 1) { LOG.error("Fields to ignore specified by 'index.ignore.fields'" + " should contain Class.field, e.g. Company.name"); } else { String clsName = ignoredPath.split("\\.")[0]; String fieldName = ignoredPath.split("\\.")[1]; ClassDescriptor cld = os.getModel().getClassDescriptorByName(clsName); if (cld != null) { FieldDescriptor fld = cld.getFieldDescriptorByName(fieldName); if (fld != null) { addToIgnoredFields(ignoredFields, cld, fieldName); } else { LOG.error("Field name '" + fieldName + "' not found for" + " class '" + clsName + "' specified in" + "'index.ignore.fields'"); } } else { LOG.error("Class name specified in 'index.ignore.fields'" + " not found: " + clsName); } } } } else if (key.startsWith("index.references.")) { String classToIndex = key.substring("index.references.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToIndex); if (cld != null) { Class<? extends InterMineObject> cls = (Class<? extends InterMineObject>) cld.getType(); // special fields (references to follow) come as // a // space-separated list String[] specialFields; if (!StringUtils.isBlank(value)) { specialFields = value.split("\\s+"); } else { specialFields = null; } specialReferences.put(cls, specialFields); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToIndex + "' not found!"); } } else if (key.startsWith("index.facet.single.")) { String facetName = key.substring("index.facet.single.".length()); String facetField = value; facets.add( new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.SINGLE)); } else if (key.startsWith("index.facet.multi.")) { String facetName = key.substring("index.facet.multi.".length()); String facetField = value; facets.add(new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.MULTI)); } else if (key.startsWith("index.facet.path.")) { String facetName = key.substring("index.facet.path.".length()); String[] facetFields = value.split(" "); facets.add(new KeywordSearchFacetData(facetFields, facetName, KeywordSearchFacetType.PATH)); } else if (key.startsWith("index.boost.")) { String classToBoost = key.substring("index.boost.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToBoost); if (cld != null) { classBoost.put(cld, Float.valueOf(value)); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToBoost + "' not found!"); } } else if (key.startsWith("index.prefix")) { String classAndAttribute = key.substring("index.prefix.".length()); addAttributePrefix(classAndAttribute, value); } else if ("search.debug".equals(key) && !StringUtils.isBlank(value)) { debugOutput = "1".equals(value) || "true".equals(value.toLowerCase()) || "on".equals(value.toLowerCase()); } tempDirectory = properties.getProperty("index.temp.directory", ""); } } catch (IOException e) { LOG.error("keyword_search.properties: errow while loading file '" + configFileName + "'", e); } } else { LOG.error("keyword_search.properties: file '" + configFileName + "' not found!"); } LOG.debug("Indexing - Ignored classes:"); for (Class<? extends InterMineObject> class1 : ignoredClasses) { LOG.debug("- " + class1.getSimpleName()); } LOG.debug("Indexing - Special References:"); for (Entry<Class<? extends InterMineObject>, String[]> specialReference : specialReferences.entrySet()) { LOG.debug("- " + specialReference.getKey() + " = " + Arrays.toString(specialReference.getValue())); } LOG.debug("Indexing - Facets:"); for (KeywordSearchFacetData facet : facets) { LOG.debug("- field = " + facet.getField() + ", name = " + facet.getName() + ", type = " + facet.getType().toString()); } LOG.debug("Indexing with and without attribute prefixes:"); if (attributePrefixes != null) { for (String clsAndAttribute : attributePrefixes.keySet()) { LOG.debug("- class and attribute: " + clsAndAttribute + " with prefix: " + attributePrefixes.get(clsAndAttribute)); } } LOG.info("Search - Debug mode: " + debugOutput); LOG.info("Indexing - Temp Dir: " + tempDirectory); }
From source file:org.intermine.api.searchengine.KeywordSearchPropertiesManager.java
private synchronized void parseProperties(ObjectStore os) { if (properties != null) { return;/*from w w w . j a va 2 s . c om*/ } //read class keys to figure out what are keyFields during indexing Properties classKeyProperties = new Properties(); try { classKeyProperties.load(getClass().getClassLoader().getResourceAsStream(CLASS_KEYS_FILE_NAME)); } catch (IOException e) { throw new BuildException("Could not open the class keys"); } catch (NullPointerException e) { throw new BuildException("Could not find the class keys"); } classKeys = ClassKeyHelper.readKeys(os.getModel(), classKeyProperties); specialReferences = new HashMap<Class<? extends InterMineObject>, String[]>(); ignoredClasses = new HashSet<Class<? extends InterMineObject>>(); classBoost = new HashMap<ClassDescriptor, Float>(); ignoredFields = new HashMap<Class<? extends InterMineObject>, Set<String>>(); facets = new Vector<KeywordSearchFacetData>(); debugOutput = true; // load config file to figure out special classes String configFileName = CONFIG_FILE_NAME; ClassLoader classLoader = KeywordSearchPropertiesManager.class.getClassLoader(); InputStream configStream = classLoader.getResourceAsStream(configFileName); if (configStream != null) { properties = new Properties(); try { properties.load(configStream); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = ((String) entry.getValue()).trim(); if ("index.ignore".equals(key) && !StringUtils.isBlank(value)) { String[] ignoreClassNames = value.split("\\s+"); for (String className : ignoreClassNames) { ClassDescriptor cld = os.getModel().getClassDescriptorByName(className); if (cld == null) { LOG.error("Unknown class in config file: " + className); } else { addCldToIgnored(ignoredClasses, cld); } } } else if ("index.ignore.fields".equals(key) && !StringUtils.isBlank(value)) { String[] ignoredPaths = value.split("\\s+"); for (String ignoredPath : ignoredPaths) { if (StringUtils.countMatches(ignoredPath, ".") != 1) { LOG.error("Fields to ignore specified by 'index.ignore.fields'" + " should contain Class.field, e.g. Company.name"); } else { String clsName = ignoredPath.split("\\.")[0]; String fieldName = ignoredPath.split("\\.")[1]; ClassDescriptor cld = os.getModel().getClassDescriptorByName(clsName); if (cld != null) { FieldDescriptor fld = cld.getFieldDescriptorByName(fieldName); if (fld != null) { addToIgnoredFields(ignoredFields, cld, fieldName); } else { LOG.error("Field name '" + fieldName + "' not found for" + " class '" + clsName + "' specified in" + "'index.ignore.fields'"); } } else { LOG.error("Class name specified in 'index.ignore.fields'" + " not found: " + clsName); } } } } else if (key.startsWith("index.references.")) { String classToIndex = key.substring("index.references.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToIndex); if (cld != null) { Class<? extends InterMineObject> cls = (Class<? extends InterMineObject>) cld.getType(); // special fields (references to follow) come as // a // space-separated list String[] specialFields; if (!StringUtils.isBlank(value)) { specialFields = value.split("\\s+"); } else { specialFields = null; } specialReferences.put(cls, specialFields); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToIndex + "' not found!"); } } else if (key.startsWith("index.facet.single.")) { String facetName = key.substring("index.facet.single.".length()); String facetField = value; facets.add( new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.SINGLE)); } else if (key.startsWith("index.facet.multi.")) { String facetName = key.substring("index.facet.multi.".length()); String facetField = value; facets.add(new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.MULTI)); } else if (key.startsWith("index.facet.path.")) { String facetName = key.substring("index.facet.path.".length()); String[] facetFields = value.split(" "); facets.add(new KeywordSearchFacetData(facetFields, facetName, KeywordSearchFacetType.PATH)); } else if (key.startsWith("index.boost.")) { String classToBoost = key.substring("index.boost.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToBoost); if (cld != null) { classBoost.put(cld, Float.valueOf(value)); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToBoost + "' not found!"); } } else if (key.startsWith("index.prefix")) { String classAndAttribute = key.substring("index.prefix.".length()); addAttributePrefix(classAndAttribute, value); } else if ("search.debug".equals(key) && !StringUtils.isBlank(value)) { debugOutput = "1".equals(value) || "true".equals(value.toLowerCase()) || "on".equals(value.toLowerCase()); } else if ("index.solrurl".equals(key) && !StringUtils.isBlank(value)) { solrUrl = value; } else if ("index.batch.size".equals(key) && !StringUtils.isBlank(value)) { indexBatchSize = Integer.parseInt(value); } else if ("index.optimize".equals(key) && !StringUtils.isBlank(value)) { enableOptimize = Boolean.parseBoolean(value); } } } catch (IOException e) { LOG.error("keyword_search.properties: errow while loading file '" + configFileName + "'", e); } } else { LOG.error("keyword_search.properties: file '" + configFileName + "' not found!"); } LOG.debug("Indexing - Ignored classes:"); for (Class<? extends InterMineObject> class1 : ignoredClasses) { LOG.debug("- " + class1.getSimpleName()); } LOG.debug("Indexing - Special References:"); for (Map.Entry<Class<? extends InterMineObject>, String[]> specialReference : specialReferences .entrySet()) { LOG.debug("- " + specialReference.getKey() + " = " + Arrays.toString(specialReference.getValue())); } LOG.debug("Indexing - Facets:"); for (KeywordSearchFacetData facet : facets) { LOG.debug("- field = " + facet.getField() + ", name = " + facet.getName() + ", type = " + facet.getType().toString()); } LOG.debug("Indexing with and without attribute prefixes:"); if (attributePrefixes != null) { for (String clsAndAttribute : attributePrefixes.keySet()) { LOG.debug("- class and attribute: " + clsAndAttribute + " with prefix: " + attributePrefixes.get(clsAndAttribute)); } } LOG.info("Search - Debug mode: " + debugOutput); }
From source file:org.intermine.web.search.ClassAttributes.java
@SuppressWarnings("unchecked") private static synchronized void parseProperties(ObjectStore os) { if (properties != null) { return;//from ww w. j av a2s . co m } specialReferences = new HashMap<Class<? extends InterMineObject>, String[]>(); ignoredClasses = new HashSet<Class<? extends InterMineObject>>(); classBoost = new HashMap<ClassDescriptor, Float>(); ignoredFields = new HashMap<Class<? extends InterMineObject>, Set<String>>(); facets = new Vector<KeywordSearchFacetData>(); debugOutput = true; // load config file to figure out special classes String configFileName = "keyword_search.properties"; ClassLoader classLoader = KeywordSearch.class.getClassLoader(); InputStream configStream = classLoader.getResourceAsStream(configFileName); if (configStream != null) { properties = new Properties(); try { properties.load(configStream); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = ((String) entry.getValue()).trim(); if ("index.ignore".equals(key) && !StringUtils.isBlank(value)) { String[] ignoreClassNames = value.split("\\s+"); for (String className : ignoreClassNames) { ClassDescriptor cld = os.getModel().getClassDescriptorByName(className); if (cld == null) { LOG.error("Unknown class in config file: " + className); } else { addCldToIgnored(ignoredClasses, cld); } } } else if ("index.ignore.fields".equals(key) && !StringUtils.isBlank(value)) { String[] ignoredPaths = value.split("\\s+"); for (String ignoredPath : ignoredPaths) { if (StringUtils.countMatches(ignoredPath, ".") != 1) { LOG.error("Fields to ignore specified by 'index.ignore.fields'" + " should contain Class.field, e.g. Company.name"); } else { String clsName = ignoredPath.split("\\.")[0]; String fieldName = ignoredPath.split("\\.")[1]; ClassDescriptor cld = os.getModel().getClassDescriptorByName(clsName); if (cld != null) { FieldDescriptor fld = cld.getFieldDescriptorByName(fieldName); if (fld != null) { addToIgnoredFields(ignoredFields, cld, fieldName); } else { LOG.error("Field name '" + fieldName + "' not found for" + " class '" + clsName + "' specified in" + "'index.ignore.fields'"); } } else { LOG.error("Class name specified in 'index.ignore.fields'" + " not found: " + clsName); } } } } else if (key.startsWith("index.references.")) { String classToIndex = key.substring("index.references.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToIndex); if (cld != null) { Class<? extends InterMineObject> cls = (Class<? extends InterMineObject>) cld.getType(); // special fields (references to follow) come as // a // space-separated list String[] specialFields; if (!StringUtils.isBlank(value)) { specialFields = value.split("\\s+"); } else { specialFields = null; } specialReferences.put(cls, specialFields); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToIndex + "' not found!"); } } else if (key.startsWith("index.facet.single.")) { String facetName = key.substring("index.facet.single.".length()); String facetField = value; facets.add( new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.SINGLE)); } else if (key.startsWith("index.facet.multi.")) { String facetName = key.substring("index.facet.multi.".length()); String facetField = value; facets.add(new KeywordSearchFacetData(facetField, facetName, KeywordSearchFacetType.MULTI)); } else if (key.startsWith("index.facet.path.")) { String facetName = key.substring("index.facet.path.".length()); String[] facetFields = value.split(" "); facets.add(new KeywordSearchFacetData(facetFields, facetName, KeywordSearchFacetType.PATH)); } else if (key.startsWith("index.boost.")) { String classToBoost = key.substring("index.boost.".length()); ClassDescriptor cld = os.getModel().getClassDescriptorByName(classToBoost); if (cld != null) { classBoost.put(cld, Float.valueOf(value)); } else { LOG.error("keyword_search.properties: classDescriptor for '" + classToBoost + "' not found!"); } } else if (key.startsWith("index.prefix")) { String classAndAttribute = key.substring("index.prefix.".length()); addAttributePrefix(classAndAttribute, value); } else if ("search.debug".equals(key) && !StringUtils.isBlank(value)) { debugOutput = "1".equals(value) || "true".equals(value.toLowerCase()) || "on".equals(value.toLowerCase()); } tempDirectory = properties.getProperty("index.temp.directory", ""); } } catch (IOException e) { LOG.error("keyword_search.properties: errow while loading file '" + configFileName + "'", e); } } else { LOG.error("keyword_search.properties: file '" + configFileName + "' not found!"); } LOG.info("Indexing - Ignored classes:"); for (Class<? extends InterMineObject> class1 : ignoredClasses) { LOG.info("- " + class1.getSimpleName()); } LOG.info("Indexing - Special References:"); for (Entry<Class<? extends InterMineObject>, String[]> specialReference : specialReferences.entrySet()) { LOG.info("- " + specialReference.getKey() + " = " + Arrays.toString(specialReference.getValue())); } LOG.info("Indexing - Facets:"); for (KeywordSearchFacetData facet : facets) { LOG.info("- field = " + facet.getField() + ", name = " + facet.getName() + ", type = " + facet.getType().toString()); } LOG.info("Indexing with and without attribute prefixes:"); if (attributePrefixes != null) { for (String clsAndAttribute : attributePrefixes.keySet()) { LOG.info("- class and attribute: " + clsAndAttribute + " with prefix: " + attributePrefixes.get(clsAndAttribute)); } } LOG.info("Search - Debug mode: " + debugOutput); LOG.info("Indexing - Temp Dir: " + tempDirectory); }
From source file:org.jajuk.util.UpgradeManager.java
/** * Return Jajuk number version = integer format of the padded release * /*w w w . ja v a 2 s .co m*/ * Jajuk version scheme is XX.YY.ZZ[RCn] (two digits possible for each part of the release) * * @param pStringRelease * * @return Jajuk number version = integer format of the padded release */ static int getNumberRelease(String pStringRelease) { if (pStringRelease == null) { // no string provided: use 1.0.0 return 10000; } String stringRelease = pStringRelease; // We drop any RCx part of the release if (pStringRelease.contains("RC")) { stringRelease = pStringRelease.split("RC.*")[0]; } // We drop any "dev" part of the release if (pStringRelease.contains("dev")) { stringRelease = pStringRelease.split("dev.*")[0]; } // Add a trailing .0 if it is a main release like 1.X -> 1.X.0 int countDot = StringUtils.countMatches(stringRelease, "."); if (countDot == 1) { stringRelease = stringRelease + ".0"; } // Analyze each part of the release, throw a runtime exception if // the format is wrong at this point StringTokenizer st = new StringTokenizer(stringRelease, "."); int main = 10000 * Integer.parseInt(st.nextToken()); int minor = 100 * Integer.parseInt(st.nextToken()); int fix = Integer.parseInt(st.nextToken()); return main + minor + fix; }
From source file:org.jalgo.module.am0c0.model.c0.ast.C0AST.java
@Override public int getLinesCount() { String codeText = compressText(getCodeTextInternal()); return StringUtils.countMatches(codeText, "\n") + 1; //$NON-NLS-1$ }
From source file:org.jalgo.module.am0c0.model.c0.trans.TransformFunction.java
@Override public int getLinesCount() { return StringUtils.countMatches(getCodeText(), "\n") + 1; //$NON-NLS-1$ }
From source file:org.jamwiki.db.WikiPreparedStatement.java
/** * *///w w w . ja va 2s . c om public WikiPreparedStatement(String sql) { this.sql = sql; this.numElements = StringUtils.countMatches(sql, "?"); this.params = new Object[numElements]; this.paramTypes = new int[numElements]; }
From source file:org.jamwiki.parser.jflex.JFlexLexer.java
/** * *//*from ww w.ja va 2s. c o m*/ protected void parseParagraphStart(String raw) { int pushback = raw.length(); if (this.mode >= JFlexParser.MODE_LAYOUT) { this.pushTag("p", null); int newlineCount = StringUtils.countMatches(raw, "\n"); if (newlineCount > 0) { pushback = StringUtils.stripStart(raw, " \n\r\t").length(); } if (newlineCount == 2) { // if the pattern matched two opening newlines then start the paragraph with a <br /> tag this.append("<br />\n"); } } yypushback(pushback); }