Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.pindroid.client.PinboardApi.java

/**
 * Sends a request to Pinboard's Add Bookmark api.
 * /*from www. ja  v  a  2  s .  co m*/
 * @param bookmark The bookmark to be added.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A boolean indicating whether or not the api call was successful.
 * @throws IOException If an IO error was encountered.
 * @throws TooManyRequestsException 
 * @throws AuthenticationException If an authentication error was encountered.
 * @throws PinboardException If a server error is encountered.
 * @throws ParseException 
 * @throws Exception If an unknown error is encountered.
 */
public static Boolean addBookmark(Bookmark bookmark, Account account, Context context) throws IOException,
        AuthenticationException, TooManyRequestsException, PinboardException, ParseException {

    String url = bookmark.getUrl();
    if (url.endsWith("/")) {
        url = url.substring(0, url.lastIndexOf('/'));
    }

    TreeMap<String, String> params = new TreeMap<String, String>();

    params.put("description", bookmark.getDescription());
    params.put("extended", bookmark.getNotes());
    params.put("tags", bookmark.getTagString());
    params.put("url", bookmark.getUrl());

    if (bookmark.getShared()) {
        params.put("shared", "yes");
    } else
        params.put("shared", "no");

    if (bookmark.getToRead()) {
        params.put("toread", "yes");
    }

    String uri = ADD_BOOKMARKS_URI;
    InputStream responseStream = null;

    responseStream = PinboardApiCall(uri, params, account, context);

    SaxResultParser parser = new SaxResultParser(responseStream);
    PinboardApiResult result = parser.parse();
    responseStream.close();

    if (result.getCode().equalsIgnoreCase("done")) {
        return true;
    } else if (result.getCode().equalsIgnoreCase("something went wrong")) {
        Log.e(TAG, "Pinboard server error in adding bookmark");
        throw new PinboardException();
    } else {
        Log.e(TAG, "IO error in adding bookmark");
        throw new IOException();
    }
}

From source file:eu.trentorise.opendata.josman.Josmans.java

/**
 * Returns new sorted map of only version tags of the format repoName-x.y.z
 * filtered tags, the latter having the highest version.
 *
 * @param repoName the github repository name i.e. josman
 * @param tags a list of tags from the repository
 * @return map of version as string and correspondig RepositoryTag
 *//*ww  w  .  j av a  2  s .com*/
public static SortedMap<String, RepositoryTag> versionTags(String repoName, List<RepositoryTag> tags) {

    List<RepositoryTag> ret = new ArrayList();
    for (RepositoryTag candidateTag : tags) {
        if (candidateTag.getName().startsWith(repoName + "-")) {
            updateTags(repoName, candidateTag, ret);
        }
    }

    TreeMap map = new TreeMap();
    for (RepositoryTag tag : ret) {
        map.put(tag.getName(), tag);
    }
    return map;
}

From source file:com.deliciousdroid.client.DeliciousApi.java

/**
 * Retrieves the entire list of bookmarks for a user from Delicious.  Warning:  Overuse of this 
 * api call will get your account throttled.
 * // w  w  w .  j a  v  a  2 s. c  o m
 * @param tagname If specified, will only retrieve bookmarks with a specific tag.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A list of bookmarks received from the server.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 */
public static ArrayList<Bookmark> getAllBookmarks(String tagName, int start, int count, Account account,
        Context context) throws IOException, AuthenticationException, TooManyRequestsException {
    ArrayList<Bookmark> bookmarkList = new ArrayList<Bookmark>();

    InputStream responseStream = null;
    TreeMap<String, String> params = new TreeMap<String, String>();
    String url = FETCH_BOOKMARKS_URI;

    if (tagName != null && tagName != "") {
        params.put("tag", tagName);
    }

    if (start != 0) {
        params.put("start", Integer.toString(start));
    }

    if (count != 0) {
        params.put("results", Integer.toString(count));
    }

    params.put("meta", "yes");

    responseStream = DeliciousApiCall(url, params, account, context);
    SaxBookmarkParser parser = new SaxBookmarkParser(responseStream);

    //Log.d("kdf", convertStreamToString(responseStream));

    try {
        bookmarkList = parser.parse();
    } catch (ParseException e) {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }

    responseStream.close();

    return bookmarkList;
}

From source file:module.entities.NameFinder.DB.java

/**
 * //from   w  w w  .jav  a  2  s  .  com
 *
 * @return
 * @throws java.sql.SQLException
 */
public static TreeMap<Integer, String> GetAnnotatedData() throws SQLException {
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM assignmentsdone;");
    TreeMap<Integer, String> dbJsonString = new TreeMap<>();
    //        ArrayList<String> dbJsonString = new ArrayList<>();
    while (rs.next()) {
        int json_id = rs.getInt("text_id");
        String json = rs.getString("json_out");
        dbJsonString.put(json_id, json);
    }
    return dbJsonString;
}

From source file:com.deliciousdroid.client.DeliciousApi.java

/**
 * Sends a request to Delicious's Delete Bookmark api.
 * /*from w w w.  ja  va 2  s  . c  o  m*/
 * @param bookmark The bookmark to be deleted.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A boolean indicating whether or not the api call was successful.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 */
public static Boolean deleteBookmark(Bookmark bookmark, Account account, Context context)
        throws IOException, AuthenticationException, TooManyRequestsException {

    TreeMap<String, String> params = new TreeMap<String, String>();
    String response = null;
    InputStream responseStream = null;
    String url = DELETE_BOOKMARK_URI;

    params.put("url", bookmark.getUrl());

    responseStream = DeliciousApiCall(url, params, account, context);
    response = convertStreamToString(responseStream);
    responseStream.close();

    if (response.contains("<result code=\"done\"") || response.contains("<result code=\"item not found\"")) {
        return true;
    } else {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

public static boolean createAddVODialog() {
    boolean isSuccessful = false;
    NewVOPanel newVOPanel = new NewVOPanel();

    while (true) {
        int result = JOptionPane.showConfirmDialog(null, newVOPanel, "New VO", JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE, new ResourceIcon(newVOPanel.getClass(), ConfigHelper.ICON));

        if (result == JOptionPane.OK_OPTION) {

            String msg = "";
            if (newVOPanel.getServerIssuerDN().equals("")) {
                msg = "Field 'Server Certificate Issuer DN' cannot be empty.";
            }//ww  w  . j a v  a 2s.c  o  m
            if (newVOPanel.getServerDN().equals("")) {
                msg = "Field 'Server DN' cannot be empty.\n" + msg;
            }
            if (newVOPanel.getPort() == 0) {
                msg = "Field 'Port' cannot be empty.\n" + msg;
            }
            if (newVOPanel.getServer().equals("")) {
                msg = "Field 'Server' cannot be empty.\n" + msg;
            }
            if (newVOPanel.getVOName().equals("")) {
                msg = "Field 'VO name' cannot be empty.\n" + msg;
            }

            if (!msg.equals("")) {
                JOptionPane.showMessageDialog(null, msg, "Error: Add new VO", JOptionPane.ERROR_MESSAGE);
            } else {
                TreeMap vo = new TreeMap();
                vo.put("localvoname", newVOPanel.getVOName());
                vo.put("servervoname", newVOPanel.getVOName());
                vo.put("server", newVOPanel.getServer());
                vo.put("port", newVOPanel.getPort());
                vo.put("serverdn", newVOPanel.getServerDN());
                vo.put("serverissuerdn", newVOPanel.getServerIssuerDN());
                try {
                    isSuccessful = addNewVO(vo);
                    break;
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(null, e.getMessage(), "Error: Add new VO",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {
            break;
        }
    }

    return isSuccessful;
}

From source file:com.sangupta.jerry.oauth.OAuthUtils.java

/**
 * //w w w  . j  av a  2s. c  om
 * @param endPoint
 * @param method
 * @param oAuthHeaderName
 * @param consumerKey
 * @param consumerSecret
 * @param signatureMethod
 * @param oAuthVersion
 * @param requestParams
 * @param includeOAuthParamsInBody
 * @return
 */
public static WebRequest createOAuthRequest(String endPoint, WebRequestMethod method,
        OAuthSignatureMethod signatureMethod, String oAuthVersion, String oAuthHeaderName, String consumerKey,
        String consumerSecret, String timestamp, String nonce, Map<String, String> requestParams,
        boolean includeOAuthParamsInBody) {

    StringBuilder builder = new StringBuilder();
    builder.append(method.toString().toUpperCase());
    builder.append("&");

    builder.append(UriUtils.encodeURIComponent(endPoint, true));

    TreeMap<String, String> params = new TreeMap<String, String>();
    params.put(OAuthConstants.CONSUMER_KEY, consumerKey);
    params.put(OAuthConstants.NONCE, NonceUtils.getNonce());
    params.put(OAuthConstants.SIGNATURE_METHOD, signatureMethod.getOAuthName());
    params.put(OAuthConstants.TIMESTAMP, String.valueOf(System.currentTimeMillis()));
    params.put(OAuthConstants.VERSION, oAuthVersion);

    if (AssertUtils.isNotEmpty(requestParams)) {
        for (Entry<String, String> entry : requestParams.entrySet()) {
            params.put(entry.getKey(), entry.getValue());
        }
    }

    String paramString = generateParamString(params, true);

    builder.append("&");
    builder.append(UriUtils.encodeURIComponent(paramString, true));

    LOGGER.debug("Signable: {}", builder.toString());

    String signature = generateSignature(consumerSecret, "", builder.toString(), signatureMethod);
    params.put(OAuthConstants.SIGNATURE, signature);

    // build oauth header
    WebRequest request = WebInvoker.getWebRequest(endPoint, method);
    if (oAuthHeaderName != null) {
        request.addHeader(oAuthHeaderName, "OAuth " + getAllOAuthParams(params));
    }

    request.bodyForm(getBodyParams(params, includeOAuthParamsInBody));

    return request;
}

From source file:com.pindroid.client.PinboardApi.java

/**
 * Sends a request to Pinboard's Delete Bookmark api.
 * /*from  w w  w  .ja v  a  2  s.com*/
 * @param bookmark The bookmark to be deleted.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A boolean indicating whether or not the api call was successful.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 * @throws TooManyRequestsException 
 * @throws ParseException 
 * @throws PinboardException 
 */
public static Boolean deleteBookmark(Bookmark bookmark, Account account, Context context) throws IOException,
        AuthenticationException, TooManyRequestsException, ParseException, PinboardException {

    TreeMap<String, String> params = new TreeMap<String, String>();
    InputStream responseStream = null;
    String url = DELETE_BOOKMARK_URI;

    params.put("url", bookmark.getUrl());

    responseStream = PinboardApiCall(url, params, account, context);

    SaxResultParser parser = new SaxResultParser(responseStream);
    PinboardApiResult result = parser.parse();
    responseStream.close();

    if (result.getCode().equalsIgnoreCase("done") || result.getCode().equalsIgnoreCase("item not found")) {
        return true;
    } else {
        Log.e(TAG, "Server error in fetching bookmark list");
        throw new IOException();
    }
}

From source file:com.sangupta.jerry.oauth.OAuthUtils.java

/**
 * @param endPoint//from  w ww  . j  a  va 2 s  . c  om
 * @param method
 * @param signatureMethod
 * @param oAuthVersion
 * @param authorizationHeader
 * @param consumerKey
 * @param consumerSecret
 * @param tokenKey
 * @param tokenSecret
 * @param params
 * @param includeOAuthParamsInBody
 * @return
 */
public static WebRequest createUserSignedOAuthRequest(String endPoint, WebRequestMethod method,
        OAuthSignatureMethod signatureMethod, String oAuthVersion, String oAuthHeaderName, String consumerKey,
        String consumerSecret, String tokenKey, String tokenSecret, String timestamp, String nonce,
        Map<String, String> requestParams, boolean includeOAuthParamsInBody) {

    StringBuilder builder = new StringBuilder();
    builder.append(method.toString().toUpperCase());
    builder.append("&");

    builder.append(UriUtils.encodeURIComponent(endPoint, true));

    TreeMap<String, String> params = new TreeMap<String, String>();
    params.put(OAuthConstants.CONSUMER_KEY, consumerKey);
    params.put(OAuthConstants.NONCE, NonceUtils.getNonce());
    params.put(OAuthConstants.SIGNATURE_METHOD, signatureMethod.getOAuthName());
    params.put(OAuthConstants.TIMESTAMP, String.valueOf(System.currentTimeMillis()));
    params.put(OAuthConstants.VERSION, oAuthVersion);
    params.put(OAuthConstants.TOKEN, tokenKey);

    if (AssertUtils.isNotEmpty(requestParams)) {
        for (Entry<String, String> entry : requestParams.entrySet()) {
            params.put(entry.getKey(), entry.getValue());
        }
    }

    String paramString = generateParamString(params, true);

    builder.append("&");
    builder.append(UriUtils.encodeURIComponent(paramString, true));

    LOGGER.debug("Signable: {}", builder.toString());

    String signature = generateSignature(consumerSecret, tokenSecret, builder.toString(), signatureMethod);
    params.put(OAuthConstants.SIGNATURE, signature);

    // build oauth header
    WebRequest request = WebInvoker.getWebRequest(endPoint, method);
    if (oAuthHeaderName != null) {
        request.addHeader(oAuthHeaderName, "OAuth " + getAllOAuthParams(params));
    }

    List<NameValuePair> pairs = getBodyParams(params, includeOAuthParamsInBody);
    if (pairs != null && !pairs.isEmpty()) {
        request.bodyForm(pairs);
    }

    return request;
}

From source file:com.niki.normalizer.Metaphone.java

public static int DamerauLevenshteinDistance(String source, String target) {
    int m = source.length();
    int n = target.length();
    int[][] H = new int[m + 2][n + 2];

    int INF = m + n;
    H[0][0] = INF;//from w  w  w  .j  a  v  a2  s . c om
    for (int i = 0; i <= m; i++) {
        H[i + 1][1] = i;
        H[i + 1][0] = INF;
    }
    for (int j = 0; j <= n; j++) {
        H[1][j + 1] = j;
        H[0][j + 1] = INF;
    }
    TreeMap<Character, Integer> sd = new TreeMap<Character, Integer>();
    for (int iter = 0; iter < (source + target).length(); iter++) {
        if (!sd.containsKey((source + target).charAt(iter))) {
            sd.put((source + target).charAt(iter), 0);
        }
    }

    for (int i = 1; i <= m; i++) {
        int DB = 0;
        for (int j = 1; j <= n; j++) {
            int i1 = sd.get(target.charAt(j - 1));
            int j1 = DB;

            if (source.charAt(i - 1) == target.charAt(j - 1)) {
                H[i + 1][j + 1] = H[i][j];
                DB = j;
            } else {
                H[i + 1][j + 1] = Math.min(H[i][j], Math.min(H[i + 1][j], H[i][j + 1])) + 1;
            }

            H[i + 1][j + 1] = Math.min(H[i + 1][j + 1], H[i1][j1] + (i - i1 - 1) + 1 + (j - j1 - 1));
        }

        sd.put(source.charAt(i - 1), i);
    }
    return H[m + 1][n + 1];
}