List of usage examples for java.util Deque addLast
void addLast(E e);
From source file:uniol.apt.adt.automaton.FiniteAutomatonUtility.java
/** * Find a word whose prefixes (including the word) conform to a given predicate and which itself also conforms * to a second predicate.//from w w w.j av a 2 s . c o m * * This method uses a depth-first search. A breath-first search would use more memory. * * @param a The automaton whose accepted words should get checked. * @param prefixPredicate The predicate to check the prefixes. * @param wordPredicate The predicate to check the words. * @return A word which conforms to the predicates. */ static public List<String> findPredicateWord(FiniteAutomaton a, Predicate<List<String>> prefixPredicate, Predicate<List<String>> wordPredicate) { MinimalDeterministicFiniteAutomaton dfa = minimizeInternal(a); Deque<Pair<DFAState, Iterator<Symbol>>> trace = new ArrayDeque<>(); LinkedList<String> word = new LinkedList<>(); DFAState initial = dfa.getInitialState(); DFAState sinkState = findSinkState(dfa); trace.add(new Pair<>(initial, initial.getDefinedSymbols().iterator())); while (!trace.isEmpty()) { Pair<DFAState, Iterator<Symbol>> pair = trace.peekLast(); if (!pair.getSecond().hasNext()) { trace.removeLast(); word.pollLast(); } else { Symbol symbol = pair.getSecond().next(); DFAState nextState = pair.getFirst().getFollowingState(symbol); if (!nextState.equals(sinkState)) { word.add(symbol.getEvent()); List<String> roWord = ListUtils.unmodifiableList(word); if (prefixPredicate.evaluate(roWord)) { trace.addLast(new Pair<>(nextState, nextState.getDefinedSymbols().iterator())); if (nextState.isFinalState() && wordPredicate.evaluate(roWord)) return word; } else { word.removeLast(); } } } } return null; }
From source file:amfservices.actions.PGServicesAction.java
public Map<String, Object> takeRandomizePrizeAction(String uid, long now) { UserTempData uTempData = UserTempData.getTempData(uid); int nTurn = PGHelper.toInteger(uTempData.getData(PGMacro.RAND_PRIZE_TURN)); PGException.Assert(nTurn > 0, PGError.NOT_ENOUGH_RP_TURN, "You have 0 turn"); // reduce turn --nTurn;/*w w w .j av a2 s .co m*/ uTempData.setData(PGMacro.RAND_PRIZE_TURN, nTurn); String prizeID = PGConfig.inst().getRandomizePrizes().randomPrize(); CFRandomizePrize.Prize prizeData = PGConfig.inst().getRandomizePrizes().get(prizeID); if (prizeData.isAutoPrize()) { PGPrize prize = PrizeFactory.getPrize(prizeData.getPrize()); EntityContext context = EntityContext.getContext(uid); Map<String, Object> pzDesc = prize.award(context, now); context.saveToDB(); // find total gold prized: Deque<Map<String, Object>> pzStack = new ArrayDeque(); int totalGoldPrized = 0; pzStack.add(prizeData.getPrize()); while (!pzStack.isEmpty()) { Map<String, Object> pz = pzStack.pollLast(); for (Map.Entry<String, Object> pzEntry : pz.entrySet()) { String pzKey = pzEntry.getKey(); Object pzVal = pzEntry.getValue(); if (pzVal instanceof Map) { pzStack.addLast((Map) pzVal); } else if ("gold".equals(pzKey)) { totalGoldPrized += PGHelper.toInteger(pzVal); } } } if (totalGoldPrized > 0) { QuestLogger qLogger = QuestServices.inst().getQuestLogger(uid, now); qLogger.log(new GoldDialRecord(totalGoldPrized)); } return AMFBuilder.make(PGMacro.RAND_PRIZE_ID, prizeID, PGMacro.PRIZE, pzDesc); } else { String giftID = GiftServices.inst().sendGift(Arrays.asList(new String[] { uid }), prizeData.getPrize(), now, PGConfig.inst().temp().RandomizePrize_Expire()).getGiftID(); return AMFBuilder.make(PGMacro.RAND_PRIZE_ID, prizeID, PGMacro.GIFT_ID, giftID); } }
From source file:org.mypsycho.util.PropertiesLoader.java
protected String resolveProperty(Bundle bundle, String key, Deque<String> refStack) { String fullKey = key;/*w w w . j a v a2 s .c om*/ String localKey = key; int indexBundle = key.indexOf(MEMBER_TOKEN); Bundle definingBundle = bundle; if (indexBundle < 0) { // local name fullKey = bundle.getBasename() + MEMBER_TOKEN + key; } else if ((indexBundle > 0) && (key.indexOf(MEMBER_TOKEN, indexBundle + 1) < 0)) { String basename = key.substring(0, indexBundle); localKey = key.substring(indexBundle + 1); definingBundle = getBundle(basename, bundle.getLocale(), bundle.getContext()); } else { handle("malformedKey", key + " in " + bundle.getBasename()); } // else not a cross reference fullKey == localKey == key if (refStack.contains(fullKey)) { handle("recursivity", fullKey); return SUBST_TOKEN + key + END_TOKEN; } Object value = null; for (int fb = localKey.length(); (value == null) && (fb != -1); fb = localKey.lastIndexOf(FALLBACK_TOKEN, fb - 1)) { value = definingBundle.getDefinition(localKey.substring(0, fb)); } // value = definingBundle.getDefinition(localKey); if (value == null) { // not defined if (env != null) { // Extension Point value = env.getProperty(key); if (value != null) { return (String) value; } } handle("undefined", fullKey); return SUBST_TOKEN + key + END_TOKEN; } if (value instanceof String) { // already substituted return (String) value; } // else unresolved value refStack.addLast(fullKey); String newValue = resolveExpression(definingBundle, ((String[]) value)[0], refStack); refStack.removeLast(); definingBundle.putValue(localKey, newValue); return newValue; }
From source file:hudson.plugins.project_inheritance.projects.InheritanceProject.java
public List<JobProperty<? super InheritanceProject>> getAllProperties(IMode mode) { //Fetching the variance of the current project; it is necessary //to access the correct compatibility setting in the correct parent final InheritanceProject rootProject = this; InheritanceGovernor<List<JobProperty<? super InheritanceProject>>> gov = new InheritanceGovernor<List<JobProperty<? super InheritanceProject>>>( "properties", SELECTOR.PARAMETER, this) { @Override/*from w ww. ja va 2 s. c o m*/ protected List<JobProperty<? super InheritanceProject>> castToDestinationType(Object o) { return castToList(o); } @Override public List<JobProperty<? super InheritanceProject>> getRawField(InheritanceProject ip) { return ip.getRawAllProperties(); } @Override protected List<JobProperty<? super InheritanceProject>> reduceFromFullInheritance( Deque<List<JobProperty<? super InheritanceProject>>> list) { //First, we add the variances for the root project InheritanceParametersDefinitionProperty variance = rootProject.getVarianceParameters(); if (variance != null) { List<JobProperty<? super InheritanceProject>> varLst = new LinkedList<JobProperty<? super InheritanceProject>>(); varLst.add(variance); list.addLast(varLst); } return InheritanceGovernor.reduceByMerge(list, JobProperty.class, this.caller); } }; return gov.retrieveFullyDerivedField(this, mode); }