List of usage examples for java.util List contains
boolean contains(Object o);
From source file:models.GlobalPrivateCode.java
private static void arrangeItems(Map<Integer, List<GlobalPrivateCode>> map, GlobalPrivateCode item, Integer parId) {/*from ww w .j av a 2s.com*/ List<GlobalPrivateCode> list = map.get(parId); if (list == null) list = new ArrayList<GlobalPrivateCode>(); if (!list.contains(item)) { list.add(item); } map.put(parId, list); }
From source file:Main.java
/** * Returns whether lists are equal or not. * * @param list1/* w ww . j av a 2 s. c o m*/ * first list * @param list2 * second list * @return true if lists are equal, false otherwise */ public static boolean areEqual(final List list1, final List list2) { if (list1 == null && list2 == null) { return true; } else if ((list1 == null || list2 == null) && list1 != list2) { return false; } else { if (list1.size() != list2.size()) { return false; } else { for (final Object object : list1) { if (!list2.contains(object)) { return false; } } return true; } } }
From source file:com.yahoo.sql4d.sql4ddriver.Joiner4All.java
/** * Extract fields(k,v) from json /*w w w.j av a 2 s .c om*/ * k = primary field(s) could be a composite key. * v = all fields . The first field is always timestamp. * Presumption is jsonRow object passed to this method should not have timestamp field. * @param timestamp * @param jsonRow (This is a jsonObject without timestamp(even for select query response though timestamp is present it is stripped off before passing it to this method) * @param joinFields * @return */ private static Tuple2<Object, List<Object>> mapPkToRow(String timestamp, JSONObject jsonRow, List<String> joinFields) { Object joinValue = null; List<Object> rowValues = new ArrayList<>(); rowValues.add(timestamp); for (Object key : jsonRow.keySet()) { String colName = key.toString(); rowValues.add(jsonRow.get(colName)); if (joinFields.contains(colName)) { joinValue = (joinValue == null) ? jsonRow.get(colName) : (joinValue + "\u0001" + jsonRow.get(colName)); } } if (joinFields.contains("timestamp")) {// Join field could contain timestamp(timestamp can be out of the actual data JSON, so we try this way) joinValue = (joinValue == null) ? timestamp : (joinValue + "\u0001" + timestamp); } //Though join field could be specified like (a,timestamp,b) the value of the join, //field will be (a.value^Ab.value^Atimestamp.value) if b appears after a in the json //object. And timestamp value is always appended to last. return new Tuple2<>(joinValue, rowValues); }
From source file:com.ruzhi.demo.lifeserverweb.StringUtil.java
public static boolean checkOnlyInList(String str, List<String> includeStr) { boolean isOnly = false; char[] chars = str.toCharArray(); if (CollectionUtils.isEmpty(includeStr)) { return isOnly; }/*from www . jav a 2s. co m*/ String regex = ""; if (includeStr.contains(INCLUDE_ENGLISH)) { regex += "a-zA-Z"; } if (includeStr.contains(INCLUDE_NUMBER)) { regex += "0-9"; } if (includeStr.contains(INCLUDE_ZH_GBK)) { regex += "\u4081-\ufefe"; } regex = "^[" + regex + "]+?$"; Pattern pattern = Pattern.compile(regex); Matcher match = pattern.matcher(str); isOnly = match.matches(); return isOnly; }
From source file:edu.berkeley.nwbqueryengine.util.ValuesUtil.java
public static List<NwbResult> removeDatasetWithDuplicitPath(List<NwbResult> first, List<NwbResult> second) { List<NwbResult> results = new LinkedList<>(); List<Wrapper> firstWrapper = new LinkedList<>(); List<Wrapper> secondWrapper = new LinkedList<>(); first.forEach(item -> firstWrapper.add(new Wrapper(getPathWithoutDatasetName(item), item))); second.forEach(item -> secondWrapper.add(new Wrapper(getPathWithoutDatasetName(item), item))); firstWrapper.forEach(item -> {// w w w . j av a 2 s . c om if (secondWrapper.contains(item)) { results.add(item.getResult()); } }); secondWrapper.forEach(item -> { if (firstWrapper.contains(item)) { results.add(item.getResult()); } }); return results; }
From source file:com.nextep.designer.sqlclient.ui.helpers.SQLHelper.java
private static DMLParseResult parseSQL(String sql, int start) { final ISQLParser parser = GeneratorFactory.getSQLParser(DBGMHelper.getCurrentVendor()); // Retrieving the corresponding statement start IDocument doc = new Document(); doc.set(sql + " "); //$NON-NLS-1$ FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(doc); try {/*w w w . j a v a 2 s . c om*/ IRegion lastSemicolonRegion = finder.find(start - 1, ";", false, false, false, false); //$NON-NLS-1$ if (lastSemicolonRegion == null) { lastSemicolonRegion = new Region(0, 1); } IRegion selectRegion = finder.find(lastSemicolonRegion.getOffset(), "SELECT|INSERT|UPDATE|DELETE", true, //$NON-NLS-1$ false, false, true); IRegion endSemicolonRegion = finder.find(start == doc.getLength() ? start - 1 : start, ";", true, false, //$NON-NLS-1$ false, false); if (endSemicolonRegion == null) { endSemicolonRegion = new Region(doc.getLength() - 1, 0); } if (selectRegion == null || lastSemicolonRegion == null || endSemicolonRegion == null) { return null; } // The select must be found after the first semicolon, else it is not the // same SQL statement if (selectRegion.getOffset() >= lastSemicolonRegion.getOffset() && endSemicolonRegion.getOffset() >= selectRegion.getOffset()) { DMLScanner scanner = new DMLScanner(parser); scanner.setRange(doc, selectRegion.getOffset(), endSemicolonRegion.getOffset() - selectRegion.getOffset()); IToken token = scanner.nextToken(); DMLParseResult result = new DMLParseResult(); Stack<DMLParseResult> stack = new Stack<DMLParseResult>(); Map<Segment, DMLParseResult> results = new HashMap<Segment, DMLParseResult>(); while (!token.isEOF()) { // Counting parenthethis if (token == DMLScanner.LEFTPAR_TOKEN) { result.parCount++; } else if (token == DMLScanner.RIGHTPAR_TOKEN) { result.parCount--; } if (token == DMLScanner.SELECT_TOKEN) { // && (result.tableSegStart>0 || // result.whereSegStart>0)) { stack.push(result); result = new DMLParseResult(); result.stackStart = scanner.getTokenOffset(); } else if (token == DMLScanner.RIGHTPAR_TOKEN && result.parCount < 0) { // && // stack.size()>0) // { results.put(new Segment(result.stackStart, scanner.getTokenOffset() - result.stackStart), result); result = stack.pop(); } else if (token == DMLScanner.INSERT_TOKEN) { result.ignoreInto = false; } else if (token == DMLScanner.FROM_TOKEN || token == DMLScanner.UPDATE_TOKEN || (token == DMLScanner.INTO_TOKEN && !result.ignoreInto)) { result.ignoreInto = true; // We have a table segment start result.tableSegStart = scanner.getTokenOffset(); result.tableStartToken = token; } else if (token == DMLScanner.WORD_TOKEN && result.tableSegStart > 0) { // We are in a table segment so we instantiate appropriate table references // and aliases // in the parse result if (result.lastAlias == null) { // This is a new table definition, we add it result.lastAlias = new TableAlias( doc.get(scanner.getTokenOffset(), scanner.getTokenLength()).toUpperCase()); // result.lastAlias // .setTable(tablesMap.get(result.lastAlias.getTableName())); result.addFromTable(result.lastAlias); } else if (result.lastAlias.getTableAlias() == null) { // This is an alias of a defined table final String alias = doc.get(scanner.getTokenOffset(), scanner.getTokenLength()); final List<String> reservedWords = parser.getTypedTokens().get(ISQLParser.DML); if (!reservedWords.contains(alias.toUpperCase())) { result.lastAlias.setAlias(alias); } else { result.lastAlias = null; } } } else if (token == DMLScanner.COMMA_TOKEN) { // On a comma, we reset any table reference result.lastAlias = null; } else if (token == DMLScanner.DML_TOKEN) { result.lastAlias = null; if (result.tableSegStart != -1) { int tableSegEnd = scanner.getTokenOffset(); result.addTableSegment( new Segment(result.tableSegStart, tableSegEnd - result.tableSegStart)); result.tableSegStart = -1; } } else if (result.tableSegStart != -1 && ((result.tableStartToken == DMLScanner.FROM_TOKEN && token == DMLScanner.WHERE_TOKEN) || (result.tableStartToken == DMLScanner.UPDATE_TOKEN && token == DMLScanner.SET_TOKEN) || (result.tableStartToken == DMLScanner.INTO_TOKEN && token == DMLScanner.LEFTPAR_TOKEN))) { // We have matched a table segment end, so we close the segment // and we add it to the parse result's table segments int tableSegEnd = scanner.getTokenOffset(); result.addTableSegment( new Segment(result.tableSegStart, tableSegEnd - result.tableSegStart)); result.tableSegStart = -1; if (token == DMLScanner.WHERE_TOKEN) { result.whereSegStart = scanner.getTokenOffset() + scanner.getTokenLength(); } } token = scanner.nextToken(); } // If the table segment is still opened, we close it at the end of the SQL statement if (result.tableSegStart > -1) { int tableSegEnd = endSemicolonRegion.getOffset(); result.addTableSegment( new Segment(result.tableSegStart, tableSegEnd - result.tableSegStart + 1)); } // Locating the appropriate result for (Segment s : results.keySet()) { if (s.getOffset() <= start && s.getOffset() + s.getLength() > start) { return results.get(s); } } return result; } } catch (BadLocationException e) { LOGGER.debug("Problems while retrieving SQL statement"); } return null; }
From source file:com.thoughtworks.go.matchers.ConsoleOutMatcher.java
public static TypeSafeMatcher<List<UploadEntry>> uploadFileToDestination(final File file, final String dest) { return new TypeSafeMatcher<List<UploadEntry>>() { private List<UploadEntry> entries; private UploadEntry uploadEntry; public boolean matchesSafely(List<UploadEntry> entries) { this.entries = entries; uploadEntry = new UploadEntry(file, dest); return entries.contains(uploadEntry); }// ww w . j av a 2 s . c om public void describeTo(Description description) { description.appendText("Expected console to contain [" + uploadEntry + "] but was " + entries); } }; }
From source file:com.adguard.android.commons.RawResources.java
/** * @param context Current context//from ww w .jav a2s . c o m * @return enable default filters script string */ public static String getEnableDefaultFiltersScript(Context context) { if (enableDefaultFiltersScript == null) { List<String> languages = getInputLanguages(context); String defaultLanguage = cleanUpLanguageCode(Locale.getDefault().getLanguage()); if (!languages.contains(defaultLanguage)) { languages.add(defaultLanguage); } enableDefaultFiltersScript = getResourceAsString(context, R.raw.enable_default_filters).replace("{0}", StringUtils.join(languages, ",")); } return enableDefaultFiltersScript; }
From source file:com.autobizlogic.abl.rule.JexlExpressionAnalyzer.java
/** * Add a dependency to a Map of them.//from w w w . java 2s . co m * @param dependencies The collection of dependencies to add to * @param className The name of the class * @param attributeName The name of the attribute * @param roleName The name of the role (if any) * @param metaModel The meta model in which this all happens */ private static void addDependency(Map<ClassDependency, List<PropertyDependency>> dependencies, String className, String attributeName, String roleName, MetaModel metaModel) { LogicAnalysisManager lam = LogicAnalysisManager.getInstance(metaModel); ClassDependency clsDep = lam.getDependencyForClass(className); List<PropertyDependency> propDeps = dependencies.get(clsDep); if (propDeps == null) { propDeps = new Vector<PropertyDependency>(); dependencies.put(clsDep, propDeps); } PropertyDependency propDep = clsDep.getOrCreatePropertyDependency(attributeName, roleName); if (!propDeps.contains(propDep)) propDeps.add(propDep); }
From source file:com.trilemon.boss.infra.base.util.TopApiUtils.java
public static List<Item> excludeItems(List<Item> items, List<Long> excludeItemIds) { List<Item> newItems = Lists.newArrayList(); for (Item item : items) { if (!excludeItemIds.contains(item.getNumIid())) { newItems.add(item);/*from w w w . j a v a 2s . c o m*/ } } return newItems; }