Java Code Examples for java.util.Deque#getFirst()
The following examples show how to use
java.util.Deque#getFirst() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathParameterAttribute.java From quarkus-http with Apache License 2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { Deque<String> res = exchange.getPathParameters().get(parameter); if(res == null) { return null; }else if(res.isEmpty()) { return ""; } else if(res.size() ==1) { return res.getFirst(); } else { StringBuilder sb = new StringBuilder("["); int i = 0; for(String s : res) { sb.append(s); if(++i != res.size()) { sb.append(", "); } } sb.append("]"); return sb.toString(); } }
Example 2
Source File: Oauth2UserGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void handleRequest(HttpServerExchange exchange) throws Exception { IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users"); Deque<String> userIdDeque = exchange.getQueryParameters().get("userId"); String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%"; int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1; Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize"); int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst()); LikePredicate likePredicate = new LikePredicate("userId", userId); PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new UserComparator(), pageSize); pagingPredicate.setPage(page); Collection<User> values = users.values(pagingPredicate); for (User value : values) { value.setPassword(null); } exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values)); processAudit(exchange); }
Example 3
Source File: OpenApiHttpHandler.java From thorntail with Apache License 2.0 | 6 votes |
private void sendOai(HttpServerExchange exchange) throws IOException { String accept = exchange.getRequestHeaders().getFirst(Headers.ACCEPT); Deque<String> formatQueryParams = exchange.getQueryParameters().get(QUERY_PARAM_FORMAT); String formatParam = null; if (formatQueryParams != null) { formatParam = formatQueryParams.getFirst(); } // Default content type is YAML Format format = Format.YAML; // Check Accept, then query parameter "format" for JSON; else use YAML. if ((accept != null && accept.contains(Format.JSON.getMimeType())) || Format.JSON.name().equalsIgnoreCase(formatParam) || Format.JSON.getMimeType().equalsIgnoreCase(formatParam)) { format = Format.JSON; } String oai = getCachedOaiString(format); addCorsResponseHeaders(exchange); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, format.getMimeType()); exchange.getResponseSender().send(oai); }
Example 4
Source File: Oauth2ClientGetHandler.java From light-oauth2 with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients"); Deque<String> clientNameDeque = exchange.getQueryParameters().get("clientName"); String clientName = clientNameDeque == null? "%" : clientNameDeque.getFirst() + "%"; int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1; Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize"); int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst()); LikePredicate likePredicate = new LikePredicate("clientName", clientName); PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ClientComparator(), pageSize); pagingPredicate.setPage(page); Collection<Client> values = clients.values(pagingPredicate); List results = new ArrayList(); for (Client value : values) { Client c = Client.copyClient(value); c.setClientSecret(null); results.add(c); } exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(results)); processAudit(exchange); }
Example 5
Source File: PathParameterAttribute.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { Deque<String> res = exchange.getPathParameters().get(parameter); if(res == null) { return null; }else if(res.isEmpty()) { return ""; } else if(res.size() ==1) { return res.getFirst(); } else { StringBuilder sb = new StringBuilder("["); int i = 0; for(String s : res) { sb.append(s); if(++i != res.size()) { sb.append(", "); } } sb.append("]"); return sb.toString(); } }
Example 6
Source File: Solution.java From LeetCode-Solution-in-Good-Style with Apache License 2.0 | 5 votes |
/** * 双端队列的做法 * * @param nums * @param k * @return */ public int[] maxSlidingWindow(int[] nums, int k) { int len = nums.length; if (len == 0) { return new int[0]; } int[] res = new int[len - k + 1]; // 循环不变量: // queue 中的元素,如果先进来的元素比后进来的元素小,先进来的元素需要从对尾弹出以后,后进来的元素才进来 // queue 首一定是当前滑动窗口内最大元素的索引 Deque<Integer> queue = new LinkedList<>(); for (int i = 0; i < len; i++) { if (i >= k && queue.getFirst() == i - k) { queue.removeFirst(); } while (!queue.isEmpty() && nums[queue.getLast()] <= nums[i]) { queue.removeLast(); } queue.add(i); if (i >= k - 1) { res[i - k + 1] = nums[queue.getFirst()]; } } return res; }
Example 7
Source File: NotificationAccumulator.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected Runnable head( Consumer<? super T> observer, Deque<T> accumulatedValue) { T t = accumulatedValue.getFirst(); return () -> observer.accept(t); }
Example 8
Source File: LoggingServiceActivator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Set<Logger.Level> getLevels(final Map<String, Deque<String>> params) { final Deque<String> values = params.remove(LOG_LEVELS_KEY); if (values != null) { // We're only taking the first value which should be comma delimited final String levelValue = values.getFirst(); if (levelValue != null) { final EnumSet<Logger.Level> result = EnumSet.noneOf(Logger.Level.class); for (String level : levelValue.split(",")) { result.add(Logger.Level.valueOf(level.toUpperCase(Locale.ROOT))); } return result; } } return EnumSet.allOf(Logger.Level.class); }
Example 9
Source File: UndertowHttpFacade.java From keycloak with Apache License 2.0 | 5 votes |
@Override public String getFirstParam(String param) { Deque<String> values = exchange.getQueryParameters().get(param); if (values != null && !values.isEmpty()) { return values.getFirst(); } if (formData == null && "post".equalsIgnoreCase(getMethod())) { FormDataParser parser = formParserFactory.createParser(exchange); try { formData = parser.parseBlocking(); } catch (IOException cause) { throw new RuntimeException("Failed to parse form parameters", cause); } } if (formData != null) { Deque<FormValue> formValues = formData.get(param); if (formValues != null && !formValues.isEmpty()) { FormValue firstValue = formValues.getFirst(); if (!firstValue.isFile()) { return firstValue.getValue(); } } } return null; }
Example 10
Source File: Log4jServiceActivator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private String getFirstValue(final Map<String, Deque<String>> params, final String key) { if (params.containsKey(key)) { final Deque<String> values = params.get(key); if (values != null && !values.isEmpty()) { return values.getFirst(); } } return null; }
Example 11
Source File: InferredModelAssociator.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** {@inheritDoc} */ @Override public EObject getPrimarySourceModelElement(final EObject inferredModelElement) { if (inferredModelElement == null) { return null; } Map<EObject, Deque<EObject>> map = getInferredModelToSourceMap(inferredModelElement.eResource()); Deque<EObject> result = map.get(inferredModelElement); return result != null && !result.isEmpty() ? result.getFirst() : null; }
Example 12
Source File: Solution7.java From LeetCode-Solution-in-Good-Style with Apache License 2.0 | 5 votes |
public int[] maxSlidingWindow(int[] nums, int k) { int len = nums.length; if (len == 0) { return new int[0]; } // 0 1 2 3 4 5 , k = 3 // 0 1 2 3 int[] res = new int[len - k + 1]; // 存索引值,因为需要知道它什么时候应该被删除 Deque<Integer> deque = new ArrayDeque<>(); for (int i = 0; i < len; i++) { // 先考虑收缩左区间 if (i >= k && deque.getFirst() == i - k) { deque.removeFirst(); } while (!deque.isEmpty() && nums[deque.getLast()] <= nums[i]) { deque.removeLast(); } deque.add(i); if (i >= k - 1) { res[i - k + 1] = nums[deque.getFirst()]; } } return res; }
Example 13
Source File: UndertowHttpFacade.java From keycloak with Apache License 2.0 | 5 votes |
@Override public String getQueryParamValue(String param) { Map<String,Deque<String>> queryParameters = exchange.getQueryParameters(); if (queryParameters == null) return null; Deque<String> strings = queryParameters.get(param); if (strings == null) return null; return strings.getFirst(); }
Example 14
Source File: ClippedEventDelegate.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
private Path createPathFromResource(@DrawableRes int res) { VectorShape shape = new VectorShape(mView.getContext(), res); shape.onResize(mView.getWidth(), mView.getHeight()); Deque<VectorShape.Layer> layers = shape.getLayers(); VectorShape.Layer layer = layers.getFirst(); // TODO Handle state changes and update the Region based on the new current state shape return layer.transformedPath; }
Example 15
Source File: SymjaServer.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
static String getParam(Map<String, Deque<String>> queryParameters, String longParameter, String shortParameter, String defaultStr) { Deque<String> d = queryParameters.get(shortParameter); if (d != null && !d.isEmpty()) { return d.getFirst(); } d = queryParameters.get(longParameter); if (d != null && !d.isEmpty()) { return d.getFirst(); } return defaultStr; }
Example 16
Source File: PathParameterSessionConfig.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public String findSessionId(final HttpServerExchange exchange) { Deque<String> stringDeque = exchange.getPathParameters().get(name); if (stringDeque == null) { return null; } UndertowLogger.SESSION_LOGGER.tracef("Found path parameter session id %s on %s", stringDeque.getFirst(), exchange); return stringDeque.getFirst(); }
Example 17
Source File: Slf4jServiceActivator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private String getFirstValue(final Map<String, Deque<String>> params, final String key) { if (params.containsKey(key)) { final Deque<String> values = params.get(key); if (values != null && !values.isEmpty()) { return values.getFirst(); } } return null; }
Example 18
Source File: LinkedDequeTest.java From multiway-pool with Apache License 2.0 | 4 votes |
@Test(dataProvider = "emptyDeque", expectedExceptions = NoSuchElementException.class) public void getFirst_whenEmpty(Deque<SimpleLinkedValue> deque) { deque.getFirst(); }
Example 19
Source File: ProtoTruthMessageDifferencer.java From curiostack with MIT License | 4 votes |
private RepeatedField compareRepeatedFieldExpectingSubsequence( List<?> actualList, List<?> expectedList, boolean excludeNonRecursive, FieldDescriptor fieldDescriptor, FluentEqualityConfig config) { RepeatedField.Builder builder = RepeatedField.newBuilder() .setFieldDescriptor(fieldDescriptor) .setActual(actualList) .setExpected(expectedList); // Search for expectedList as a subsequence of actualList. // // This mostly replicates the algorithm used by IterableSubject.containsAll().inOrder(), but // with some tweaks for fuzzy equality and structured output. Deque<Integer> actualIndices = new ArrayDeque<>(); for (int i = 0; i < actualList.size(); i++) { actualIndices.addLast(i); } Deque<Integer> actualNotInOrder = new ArrayDeque<>(); for (int expectedIndex = 0; expectedIndex < expectedList.size(); expectedIndex++) { Object expected = expectedList.get(expectedIndex); // Find the first actual element which matches. @NullableDecl RepeatedField.PairResult matchingResult = findMatchingPairResult( actualIndices, actualList, expectedIndex, expected, excludeNonRecursive, fieldDescriptor, config); if (matchingResult != null) { // Move all prior elements to actualNotInOrder. while (!actualIndices.isEmpty() && actualIndices.getFirst() < matchingResult.actualFieldIndex().get()) { actualNotInOrder.add(actualIndices.removeFirst()); } builder.addPairResult(matchingResult); } else { // Otherwise, see if a previous element matches, so we can improve the diff. matchingResult = findMatchingPairResult( actualNotInOrder, actualList, expectedIndex, expected, excludeNonRecursive, fieldDescriptor, config); if (matchingResult != null) { // Report an out-of-order match, which is treated as not-matched. matchingResult = matchingResult.toBuilder().setResult(Result.MOVED_OUT_OF_ORDER).build(); builder.addPairResult(matchingResult); } else { // Report a missing expected element. builder.addPairResult( RepeatedField.PairResult.newBuilder() .setResult(Result.REMOVED) .setFieldDescriptor(fieldDescriptor) .setExpected(expected) .setExpectedFieldIndex(expectedIndex) .build()); } } } // Report any remaining not-in-order elements as ignored. for (int index : actualNotInOrder) { builder.addPairResult( RepeatedField.PairResult.newBuilder() .setResult(Result.IGNORED) .setFieldDescriptor(fieldDescriptor) .setActual(actualList.get(index)) .setActualFieldIndex(index) .build()); } return builder.build(); }
Example 20
Source File: LightGSSAPIAuthenticationMechanism.java From light-oauth2 with Apache License 2.0 | 4 votes |
@Override public AuthenticationMechanismOutcome run() throws GSSException { NegotiationContext negContext = exchange.getAttachment(NegotiationContext.ATTACHMENT_KEY); if (negContext == null) { negContext = new NegotiationContext(); exchange.putAttachment(NegotiationContext.ATTACHMENT_KEY, negContext); // Also cache it on the connection for future calls. exchange.getConnection().putAttachment(NegotiationContext.ATTACHMENT_KEY, negContext); } GSSContext gssContext = negContext.getGssContext(); if (gssContext == null) { GSSManager manager = GSSManager.getInstance(); GSSCredential credential = manager.createCredential(null, GSSCredential.INDEFINITE_LIFETIME, mechanisms, GSSCredential.ACCEPT_ONLY); gssContext = manager.createContext(credential); negContext.setGssContext(gssContext); } byte[] respToken = gssContext.acceptSecContext(challenge.array(), challenge.arrayOffset(), challenge.limit()); negContext.setResponseToken(respToken); if (negContext.isEstablished()) { if (respToken != null) { // There will be no further challenge but we do have a token so set it here. exchange.getResponseHeaders().add(WWW_AUTHENTICATE, NEGOTIATE_PREFIX + FlexBase64.encodeString(respToken, false)); } IdentityManager identityManager = securityContext.getIdentityManager(); // get the client authenticate class and user type from the exchange. String clientAuthClass = null; String userType = null; Map<String, Deque<String>> params = exchange.getQueryParameters(); Deque<String> clientIdDeque = params.get("client_id"); if(clientIdDeque != null) { String clientId = clientIdDeque.getFirst(); IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients"); Client client = clients.get(clientId); if(client != null) { clientAuthClass = client.getAuthenticateClass(); } } Deque<String> userTypeDeque = params.get("user_type"); if(userTypeDeque != null) { userType = userTypeDeque.getFirst(); } final Account account = identityManager.verify(new LightGSSContextCredential(negContext.getGssContext(), clientAuthClass, userType)); if (account != null) { securityContext.authenticationComplete(account, name, false); return AuthenticationMechanismOutcome.AUTHENTICATED; } else { return AuthenticationMechanismOutcome.NOT_AUTHENTICATED; } } else { // This isn't a failure but as the context is not established another round trip with the client is needed. return AuthenticationMechanismOutcome.NOT_AUTHENTICATED; } }