Example usage for java.util Map values

List of usage examples for java.util Map values

Introduction

In this page you can find the example usage for java.util Map values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:org.archive.modules.fetcher.AbstractCookieStorage.java

public static void saveCookies(String saveCookiesFile, Map<String, Cookie> cookies) {
    // Do nothing if cookiesFile is not specified. 
    if (saveCookiesFile == null || saveCookiesFile.length() <= 0) {
        return;/*from  w  ww  . j  a v  a 2s.  c o m*/
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(saveCookiesFile));
        String tab = "\t";
        out.write("# Heritrix Cookie File\n".getBytes());
        out.write("# This file is the Netscape cookies.txt format\n\n".getBytes());
        for (Cookie cookie : cookies.values()) {
            // Guess an initial size 
            MutableString line = new MutableString(1024 * 2);
            line.append(cookie.getDomain());
            line.append(tab);
            line.append(cookie.isDomainAttributeSpecified() ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getPath());
            line.append(tab);
            line.append(cookie.getSecure() ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getExpiryDate() != null ? cookie.getExpiryDate().getTime() / 1000 : -1);
            line.append(tab);
            line.append(cookie.getName());
            line.append(tab);
            line.append(cookie.getValue() != null ? cookie.getValue() : "");
            line.append("\n");
            out.write(line.toString().getBytes());
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to write " + saveCookiesFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.egt.ejb.toolkit.ToolKitUtils.java

public static Collection sortIncludedFieldsMap(Map map) {
    List<ClaseRecursoPar> list = new ArrayList<>(map.values());
    return ColUtils.sort(list, includedFieldsComparator());
}

From source file:org.thoughtland.xlocation.Util.java

public static Activity getActivity() {
    // public static ActivityManagerService self()
    // frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
    Object activity = null;/*w w  w.j  av  a  2s.c om*/
    try {
        Class<?> atClazz = Class.forName("android.app.ActivityThread");
        Object activityThread = atClazz.getMethod("currentActivityThread").invoke(null);
        Field fActivities = atClazz.getDeclaredField("mActivities");
        fActivities.setAccessible(true);
        Map<?, ?> activities = (Map<?, ?>) fActivities.get(activityThread);
        Object acr = activities.values().toArray()[0];
        Field fActivity = acr.getClass().getDeclaredField("activity");
        fActivity.setAccessible(true);
        activity = fActivity.get(acr);
    } catch (Throwable e) {
    }
    return (Activity) activity;
}

From source file:de.escalon.hypermedia.spring.uber.UberUtils.java

/**
 * Renders input fields for bean properties of bean to add or update or patch.
 *
 * @param uberFields//from www.  j  a v  a  2 s. c o  m
 *         to add to
 * @param beanType
 *         to render
 * @param annotatedParameters
 *         which describes the method
 * @param annotatedParameter
 *         which requires the bean
 * @param currentCallValue
 *         sample call value
 */
private static void recurseBeanCreationParams(List<UberField> uberFields, Class<?> beanType,
        ActionDescriptor annotatedParameters, ActionInputParameter annotatedParameter, Object currentCallValue,
        String parentParamName, Set<String> knownFields) {
    // TODO collection, map and object node creation are only describable by an annotation, not via type reflection
    if (ObjectNode.class.isAssignableFrom(beanType) || Map.class.isAssignableFrom(beanType)
            || Collection.class.isAssignableFrom(beanType) || beanType.isArray()) {
        return; // use @Input(include) to list parameter names, at least? Or mix with hdiv's form builder?
    }
    try {
        Constructor[] constructors = beanType.getConstructors();
        // find default ctor
        Constructor constructor = PropertyUtils.findDefaultCtor(constructors);
        // find ctor with JsonCreator ann
        if (constructor == null) {
            constructor = PropertyUtils.findJsonCreator(constructors, JsonCreator.class);
        }
        Assert.notNull(constructor,
                "no default constructor or JsonCreator found for type " + beanType.getName());
        int parameterCount = constructor.getParameterTypes().length;

        if (parameterCount > 0) {
            Annotation[][] annotationsOnParameters = constructor.getParameterAnnotations();

            Class[] parameters = constructor.getParameterTypes();
            int paramIndex = 0;
            for (Annotation[] annotationsOnParameter : annotationsOnParameters) {
                for (Annotation annotation : annotationsOnParameter) {
                    if (JsonProperty.class == annotation.annotationType()) {
                        JsonProperty jsonProperty = (JsonProperty) annotation;

                        // TODO use required attribute of JsonProperty for required fields
                        String paramName = jsonProperty.value();
                        Class parameterType = parameters[paramIndex];
                        Object propertyValue = PropertyUtils.getPropertyOrFieldValue(currentCallValue,
                                paramName);
                        MethodParameter methodParameter = new MethodParameter(constructor, paramIndex);

                        addUberFieldsForMethodParameter(uberFields, methodParameter, annotatedParameter,
                                annotatedParameters, parentParamName, paramName, parameterType, propertyValue,
                                knownFields);
                        paramIndex++; // increase for each @JsonProperty
                    }
                }
            }
            Assert.isTrue(parameters.length == paramIndex, "not all constructor arguments of @JsonCreator "
                    + constructor.getName() + " are annotated with @JsonProperty");
        }

        Set<String> knownConstructorFields = new HashSet<String>(uberFields.size());
        for (UberField sirenField : uberFields) {
            knownConstructorFields.add(sirenField.getName());
        }

        // TODO support Option provider by other method args?
        Map<String, PropertyDescriptor> propertyDescriptors = PropertyUtils.getPropertyDescriptors(beanType);

        // add input field for every setter
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors.values()) {
            final Method writeMethod = propertyDescriptor.getWriteMethod();
            String propertyName = propertyDescriptor.getName();

            if (writeMethod == null || knownFields.contains(parentParamName + propertyName)) {
                continue;
            }
            final Class<?> propertyType = propertyDescriptor.getPropertyType();

            Object propertyValue = PropertyUtils.getPropertyOrFieldValue(currentCallValue, propertyName);
            MethodParameter methodParameter = new MethodParameter(propertyDescriptor.getWriteMethod(), 0);

            addUberFieldsForMethodParameter(uberFields, methodParameter, annotatedParameter,
                    annotatedParameters, parentParamName, propertyName, propertyType, propertyValue,
                    knownConstructorFields);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to write input fields for constructor", e);
    }
}

From source file:de.fhg.igd.mapviewer.server.wms.capabilities.WMSUtil.java

/**
 * Get the preferred bounding box//from   w  w w  . j  ava  2s . c  o m
 * 
 * @param capabilities the WMS capabilities
 * @param preferredEpsg the preferred EPSG code
 * @return the preferred bounding box, an available bounding box or
 *         <code>null</code>
 */
private static WMSBounds getPreferredBoundingBox(WMSCapabilities capabilities, int preferredEpsg) {
    // get bounding boxes
    Map<String, WMSBounds> bbs = capabilities.getBoundingBoxes();

    WMSBounds bb = null;

    if (!bbs.isEmpty()) {
        // bounding box present
        if (preferredEpsg != 0) {
            bb = bbs.get("EPSG:" + preferredEpsg); //$NON-NLS-1$
        }

        if (bb != null) {
            // log.info("Found bounding box for preferred srs");
            // //$NON-NLS-1$
        } else {
            Iterator<WMSBounds> itBB = bbs.values().iterator();

            while (bb == null && itBB.hasNext()) {
                WMSBounds temp = itBB.next();

                if (temp.getSRS().startsWith("EPSG:") //$NON-NLS-1$
                ) {// &&
                   // capabilities.getSupportedSRS().contains(temp.getSRS()))
                   // {
                    bb = temp;
                    // log.info("Found epsg bounding box"); //$NON-NLS-1$
                }
            }
        }
    }
    return bb;
}

From source file:com.bitbreeds.webrtc.stun.StunMessage.java

/**
 * @param type          {@link StunRequestTypeEnum}
 * @param cookie        see rfc5389// w ww. j a  v  a  2  s.  c  om
 * @param transactionId see rfc5389
 * @param attr          {@Link StunAttributeTypeEnum}
 * @return StunMessage to operate on.
 */
public static StunMessage fromData(StunRequestTypeEnum type, byte[] cookie, byte[] transactionId,
        Map<StunAttributeTypeEnum, StunAttribute> attr, boolean withIntegrity, boolean withFingerprint,
        String username, String password) {

    //attr.add(new StunAttribute(StunAttributeTypeEnum.PASSWORD, password.getBytes()));

    attr.remove(StunAttributeTypeEnum.MESSAGE_INTEGRITY);
    attr.remove(StunAttributeTypeEnum.FINGERPRINT);
    attr.remove(StunAttributeTypeEnum.ICE_CONTROLLING);
    attr.remove(StunAttributeTypeEnum.USE_CANDIDATE);
    attr.remove(StunAttributeTypeEnum.PRIORITY);
    attr.remove(StunAttributeTypeEnum.USERNAME);

    int lgt = attr.values().stream().map(i -> SignalUtil.multipleOfFour(4 + i.getLength())) //Lengths to multiple of 4 + 4 for lgt and type
            .reduce(0, Integer::sum); //Sum integers

    return new StunMessage(new StunHeader(type, lgt, cookie, transactionId), attr, withIntegrity,
            withFingerprint, username, password);
}

From source file:com.jsmartdb.framework.manager.EntityWhere.java

public static void getCustomWhere(Class<?> entityClazz, Field[] fields, QueryParam param) {

    String customWhere = EntityContext.getWhereBuilder().toString();
    Map<Integer, Object> paramValues = new TreeMap<Integer, Object>();

    for (String key : param.getFilterParamKeys()) {
        int index = 0;
        for (int i = 0; i < StringUtils.countMatches(customWhere, key); i++) {
            index = customWhere.indexOf(key, index);
            paramValues.put(index, param.get(key));
        }// www  .ja v  a 2 s .  c om
    }

    EntityContext.addAllBuilderValue(paramValues.values());

    for (String key : param.getFilterParamKeys()) {
        customWhere = customWhere.replaceAll(key, " ? ");
    }

    String[] matches = customWhere.split(" ");
    Map<String, String> queryMap = new HashMap<String, String>();

    for (String match : matches) {
        if (match.trim().isEmpty()) {
            continue;
        }
        Matcher matcher = EntitySelect.SQL_FUNCTION_PATTERN.matcher(match);
        if (matcher.find()) {
            match = matcher.group();
            match = match.replace("(", "").replace(")", "");
        }

        String value = EntityAlias.getMatchColumn(entityClazz, fields, match, EntityAlias.getAlias(entityClazz),
                EntityContext.getJoinBuilder());
        if (value != null) {
            queryMap.put(match, value);
        }
    }

    for (String key : queryMap.keySet()) {
        customWhere = customWhere.replace(key, queryMap.get(key));
    }

    EntityContext.getWhereBuilder().replace(0, EntityContext.getWhereBuilder().length(), customWhere);

    if (EntityContext.getWhereBuilder().length() <= WHERE_STATEMENT.length()) {
        EntityContext.getWhereBuilder().replace(
                EntityContext.getWhereBuilder().length() - WHERE_STATEMENT.length(),
                EntityContext.getWhereBuilder().length(), "");
    }
}

From source file:eu.europeana.corelib.search.utils.SearchUtils.java

/**
 * The QueryFacets are in this form://from  w w w.j  a  va2s.  c om
 * {!id=REUSABILITY:Limited}RIGHTS:(http\:\
 * /\/creativecommons.org\/licenses\/by-nc\/* OR
 * http\:\/\/creativecommons.org\/licenses\/by-nc-sa\/* OR
 * http\:\/\/creativecommons.org\/licenses\/by-nc-nd\/* OR
 * http\:\/\/creativecommons.org\/licenses\/by-nd\/* OR
 * http\:\/\/www.europeana.eu\/rights\/out-of-copyright-non-commercial\/*)
 *
 * this function creates a hierarchy: REUSABILITY Limited: x Free: y ...
 *
 * @param queryFacets
 * @return
 */
public static List<FacetField> extractQueryFacets(Map<String, Integer> queryFacets) {
    Map<String, FacetField> map = new HashMap<>();
    for (String query : queryFacets.keySet()) {
        Matcher matcher = ID_PATTERN.matcher(query);
        if (!matcher.find()) {
            continue;
        }
        String field = matcher.group(1);
        String value = matcher.group(2);
        if (!map.containsKey(field)) {
            map.put(field, new FacetField(field));
        }
        map.get(field).add(value, queryFacets.get(query));
    }
    return new ArrayList<>(map.values());
}

From source file:com.acc.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(/*from  w w  w  . j a v a 2  s  .c o m*/
            new ClassPathResource("/bncfulfilmentprocess/test/bncfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;
    processService = null;
}

From source file:com.exxonmobile.ace.hybris.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
            "/exxonmobilfulfilmentprocess/test/exxonmobilfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;//ww  w .ja  v  a 2  s .c  o m
    processService = null;
}