List of usage examples for java.util List listIterator
ListIterator<E> listIterator(int index);
From source file:hu.ppke.itk.nlpg.purepos.model.internal.NGramModel.java
@Override public List<Double> getWordFrequency(List<Integer> context, W word) { ArrayList<Double> ret = new ArrayList<Double>(); ret.add(root.getAprioriProb(word));// w ww . java 2 s . com if (!(context == null || context.size() == 0)) { ListIterator<Integer> it = context.listIterator(context.size()); Integer previous; IntTrieNode<W> actNode = root; while (it.hasPrevious() && actNode != null) { previous = it.previous(); if (actNode.hasChild(previous)) { actNode = (IntTrieNode<W>) actNode.getChild(previous); ret.add(actNode.getAprioriProb(word)); } else { ret.add(0.0); while (it.hasPrevious()) { ret.add(0.0); } actNode = null; } } } return ret; }
From source file:de.schildbach.game.GameRules.java
public final void undoOperations(List<MicroOperation> ops, GamePosition position) { for (ListIterator<MicroOperation> i = ops.listIterator(ops.size()); i.hasPrevious();) i.previous().undoOperation(position); }
From source file:com.numenta.taurus.instance.InstanceDetailPageFragment.java
void updateServerHeader() { if (_chartData == null) { return;/*from w w w . ja v a2 s . c om*/ } if (_instanceChartFrag == null) { return; } // Update server header _instanceChartFrag.setChartData(_chartData); // Update time slider Date endDate = _chartData.getEndDate(); long endTime; if (endDate == null) { endTime = System.currentTimeMillis(); } else { endTime = endDate.getTime(); } _timeView.setAggregation(_chartData.getAggregation()); _timeView.setEndDate(endTime); // Check if need to collapse to market hours if (_collapseAfterHours) { EnumSet<MetricType> anomalousMetrics = _chartData.getAnomalousMetrics(); if (anomalousMetrics.contains(MetricType.TwitterVolume)) { // Collapse to market hours if twitter anomalies occurred during market hours MarketCalendar marketCalendar = TaurusApplication.getMarketCalendar(); boolean collapsed = true; // Check if is there any twitter anomaly on the last visible bars List<Pair<Long, Float>> data = _chartData.getData(); ListIterator<Pair<Long, Float>> iterator = data.listIterator(data.size()); for (int i = 0; i < TaurusApplication.getTotalBarsOnChart() && iterator.hasPrevious(); i++) { Pair<Long, Float> value = iterator.previous(); if (value != null && value.second != null && !Float.isNaN(value.second)) { double scaled = DataUtils.logScale(value.second); if (scaled >= TaurusApplication.getYellowBarFloor() && !marketCalendar.isOpen(value.first)) { // Found anomaly, don't collapse collapsed = false; break; } } } _marketHoursCheckbox.setChecked(collapsed); } else { // Collapse to market hours if we only have stock anomalies _marketHoursCheckbox.setChecked(true); } // Prevent collapsing during scroll _collapseAfterHours = false; } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java
private void pushOps(List<ILogicalOperator> opList, Mutable<ILogicalOperator> joinBranch, IOptimizationContext context) throws AlgebricksException { ILogicalOperator topOp = joinBranch.getValue(); ListIterator<ILogicalOperator> iter = opList.listIterator(opList.size()); while (iter.hasPrevious()) { ILogicalOperator op = iter.previous(); List<Mutable<ILogicalOperator>> opInpList = op.getInputs(); opInpList.clear();//from ww w. j a va 2s. c om opInpList.add(new MutableObject<ILogicalOperator>(topOp)); topOp = op; context.computeAndSetTypeEnvironmentForOperator(op); } joinBranch.setValue(topOp); }
From source file:brut.androlib.src.SmaliBuilder.java
private void buildFile(String fileName, DexBuilder dexBuilder) throws AndrolibException, IOException { File inFile = new File(mSmaliDir, fileName); InputStream inStream = new FileInputStream(inFile); if (fileName.endsWith(".smali")) { try {// ww w.j a v a 2 s. c o m if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) { throw new AndrolibException("Could not smali file: " + fileName); } } catch (IOException | RecognitionException ex) { throw new AndrolibException(ex); } return; } if (!fileName.endsWith(".java")) { LOGGER.warning("Unknown file type, ignoring: " + inFile); return; } StringBuilder out = new StringBuilder(); List<String> lines = IOUtils.readLines(inStream); if (!mDebug) { final String[] linesArray = lines.toArray(new String[0]); for (int i = 1; i < linesArray.length - 1; i++) { out.append(linesArray[i].split("//", 2)[1]).append('\n'); } } else { lines.remove(lines.size() - 1); ListIterator<String> it = lines.listIterator(1); out.append(".source \"").append(inFile.getName()).append("\"\n"); while (it.hasNext()) { String line = it.next().split("//", 2)[1].trim(); if (line.isEmpty() || line.charAt(0) == '#' || line.startsWith(".source")) { continue; } if (line.startsWith(".method ")) { it.previous(); DebugInjector.inject(it, out); continue; } out.append(line).append('\n'); } } try { if (!SmaliMod.assembleSmaliFile(out.toString(), dexBuilder, false, false, inFile)) { throw new AndrolibException("Could not smali file: " + fileName); } } catch (IOException | RecognitionException ex) { throw new AndrolibException(ex); } }
From source file:org.apache.nifi.web.security.x509.X509AuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { final X509AuthenticationRequestToken request = (X509AuthenticationRequestToken) authentication; // attempt to authenticate if certificates were found final AuthenticationResponse authenticationResponse; try {//from ww w . j a v a 2 s.co m authenticationResponse = certificateIdentityProvider.authenticate(request.getCertificates()); } catch (final IllegalArgumentException iae) { throw new InvalidAuthenticationException(iae.getMessage(), iae); } if (StringUtils.isBlank(request.getProxiedEntitiesChain())) { final String mappedIdentity = mapIdentity(authenticationResponse.getIdentity()); return new NiFiAuthenticationToken( new NiFiUserDetails(new StandardNiFiUser(mappedIdentity, request.getClientAddress()))); } else { // build the entire proxy chain if applicable - <end-user><proxy1><proxy2> final List<String> proxyChain = new ArrayList<>( ProxiedEntitiesUtils.tokenizeProxiedEntitiesChain(request.getProxiedEntitiesChain())); proxyChain.add(authenticationResponse.getIdentity()); // add the chain as appropriate to each proxy NiFiUser proxy = null; for (final ListIterator<String> chainIter = proxyChain.listIterator(proxyChain.size()); chainIter .hasPrevious();) { String identity = chainIter.previous(); // determine if the user is anonymous final boolean isAnonymous = StringUtils.isBlank(identity); if (isAnonymous) { identity = StandardNiFiUser.ANONYMOUS_IDENTITY; } else { identity = mapIdentity(identity); } if (chainIter.hasPrevious()) { // authorize this proxy in order to authenticate this user final AuthorizationRequest proxyAuthorizationRequest = new AuthorizationRequest.Builder() .identity(identity).anonymous(isAnonymous).accessAttempt(true) .action(RequestAction.WRITE).resource(ResourceFactory.getProxyResource()) .userContext(proxy == null ? getUserContext(request) : null) // only set the context for the real user .build(); final AuthorizationResult proxyAuthorizationResult = authorizer .authorize(proxyAuthorizationRequest); if (!Result.Approved.equals(proxyAuthorizationResult.getResult())) { throw new UntrustedProxyException(String.format("Untrusted proxy %s", identity)); } } // Only set the client address for user making the request because we don't know the client address of the proxies String clientAddress = (proxy == null) ? request.getClientAddress() : null; proxy = createUser(identity, proxy, clientAddress, isAnonymous); } return new NiFiAuthenticationToken(new NiFiUserDetails(proxy)); } }
From source file:jp.aegif.nemaki.tracker.CoreTracker.java
/** * * @param events//from ww w.ja v a 2s . c o m * @return */ private List<ChangeEvent> extractChangeEvent(List<ChangeEvent> events) { List<ChangeEvent> list = new ArrayList<ChangeEvent>(); Set<String> objectIds = new HashSet<String>(); int size = events.size(); ListIterator<ChangeEvent> iterator = events.listIterator(size); while (iterator.hasPrevious()) { ChangeEvent event = iterator.previous(); if (objectIds.contains(event.getObjectId())) { continue; } else { objectIds.add(event.getObjectId()); list.add(event); } } Collections.reverse(list); return list; }
From source file:hydrograph.ui.propertywindow.widgets.dialog.hiveInput.HiveFieldDialogHelper.java
/** * //from www. j a v a 2 s . c o m * Compares available fields and selected partition key fields for * hive input and output components. * */ public boolean compare_fields(TableItem[] items, List<String> sourceFieldsList) { ListIterator<String> t_itr, s_itr; boolean is_equal = true; List<String> target_fields = new ArrayList<String>(); if (items.length > 0) { for (TableItem tableItem : items) { target_fields.add((String) tableItem.getText()); } List<String> source_field = new ArrayList<String>(sourceFieldsList); t_itr = target_fields.listIterator(target_fields.size()); s_itr = source_field.listIterator(source_field.size()); while (t_itr.hasPrevious() & s_itr.hasPrevious()) { if (StringUtils.equals(s_itr.previous(), t_itr.previous())) { is_equal = true; } else { is_equal = false; break; } } } return is_equal; }
From source file:Heuristics.TermLevelHeuristics.java
public boolean isQuestionMarkAtEndOfStatus(String status) { List<String> terms = new ArrayList(); Collections.addAll(terms, status.split(" ")); StringBuilder sb = new StringBuilder(); boolean cleanEnd = false; ListIterator<String> termsIterator = terms.listIterator(terms.size()); while (termsIterator.hasPrevious() & !cleanEnd) { String string = termsIterator.previous(); if (!cleanEnd && (string.contains("/") || string.startsWith("#") || string.startsWith("@") || string.equals("\\|") || string.equals("") || string.contains("via") || string.equals("..."))) { continue; } else {/*w w w .j a v a 2 s.c o m*/ cleanEnd = true; } sb.insert(0, string); } status = sb.toString().trim(); if (status.length() == 0) { return false; } else { return ("?".equals(String.valueOf(status.charAt(status.length() - 1)))) ? true : false; } }
From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java
private void removeEndVoids(List list) { GraphicNode current;/*from w w w. j a va 2 s . c o m*/ for (ListIterator i = list.listIterator(list.size()); i.hasPrevious();) { current = (GraphicNode) i.previous(); if (current.isVoid()) { i.remove(); } else break; } }