Search in sources :

Example 51 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class ERXStats method logStatisticsForOperation.

/**
 * Logs the messages since the last call to initStatistics() ordered by some
 * key. Note that no log message is output if there aren't any values
 *
 * @param operation
 *            operation to sort on ("sum", "count", "min", "max", "avg", "key")
 */
public static void logStatisticsForOperation(Logger statsLog, String operation) {
    if (statsLog.isDebugEnabled()) {
        NSMutableDictionary statistics = ERXStats.statistics();
        if (statistics != null) {
            synchronized (statistics) {
                // NSArray values = ERXArrayUtilities.sortedArraySortedWithKey(statistics.allValues(), operation);
                // FIXME: This used to be sorted. Does it matter? Do I care?
                NSArray values = statistics.allValues();
                if (values.count() > 0) {
                    Long startTime = (Long) ERXThreadStorage.valueForKey(ERXStats.STATS_START_TIME_KEY);
                    Long lastTime = (Long) ERXThreadStorage.valueForKey(ERXStats.STATS_LAST_TIME_KEY);
                    long currentTime = System.currentTimeMillis();
                    String result = NSPropertyListSerialization.stringFromPropertyList(values);
                    // result = result.replaceAll("\\n\\t", "\n\t\t");
                    // result = result.replaceAll("\\n", "\n\t\t");
                    statsLog.debug((startTime != null ? "Time since init " + (currentTime - startTime.longValue()) + " ms" : "") + (lastTime != null ? ", last log " + (currentTime - lastTime.longValue()) + " ms" : "") + ", total cnt/sum: " + statistics.allValues().valueForKeyPath("@sum.count") + "/" + statistics.allValues().valueForKeyPath("@sum.sum") + " (cnt/sum : min/max/avg|trace cnt -> key) = " + result);
                    ERXThreadStorage.takeValueForKey(Long.valueOf(currentTime), ERXStats.STATS_LAST_TIME_KEY);
                }
            }
        }
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 52 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WODictionaryRepetition method dictionary.

public NSDictionary dictionary() {
    if (_dictionary == null) {
        _dictionary = (NSDictionary) _WOJExtensionsUtil.valueForBindingOrNull("dictionary", this);
        if (_dictionary == null) {
            _dictionary = NSDictionary.EmptyDictionary;
            _keyList = NSArray.EmptyArray;
        } else {
            _keyList = _dictionary.allKeys();
            _keyList = EOSortOrdering.sortedArrayUsingKeyOrderArray(_keyList, new NSArray<>(new EOSortOrdering("toString", EOSortOrdering.CompareAscending)));
        }
    }
    return _dictionary;
}
Also used : NSArray(com.webobjects.foundation.NSArray) EOSortOrdering(com.webobjects.eocontrol.EOSortOrdering)

Example 53 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WOHelperFunctionDeclarationParser method _associationsForDictionaryString.

private NSMutableDictionary _associationsForDictionaryString(String declarationHeader, String declarationBody) throws WOHelperFunctionDeclarationFormatException {
    NSMutableDictionary associations = new NSMutableDictionary();
    String trimmedDeclarationBody = declarationBody.trim();
    if (!trimmedDeclarationBody.startsWith("{") && !trimmedDeclarationBody.endsWith("}")) {
        throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Internal inconsistency : invalid dictionary for declaration:\n" + declarationHeader + " " + declarationBody);
    }
    int declarationBodyLength = trimmedDeclarationBody.length();
    if (declarationBodyLength <= 2) {
        return associations;
    }
    trimmedDeclarationBody = trimmedDeclarationBody.substring(1, declarationBodyLength - 1).trim();
    NSArray bindings = NSArray.componentsSeparatedByString(trimmedDeclarationBody, ";");
    Enumeration bindingsEnum = bindings.objectEnumerator();
    do {
        if (!bindingsEnum.hasMoreElements()) {
            break;
        }
        String binding = ((String) bindingsEnum.nextElement()).trim();
        if (binding.length() != 0) {
            int equalsIndex = binding.indexOf('=');
            if (equalsIndex < 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Invalid line. No equal in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            String key = binding.substring(0, equalsIndex).trim();
            if (key.length() == 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing binding in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            String value = binding.substring(equalsIndex + 1).trim();
            if (value.length() == 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing value in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            WOAssociation association = WOHelperFunctionDeclarationParser._associationWithKey(value, _quotedStrings);
            Object quotedString = _quotedStrings.objectForKey(key);
            if (quotedString != null) {
                associations.setObjectForKey(association, quotedString);
            } else {
                associations.setObjectForKey(association, key);
            }
        }
    } while (true);
    // }
    return associations;
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

NSArray (com.webobjects.foundation.NSArray)53 Enumeration (java.util.Enumeration)17 NSMutableArray (com.webobjects.foundation.NSMutableArray)13 NSBundle (com.webobjects.foundation.NSBundle)5 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)5 File (java.io.File)4 List (java.util.List)4 WOAssociation (com.webobjects.appserver.WOAssociation)3 WOComponent (com.webobjects.appserver.WOComponent)3 NSDictionary (com.webobjects.foundation.NSDictionary)3 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 WOElement (com.webobjects.appserver.WOElement)2 WOResponse (com.webobjects.appserver.WOResponse)2 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)2 EOEvent (com.webobjects.eocontrol.EOEvent)2 EOSortOrdering (com.webobjects.eocontrol.EOSortOrdering)2 NSForwardException (com.webobjects.foundation.NSForwardException)2 NSKeyValueCoding (com.webobjects.foundation.NSKeyValueCoding)2