List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:org.apache.camel.component.box.internal.BoxClientHelper.java
@SuppressWarnings("deprecation") public static CachedBoxClient createBoxClient(final BoxConfiguration configuration) { final String clientId = configuration.getClientId(); final String clientSecret = configuration.getClientSecret(); final IAuthSecureStorage authSecureStorage = configuration.getAuthSecureStorage(); final String userName = configuration.getUserName(); final String userPassword = configuration.getUserPassword(); if ((authSecureStorage == null && ObjectHelper.isEmpty(userPassword)) || ObjectHelper.isEmpty(userName) || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) { throw new IllegalArgumentException("Missing one or more required properties " + "clientId, clientSecret, userName and either authSecureStorage or userPassword"); }/* w w w.ja va 2 s . c o m*/ LOG.debug("Creating BoxClient for login:{}, client_id:{} ...", userName, clientId); // if set, use configured connection manager builder final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder(); final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null ? connectionManagerBuilder : new BoxConnectionManagerBuilder(); // create REST client for BoxClient final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1]; final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) { @Override public HttpClient getRawHttpClient() { final HttpClient httpClient = super.getRawHttpClient(); clientConnectionManager[0] = httpClient.getConnectionManager(); // set custom HTTP params final Map<String, Object> configParams = configuration.getHttpParams(); if (configParams != null && !configParams.isEmpty()) { LOG.debug("Setting {} HTTP Params", configParams.size()); final HttpParams httpParams = httpClient.getParams(); for (Map.Entry<String, Object> param : configParams.entrySet()) { httpParams.setParameter(param.getKey(), param.getValue()); } } return httpClient; } }; final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null, restClient, configuration.getBoxConfig()); // enable OAuth auto-refresh boxClient.setAutoRefreshOAuth(true); // wrap the configured storage in a caching storage final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage); // set up a listener to notify secure storage and user provided listener, store it in configuration! final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener()); boxClient.addOAuthRefreshListener(listener); final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage, listener, clientConnectionManager); LOG.debug("BoxClient created {}", cachedBoxClient); return cachedBoxClient; }
From source file:de.innovationgate.wgpublisher.bi.BiBase.java
public static String getUsername(javax.servlet.jsp.PageContext pageContext, String dbKey, String format) throws WGException { Map hm = WGACore.getSessionLogins(pageContext.getSession()); WGDatabase db = getDB(pageContext, dbKey); if (hm == null) return ""; if (hm.isEmpty()) return ""; if (dbKey.equals("")) return ""; String fullUsername = db.getSessionContext().getUser(); WGFactory.getInstance().closeSessions(); if (format != null) { if (format.equals("")) { return fullUsername; }/*from w w w . j a va2 s .c o m*/ if (format.equals("CN")) { int pos2 = fullUsername.indexOf("/"); if (pos2 != -1) { return fullUsername.substring(3, pos2); } else { return fullUsername; } } return fullUsername; } else { return fullUsername; } }
From source file:com.datumbox.framework.core.common.dataobjects.DataframeMatrix.java
/** * Method used to generate a training Dataframe to a DataframeMatrix and extracts its contents to Matrixes. It populates the featureIdsReference map with the mappings * between the feature names and the column ids of the matrix. Typically used * to convert the training dataset.//w ww . ja v a 2 s.co m * * @param dataset * @param addConstantColumn * @param recordIdsReference * @param featureIdsReference * @return */ public static DataframeMatrix newInstance(Dataframe dataset, boolean addConstantColumn, Map<Integer, Integer> recordIdsReference, Map<Object, Integer> featureIdsReference) { if (!featureIdsReference.isEmpty()) { throw new IllegalArgumentException("The featureIdsReference map should be empty."); } setStorageEngine(dataset); int n = dataset.size(); int d = dataset.xColumnSize(); if (addConstantColumn) { ++d; } DataframeMatrix m = new DataframeMatrix(new MapRealMatrix(n, d), new MapRealVector(n)); if (dataset.isEmpty()) { return m; } boolean extractY = (dataset.getYDataType() == TypeInference.DataType.NUMERICAL); int featureId = 0; if (addConstantColumn) { for (int row = 0; row < n; ++row) { m.X.setEntry(row, featureId, 1.0); //put the constant in evey row } featureIdsReference.put(Dataframe.COLUMN_NAME_CONSTANT, featureId); ++featureId; } int rowId = 0; for (Map.Entry<Integer, Record> e : dataset.entries()) { Integer rId = e.getKey(); Record r = e.getValue(); if (recordIdsReference != null) { recordIdsReference.put(rId, rowId); } if (extractY) { m.Y.setEntry(rowId, TypeInference.toDouble(r.getY())); } for (Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Integer knownFeatureId = featureIdsReference.get(feature); if (knownFeatureId == null) { featureIdsReference.put(feature, featureId); knownFeatureId = featureId; ++featureId; } Double value = TypeInference.toDouble(entry.getValue()); if (value != null) { m.X.setEntry(rowId, knownFeatureId, value); } //else the X matrix maintains the 0.0 default value } ++rowId; } return m; }
From source file:ca.uhn.fhir.rest.client.BaseHttpClientInvocation.java
protected static void appendExtraParamsWithQuestionMark(Map<String, List<String>> theExtraParams, StringBuilder theUrlBuilder, boolean theWithQuestionMark) { if (theExtraParams == null) { return;/*from w ww . j ava2 s. c o m*/ } boolean first = theWithQuestionMark; if (theExtraParams != null && theExtraParams.isEmpty() == false) { for (Entry<String, List<String>> next : theExtraParams.entrySet()) { for (String nextValue : next.getValue()) { if (first) { theUrlBuilder.append('?'); first = false; } else { theUrlBuilder.append('&'); } try { theUrlBuilder.append(URLEncoder.encode(next.getKey(), "UTF-8")); theUrlBuilder.append('='); theUrlBuilder.append(URLEncoder.encode(nextValue, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error("UTF-8 not supported - This should not happen"); } } } } }
From source file:com.wisdombud.right.client.common.HttpKit.java
/** * Build queryString of the url//w w w . ja v a 2s.co m */ private static String buildUrlWithQueryString(String url, Map<String, String> queryParas) { if (queryParas == null || queryParas.isEmpty()) { return url; } final StringBuilder sb = new StringBuilder(url); boolean isFirst; if (!url.contains("?")) { isFirst = true; sb.append("?"); } else { isFirst = false; } for (final Entry<String, String> entry : queryParas.entrySet()) { if (isFirst) { isFirst = false; } else { sb.append("&"); } final String key = entry.getKey(); String value = entry.getValue(); if (StringUtils.isNotEmpty(value)) { try { value = URLEncoder.encode(value, CHARSET); } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } } sb.append(key).append("=").append(value); } return sb.toString(); }
From source file:com.github.gaoyangthu.core.hbase.HbaseSynchronizationManager.java
/** * Actually remove the value of the resource that is bound for the given key. *///from ww w . j a va 2s. c om private static HTableInterface doUnbindResource(Object actualKey) { Map<String, HTableInterface> map = resources.get(); if (map == null) { return null; } HTableInterface value = map.remove(actualKey); // Remove entire ThreadLocal if empty... if (map.isEmpty()) { resources.remove(); } if (value != null && logger.isTraceEnabled()) { logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread [" + Thread.currentThread().getName() + "]"); } return value; }
From source file:br.com.thiagopagonha.psnapi.gcm.ServerUtilities.java
/** * Issue a POST request to the server./*from w w w. j a v a 2 s .c om*/ * * @param endpoint * POST address. * @param params * request parameters. * * @throws IOException * propagated from POST. */ private static void request(Method method, String endpoint, Map<String, String> params) throws IOException { String body = null; if (params != null && !params.isEmpty()) { StringBuilder bodyBuilder = new StringBuilder(); Iterator<Entry<String, String>> iterator = params.entrySet().iterator(); // constructs the POST body using the parameters while (iterator.hasNext()) { Entry<String, String> param = iterator.next(); bodyBuilder.append(param.getKey()).append('=').append(param.getValue()); if (iterator.hasNext()) { bodyBuilder.append('&'); } } body = bodyBuilder.toString(); } URI url; try { if (!POST.equals(method)) { url = new URI(endpoint + "?" + body); } else { url = new URI(endpoint); } Log.v(TAG, "Posting '" + body + "' to " + url); HttpUriRequest request; HttpClient httpclient = new DefaultHttpClient(); if (POST.equals(method)) { List nameValuePairs = new ArrayList(); for (Map.Entry<String, String> param : params.entrySet()) { nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue())); } request = new HttpPost(url); ((HttpPost) request).setEntity(new UrlEncodedFormEntity(nameValuePairs)); } else if (DELETE.equals(method)) { request = new HttpDelete(url); } else { request = new HttpGet(url); } HttpResponse response = httpclient.execute(request); InputStream content = response.getEntity().getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(content)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) { total.append(line); } // handle the response int status = response.getStatusLine().getStatusCode(); if (status != 200) { throw new IOException("Post failed with error code " + status + " and message " + total); } } catch (URISyntaxException e) { throw new IllegalArgumentException("invalid url: " + endpoint); } }
From source file:lti.oauth.OAuthUtil.java
public static String constructAuthorizationHeader(String realm, Map<String, String> parameters) { StringBuilder header = new StringBuilder(); if (realm != null) { header.append(" realm=\"").append(OAuthUtil.percentEncode(realm)).append('"'); }/*from ww w. j av a 2 s . c o m*/ if (parameters != null && !parameters.isEmpty()) { for (Entry<String, String> entry : parameters.entrySet()) { String key = entry.getKey(); if (key.startsWith("oauth_")) { String value = StringUtils.defaultString(entry.getValue()); if (header.length() > 0) header.append(","); header.append(" "); header.append(OAuthUtil.percentEncode(key)).append("=\""); header.append(OAuthUtil.percentEncode(value)).append('"'); } } } return AUTH_SCHEME + header.toString(); }
From source file:io.cloudslang.content.couchbase.utils.InputsUtil.java
public static String getPayloadString(Map<String, String> payloadMap, String separator, String suffix, boolean deleteLastChar) { if (payloadMap.isEmpty()) { return EMPTY; }//from w w w .j a va 2 s. co m StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : payloadMap.entrySet()) { sb.append(entry.getKey()).append(separator).append(entry.getValue()).append(suffix); } return deleteLastChar ? sb.deleteCharAt(sb.length() - 1).toString() : sb.toString(); }
From source file:org.echocat.jomon.net.http.HttpUtils.java
@Nonnull public static HttpGet getFor(@Nonnull URI uri, @Nonnull Charset charset, @Nullable Map<String, String> parameters) throws UnsupportedEncodingException { final HttpGet httpGet; if (parameters != null && !parameters.isEmpty()) { final StringBuilder sb = new StringBuilder(); sb.append(uri);// w w w . java 2 s . co m boolean questionMarkAdded = uri.getQuery() != null; for (final Entry<String, String> keyToValue : parameters.entrySet()) { if (questionMarkAdded) { sb.append('&'); } else { sb.append('?'); questionMarkAdded = true; } sb.append(encode(keyToValue.getKey(), charset.name())).append('=') .append(encode(keyToValue.getValue(), charset.name())); } httpGet = new HttpGet(create(sb.toString())); } else { httpGet = new HttpGet(uri); } return httpGet; }