下面列出了java.util.Collections#unmodifiableList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private NavigationPropertyImpl(Builder builder) {
super(builder);
this.partnerName = builder.partnerName;
this.containsTarget = builder.containsTarget;
this.referentialConstraints = Collections.unmodifiableList(builder.constraintsBuilder);
this.onDeleteActions = Collections.unmodifiableList(builder.onDeleteActionsBuilder);
}
public MatchedElement( String key ) {
super(key);
List<String> keys = new ArrayList<>(1);
keys.add( key ); // always add the full key to index 0
this.subKeys = Collections.unmodifiableList( keys );
}
@Override
protected void init(final ProcessorInitializationContext context) {
final Set<Relationship> _relationships = new HashSet<>();
_relationships.add(REL_FAILURE);
_relationships.add(REL_SUCCESS);
relationships = Collections.unmodifiableSet(_relationships);
final List<PropertyDescriptor> _properties = new ArrayList<>();
_properties.add(FAIL_WHEN_EMPTY);
_properties.add(HASH_ALGORITHM);
properties = Collections.unmodifiableList(_properties);
}
/**
* Converts a list of mutable bos to it's immutable counterpart
*
* @param bos the list of mutable business objects
* @return and immutable list containing the immutable objects
*/
public static List<CategoryDefinition> to(List<CategoryBo> bos) {
if (bos == null) {
return null;
}
List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
for (CategoryBo p : bos) {
categories.add(CategoryDefinition.Builder.create(p).build());
}
return Collections.unmodifiableList(categories);
}
@Override
public List<IContainer> getSubBlocks() {
List<IContainer> all = new ArrayList<>(cases.size() + 1);
all.add(header);
all.addAll(getCaseContainers());
return Collections.unmodifiableList(all);
}
/**
* Create a new instance.
* @param protocol The application protocol functionality to use.
* @param selectorBehavior How the peer selecting the protocol should behave.
* @param selectedBehavior How the peer being notified of the selected protocol should behave.
* @param supportedProtocols The order of iteration determines the preference of support for protocols.
*/
private ApplicationProtocolConfig(
Protocol protocol, SelectorFailureBehavior selectorBehavior,
SelectedListenerFailureBehavior selectedBehavior, List<String> supportedProtocols) {
this.supportedProtocols = Collections.unmodifiableList(checkNotNull(supportedProtocols, "supportedProtocols"));
this.protocol = checkNotNull(protocol, "protocol");
this.selectorBehavior = checkNotNull(selectorBehavior, "selectorBehavior");
this.selectedBehavior = checkNotNull(selectedBehavior, "selectedBehavior");
if (protocol == Protocol.NONE) {
throw new IllegalArgumentException("protocol (" + Protocol.NONE + ") must not be " + Protocol.NONE + '.');
}
}
public List<ReferenceObjectBinding> convertBosToImmutables(final Collection<ReferenceObjectBindingBo> referenceObjectBindingBos) {
List<ReferenceObjectBinding> immutables = new LinkedList<ReferenceObjectBinding>();
if (referenceObjectBindingBos != null) {
ReferenceObjectBinding immutable = null;
for (ReferenceObjectBindingBo bo : referenceObjectBindingBos ) {
immutable = to(bo);
immutables.add(immutable);
}
}
return Collections.unmodifiableList(immutables);
}
public List<SimpleEntry<Integer, ErrorCondition>> getAlerts() {
return Collections.unmodifiableList(alerts);
}
@Override
public List<Channel> getTargetTrees() {
return Collections.unmodifiableList(mTrees);
}
public List<String> getExtlangs() {
if (extlangs.isEmpty()) {
return Collections.emptyList();
}
return Collections.unmodifiableList(extlangs);
}
/**
* Constructor for when the Content-Type is not supported.
*/
public MediaTypeNotSupportedStatusException(List<MediaType> supportedMediaTypes) {
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported media type", null);
this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
}
@Override
public List<TreeBackedVariableElement> getParameters() {
return Collections.unmodifiableList(parameters);
}
@Override
public Collection<AttributeAssignment> getAttributeAssignments() {
return (this.attributeAssignments == EMPTY_ATTRIBUTE_ASSIGNMENTS ? this.attributeAssignments : Collections.unmodifiableList(this.attributeAssignments));
}
public List<Entry> getEntries() {
return Collections.unmodifiableList(entries);
}
public List<String> getWritableDatabaseWhiteList() {
if (writableDatabaseWhitelist == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(writableDatabaseWhitelist);
}
@Test(dataProvider = "checkIndexProvider")
public void testCheckIndex(int index, int length, boolean withinBounds) {
List<Integer> list = Collections.unmodifiableList(Arrays.asList(new Integer[] { index, length }));
String expectedMessage = withinBounds
? null
: Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
apply("checkIndex", list).getMessage();
BiConsumer<Class<? extends RuntimeException>, IntSupplier> checker = (ec, s) -> {
try {
int rIndex = s.getAsInt();
if (!withinBounds)
fail(String.format(
"Index %d is out of bounds of [0, %d), but was reported to be within bounds", index, length));
assertEquals(rIndex, index);
}
catch (RuntimeException e) {
assertTrue(ec.isInstance(e));
if (withinBounds)
fail(String.format(
"Index %d is within bounds of [0, %d), but was reported to be out of bounds", index, length));
else
assertEquals(e.getMessage(), expectedMessage);
}
};
checker.accept(AssertingOutOfBoundsException.class,
() -> Preconditions.checkIndex(index, length,
assertingOutOfBounds(expectedMessage, "checkIndex", index, length)));
checker.accept(IndexOutOfBoundsException.class,
() -> Preconditions.checkIndex(index, length,
assertingOutOfBoundsReturnNull("checkIndex", index, length)));
checker.accept(IndexOutOfBoundsException.class,
() -> Preconditions.checkIndex(index, length, null));
checker.accept(ArrayIndexOutOfBoundsException.class,
() -> Preconditions.checkIndex(index, length,
Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
checker.accept(StringIndexOutOfBoundsException.class,
() -> Preconditions.checkIndex(index, length,
Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
public JAXRSBindingFactory(Bus b) {
super(b, Collections.unmodifiableList(Arrays.asList(
JAXRS_BINDING_ID)));
}
/**
* @return the {@code DataAvailabilities}.
*/
public List<DataAvailability> getDataAvailabilities() {
return Collections.unmodifiableList(dataAvailabilities);
}
@Override
public void doOnConfigured(final AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
try {
final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE);
if (StringUtils.isBlank(tenantsPath.getValue())) {
throw new AuthorizerCreationException("The users file must be specified.");
}
// get the tenants file and ensure it exists
tenantsFile = new File(tenantsPath.getValue());
if (!tenantsFile.exists()) {
logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()});
saveTenants(new Tenants());
}
final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE);
if (StringUtils.isBlank(authorizationsPath.getValue())) {
throw new AuthorizerCreationException("The authorizations file must be specified.");
}
// get the authorizations file and ensure it exists
authorizationsFile = new File(authorizationsPath.getValue());
if (!authorizationsFile.exists()) {
logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()});
saveAuthorizations(new Authorizations());
}
final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile();
final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile();
// the restore directory is optional and may be null
final File restoreDirectory = properties.getRestoreDirectory();
if (restoreDirectory != null) {
// sanity check that restore directory is a directory, creating it if necessary
FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory);
// check that restore directory is not the same as the authorizations directory
if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) {
throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ",
authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath()));
}
// check that restore directory is not the same as the user's directory
if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) {
throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ",
tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath()));
}
// the restore copy will have same file name, but reside in a different directory
restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName());
restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName());
try {
// sync the primary copy with the restore copy
FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger);
FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger);
} catch (final IOException | IllegalStateException ioe) {
throw new AuthorizerCreationException(ioe);
}
}
// extract the identity mappings from nifi.properties if any are provided
identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties));
// get the value of the initial admin identity
final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY);
initialAdminIdentity = initialAdminIdentityProp == null ? null : IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings);
// get the value of the legacy authorized users file
final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(PROP_LEGACY_AUTHORIZED_USERS_FILE);
legacyAuthorizedUsersFile = legacyAuthorizedUsersProp == null ? null : legacyAuthorizedUsersProp.getValue();
// extract any node identities
nodeIdentities = new HashSet<>();
for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) {
Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey());
if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) {
nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings));
}
}
// load the authorizations
load();
// if we've copied the authorizations file to a restore directory synchronize it
if (restoreAuthorizationsFile != null) {
FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger);
}
// if we've copied the authorizations file to a restore directory synchronize it
if (restoreTenantsFile != null) {
FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger);
}
logger.info(String.format("Authorizations file loaded at %s", new Date().toString()));
} catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) {
throw new AuthorizerCreationException(e);
}
}
/**
* Creates a new instance.
*
* @param fileNames The list of available script files.
*/
public QueryAvailableScriptFiles(List<String> fileNames) {
this.fileNames = Collections.unmodifiableList(
Objects.requireNonNull(fileNames, "fileNames is null"));
}