下面列出了org.apache.commons.lang.ArrayUtils#removeElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Property[] removeUniqueIdProperty(Property[] properties) {
if (ArrayUtils.isEmpty(properties)) {
return new Property[0];
}
for (int i = 0; i < properties.length; i++) {
if (properties[i] == null) {
continue;
}
if (IdentityApplicationConstants.UNIQUE_ID_CONSTANT.equals(properties[i].getName())) {
Property[] propertiesTemp = properties;
if (log.isDebugEnabled()) {
log.debug("Removing uniqueId property: " + properties[i].getName());
}
properties = (Property[]) ArrayUtils.removeElement(properties, properties[i]);
//Removing uniqueId property from existing properties too
propertiesTemp[i] = null;
}
}
return properties;
}
private Property[] removeUniqueIdProperty(Property [] properties) {
if (ArrayUtils.isEmpty(properties)){
return new Property[0];
}
for (int i=0 ; i < properties.length; i++) {
if (properties[i] == null){
continue;
}
if (IdentityApplicationConstants.UNIQUE_ID_CONSTANT.equals(properties[i].getName())) {
Property[] propertiesTemp = properties;
if (log.isDebugEnabled()){
log.debug("Removing uniqueId property: " + properties[i].getName());
}
properties = (Property[])ArrayUtils.removeElement(properties, properties[i]);
//Removing uniqueId property from existing properties too
propertiesTemp[i] = null;
}
}
return properties;
}
/**
* This method returns 2D array, where each row represents corresponding label
*
* @param labels
* @return
*/
@Override
public INDArray getWordVectors(@NonNull Collection<String> labels) {
int indexes[] = new int[labels.size()];
int cnt = 0;
boolean useIndexUnknown = useUnknown && vocab.containsWord(getUNK());
for (String label : labels) {
if (vocab.containsWord(label)) {
indexes[cnt] = vocab.indexOf(label);
} else
indexes[cnt] = useIndexUnknown ? vocab.indexOf(getUNK()) : -1;
cnt++;
}
while (ArrayUtils.contains(indexes, -1)) {
indexes = ArrayUtils.removeElement(indexes, -1);
}
if (indexes.length == 0) {
return Nd4j.empty(((InMemoryLookupTable)lookupTable).getSyn0().dataType());
}
INDArray result = Nd4j.pullRows(lookupTable.getWeights(), 1, indexes);
return result;
}
/**
* {@inheritDoc} @param values the values
*
* @return the object
*/
@Override public Object execute(Object[] values) {
Object[] parameters = values;
// config via Query annotation (dynamicQuery = false)
DynamicQueryConfig config = staticQueryConfiguration;
// or condition to allow query tunning
if (config == null || dynamicQueryConfigurationIndex != -1) {
DynamicQueryConfig newConfig = (DynamicQueryConfig)values[dynamicQueryConfigurationIndex];
parameters = ArrayUtils.removeElement(parameters, dynamicQueryConfigurationIndex);
if (newConfig != null) {
// upset query configuration
config = newConfig;
}
}
// query configuration is required, via Query annotation or per parameter (within provided values param)
if (config == null) {
throw new IllegalStateException(
"Unable to execute query. When passing dynamicQuery = true via org.apache.ignite.springdata"
+ ".repository.config.Query annotation, you must provide a non null method parameter of type "
+ "DynamicQueryConfig");
}
IgniteQuery qry = getQuery(config);
ReturnStrategy returnStgy = getReturnStgy(qry);
Query iQry = prepareQuery(qry, config, returnStgy, parameters);
QueryCursor qryCursor = cache.query(iQry);
return transformQueryCursor(qry, returnStgy, parameters, qryCursor);
}
/**
* {@inheritDoc} @param values the values
*
* @return the object
*/
@Override public Object execute(Object[] values) {
Object[] parameters = values;
// config via Query annotation (dynamicQuery = false)
DynamicQueryConfig config = staticQueryConfiguration;
// or condition to allow query tunning
if (config == null || dynamicQueryConfigurationIndex != -1) {
DynamicQueryConfig newConfig = (DynamicQueryConfig)values[dynamicQueryConfigurationIndex];
parameters = ArrayUtils.removeElement(parameters, dynamicQueryConfigurationIndex);
if (newConfig != null) {
// upset query configuration
config = newConfig;
}
}
// query configuration is required, via Query annotation or per parameter (within provided values param)
if (config == null) {
throw new IllegalStateException(
"Unable to execute query. When passing dynamicQuery = true via org.apache.ignite.springdata"
+ ".repository.config.Query annotation, you must provide a non null method parameter of type "
+ "DynamicQueryConfig");
}
IgniteQuery qry = getQuery(config);
ReturnStrategy returnStgy = getReturnStgy(qry);
Query iQry = prepareQuery(qry, config, returnStgy, parameters);
QueryCursor qryCursor = cache.query(iQry);
return transformQueryCursor(qry, returnStgy, parameters, qryCursor);
}
private void removeClientSecret(ServiceProvider serviceProvider) {
InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
if (inboundAuthenticationConfig != null) {
InboundAuthenticationRequestConfig[] inboundRequestConfigs = inboundAuthenticationConfig.
getInboundAuthenticationRequestConfigs();
if (inboundRequestConfigs != null) {
for (InboundAuthenticationRequestConfig inboundRequestConfig : inboundRequestConfigs) {
if (inboundRequestConfig.getInboundAuthType().equals(OAUTH2)) {
Property[] props = inboundRequestConfig.getProperties();
for (Property prop : props) {
if (prop.getName().equalsIgnoreCase(OAUTH2_CONSUMER_SECRET)) {
props = (Property[]) ArrayUtils.removeElement(props, prop);
inboundRequestConfig.setProperties(props);
continue; //we are interested only on this property
} else {
//ignore
}
}
continue;// we are interested only on oauth2 config. Only one will be present.
} else {
//ignore
}
}
} else {
//ignore
}
} else {
//nothing to do
}
}
public static void main(String... args) throws Exception {
// Remove all nulls and empty strings from the argument list. This can happen as if the maven command
// starts the service with no permission YAML files.
args = Arrays.stream(args).filter(arg -> !Strings.isNullOrEmpty(arg)).toArray(String[]::new);
// Start cassandra if necessary (cassandra.yaml is provided)
ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar emodb-web-local*.jar");
parser.addArgument("server").required(true).help("server");
parser.addArgument("emo-config").required(true).help("config.yaml - EmoDB's config file");
parser.addArgument("emo-config-ddl").required(true).help("config-ddl.yaml - EmoDB's cassandra schema file");
parser.addArgument("cassandra-yaml").nargs("?").help("cassandra.yaml - Cassandra configuration file to start an" +
" in memory embedded Cassandra.");
parser.addArgument("-z","--zookeeper").dest("zookeeper").action(Arguments.storeTrue()).help("Starts zookeeper");
parser.addArgument("-p","--permissions-yaml").dest("permissions").nargs("*").help("Permissions file(s)");
// Get the path to cassandraYaml or if zookeeper is available
Namespace result = parser.parseArgs(args);
String cassandraYaml = result.getString("cassandra-yaml");
boolean startZk = result.getBoolean("zookeeper");
String emoConfigYaml = result.getString("emo-config");
List<String> permissionsYamls = result.getList("permissions");
String[] emoServiceArgs = args;
// Start ZooKeeper
TestingServer zooKeeperServer = null;
if (startZk) {
zooKeeperServer = isLocalZooKeeperRunning() ? null : startLocalZooKeeper();
emoServiceArgs = (String[]) ArrayUtils.removeElement(args, "-z");
emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, "--zookeeper");
}
boolean success = false;
if (cassandraYaml != null) {
// Replace $DIR$ so we can correctly specify location during runtime
File templateFile = new File(cassandraYaml);
String baseFile = Files.toString(templateFile, Charset.defaultCharset());
// Get the jar location
String path = EmoServiceWithZK.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String parentDir = new File(path).getParent();
String newFile = baseFile.replace("$DATADIR$", new File(parentDir, "data").getAbsolutePath());
newFile = newFile.replace("$COMMITDIR$", new File(parentDir, "commitlog").getAbsolutePath());
newFile = newFile.replace("$CACHEDIR$", new File(parentDir, "saved_caches").getAbsolutePath());
File newYamlFile = new File(templateFile.getParent(), "emo-cassandra.yaml");
Files.write(newFile, newYamlFile, Charset.defaultCharset());
startLocalCassandra(newYamlFile.getAbsolutePath());
emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, cassandraYaml);
}
// If permissions files were configured remove them from the argument list
int permissionsIndex = Math.max(ArrayUtils.indexOf(emoServiceArgs, "-p"), ArrayUtils.indexOf(emoServiceArgs, "--permissions-yaml"));
if (permissionsIndex >= 0) {
int permissionsArgCount = 1 + permissionsYamls.size();
for (int i=0; i < permissionsArgCount; i++) {
emoServiceArgs = (String[]) ArrayUtils.remove(emoServiceArgs, permissionsIndex);
}
}
try {
EmoService.main(emoServiceArgs);
success = true;
setPermissionsFromFiles(permissionsYamls, emoConfigYaml);
} catch (Throwable t) {
t.printStackTrace();
} finally {
// The main web server command returns immediately--don't stop ZooKeeper/Cassandra in that case.
if (zooKeeperServer != null && !(success && args.length > 0 && "server".equals(args[0]))) {
zooKeeperServer.stop();
service.shutdown();
}
}
}
private XmlReader createNextReader(int removeIndex) {
return new ItemReader(ArrayUtils.removeElement(unselectedIndexes, removeIndex));
}