List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:org.statmantis.util.CollectionUtils.java
@SuppressWarnings("unchecked") public static <T, U extends Collection<T>> U newCollectionFromInterface(Class<U> collectionClass) { if (BlockingDeque.class.isAssignableFrom(collectionClass)) { return (U) new LinkedBlockingDeque<T>(); } else if (BlockingQueue.class.isAssignableFrom(collectionClass)) { return (U) new LinkedBlockingQueue<T>(); } else if (Queue.class.isAssignableFrom(collectionClass)) { return (U) new ArrayDeque<T>(); } else if (List.class.isAssignableFrom(collectionClass)) { return (U) new ArrayList<T>(); } else if (SortedSet.class.isAssignableFrom(collectionClass)) { return (U) new TreeSet<T>(); } else if (Set.class.isAssignableFrom(collectionClass)) { return (U) new HashSet<T>(); } else if (Collection.class.isAssignableFrom(collectionClass)) { return (U) new ArrayList<T>(); } else {//from w w w . j a v a 2 s .co m throw new BaseRuntimeException("Unrecognized interface: " + collectionClass); } }
From source file:com.fizzed.blaze.system.LineAction.java
static public Deque<String> processLines(final Charset charset, final PipeMixin pipable, final LineOutputSupplier lineOuputSupplier) throws BlazeException { ObjectHelper.requireNonNull(pipable.getPipeInput(), "pipeInput is required"); final Deque<String> lines = new ArrayDeque<>(); final StreamableOutput lineOutput = lineOuputSupplier.create(lines); try {// w w w . ja v a 2 s . c o m Streamables.copy(pipable.getPipeInput(), lineOutput); } catch (IOException e) { throw new WrappedBlazeException(e); } Streamables.close(pipable.getPipeInput()); Streamables.close(lineOutput); if (pipable.getPipeOutput() != null) { try { OutputStream os = pipable.getPipeOutput().stream(); for (String line : lines) { String s = line + "\r\n"; os.write(s.getBytes(charset)); } } catch (IOException e) { throw new WrappedBlazeException(e); } finally { Streamables.closeQuietly(pipable.getPipeOutput()); } } return lines; }
From source file:net.myrrix.common.io.IOUtils.java
/** * Attempts to recursively delete a directory. This may not work across symlinks. * * @param dir directory to delete along with contents * @return {@code true} if all files and dirs were deleted successfully *///from ww w . j a v a 2s. com public static boolean deleteRecursively(File dir) { if (dir == null) { return false; } Deque<File> stack = new ArrayDeque<File>(); stack.push(dir); boolean result = true; while (!stack.isEmpty()) { File topElement = stack.peek(); if (topElement.isDirectory()) { File[] directoryContents = topElement.listFiles(); if (directoryContents != null && directoryContents.length > 0) { for (File fileOrSubDirectory : directoryContents) { stack.push(fileOrSubDirectory); } } else { result = result && stack.pop().delete(); } } else { result = result && stack.pop().delete(); } } return result; }
From source file:org.apache.nifi.web.security.DnUtils.java
/** * Tokenizes the specified proxy chain.//from w w w. j a v a 2s . c om * * @param rawProxyChain raw chain * @return tokenized proxy chain */ public static Deque<String> tokenizeProxyChain(String rawProxyChain) { final Deque<String> dnList = new ArrayDeque<>(); // parse the proxy chain final Matcher rawProxyChainMatcher = proxyChainPattern.matcher(rawProxyChain); while (rawProxyChainMatcher.find()) { dnList.push(rawProxyChainMatcher.group(1)); } return dnList; }
From source file:com.cinchapi.concourse.lang.Parser.java
/** * Convert a valid and well-formed list of {@link Symbol} objects into a * an {@link AST}.//ww w.j ava2 s . c om * <p> * NOTE: This method will group non-conjunctive symbols into * {@link Expression} objects. * </p> * * @param symbols * @return the symbols in an AST */ public static AST toAbstractSyntaxTree(List<Symbol> symbols) { Deque<Symbol> operatorStack = new ArrayDeque<Symbol>(); Deque<AST> operandStack = new ArrayDeque<AST>(); symbols = groupExpressions(symbols); main: for (Symbol symbol : symbols) { if (symbol == ParenthesisSymbol.LEFT) { operatorStack.push(symbol); } else if (symbol == ParenthesisSymbol.RIGHT) { while (!operatorStack.isEmpty()) { Symbol popped = operatorStack.pop(); if (popped == ParenthesisSymbol.LEFT) { continue main; } else { addASTNode(operandStack, popped); } } throw new SyntaxException( MessageFormat.format("Syntax error in {0}: Mismatched parenthesis", symbols)); } else if (symbol instanceof Expression) { operandStack.add(ExpressionTree.create((Expression) symbol)); } else { operatorStack.push(symbol); } } while (!operatorStack.isEmpty()) { addASTNode(operandStack, operatorStack.pop()); } return operandStack.pop(); }
From source file:specminers.evaluation.RandoopGeneratedTestParser.java
private void loadTestMethods() { this.testMethods = new LinkedList<>(); this.testMethodDetails = new HashMap<>(); String testMethodRegularExpressionDeclaration = "^public\\svoid\\stest(\\d+)\\(\\).+$"; Deque<String> openBraces = new ArrayDeque<>(); String currentMethod = null;// ww w. ja v a 2 s .c om List<String> statementsBeforeTryCatch = null; String currentClass = ""; boolean foundTryCatchForCurrentTestMethod = false; String firstVarFound = ""; String varRegex = "var\\d+\\W"; Pattern p = Pattern.compile(varRegex); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (line.matches(testMethodRegularExpressionDeclaration)) { openBraces.add("{"); currentMethod = StringHelper.extractSingleValueWithRegex(line, testMethodRegularExpressionDeclaration, 1); statementsBeforeTryCatch = new LinkedList<>(); foundTryCatchForCurrentTestMethod = false; } else { if (currentMethod != null) { if (line.contains("try {")) { foundTryCatchForCurrentTestMethod = true; } if (!line.contains("if (debug) { System.out.println();")) { Matcher m = p.matcher(line); if (m.find()) { if (!foundTryCatchForCurrentTestMethod) { if (StringUtils.isEmpty(firstVarFound)) { firstVarFound = m.group(0).trim(); } if (line.contains(firstVarFound)) { if (line.contains(firstVarFound + " = new java.")) { int startIndex = line.indexOf("new") + 3; int endIndex = line.indexOf("(", startIndex); try { currentClass = line.substring(startIndex, endIndex); statementsBeforeTryCatch.add((currentClass + ".<init>()").trim()); } catch (StringIndexOutOfBoundsException ex) { System.out.println("Error parsing line " + line + " startIndex " + startIndex + " endIndex " + endIndex + " from java file " + javaFile.getAbsolutePath() + " current test method test" + currentMethod); } } else { if (line.contains(firstVarFound + ".")) { int startIndex = line.indexOf(firstVarFound + ".") + 4; int endIndex = line.lastIndexOf("("); String calledMethod = ""; calledMethod = line.substring(startIndex, endIndex); statementsBeforeTryCatch.add(currentClass + calledMethod + (calledMethod.endsWith("(") ? "" : "(") + ")"); } } } } } for (int j = 0; j < line.length(); j++) { if (line.charAt(j) == '{') { openBraces.add("{"); } if (line.charAt(j) == '}') { if (!openBraces.isEmpty()) { openBraces.pop(); } } } } if (openBraces.isEmpty()) { String testMethodStatements = statementsBeforeTryCatch.stream().map(st -> st.trim()) .collect(Collectors.joining("")); Map<String, String> currentTestDetails = new HashMap<>(); currentTestDetails.put("foundTryCatch", foundTryCatchForCurrentTestMethod + ""); currentTestDetails.put("statementsBeforeTryCatch", testMethodStatements); if (StringUtils.isNotBlank(currentMethod)) { testMethodDetails.put(currentMethod, currentTestDetails); } currentMethod = null; statementsBeforeTryCatch.clear(); ; foundTryCatchForCurrentTestMethod = false; firstVarFound = null; // Prepare for new method } } } } }
From source file:org.apache.asterix.metadata.utils.TypeUtil.java
/** * Merges typed index fields with specified recordType, allowing indexed fields to be optional. * I.e. the type { "personId":int32, "name": string, "address" : { "street": string } } with typed indexes * on age:int32, address.state:string will be merged into type { "personId":int32, "name": string, * "age": int32? "address" : { "street": string, "state": string? } } Used by open indexes to enforce * the type of an indexed record//from w w w. ja va2 s . c o m */ public static Pair<ARecordType, ARecordType> createEnforcedType(ARecordType recordType, ARecordType metaType, List<Index> indexes) throws AlgebricksException { ARecordType enforcedRecordType = recordType; ARecordType enforcedMetaType = metaType; for (Index index : indexes) { if (!index.isSecondaryIndex() || !index.isEnforcingKeyFileds()) { continue; } if (index.hasMetaFields()) { throw new AlgebricksException("Indexing an open field is only supported on the record part"); } for (int i = 0; i < index.getKeyFieldNames().size(); i++) { Deque<Pair<ARecordType, String>> nestedTypeStack = new ArrayDeque<>(); List<String> splits = index.getKeyFieldNames().get(i); ARecordType nestedFieldType = enforcedRecordType; boolean openRecords = false; String bridgeName = nestedFieldType.getTypeName(); int j; // Build the stack for the enforced type for (j = 1; j < splits.size(); j++) { nestedTypeStack.push(new Pair<>(nestedFieldType, splits.get(j - 1))); bridgeName = nestedFieldType.getTypeName(); nestedFieldType = (ARecordType) enforcedRecordType.getSubFieldType(splits.subList(0, j)); if (nestedFieldType == null) { openRecords = true; break; } } if (openRecords) { // create the smallest record enforcedRecordType = new ARecordType(splits.get(splits.size() - 2), new String[] { splits.get(splits.size() - 1) }, new IAType[] { AUnionType.createUnknownableType(index.getKeyFieldTypes().get(i)) }, true); // create the open part of the nested field for (int k = splits.size() - 3; k > (j - 2); k--) { enforcedRecordType = new ARecordType(splits.get(k), new String[] { splits.get(k + 1) }, new IAType[] { AUnionType.createUnknownableType(enforcedRecordType) }, true); } // Bridge the gap Pair<ARecordType, String> gapPair = nestedTypeStack.pop(); ARecordType parent = gapPair.first; IAType[] parentFieldTypes = ArrayUtils.addAll(parent.getFieldTypes().clone(), new IAType[] { AUnionType.createUnknownableType(enforcedRecordType) }); enforcedRecordType = new ARecordType(bridgeName, ArrayUtils.addAll(parent.getFieldNames(), enforcedRecordType.getTypeName()), parentFieldTypes, true); } else { //Schema is closed all the way to the field //enforced fields are either null or strongly typed Map<String, IAType> recordNameTypesMap = TypeUtil.createRecordNameTypeMap(nestedFieldType); // if a an enforced field already exists and the type is correct IAType enforcedFieldType = recordNameTypesMap.get(splits.get(splits.size() - 1)); if (enforcedFieldType != null && enforcedFieldType.getTypeTag() == ATypeTag.UNION && ((AUnionType) enforcedFieldType).isUnknownableType()) { enforcedFieldType = ((AUnionType) enforcedFieldType).getActualType(); } if (enforcedFieldType != null && !ATypeHierarchy.canPromote(enforcedFieldType.getTypeTag(), index.getKeyFieldTypes().get(i).getTypeTag())) { throw new AlgebricksException("Cannot enforce field " + index.getKeyFieldNames().get(i) + " to have type " + index.getKeyFieldTypes().get(i)); } if (enforcedFieldType == null) { recordNameTypesMap.put(splits.get(splits.size() - 1), AUnionType.createUnknownableType(index.getKeyFieldTypes().get(i))); } enforcedRecordType = new ARecordType(nestedFieldType.getTypeName(), recordNameTypesMap.keySet().toArray(new String[recordNameTypesMap.size()]), recordNameTypesMap.values().toArray(new IAType[recordNameTypesMap.size()]), nestedFieldType.isOpen()); } // Create the enforced type for the nested fields in the schema, from the ground up if (!nestedTypeStack.isEmpty()) { while (!nestedTypeStack.isEmpty()) { Pair<ARecordType, String> nestedTypePair = nestedTypeStack.pop(); ARecordType nestedRecType = nestedTypePair.first; IAType[] nestedRecTypeFieldTypes = nestedRecType.getFieldTypes().clone(); nestedRecTypeFieldTypes[nestedRecType .getFieldIndex(nestedTypePair.second)] = enforcedRecordType; enforcedRecordType = new ARecordType(nestedRecType.getTypeName() + "_enforced", nestedRecType.getFieldNames(), nestedRecTypeFieldTypes, nestedRecType.isOpen()); } } } } return new Pair<>(enforcedRecordType, enforcedMetaType); }
From source file:kkdev.kksystem.plugin.extconnector.adapters.inet.EXAdapterInet.java
public EXAdapterInet(EXAdapterConfig Conf, IEXConnManager Conn) { Configuration = Conf;/*from w w w .j ava 2 s .c o m*/ ConnManager = Conn; PMStack = new ArrayDeque<>(); LinkState = new SysExtLinkStates(); }
From source file:net.straylightlabs.archivo.controller.TelemetryController.java
public TelemetryController() { mixpanel = new MixpanelAPI(); messageBuilder = new MessageBuilder(MIXPANEL_TOKEN); eventQueue = new ArrayDeque<>(); }
From source file:org.jboss.qa.brms.performance.examples.projectjobscheduling.domain.solver.PredecessorsDoneDateUpdatingVariableListener.java
protected void updateAllocation(ScoreDirector scoreDirector, Allocation originalAllocation) { Queue<Allocation> uncheckedSuccessorQueue = new ArrayDeque<Allocation>(); uncheckedSuccessorQueue.addAll(originalAllocation.getSuccessorAllocationList()); while (!uncheckedSuccessorQueue.isEmpty()) { Allocation allocation = uncheckedSuccessorQueue.remove(); boolean updated = updatePredecessorsDoneDate(scoreDirector, allocation); if (updated) { uncheckedSuccessorQueue.addAll(allocation.getSuccessorAllocationList()); }/*from w w w .java2s .c o m*/ } }