use of java.util.ArrayList in project blade by biezhi.
the class ConstraintSecurityHandler method createConstraintsWithMappingsForPath.
/* ------------------------------------------------------------ */
/**
* Generate Constraints and ContraintMappings for the given url pattern and ServletSecurityElement
*
* @param name the name
* @param pathSpec the path spec
* @param securityElement the servlet security element
* @return the list of constraint mappings
*/
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement) {
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
//Create a constraint that will describe the default case (ie if not overridden by specific HttpMethodConstraints)
Constraint httpConstraint = null;
ConstraintMapping httpConstraintMapping = null;
if (securityElement.getEmptyRoleSemantic() != EmptyRoleSemantic.PERMIT || securityElement.getRolesAllowed().length != 0 || securityElement.getTransportGuarantee() != TransportGuarantee.NONE) {
httpConstraint = ConstraintSecurityHandler.createConstraint(name, securityElement);
//Create a mapping for the pathSpec for the default case
httpConstraintMapping = new ConstraintMapping();
httpConstraintMapping.setPathSpec(pathSpec);
httpConstraintMapping.setConstraint(httpConstraint);
mappings.add(httpConstraintMapping);
}
//See Spec 13.4.1.2 p127
List<String> methodOmissions = new ArrayList<String>();
//make constraint mappings for this url for each of the HttpMethodConstraintElements
Collection<HttpMethodConstraintElement> methodConstraintElements = securityElement.getHttpMethodConstraints();
if (methodConstraintElements != null) {
for (HttpMethodConstraintElement methodConstraintElement : methodConstraintElements) {
//Make a Constraint that captures the <auth-constraint> and <user-data-constraint> elements supplied for the HttpMethodConstraintElement
Constraint methodConstraint = ConstraintSecurityHandler.createConstraint(name, methodConstraintElement);
ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(methodConstraint);
mapping.setPathSpec(pathSpec);
if (methodConstraintElement.getMethodName() != null) {
mapping.setMethod(methodConstraintElement.getMethodName());
//See spec 13.4.1.2 p127 - add an omission for every method name to the default constraint
methodOmissions.add(methodConstraintElement.getMethodName());
}
mappings.add(mapping);
}
}
//UNLESS the default constraint contains all default values. In that case, we won't add it. See Servlet Spec 3.1 pg 129
if (methodOmissions.size() > 0 && httpConstraintMapping != null)
httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[methodOmissions.size()]));
return mappings;
}
use of java.util.ArrayList in project blade by biezhi.
the class HashLoginService method loadRoleInfo.
/* ------------------------------------------------------------ */
@Override
protected String[] loadRoleInfo(UserPrincipal user) {
UserIdentity id = _propertyUserStore.getUserIdentity(user.getName());
if (id == null)
return null;
Set<RolePrincipal> roles = id.getSubject().getPrincipals(RolePrincipal.class);
if (roles == null)
return null;
List<String> list = new ArrayList<>();
for (RolePrincipal r : roles) list.add(r.getName());
return list.toArray(new String[roles.size()]);
}
use of java.util.ArrayList in project blade by biezhi.
the class AbstractFileRouteLoader method load.
/**
* Load Route
*
* @param inputStream route inputstream
* @return return route list
* @throws ParseException parse exception
* @throws IOException io exception
*/
private List<Route> load(InputStream inputStream) throws ParseException, IOException {
int line = 0;
List<Route> routes = new ArrayList<Route>();
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(inputStream));
String input;
while ((input = in.readLine()) != null) {
line++;
input = input.trim();
if (!input.equals("") && !input.startsWith(".")) {
Route route = parse(input, line);
routes.add(route);
}
}
} finally {
IOKit.closeQuietly(in);
}
return routes;
}
use of java.util.ArrayList in project kata-tcg by bkimminich.
the class AiStrategy method collectMaxDamageCardCombo.
private void collectMaxDamageCardCombo(List<Card> selectedCards, int availableMana, List<Card> availableCards) {
for (Card card : availableCards) {
List<Card> remainingCards = new ArrayList<>(availableCards);
if (selectedCards.stream().mapToInt(Card::getValue).sum() + card.getValue() <= availableMana) {
selectedCards.add(card);
remainingCards.remove(card);
collectMaxDamageCardCombo(selectedCards, availableMana - card.getValue(), remainingCards);
}
}
}
use of java.util.ArrayList in project Japid by branaway.
the class JavaSyntaxTool method parseParams.
/**
* parse a line of text that is supposed to be parameter list for a method
* declaration.
*
* TODO: the parameter annotation, modifiers, etc ignored. should do it!
*
* @param line
* @return
*/
public static List<Parameter> parseParams(String line) {
final List<Parameter> ret = new ArrayList<Parameter>();
if (line == null || line.trim().length() == 0)
return ret;
// make it tolerant of lowercase default
line = line.replace("@default(", "@Default(");
String cl = String.format(classTempForParams, line);
try {
CompilationUnit cu = parse(cl);
VoidVisitorAdapter visitor = new VoidVisitorAdapter() {
@Override
public void visit(Parameter p, Object arg) {
ret.add(p);
}
};
cu.accept(visitor, null);
} catch (ParseException e) {
throw new RuntimeException("the line does not seem to be a valid param list declaration: " + line);
}
return ret;
}
Aggregations