List of usage examples for java.util LinkedHashSet add
boolean add(E e);
From source file:edu.emory.cci.aiw.cvrg.eureka.etl.ksb.PropositionDefinitionFinder.java
private void getNodesToLoad(Stack<String> processedStack, LinkedHashSet<String> nodesToLoad) { while (!processedStack.empty()) { String node = processedStack.pop(); if (!nodesToLoad.contains(node)) { if (defaultProps.contains(node)) { nodesToLoad.add(node); } else { List<PropositionDefinition> parents; synchronized (parentsCache) { parents = parentsCache.get(node); }/*from w w w.jav a2 s. c o m*/ if (parents != null) { for (PropositionDefinition parent : parents) { if (nodesToLoad.contains(parent.getId())) { nodesToLoad.add(node); break; } } } } } } }
From source file:com.gs.obevo.api.appdata.Environment.java
public RichIterable<FileObject> getSourceDirs() { if (this.sourceDirs == null) { // only keep the distinct list of files here LinkedHashSet<FileObject> fileObjects = new LinkedHashSet<FileObject>(); if (coreSourcePath != null) { fileObjects.add(coreSourcePath); }// w ww . ja v a 2 s .c om if (additionalSourceDirs != null) { fileObjects.addAll(additionalSourceDirs.flatCollect(new Function<String, Iterable<FileObject>>() { @Override public Iterable<FileObject> valueOf(String path) { MutableList<FileObject> resolvedFileObjects = Lists.mutable.empty(); for (FileResolverStrategy fileResolverStrategy : fileResolverStrategies) { resolvedFileObjects.addAllIterable(fileResolverStrategy.resolveFileObjects(path)); } if (resolvedFileObjects.isEmpty()) { throw new IllegalArgumentException("Unable to find the given path [" + path + "] via any of the fileResolverStrategies:" + fileResolverStrategies.makeString(", ")); } return resolvedFileObjects; } }).toList()); } this.sourceDirs = Lists.mutable.withAll(fileObjects); } return this.sourceDirs; }
From source file:org.gradle.language.base.internal.model.BinarySourceTransformations.java
private Set<LanguageSourceSetInternal> getSourcesToCompile(BinarySpecInternal binary) { LinkedHashSet<LanguageSourceSetInternal> sourceSets = Sets.newLinkedHashSet(); for (LanguageSourceSet languageSourceSet : binary.getInputs()) { LanguageSourceSetInternal languageSourceSetInternal = (LanguageSourceSetInternal) languageSourceSet; if (languageSourceSetInternal.getMayHaveSources()) { sourceSets.add(languageSourceSetInternal); }//from w ww . j av a 2 s .c o m } return sourceSets; }
From source file:opennlp.tools.parse_thicket.pattern_structure.JSMLearnerOnLatticeTest.java
public void testJSMLearner() { String text1p = "I rent an office space. This office is for my business. I can deduct office rental expense from my business profit to calculate net income. "; String text2p = "To run my business, I have to rent an office. The net business profit is calculated as follows. Rental expense needs to be subtracted from revenue. "; String text3p = "To store goods for my retail business I rent some space. When I calculate the net income, I take revenue and subtract business expenses such as office rent. "; String text4p = "I rent some space for my business. To calculate my net income, I subtract from revenue my rental business expense."; String text1n = "I rent out a first floor unit of my house to a travel business. I need to add the rental income to my profit. However, when I repair my house, I can deduct the repair expense from my rental income. "; String text2n = "I receive rental income from my office. I have to claim it as a profit in my tax forms. I need to add my rental income to my profits, but subtract rental expenses such as repair from it. "; String text3n = "I advertised my property as a business rental. Advertisement and repair expenses can be subtracted from the rental income. Remaining rental income needs to be added to my profit and be reported as taxable profit. "; String text4n = "I showed my property to a business owner to rent. Expenses on my time spent on advertisement are subtracted from the rental income. My rental profits are added to my taxable income. "; List<List<ParseTreeChunk>> chunks1p = chunk_maker.formGroupedPhrasesFromChunksForPara(text1p); List<List<ParseTreeChunk>> chunks2p = chunk_maker.formGroupedPhrasesFromChunksForPara(text2p); List<List<ParseTreeChunk>> chunks3p = chunk_maker.formGroupedPhrasesFromChunksForPara(text3p); List<List<ParseTreeChunk>> chunks4p = chunk_maker.formGroupedPhrasesFromChunksForPara(text4p); List<List<ParseTreeChunk>> chunks1n = chunk_maker.formGroupedPhrasesFromChunksForPara(text1n); List<List<ParseTreeChunk>> chunks2n = chunk_maker.formGroupedPhrasesFromChunksForPara(text2n); List<List<ParseTreeChunk>> chunks3n = chunk_maker.formGroupedPhrasesFromChunksForPara(text3n); List<List<ParseTreeChunk>> chunks4n = chunk_maker.formGroupedPhrasesFromChunksForPara(text4n); LinkedHashSet<Integer> obj = null; obj = new LinkedHashSet<Integer>(); obj.add(0); psPos.AddIntent(chunks1p, obj, 0);/*from w w w. j a v a 2 s. c o m*/ obj = new LinkedHashSet<Integer>(); obj.add(1); psPos.AddIntent(chunks2p, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(2); psPos.AddIntent(chunks3p, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(3); psPos.AddIntent(chunks4p, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(0); psNeg.AddIntent(chunks1n, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(1); psNeg.AddIntent(chunks2n, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(2); psNeg.AddIntent(chunks3n, obj, 0); obj = new LinkedHashSet<Integer>(); obj.add(3); psNeg.AddIntent(chunks4n, obj, 0); String unknown = "I do not want to rent anything to anyone. I just want to rent a space for myself. I neither calculate deduction of individual or business tax. I subtract my tax from my income"; List<List<ParseTreeChunk>> chunksUnknown = chunk_maker.formGroupedPhrasesFromChunksForPara(unknown); List<List<List<ParseTreeChunk>>> posIntersections = new ArrayList<List<List<ParseTreeChunk>>>(), negIntersections = new ArrayList<List<List<ParseTreeChunk>>>(); List<List<ParseTreeChunk>> intersection = null; for (int iConcept = 0; iConcept < psPos.conceptList.size(); iConcept++) { if (psPos.conceptList.get(iConcept).intent != null && psPos.conceptList.get(iConcept).intent.size() > 0) { intersection = md.matchTwoSentencesGroupedChunksDeterministic( psPos.conceptList.get(iConcept).intent, chunksUnknown); if (reduceList(intersection).size() > 0) posIntersections.add(reduceList(intersection)); } if (psNeg.conceptList.get(iConcept).intent != null && psNeg.conceptList.get(iConcept).intent.size() > 0) { intersection = md.matchTwoSentencesGroupedChunksDeterministic( psNeg.conceptList.get(iConcept).intent, chunksUnknown); if (reduceList(intersection).size() > 0) negIntersections.add(reduceList(intersection)); } } Pair<List<List<List<ParseTreeChunk>>>, List<List<List<ParseTreeChunk>>>> pair = removeInconsistenciesFromPosNegIntersections( posIntersections, negIntersections); posIntersections = pair.getFirst(); negIntersections = pair.getSecond(); List<List<List<ParseTreeChunk>>> posIntersectionsUnderNeg = new ArrayList<List<List<ParseTreeChunk>>>(), negIntersectionsUnderPos = new ArrayList<List<List<ParseTreeChunk>>>(); for (int iConcept = 0; iConcept < psNeg.conceptList.size(); iConcept++) { for (int iConceptJ = 0; iConceptJ < negIntersections.size(); iConceptJ++) { intersection = md.matchTwoSentencesGroupedChunksDeterministic( psNeg.conceptList.get(iConcept).intent, negIntersections.get(iConceptJ)); if (reduceList(intersection).size() > 0) posIntersectionsUnderNeg.add(reduceList(intersection)); } } for (int iConcept = 0; iConcept < psPos.conceptList.size(); iConcept++) { for (int iConceptJ = 0; iConceptJ < posIntersections.size(); iConceptJ++) { intersection = md.matchTwoSentencesGroupedChunksDeterministic( psPos.conceptList.get(iConcept).intent, posIntersections.get(iConceptJ)); if (reduceList(intersection).size() > 0) negIntersectionsUnderPos.add(reduceList(intersection)); } } List<ParseTreeChunk> posIntersectionsUnderNegLst = flattenParseTreeChunkLst(posIntersectionsUnderNeg); List<ParseTreeChunk> negIntersectionsUnderPosLst = flattenParseTreeChunkLst(negIntersectionsUnderPos); posIntersectionsUnderNegLst = subtract(posIntersectionsUnderNegLst, negIntersectionsUnderPosLst); negIntersectionsUnderPosLst = subtract(negIntersectionsUnderPosLst, posIntersectionsUnderNegLst); System.out.println("Pos - neg inters = " + posIntersectionsUnderNegLst); System.out.println("Neg - pos inters = " + negIntersectionsUnderPosLst); }
From source file:org.fusesource.meshkeeper.distribution.remoting.AbstractRemotingClient.java
private final <T> T exportInternal(T obj, String multicastAddress, Class<?>... serviceInterfaces) throws Exception { LinkedHashSet<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); if (serviceInterfaces == null || serviceInterfaces.length == 0) { collectDistributableInterfaces(obj.getClass(), interfaces); } else {//from w w w .j a v a 2s . c o m for (Class<?> serviceInterface : serviceInterfaces) { validateInterface(serviceInterface); interfaces.add(serviceInterface); } } //If the only interfaces is the Distributable interface itself, then we're //just trying to export the class: if (interfaces.size() == 0 || (interfaces.size() == 1 && interfaces.contains(Distributable.class))) { if (LOG.isDebugEnabled()) { LOG.debug("Exporting " + obj.getClass() + " with no service interfaces"); } return (T) exportInterfaces(obj, multicastAddress, (Class<?>[]) null); } if (LOG.isDebugEnabled()) { LOG.debug("Exporting " + obj.getClass() + " as: " + interfaces); } Class<?>[] distributable = null; //System.out.println("Found distributable interfaces for: " + obj + ": " + interfaces); distributable = new Class<?>[interfaces.size()]; interfaces.toArray(distributable); return (T) exportInterfaces(obj, multicastAddress, distributable); }
From source file:com.soulgalore.crawler.core.impl.DefaultCrawler.java
/** * Get the urls.//from ww w .ja v a 2 s .c om * * @param configuration how to perform the crawl * @return the result of the crawl */ public CrawlerResult getUrls(CrawlerConfiguration configuration) { final Map<String, String> requestHeaders = configuration.getRequestHeadersMap(); final HTMLPageResponse resp = verifyInput(configuration.getStartUrl(), configuration.getOnlyOnPath(), requestHeaders); int level = 0; final Set<CrawlerURL> allUrls = new LinkedHashSet<CrawlerURL>(); final Set<HTMLPageResponse> verifiedUrls = new LinkedHashSet<HTMLPageResponse>(); final Set<HTMLPageResponse> nonWorkingResponses = new LinkedHashSet<HTMLPageResponse>(); verifiedUrls.add(resp); final String host = resp.getPageUrl().getHost(); if (configuration.getMaxLevels() > 0) { // set the start url Set<CrawlerURL> nextToFetch = new LinkedHashSet<CrawlerURL>(); nextToFetch.add(resp.getPageUrl()); while (level < configuration.getMaxLevels()) { final Map<Future<HTMLPageResponse>, CrawlerURL> futures = new HashMap<Future<HTMLPageResponse>, CrawlerURL>( nextToFetch.size()); for (CrawlerURL testURL : nextToFetch) { futures.put(service.submit( new HTMLPageResponseCallable(testURL, responseFetcher, true, requestHeaders, false)), testURL); } nextToFetch = fetchNextLevelLinks(futures, allUrls, nonWorkingResponses, verifiedUrls, host, configuration.getOnlyOnPath(), configuration.getNotOnPath()); level++; } } else { allUrls.add(resp.getPageUrl()); } if (configuration.isVerifyUrls()) verifyUrls(allUrls, verifiedUrls, nonWorkingResponses, requestHeaders); LinkedHashSet<CrawlerURL> workingUrls = new LinkedHashSet<CrawlerURL>(); for (HTMLPageResponse workingResponses : verifiedUrls) { workingUrls.add(workingResponses.getPageUrl()); } // TODO find a better fix for this // wow, this is a hack to fix if the first URL is redirected, // then we want to keep that original start url if (workingUrls.size() >= 1) { List<CrawlerURL> list = new ArrayList<CrawlerURL>(workingUrls); list.add(0, new CrawlerURL(configuration.getStartUrl())); list.remove(1); workingUrls.clear(); workingUrls.addAll(list); } return new CrawlerResult(configuration.getStartUrl(), configuration.isVerifyUrls() ? workingUrls : allUrls, verifiedUrls, nonWorkingResponses); }
From source file:netbeanstypescript.TSHintsProvider.java
@Override public void computeSuggestions(HintsManager manager, final RuleContext context, List<Hint> suggestions, int caretOffset) { // Group the possibly-fixable errors by span and dedupe, as getCodeFixesAtPosition requires LinkedHashMap<OffsetRange, LinkedHashSet<Integer>> errsBySpan = new LinkedHashMap<>(); for (Error err : context.parserResult.getDiagnostics()) { int errStart = err.getStartPosition(), errEnd = err.getEndPosition(); if (err.getKey() != null && caretOffset >= errStart && caretOffset <= errEnd) { OffsetRange span = new OffsetRange(errStart, errEnd); LinkedHashSet<Integer> errCodes = errsBySpan.get(span); if (errCodes == null) { errsBySpan.put(span, errCodes = new LinkedHashSet<>()); }/*from ww w . ja va 2s.c om*/ errCodes.add(Integer.parseInt(err.getKey())); } } for (OffsetRange span : errsBySpan.keySet()) { final FileObject fileObj = context.parserResult.getSnapshot().getSource().getFileObject(); Object fixes = TSService.call("getCodeFixesAtPosition", fileObj, span.getStart(), span.getEnd(), errsBySpan.get(span)); // amazingly, LinkedHashSet<Integer>'s toString is valid JSON if (fixes == null) { continue; } List<HintFix> hintFixes = new ArrayList<>(); final Reformat formatter = Reformat.get(context.doc); for (final JSONObject fix : (List<JSONObject>) fixes) { hintFixes.add(new HintFix() { @Override public String getDescription() { return (String) fix.get("description"); } @Override public void implement() { for (JSONObject change : (List<JSONObject>) fix.get("changes")) { Object fileName = change.get("fileName"); if (!fileName.equals(fileObj.getPath())) { String error = "Unimplemented: code fix involves changes to a different file " + fileName; DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(error, NotifyDescriptor.ERROR_MESSAGE)); return; } } formatter.lock(); try { context.doc.runAtomic(new Runnable() { @Override public void run() { try { for (JSONObject change : (List<JSONObject>) fix.get("changes")) { OffsetRange changed = TSFormatter.applyEdits(context.doc, change.get("textChanges")); // Code fixes are badly formatted, so reformat the affected range // https://github.com/Microsoft/TypeScript/issues/12249 if (changed != null) { formatter.reformat(changed.getStart(), changed.getEnd()); } } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); } finally { formatter.unlock(); } } @Override public boolean isSafe() { return false; } @Override public boolean isInteractive() { return false; } }); } if (!hintFixes.isEmpty()) { Rule rule = new Rule() { @Override public boolean appliesTo(RuleContext rc) { return true; } @Override public String getDisplayName() { return "TS code fix"; } @Override public boolean showInTasklist() { return false; } @Override public HintSeverity getDefaultSeverity() { return HintSeverity.ERROR; } }; suggestions.add(new Hint(rule, hintFixes.size() + (hintFixes.size() == 1 ? " code fix" : " code fixes") + " available", fileObj, span, hintFixes, 0)); } } }
From source file:org.bjason.oauth2.TokenResource.java
@POST @Produces("application/json") public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException { try {//from w w w.j a va 2 s . co m OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request); OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator()); if (Common.checkClientIdandSecret(oauthRequest) == false) { return Common.unauthorisedResponse(); } if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString())) { TOKEN_STATE ts = checkAuthCode(oauthRequest.getParam(OAuth.OAUTH_CODE)); if (ts == TOKEN_STATE.BAD) { return buildBadAuthCodeResponse("invalid authorization code"); } if (ts == TOKEN_STATE.EXPIRED) { return buildBadAuthCodeResponse("expired authorization code"); } } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) { if (!checkUserPass(oauthRequest.getUsername(), oauthRequest.getPassword())) { return buildInvalidUserPassResponse(); } } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) { buildInvalidUserPassResponse(); } final String accessToken = oauthIssuerImpl.accessToken(); GenerictokenData authCodeFromUser = database.getTokenCode(oauthRequest.getParam(OAuth.OAUTH_CODE)); GenerictokenData newAccessToken = new GenerictokenData(accessToken, Common.THIRTY_SECONDS); Set<String> requestedScopes = oauthRequest.getScopes(); // check if we are limiting scope to access token if (requestedScopes != null && requestedScopes.size() > 0) { LinkedHashSet<String> permToGrant = new LinkedHashSet<String>(); for (String what : requestedScopes) { if (authCodeFromUser.allowedTo(what) == false) { return buildBadAuthCodeResponse("invalid scope"); } permToGrant.add(what + "true"); } newAccessToken.copyPermission(permToGrant); } else { newAccessToken.copyPermission(authCodeFromUser); } database.addAccessToken(newAccessToken); OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK) .setAccessToken(accessToken).setExpiresIn("" + newAccessToken.getExpires()).buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } catch (OAuthProblemException e) { OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e) .buildJSONMessage(); return Response.status(res.getResponseStatus()).entity(res.getBody()).build(); } }
From source file:com.google.gwt.emultest.java.util.LinkedHashSetTest.java
@SuppressWarnings("unchecked") public void testClone() { LinkedHashSet<String> srcSet = new LinkedHashSet<String>(); checkEmptyLinkedHashSetAssumptions(srcSet); // Check empty clone behavior LinkedHashSet<String> dstSet = (LinkedHashSet<String>) srcSet.clone(); assertNotNull(dstSet);/*from w w w . ja v a 2s . com*/ assertEquals(dstSet.size(), srcSet.size()); assertEquals(dstSet.toArray(), srcSet.toArray()); // Check non-empty clone behavior srcSet.add(VALUE_1); srcSet.add(VALUE_2); srcSet.add(VALUE_3); srcSet.add(VALUE_4); dstSet = (LinkedHashSet<String>) srcSet.clone(); assertNotNull(dstSet); assertEquals(dstSet.size(), srcSet.size()); assertEquals(dstSet.toArray(), srcSet.toArray()); }
From source file:com.redhat.rhn.frontend.action.token.configuration.RankChannelsAction.java
/** * Sets up the rangling widget./*from w w w. j a va2 s .c om*/ * @param context the request context of the current request * @param form the dynaform related to the current request. * @param set the set holding the channel ids. */ private void setupWidget(RequestContext context, DynaActionForm form, Set<String> set) { LinkedHashSet labelValues = new LinkedHashSet(); populateWidgetLabels(labelValues, context); for (String id : set) { Long ccid = Long.valueOf(id); ConfigChannel channel = ConfigurationFactory.lookupConfigChannelById(ccid); labelValues.add(lv(channel.getName(), channel.getId().toString())); } //set the form variables for the widget to read. form.set(POSSIBLE_CHANNELS, labelValues); if (!labelValues.isEmpty()) { if (form.get(SELECTED_CHANNEL) == null) { String selected = ((LabelValueBean) labelValues.iterator().next()).getValue(); form.set(SELECTED_CHANNEL, selected); } } }