public String getTime() { return StringUtil.convertTime(endTime - startTime); }
private int[] getDimFromString(String str) { str = str.trim(); if(str.startsWith("[") && str.endsWith("]")) { str = str.substring(1, str.length()-1); // remove [ and ] } String [] dimAsString = StringUtil.split(str, ","); int[] result = new int[dimAsString.length]; int i = 0; for (String dim : dimAsString) { int val = Integer.parseInt(dim.trim()); result[i++] = val; } return result; }
protected static Properties addTopiaPersistenceClassesToProperties(Properties topiaProperties, Set<Class<?>> implementationClasses) { StringUtil.ToString<Class<?>> classToString = new StringUtil.ToString<Class<?>>() { @Override public String toString(Class<?> aClass) { return aClass.getName(); } }; topiaProperties.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, StringUtil.join(implementationClasses, classToString, ", ", true)); return topiaProperties; }
protected void statAdd(int asked, int missed) { this.asked += asked; this.missed += missed; if(log.isDebugEnabled()) { String total = StringUtil.convertMemory(Runtime.getRuntime().totalMemory()); String free = StringUtil.convertMemory(Runtime.getRuntime().freeMemory()); String msg = String.format("cache stat (missed/asked): %s/%s (memory %s/%s [total/free])", this.missed, this.asked, total, free); log.debug(msg); } }
/** * Get sha1 encoding for string list * * @param values * @return */ public static String getSHA1Hash(String... values) { StringBuilder builder = new StringBuilder(); for (String value : values) { builder.append(value); } return StringUtil.encodeSHA1(builder.toString()); }
String localMd5 = StringUtil.asHex(MD5InputStream.hash(new BufferedInputStream(new FileInputStream(localFile)))); if (!localMd5.equals(md5sum)) { if (log.isWarnEnabled()) {
@Override public String getStat() { long mean = totalCached / Math.max(1, numberCached); long stepMean = totalStepCached / Math.max(1, numberStepCached); double variance = M2/Math.max(1, numberCached - 1); double stepVariance = stepM2/Math.max(1, numberStepCached - 1); double standardDeviation = Math.sqrt(variance); double stepStandardDeviation = Math.sqrt(stepVariance); String trick = ""; if (sizeCache < biggestStepCached) { trick = String.format( "TRICK: for better performance you must set memory at least to %s\n", StringUtil.convertMemory(biggestStepCached + 500 * 1024 *1024)); } String result = String.format("%s - \n%s" + "\tmaxMemory: %s, cacheMemory: %s, totalCached: %s, numberStep: %s, numberEntries: %s\n" + "\tStep min: %s, max: %s, mean: %s, standard deviation: %s\n" + "\tEntry min: %s, max: %s, mean: %s, standard deviation: %s\n", trick, getClass().getSimpleName(), StringUtil.convertMemory(maxMemory), StringUtil.convertMemory(sizeCache), StringUtil.convertMemory(totalCached), numberStepCached, numberCached, StringUtil.convertMemory(smallestStepCached), StringUtil.convertMemory(biggestStepCached), StringUtil.convertMemory(stepMean), StringUtil.convertMemory((long)stepStandardDeviation), StringUtil.convertMemory(smallestCached), StringUtil.convertMemory(biggestCached), StringUtil.convertMemory(mean), StringUtil.convertMemory((long)standardDeviation) ); return result; }
private String[] getDimNamesFromString(String str) { str = str.trim(); if(str.startsWith("[") && str.endsWith("]")) { str = str.substring(1, str.length()-1); // remove [ and ] } String [] result = StringUtil.split(str, ","); for (int i=0; i<result.length; i++) { result[i] = result[i].trim(); if(result[i].startsWith("\"") && result[i].endsWith("\"")) { result[i] = result[i].substring(1, result[i].length()-1); // remove " and " } } return result; }
protected void printReportLine2(StringBuilder buffer, String reportPattern, String label, long firstPassCounter, long secondPassCounter, long cssCounter, long finalizeCounter, long generatorCounter, long totalCounter) { buffer.append(String.format(reportPattern, label, StringUtil.convertTime(firstPassCounter), StringUtil.convertTime(secondPassCounter), StringUtil.convertTime(cssCounter), StringUtil.convertTime(finalizeCounter), StringUtil.convertTime(generatorCounter), StringUtil.convertTime(totalCounter)) ); }
protected static Properties addTopiaPersistenceClassesToProperties(Properties topiaProperties, Set<Class<?>> implementationClasses) { StringUtil.ToString<Class<?>> classToString = new StringUtil.ToString<Class<?>>() { @Override public String toString(Class<?> aClass) { return aClass.getName(); } }; topiaProperties.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, StringUtil.join(implementationClasses, classToString, ", ", true)); return topiaProperties; }
/** * resizes the cache if amount is not greater than autorized maxCache * @param amount new size of cache in byte */ public void adjustedCache(long amount){ if (amount == 0) { log.info("Cache size not ajusted because 0 is not acceptable amount"); } else { // on estime le nombre d'entree necessaire pour ce volume de donnees long bytePerStep = totalCached / Math.max(1, numberStepCached); long entriesPerStep = numberCached / Math.max(1, numberStepCached); long initialCapacity = amount * entriesPerStep / Math.max(1, bytePerStep); long stepEquivalent = initialCapacity / Math.max(1, entriesPerStep); // use amount as new size for cache // if this new size is less than maxCache, use it // to keep more memory for JVM sizeCache = Math.min(this.maxCache, amount); CacheBuilder builder = CacheBuilder.newBuilder(); builder.maximumWeight(sizeCache); builder.weigher(isisWeigher); if (initialCapacity > 0) { builder.initialCapacity((int)initialCapacity); } cache = builder.build(); log.info(String.format("Cache size ajusted to %s (equivalent to %s step need)", StringUtil.convertMemory(sizeCache), stepEquivalent)); } }
/** * String to matrix dim. * * @param str string to parse * @return dim array */ public int[] getDimFromString(String str) { String localStr = str.trim(); if (localStr.startsWith("[") && localStr.endsWith("]")) { localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ] } String[] dimAsString = StringUtil.split(localStr, ","); int[] result = new int[dimAsString.length]; int i = 0; for (String dim : dimAsString) { int val = Integer.parseInt(dim.trim()); result[i++] = val; } return result; }
StringUtil.convertTime(firstPassCounter), (int) percentCFP ); String strCSP = String.format(TIME_PATTERN, StringUtil.convertTime(secondPassCounter), (int) percentCSP ); String strCSSP = String.format(TIME_PATTERN, StringUtil.convertTime(cssCounter), (int) percentCSSP ); String strFP = String.format(TIME_PATTERN, StringUtil.convertTime(finalizeCounter), (int) percentFP ); String strGP = String.format(TIME_PATTERN, StringUtil.convertTime(generatorCounter), (int) percentGP ); strFP, strGP, StringUtil.convertTime(totalCounter)) );
public String getXsls() { String xslAsString = StringUtil.join(getXslFileList(), new StringUtil.ToString<File>() { @Override public String toString(File file) { return file.getAbsolutePath(); } }, ",", true); return xslAsString; }
/** * @return les resultats par defaut d'une simulation sous forme de liste * a partir de la propriete {@link Option#DEFAULT_RESULT_NAMES} * @see Option#DEFAULT_RESULT_NAMES */ public List<String> getDefaultResultNamesAsList() { List<String> result = null; String resultNamesList = getDefaultResultNames(); if (resultNamesList != null) { result = new ArrayList<String>(); String[] resultNames = StringUtil.split(resultNamesList, ","); result.addAll(Arrays.asList(resultNames)); } return result; }
protected UIProvider[] detectProviders() { long t0 = System.nanoTime(); List<UIProvider> providers = new ArrayList<UIProvider>(); for (UIProvider provider : ServiceLoader.load(UIProvider.class)) { if (applicationName.equals(provider.getApplicationName())) { if (log.isDebugEnabled()) { log.debug("provider detected [" + provider + ']'); } providers.add(provider); } } log.info("found " + providers.size() + " ui provider(s) in " + StringUtil.convertTime(t0, System.nanoTime()) + " : " + providers); return providers.toArray(new UIProvider[providers.size()]); }
/** * @return le dictionnaire des tags par defaut d'une simulation a partir * de la propriete {@link Option#DEFAULT_TAG_VALUE} * @see Option#DEFAULT_TAG_VALUE */ public Map<String, String> getDefaultTagValueAsMap() { Map<String, String> result = new HashMap<String, String>(); String tagValuesList = getDefaultTagValue(); if (tagValuesList != null) { String[] tagValues = StringUtil.split(tagValuesList, ","); for (String tagValue : tagValues) { String[] tagAndValue = StringUtil.split(tagValue, ":"); String tag = tagAndValue[0].trim(); tag = tag.substring(1, tag.length() - 1); // remove "..." String value = tagAndValue[1].trim(); value = value.substring(1, value.length() - 1); // remove "..." result.put(tag, value); } } return result; }
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { TreePath path = tree.getPathForRow(row); if (path == null) { return delegate; } if (value != null) { long t0 = System.nanoTime(); NodeRenderer renderer = getNodeRenderer(value); long t1 = System.nanoTime(); if (renderer != null) { value = renderer.toString(context); long t2 = System.nanoTime(); if (log.isDebugEnabled()) { log.debug("use renderer [" + (t++) + "]<" + row + ">" + renderer.decorator + " <" + StringUtil.convertTime(t0, t1) + "/" + StringUtil.convertTime(t1, t2) + ">"); } } } return delegate.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); }
/** * String to semantics. * * @param str la chaine representant la semantique * @return semantics list */ public List<?>[] getSemanticsFromString(String str) { String localStr = str.trim(); if (localStr.startsWith("[") && localStr.endsWith("]")) { localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ] } String[] sems = StringUtil.split(localStr, ","); List<?>[] result = new List<?>[sems.length]; for (int i = 0; i < sems.length; i++) { result[i] = splitObjects(sems[i]); } return result; }
public UIFactory(String applicationName, DialogUIDef<?,?,?>[] defs, FactoryWindowListener... listeners) { this.applicationName = applicationName; this.listeners = new EventListenerList(); for (FactoryWindowListener listener : listeners) { listener.setFactory(this); addFactoryWindowListener(listener); } this.defs = defs; long t0 = System.nanoTime(); if (log.isDebugEnabled()) { log.debug("start at " + new java.util.Date()); } try { init(); } catch (Exception e) { log.error(e); throw new RuntimeException(e); } finally { if (log.isDebugEnabled()) { log.info("end in " + StringUtil.convertTime(t0, System.nanoTime())); } } }