Java Code Examples for java.util.List.contains()

The following are Jave code examples for showing how to use contains() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop-oss   File: FileSystem.java   Source Code and License Vote up 6 votes
/**
 * This method provides the default implementation of
 * {@link #access(Path, FsAction)}.
 *
 * @param stat FileStatus to check
 * @param mode type of access to check
 * @throws IOException for any error
 */
@InterfaceAudience.Private
static void checkAccessPermissions(FileStatus stat, FsAction mode)
    throws IOException {
  FsPermission perm = stat.getPermission();
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  String user = ugi.getShortUserName();
  List<String> groups = Arrays.asList(ugi.getGroupNames());
  if (user.equals(stat.getOwner())) {
    if (perm.getUserAction().implies(mode)) {
      return;
    }
  } else if (groups.contains(stat.getGroup())) {
    if (perm.getGroupAction().implies(mode)) {
      return;
    }
  } else {
    if (perm.getOtherAction().implies(mode)) {
      return;
    }
  }
  throw new AccessControlException(String.format(
    "Permission denied: user=%s, path=\"%s\":%s:%s:%s%s", user, stat.getPath(),
    stat.getOwner(), stat.getGroup(), stat.isDirectory() ? "d" : "-", perm));
}
 
Example 2
Project: incubator-netbeans   File: BasicTestForImport.java   Source Code and License Vote up 6 votes
public void assertProperty(final String propertyName, final String expected) throws IOException, ClassNotFoundException {
    Result support = readSystemOption(false);
    
    List parsedPropNames = Arrays.asList(support.getPropertyNames());
    
    String parsedPropertyName = null;
    boolean isFakeName = !parsedPropNames.contains(propertyName);
    if (isFakeName) {
        assertTrue(propertyName+" (alias: "+parsedPropertyName + ") not found in: " + parsedPropNames,parsedPropNames.contains(parsedPropertyName));
    } else {
        parsedPropertyName = propertyName;
    }
    
    assertNotNull(parsedPropertyName);
    Class expectedClass = null;
    String actual = support.getProperty(parsedPropertyName);
    if (actual == null) {
        assertNull(expectedClass);
        assertEquals(expected, actual);
    } else {
        assertEquals(expected, actual);
    }
}
 
Example 3
Project: incubator-netbeans   File: MavenSourcesImpl.java   Source Code and License Vote up 6 votes
private boolean checkGeneratedGroupsCache() {
    boolean changed = false;
    List<File> checked = new ArrayList<File>();
    for (boolean test : new boolean[] {false, true}) {
        for (URI u : project().getGeneratedSourceRoots(test)) {
            File file = FileUtil.normalizeFile(Utilities.toFile(u));
            FileObject folder = FileUtil.toFileObject(file);
            changed |= checkGeneratedGroupCache(folder, file, file.getName(), test);
            checked.add(file);
        }
    }
    Set<File> currs = new HashSet<File>();
    currs.addAll(genSrcGroup.keySet());
    for (File curr : currs) {
        if (!checked.contains(curr)) {
            genSrcGroup.remove(curr);
            changed = true;
        }
    }
    return changed;
}
 
Example 4
Project: flume-release-1.7.0   File: ThriftRpcClient.java   Source Code and License Vote up 6 votes
private static TSocket createSSLSocket(SSLSocketFactory factory, String host,
                                       int port, int timeout, List<String> excludeProtocols)
    throws FlumeException {
  try {
    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
    socket.setSoTimeout(timeout);

    List<String> enabledProtocols = new ArrayList<String>();
    for (String protocol : socket.getEnabledProtocols()) {
      if (!excludeProtocols.contains(protocol)) {
        enabledProtocols.add(protocol);
      }
    }
    socket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
    return new TSocket(socket);
  } catch (Exception e) {
    throw new FlumeException("Could not connect to " + host + " on port " + port, e);
  }
}
 
Example 5
Project: configx   File: ConfigSearchService.java   Source Code and License Vote up 6 votes
/**
 * 使用标签来过滤配置项
 *
 * @param configItemList
 * @param tagIdList
 * @return
 */
private List<ConfigItem> filterByTag(List<ConfigItem> configItemList, List<Integer> tagIdList) {
    // 未限定
    if (tagIdList == null || tagIdList.isEmpty()) {
        return configItemList;
    }

    List<ConfigItem> filteredConfigItemList = new ArrayList<>();

    for (ConfigItem configItem : configItemList) {
        if (StringUtils.isNotEmpty(configItem.getTags())) {
            boolean tagged = false;
            for (String tagId : StringUtils.split(configItem.getTags(), ",")) {
                if (tagIdList.contains(Integer.valueOf(tagId))) {
                    tagged = true;
                    break;
                }
            }
            if (tagged) {
                filteredConfigItemList.add(configItem);
            }
        }
    }

    return filteredConfigItemList;
}
 
Example 6
Project: jmt   File: CommonModel.java   Source Code and License Vote up 5 votes
/**
 * Returns given name if a mode with the same name does not exist or makes it unique
 * for a transition
 * @param key station key
 * @param name mode name
 * @return unique name
 */
protected String getUniqueTransitionModeName(Object key, String name) {
	// Map of all unique names with their first users
	List<String> names = getAllTransitionModeNames(key);

	// If name is new, returns it
	if (!names.contains(name)) {
		return name;
	}

	int num;
	// If format is already '*_[number]' increment number
	char[] charname = name.toCharArray();
	int n = charname.length - 1;
	while (charname[n] >= '0' && charname[n] <= '9' && n > 0) {
		n--;
	}
	if (charname[n] == '_') {
		num = Integer.parseInt(name.substring(n + 1));
		name = name.substring(0, n); // Removes suffix
	}
	// Otherwise uses number 1
	else {
		num = 1;
	}
	// Finds unique number
	while (names.contains(name + "_" + num)) {
		num++;
	}
	return name + "_" + num;
}
 
Example 7
Project: firebase-admin-java   File: CompoundHashTest.java   Source Code and License Vote up 5 votes
private static CompoundHash.SplitStrategy splitAtPaths(String... paths) {
  final List<Path> pathList = new ArrayList<>();
  for (String path : paths) {
    pathList.add(path(path));
  }
  return new CompoundHash.SplitStrategy() {
    @Override
    public boolean shouldSplit(CompoundHash.CompoundHashBuilder state) {
      return pathList.contains(state.currentPath());
    }
  };
}
 
Example 8
Project: jaffa-framework   File: PolicyManager.java   Source Code and License Vote up 5 votes
/** Builds the FunctionRoleIndex based on information aquired from the PolicyCache object.
 * This supplies the information as a list of roles with function access. The build process
 * transposes this mapping.
 */
private static Map<String, List<String>> buildFunctionRoleIndex() {
    Map<String, List<String>> index = new HashMap<String, List<String>>();

    // Get the role mappings
    Map<String, List<String>> roleMap = PolicyCache.getRoleMap();
    if (roleMap != null) {
        // Loop through the role list and build the function list
        for (Map.Entry<String, List<String>> me : roleMap.entrySet()) {
            String role = me.getKey();
            List<String> funcs = me.getValue();
            for (String func : funcs) {
                // Get the function list for this function
                List<String> idxFunc = index.get(func);
                if (idxFunc == null) {
                    // New function, create a list and entry for it...
                    idxFunc = new LinkedList<String>();
                    index.put(func, idxFunc);
                }
                // Add the role to this function list if not already there
                // the uniquess check should be removed if uniqueness is inforced in
                // the XML Policy file!.. For now, assume it is not
                if (!idxFunc.contains(role))
                    idxFunc.add(role);
            }
        }
    }
    return index;
}
 
Example 9
Project: okuki   File: PlaceScoper.java   Source Code and License Vote up 5 votes
@Override
public void onPlace(Place place) {

    // get current place hierarchy
    List<Class<? extends Place>> prevHier = (currentPlace == null) ? new ArrayList<>() : currentPlace.getHierarchy();

    // get new place hierarchy
    List<Class<? extends Place>> newHier = place.getHierarchy();

    // close previous place scope hierarchy starting at first place of difference
    List<Class<? extends Place>> keysToClose = new ArrayList<>(prevHier);
    keysToClose.removeAll(newHier);
    for (Class<? extends Place> keyToClose : keysToClose) {
        Toothpick.closeScope(keyToClose);
    }

    // open new scope hierarchy setting modules for newly opened scopes
    for (Class<? extends Place> keyToOpen : newHier) {
        List<Module> modules = new ArrayList<>();
        if (!prevHier.contains(keyToOpen)) {
            Scope parentScope = openParentScope(keyToOpen);
            List<Class<? extends Module>> moduleClasses = getModuleClassesForPlaceScope(keyToOpen);
            for (Class<? extends Module> moduleClass : moduleClasses) {
                try {
                    modules.add(parentScope.getInstance(moduleClass));
                } catch (Exception e) {
                    try {
                        modules.add(moduleClass.newInstance());
                    } catch (Exception e1) {
                        throw new RuntimeException("Unable to instatiate module: " + moduleClass, e1);
                    }
                }
            }
        }
        openPlaceScope(keyToOpen, modules.toArray(new Module[modules.size()]));
    }

    currentPlace = place;
}
 
Example 10
Project: opencps-v2   File: RegistrationFormLocalServiceImpl.java   Source Code and License Vote up 5 votes
/**
 * @param pattern
 * @return
 */
protected static List<String> getSplitIndex(String pattern) {
	List<String> splitIndexs = new ArrayList<String>();
	int eliminateParenthesis = 0;
	int startIndex = 0;
	int endIndex = 0;

	for (int i = 0; i < pattern.length(); i++) {

		Character c = pattern.charAt(i);

		if (c.toString().equals(StringPool.OPEN_PARENTHESIS)) {
			eliminateParenthesis += 1;
		} else if (c.toString().equals(StringPool.CLOSE_PARENTHESIS)) {
			eliminateParenthesis += -1;
		}

		if (eliminateParenthesis == 1
				&& c.toString().equals(StringPool.OPEN_PARENTHESIS)) {
			startIndex = i;
		}

		if (eliminateParenthesis == 0
				&& c.toString().equals(StringPool.CLOSE_PARENTHESIS)) {
			endIndex = i;

		}

		if (!splitIndexs.contains(startIndex + StringPool.DASH + endIndex)
				&& startIndex < endIndex) {

			splitIndexs.add(startIndex + StringPool.DASH + endIndex);
		}
	}

	return splitIndexs;
}
 
Example 11
Project: OpenJSharp   File: ChronoZonedDateTimeImpl.java   Source Code and License Vote up 5 votes
/**
 * Obtains an instance from a local date-time using the preferred offset if possible.
 *
 * @param localDateTime  the local date-time, not null
 * @param zone  the zone identifier, not null
 * @param preferredOffset  the zone offset, null if no preference
 * @return the zoned date-time, not null
 */
static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest(
        ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(zone, "zone");
    if (zone instanceof ZoneOffset) {
        return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone);
    }
    ZoneRules rules = zone.getRules();
    LocalDateTime isoLDT = LocalDateTime.from(localDateTime);
    List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
    ZoneOffset offset;
    if (validOffsets.size() == 1) {
        offset = validOffsets.get(0);
    } else if (validOffsets.size() == 0) {
        ZoneOffsetTransition trans = rules.getTransition(isoLDT);
        localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
        offset = trans.getOffsetAfter();
    } else {
        if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
            offset = preferredOffset;
        } else {
            offset = validOffsets.get(0);
        }
    }
    Objects.requireNonNull(offset, "offset");  // protect against bad ZoneRules
    return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
}
 
Example 12
Project: linkifier   File: Tpc.java   Source Code and License Vote up 5 votes
private static double asymmetricAbbreviationSimilarity(String a, String b, List<String> otherTokens) {
	// Joker card
	if ("KEYWORD".equals(b) && Setting.KEYWORD_RELATIONSHIP.contains(a) && !otherTokens.contains(a)) return 0.95;

	// Abbreviation to two letters (e.g. address -> ad)
	if (a.length() == 2 && b.length() >= 2 && a.charAt(0) == b.charAt(0) && a.charAt(1) == b.charAt(1)) {
		return 0.95;    // We penalize that a bit
	}

	// Another abbreviation to two letters (e.g. sector -> sc)
	if (a.length() == 2 && b.length() >= 3 && a.charAt(0) == b.charAt(0) && a.charAt(1) == b.charAt(2)) {
		return 0.95;
	}

	// Employ related terms (synonyms, hypernyms and hyponyms). Unfortunately, it is a hard match/mismatch
	if (Setting.SYNONYM_PERSON.contains(a) && Setting.SYNONYM_PERSON.contains(b)) {
		return 0.95;
	}

	if (Setting.SYNONYM_COUNTRY.contains(a) && Setting.SYNONYM_COUNTRY.contains(b)) {
		return 0.95;
	}

	if (Setting.SYNONYM_PRODUCT.contains(a) && Setting.SYNONYM_PRODUCT.contains(b)) {
		return 0.95;
	}

	if (Setting.SYNONYM_CITY.contains(a) && Setting.SYNONYM_CITY.contains(b)) {
		return 0.95;
	}

	return 0.0;
}
 
Example 13
Project: Tarski   File: mxGraphStructure.java   Source Code and License Vote up 5 votes
/**
 * @param aGraph
 * @param omitVertex vertices in this array will be omitted, set this parameter to null if you
 *        don't want this feature
 * @return a vertex that has lowest degree, or one of those in case if there are more
 */
static public Object getLowestDegreeVertex(mxAnalysisGraph aGraph, Object[] omitVertex) {
  Object[] vertices = aGraph.getChildVertices(aGraph.getGraph().getDefaultParent());
  int vertexCount = vertices.length;

  int lowestEdgeCount = Integer.MAX_VALUE;
  Object bestVertex = null;
  List<Object> omitList = null;

  if (omitVertex != null) {
    omitList = Arrays.asList(omitVertex);
  }

  for (int i = 0; i < vertexCount; i++) {
    if (omitVertex == null || !omitList.contains(vertices[i])) {
      int currEdgeCount = aGraph.getEdges(vertices[i], null, true, true, true, true).length;

      if (currEdgeCount == 0) {
        return vertices[i];
      } else {
        if (currEdgeCount < lowestEdgeCount) {
          lowestEdgeCount = currEdgeCount;
          bestVertex = vertices[i];
        }
      }
    }
  }

  return bestVertex;
}
 
Example 14
Project: SuperMarketManageSystem   File: JinHuoTuiHuo.java   Source Code and License Vote up 5 votes
private void initSpBox() {
	List list = new ArrayList();
	ResultSet set = Dao.query("select * from tb_kucun where "
			+ "id in(select id from tb_spinfo where gysName='"
			+ gys.getSelectedItem() + "')");
	sp.removeAllItems();
	sp.addItem(new TbKucun());
	for (int i = 0; table != null && i < table.getRowCount(); i++) {
		TbKucun tmpInfo = (TbKucun) table.getValueAt(i, 0);
		if (tmpInfo != null && tmpInfo.getId() != null)
			list.add(tmpInfo.getId());
	}
	try {
		while (set.next()) {
			TbKucun kucun = new TbKucun();
			kucun.setId(set.getString("id").trim());
			// ���������Դ���ͬ����Ʒ����Ʒ�������оͲ��ٰ�������Ʒ
			if (list.contains(kucun.getId()))
				continue;
			kucun.setSpname(set.getString("spname").trim());
			kucun.setCd(set.getString("cd").trim());
			kucun.setJc(set.getString("jc").trim());
			kucun.setDw(set.getString("dw").trim());
			kucun.setGg(set.getString("gg").trim());
			kucun.setBz(set.getString("bz").trim());
			kucun.setDj(Double.valueOf(set.getString("dj").trim()));
			kucun.setKcsl(Integer.valueOf(set.getString("kcsl").trim()));
			sp.addItem(kucun);
		}
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
Example 15
Project: incubator-netbeans   File: AbstractSvnTestCase.java   Source Code and License Vote up 5 votes
protected void ignore(File file) throws SVNClientException {        
    File parent =  file.getParentFile();
    List patterns = getFullWorkingClient().getIgnoredPatterns(parent);
    String path = file.getName();
    if(!patterns.contains(path)) {            
        patterns.add(path);
    }
    getFullWorkingClient().setIgnoredPatterns(parent, patterns);
    assertStatus(SVNStatusKind.IGNORED, file);
}
 
Example 16
Project: ObsidianSuite   File: ImporterTabula.java   Source Code and License Vote up 5 votes
private static String containsDuplicateParts(TabulaModel tblModel) {
	List<String> names = new ArrayList<String>();
	for(TabulaBox box : tblModel.boxes) {
		if(names.contains(box.name))
			return box.name;
		names.add(box.name);
	}
	return null;
}
 
Example 17
Project: AeroStory   File: HiredMerchant.java   Source Code and License Vote up 4 votes
private static boolean check(MapleCharacter chr, List<MaplePlayerShopItem> items) {
    byte eq = 0, use = 0, setup = 0, etc = 0, cash = 0;
    List<MapleInventoryType> li = new LinkedList<>();
    for (MaplePlayerShopItem item : items) {
        final MapleInventoryType invtype = MapleItemInformationProvider.getInstance().getInventoryType(item.getItem().getItemId());
        if (!li.contains(invtype)) {
            li.add(invtype);
        }
        if (invtype == MapleInventoryType.EQUIP) {
            eq++;
        } else if (invtype == MapleInventoryType.USE) {
            use++;
        } else if (invtype == MapleInventoryType.SETUP) {
            setup++;
        } else if (invtype == MapleInventoryType.ETC) {
            etc++;
        } else if (invtype == MapleInventoryType.CASH) {
            cash++;
        }
    }
    for (MapleInventoryType mit : li) {
        if (mit == MapleInventoryType.EQUIP) {
            if (chr.getInventory(MapleInventoryType.EQUIP).getNumFreeSlot() <= eq) {
                return false;
            }
        } else if (mit == MapleInventoryType.USE) {
            if (chr.getInventory(MapleInventoryType.USE).getNumFreeSlot() <= use) {
                return false;
            }
        } else if (mit == MapleInventoryType.SETUP) {
            if (chr.getInventory(MapleInventoryType.SETUP).getNumFreeSlot() <= setup) {
                return false;
            }
        } else if (mit == MapleInventoryType.ETC) {
            if (chr.getInventory(MapleInventoryType.ETC).getNumFreeSlot() <= etc) {
                return false;
            }
        } else if (mit == MapleInventoryType.CASH) {
            if (chr.getInventory(MapleInventoryType.CASH).getNumFreeSlot() <= cash) {
                return false;
            }
        }
    }
    return true;
}
 
Example 18
Project: Spring-5.0-Cookbook   File: CustomSuccessHandler.java   Source Code and License Vote up 4 votes
private boolean isAdminRole(List<String> roles) {
    if (roles.contains("ROLE_ADMIN")) {
        return true;
    }
    return false;
}
 
Example 19
Project: ats-framework   File: JschSftpClient.java   Source Code and License Vote up 4 votes
/**
 *
 * @param directoryPath the directory path
 * @param preservedPaths a list with preserved files or folders.
 *      If the path ends with '/' it is preserved directory, not a file
 */
public void purgeRemoteDirectoryContents( String directoryPath, List<String> preservedPaths ) {

    if (isVerbose) {
        log.debug("Cleanup the content of remote directory " + directoryPath);
    }

    try {
        if (isRemoteFileOrDirectoryExisting(directoryPath)) {

            List<FileEntry> entries = ls(directoryPath);
            for (FileEntry fileEntry : entries) {

                if (fileEntry.isDirectory()) {

                    if (preservedPaths == null
                        || (preservedPaths != null
                            && !preservedPaths.contains(IoUtils.normalizeUnixDir(fileEntry.getPath())))) { // skip preserved directories

                        purgeRemoteDirectoryContents(fileEntry.getPath(), preservedPaths);
                        // the directory may not be empty now, if there are some preserved files/folders in it
                        if (preservedPaths == null
                            || (preservedPaths != null && isDirectoryEmpty(fileEntry.getPath()))) {

                            removeRemoteDirectory(fileEntry.getPath(), false);
                        }
                    }
                } else if (preservedPaths == null
                           || (preservedPaths != null
                               && !preservedPaths.contains(fileEntry.getPath()))) { // skip preserved files

                    removeRemoteFile(fileEntry.getPath());
                }
            }
        }

    } catch (Exception e) {

        throw new JschSftpClientException("Error while purging directory contnets '" + directoryPath
                                          + "'", e);
    }
}
 
Example 20
Project: FuelUp   File: VehicleProvider.java   Source Code and License Vote up 4 votes
private int validateVehicleAndUpdate(final Uri uri, final ContentValues contentValues, final long id) {

        if (contentValues.containsKey(VehicleEntry.COLUMN_NAME)) {
            String name = contentValues.getAsString(VehicleEntry.COLUMN_NAME).trim();
            if (isNotVehicleNameUnique(name, id)) {
                return VEHICLE_UPDATE_NAME_NOT_UNIQUE;
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_TYPE)) {
            Integer typeId = contentValues.getAsInteger(VehicleEntry.COLUMN_TYPE);
            if (typeId == null) {
                throw new IllegalArgumentException("Vehicle Type must be set.");
            }
            if (typeNotExists(typeId)) {
                throw new IllegalArgumentException("Vehicle Type must exists.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_VOLUME_UNIT)) {
            String volumeUnit = contentValues.getAsString(VehicleEntry.COLUMN_VOLUME_UNIT);
            List<String> allowedVolumeUnits = Arrays.asList(VolumeUnit.LITRE.name(), VolumeUnit.GALLON_UK.name(), VolumeUnit.GALLON_US.name());
            if (volumeUnit == null) {
                throw new IllegalArgumentException("Vehicle volumeUnit must be set.");
            }
            if (!allowedVolumeUnits.contains(volumeUnit)) {
                throw new IllegalArgumentException("VolumeUnit value is not allowed.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_CURRENCY)) {
            String currency = contentValues.getAsString(VehicleEntry.COLUMN_CURRENCY).toUpperCase();
            Currency currencyInstance = Currency.getInstance(currency);
            if (!CurrencyUtil.getSupportedCurrencies().contains(currencyInstance)) {
                throw new IllegalArgumentException("This currency is not supported by this app.");
            }
            if (currencyInstance == null) {
                throw new IllegalArgumentException("Currency '" + currency + "' is not supported by system.");
            }
        }

        final String selection = VehicleEntry._ID + "=?";
        final String[] idArgument = new String[] { String.valueOf(id) };

        getContext().getContentResolver().notifyChange(uri, null);
        return mDbHelper.getWritableDatabase().update(
                VehicleEntry.TABLE_NAME, contentValues, selection, idArgument);
    }