Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

In this page you can find the example usage for java.util SortedMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.orange.clara.cloud.poc.s3.upload.UploadS3StreamImpl.java

private void prepareUploadPart(String container, String key, String uploadId, int numPart, Payload chunkedPart,
        SortedMap<Integer, String> etags) {
    String eTag = null;/* w ww . j av a2s.  c  o  m*/
    try {
        eTag = s3Client.uploadPart(container, key, numPart, uploadId, chunkedPart);
        etags.put(Integer.valueOf(numPart), eTag);
    } catch (KeyNotFoundException e) {
        // note that because of eventual consistency, the upload id may not be
        // present yet we may wish to add this condition to the retry handler

        // we may also choose to implement ListParts and wait for the uploadId
        // to become available there.
        eTag = s3Client.uploadPart(container, key, numPart, uploadId, chunkedPart);
        etags.put(Integer.valueOf(numPart), eTag);
    }
}

From source file:org.broadleafcommerce.vendor.authorizenet.web.processor.AuthorizeNetTRExtensionHandler.java

@Override
public void populateFormParameters(Map<String, Map<String, String>> formParameters,
        PaymentResponseDTO responseDTO) {
    String actionUrl = (String) responseDTO.getResponseMap().get(MessageConstants.AUTHORIZENET_SERVER_URL);
    responseDTO.getResponseMap().remove(MessageConstants.AUTHORIZENET_SERVER_URL);

    Map<String, String> actionValue = new HashMap<String, String>();
    actionValue.put(getFormActionURLKey(), actionUrl);
    formParameters.put(getFormActionURLKey(), actionValue);

    Iterator<?> it = responseDTO.getResponseMap().entrySet().iterator();

    SortedMap<String, String> hiddenFields = new TreeMap<String, String>();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        hiddenFields.put((String) pairs.getKey(), (String) pairs.getValue());
    }/*ww  w.  ja  v a2  s . co  m*/

    formParameters.put(getHiddenParamsKey(), hiddenFields);
}

From source file:com.bdaum.juploadr.uploadapi.smugrest.upload.SmugmugUpload.java

@Override
public SortedMap<String, String> getParams() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("X-Smug-SessionID", session.getSessionId()); //$NON-NLS-1$
    map.put("X-Smug-Version", "1.2.0"); //$NON-NLS-1$  //$NON-NLS-2$
    map.put("X-Smug-ResponseType", "REST"); //$NON-NLS-1$ //$NON-NLS-2$
    PhotoSet album = session.matchAlbum(image);
    if (replace)//from w  w w  .j av a  2 s. co m
        map.put("X-Smug-ImageID", image.getPhotoId()); //$NON-NLS-1$
    else
        map.put("X-Smug-AlbumID", album.getId()); //$NON-NLS-1$
    Asset asset = image.getAsset();
    map.put(X_SMUG_FILE_NAME, Core.getFileName(asset.getUri(), true));
    map.put("X-Smug-Caption", image.getTitle()); //$NON-NLS-1$
    String keywords = ((ImageUploadApi) session.getApi()).getTagParser().toRequestString(image.getTags());
    map.put("X-Smug-Keywords", keywords); //$NON-NLS-1$
    double gpsLatitude = asset.getGPSLatitude();
    if (!Double.isNaN(gpsLatitude))
        map.put("X-Smug-Latitude", String.valueOf(gpsLatitude)); //$NON-NLS-1$
    double gpsLongitude = asset.getGPSLongitude();
    if (!Double.isNaN(gpsLongitude))
        map.put("X-Smug-Longitude", String.valueOf(gpsLongitude)); //$NON-NLS-1$
    double gpsAltitude = asset.getGPSAltitude();
    if (!Double.isNaN(gpsAltitude))
        map.put("X-Smug-Altitude", String.valueOf(gpsAltitude)); //$NON-NLS-1$
    if (asset.getSafety() == QueryField.SAFETY_RESTRICTED)
        map.put("X-Smug-Hidden", "1"); //$NON-NLS-1$ //$NON-NLS-2$
    return map;
}

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

/**
 * Load cookies. The input is text in the Netscape's 'cookies.txt' file
 * format. Example entry of cookies.txt file:
 * <p>/*from w  ww  . j  a  va 2 s .  c  o m*/
 * www.archive.org FALSE / FALSE 1311699995 details-visit texts-cralond
 * </p>
 * <p>
 * Each line has 7 tab-separated fields:
 * </p>
 * <ol>
 * <li>DOMAIN: The domain that created and have access to the cookie value.</li>
 * <li>FLAG: A TRUE or FALSE value indicating if hosts within the given
 * domain can access the cookie value.</li>
 * <li>PATH: The path within the domain that the cookie value is valid for.</li>
 * <li>SECURE: A TRUE or FALSE value indicating if to use a secure
 * connection to access the cookie value.</li>
 * <li>EXPIRATION: The expiration time of the cookie value, or -1 for no
 * expiration</li>
 * <li>NAME: The name of the cookie value</li>
 * <li>VALUE: The cookie value</li>
 * </ol>
 * 
 * @param reader
 *            input
 * @param cookiesFile
 *            file in the Netscape's 'cookies.txt' format.
 */
public static void loadCookies(Reader reader, SortedMap<String, Cookie> cookies) {
    BufferedReader br = new BufferedReader(reader);
    try {
        String line;
        int lineNo = 1;
        while ((line = br.readLine()) != null) {
            if (!line.matches("\\s*(?:#.*)?")) { // skip blank links and comments
                String[] tokens = line.split("\\t");
                if (tokens.length == 7) {
                    long epochSeconds = Long.parseLong(tokens[4]);
                    Date expirationDate = (epochSeconds >= 0 ? new Date(epochSeconds * 1000) : null);
                    Cookie cookie = new Cookie(tokens[0], tokens[5], tokens[6], tokens[2], expirationDate,
                            Boolean.valueOf(tokens[3]).booleanValue());
                    cookie.setDomainAttributeSpecified(Boolean.valueOf(tokens[1]).booleanValue());

                    LOGGER.fine("Adding cookie: domain " + cookie.getDomain() + " cookie "
                            + cookie.toExternalForm());
                    cookies.put(cookie.getSortKey(), cookie);
                } else {
                    LOGGER.warning(
                            "cookies input line " + lineNo + " invalid, expected 7 tab-delimited tokens");
                }
            }

            lineNo++;
        }
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, e.getMessage(), e);
    }
}

From source file:com.erinors.hpb.server.handler.SortedMapHandler.java

@Override
public Object clone(CloningContext context, Object object) {
    if (!(object instanceof SortedMap)) {
        return null;
    }/*from   www.j  av a 2  s .co  m*/

    SortedMap<Object, Object> source = (SortedMap<Object, Object>) object;
    SortedMap<Object, Object> result;

    if (source instanceof PersistentSortedMap && !((PersistentSortedMap) source).wasInitialized()) {
        result = new UninitializedPersistentSortedMap<Object, Object>(source.comparator());
        context.addProcessedObject(object, result);
    } else {
        SortedMap<Object, Object> map = new TreeMap<Object, Object>(source.comparator());
        context.addProcessedObject(object, map);

        for (Map.Entry<?, ?> entry : source.entrySet()) {
            map.put(context.clone(entry.getKey()), context.clone(entry.getValue()));
        }

        result = map;
    }

    return result;
}

From source file:com.erinors.hpb.server.handler.SortedMapHandler.java

@Override
public Object merge(MergingContext context, Object object) {
    if (!(object instanceof SortedMap)) {
        return null;
    }//from  w ww  .  jav a 2s  .co m

    SortedMap<Object, Object> source = (SortedMap<Object, Object>) object;
    SortedMap<Object, Object> result;

    if (source instanceof UninitializedPersistentSortedMap) {
        result = new PersistentSortedMap(context.getSessionImplementor(), source);
        context.addProcessedObject(object, result);
    } else {
        SortedMap<Object, Object> map = new TreeMap<Object, Object>(source.comparator());
        context.addProcessedObject(object, map);

        for (Map.Entry<?, ?> entry : source.entrySet()) {
            map.put(context.merge(entry.getKey()), context.merge(entry.getValue()));
        }

        result = map;
    }

    return result;
}

From source file:com.ebuddy.cassandra.cql.dao.CqlStructuredDataSupportSystemTest.java

@SuppressWarnings("unchecked")
@Test(groups = { "system" })
public void convertValueShouldRetainOrderingInMaps() throws Exception {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("b", "1");
    map.put("a", "2");

    ObjectMapper mapper = new ObjectMapper();
    mapper.setDefaultTyping(new CustomTypeResolverBuilder());
    Object converted = mapper.convertValue(map, Object.class);
    assertTrue(converted instanceof LinkedHashMap);
    // keys are sorted by Cassandra as UTF8
    assertEquals(((Map<String, String>) converted).keySet().iterator().next(), "a");
}

From source file:com.github.fauu.natrank.service.MatchServiceImpl.java

@Override
public Map<NotableMatchCategory, List<Match>> findNotableMatchesByTeamName(String name)
        throws DataAccessException {
    List<NotableMatch> notableMatches = notableMatchRepository.findByTeam(teamRepository.findByName(name));
    List<NotableMatchCategory> notableMatchCategories = notableMatchCategoryRepository.findAll();
    SortedMap<NotableMatchCategory, List<Match>> notableMatchMap = new TreeMap<>();

    for (NotableMatchCategory category : notableMatchCategories) {
        notableMatchMap.put(category, new LinkedList<Match>());
    }//from  w  w w  .  j a v  a 2  s  .  c om

    for (NotableMatch notableMatch : notableMatches) {
        notableMatchMap.get(notableMatch.getCategory()).add(notableMatch.getMatch());
    }

    return notableMatchMap;
}

From source file:gov.nih.nci.caarray.magetab.splitter.SdrfSplitterTest.java

private void testComments(int[] positions, String[] comments) throws IOException {
    SortedMap<Integer, String> linesToAdd = new TreeMap<Integer, String>();
    for (int i = 0; i < positions.length; ++i) {
        linesToAdd.put(positions[i], comments[i]);
    }/* w  ww .  j  ava 2  s.  c om*/

    Function<File, File> transform = getTransform(linesToAdd);
    specificationSdrfWithTransform(transform);
}

From source file:org.shept.util.FileUtils.java

/**
 * List the file directory as specified by the name filter and path directory
 * The maps keys contain the parsed date from the filename.
 * The filename can be something like Backup_db_2008_12_01_1350.xyz
 * The first part is may begin with any character, the first number found
 * is treated as year followed by month followed by day.
 * All characters are separated by "_" (underscores).
 * The last 4-letter number represents hours & minutes
 * //from   w w  w  .  jav a2s.  co m
 * @param path
 * @param filePattern
 * @return
 */
public static SortedMap<Calendar, File> fileMapByFilenameDate(String path, String filePattern) {
    FileUtils fu = new FileUtils(); // needed for inner class
    SortedMap<Calendar, File> newFileMap = new TreeMap<Calendar, File>();
    File fileDir = new File(path);
    if (null != path && fileDir.isDirectory()) {
        FileFilter filter = fu.new Filter(path, filePattern);
        File[] files = fileDir.listFiles(filter);
        for (int i = 0; i < files.length; i++) {
            Calendar cal = Calendar.getInstance();
            String[] split = files[i].getName().split("_");
            int j = 0;
            // looking for the first digit
            while (!Character.isDigit(split[j].charAt(0))) {
                j++;
            }
            try {
                cal.set(Calendar.YEAR, Integer.valueOf(split[j++]));
                cal.set(Calendar.MONTH, Integer.valueOf(split[j++]) - 1);
                cal.set(Calendar.DAY_OF_MONTH, Integer.valueOf(split[j++]));
                cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[j].substring(0, 2)));
                cal.set(Calendar.MINUTE, Integer.valueOf(split[j].substring(2, 4)));
                newFileMap.put(cal, files[i]);
            } catch (Throwable t) {
                // if format doesn't fit ignore the file
            }
        }
    }
    return newFileMap;
}