@Test public void testDefaultGroupingFilter() { final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME); final StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(groupingRule); settings.addRule(rule); final StdArrangementSettings defaultSettings = new StdArrangementSettings(); defaultSettings.addGrouping(groupingRule); final Element holder = doSerializationTest(settings, defaultSettings); assertTrue(holder.getChildren().size() == 1); assertNull(holder.getChild("groups")); assertNotNull(holder.getChild("rules")); }
@Test public void testDefaultRulesFilter() { final ArrangementGroupingRule groupingRule = new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME); final StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(groupingRule); settings.addRule(rule); final StdArrangementSettings defaultSettings = new StdArrangementSettings(); defaultSettings.addRule(rule); final Element holder = doSerializationTest(settings, defaultSettings); assertTrue(holder.getChildren().size() == 1); assertNotNull(holder.getChild("groups")); assertNull(holder.getChild("rules")); }
@Test public void testEmptyRules() throws Exception { final StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); final StdArrangementSettings defaultSettings = new StdArrangementSettings(); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); final StdArrangementMatchRule rule = new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME); defaultSettings.addRule(rule); final Element holder = doSerializationTest(settings, defaultSettings); assertTrue(holder.getChildren().size() == 2); final Element rules = holder.getChild("rules"); assertNotNull(rules); assertTrue(rules.getChildren().isEmpty()); }
public void appendExpandedRules(@NotNull final StdArrangementMatchRule rule, @NotNull final List<StdArrangementMatchRule> rules, @NotNull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) { final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition); if (sequence == null || sequence.isEmpty()) { rules.add(rule); return; } final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition()); for (StdArrangementMatchRule matchRule : sequence) { final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone(); extendedRule.addOperand(matchRule.getMatcher().getCondition()); rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule))); } }
public void appendExpandedRules(@Nonnull final StdArrangementMatchRule rule, @Nonnull final List<StdArrangementMatchRule> rules, @Nonnull final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition) { final List<StdArrangementMatchRule> sequence = getRuleSequence(rule, tokenIdToDefinition); if (sequence == null || sequence.isEmpty()) { rules.add(rule); return; } final ArrangementCompositeMatchCondition ruleTemplate = removeAliasRuleToken(rule.getMatcher().getCondition()); for (StdArrangementMatchRule matchRule : sequence) { final ArrangementCompositeMatchCondition extendedRule = ruleTemplate.clone(); extendedRule.addOperand(matchRule.getMatcher().getCondition()); rules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(extendedRule))); } }
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) { if(conditions.length == 1) { matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition(conditions[0], conditions[0])))); return; } ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition(); for(ArrangementSettingsToken condition : conditions) { composite.addOperand(new ArrangementAtomMatchCondition(condition, condition)); } matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite))); }
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) { if (conditions.length == 1) { matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition( conditions[0] )))); return; } ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition(); for (ArrangementSettingsToken condition : conditions) { composite.addOperand(new ArrangementAtomMatchCondition(condition)); } matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite))); }
@NotNull protected static StdArrangementMatchRule nameRule(@NotNull String nameFilter, @NotNull ArrangementSettingsToken... tokens) { if (tokens.length == 0) { return new StdArrangementMatchRule(new StdArrangementEntryMatcher(atom(nameFilter))); } else { ArrangementAtomMatchCondition[] conditions = new ArrangementAtomMatchCondition[tokens.length + 1]; conditions[0] = atom(nameFilter); for (int i = 0; i < tokens.length; i++) conditions[i + 1] = atom(tokens[i]); ArrangementMatchCondition compositeCondition = ArrangementUtil.combine(conditions); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(compositeCondition)); } }
private static StdArrangementMatchRule rule(boolean byName, @NotNull ArrangementSettingsToken... tokens) { final List<ArrangementAtomMatchCondition> conditions = new ArrayList<ArrangementAtomMatchCondition>(); for (ArrangementSettingsToken token : tokens) { conditions.add(new ArrangementAtomMatchCondition(token)); } final StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(new ArrangementCompositeMatchCondition(conditions)); return byName ? new StdArrangementMatchRule(matcher, BY_NAME) : new StdArrangementMatchRule(matcher); }
@Test public void all() { final StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); doSerializationTest(settings, new StdArrangementSettings()); }
@Test public void testDefaultFilter() { final StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); final Element holder = doSerializationTest(settings, settings); assertTrue(holder.getChildren().isEmpty()); }
@Test public void testEmptyGroupings() throws Exception { final StdArrangementSettings settings = new StdArrangementSettings(); final ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); final StdArrangementSettings defaultSettings = new StdArrangementSettings(); defaultSettings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); final Element holder = doSerializationTest(settings, defaultSettings); assertTrue(holder.getChildren().size() == 2); final Element groups = holder.getChild("groups"); assertNotNull(groups); assertTrue(groups.getChildren().isEmpty()); }
@NotNull public StdArrangementMatchRule createDefaultSectionRule() { final ArrangementAtomMatchCondition type = new ArrangementAtomMatchCondition(START_SECTION); final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(TEXT, createDefaultSectionText()); final ArrangementMatchCondition condition = ArrangementUtil.combine(type, text); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition)); }
@NotNull public static StdArrangementMatchRule attrArrangementRule(@NotNull String nameFilter, @NotNull String namespaceFilter, @NotNull ArrangementSettingsToken orderType) { return new StdArrangementMatchRule(new StdArrangementEntryMatcher(ArrangementUtil.combine( new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.NAME, nameFilter), new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, namespaceFilter) )), orderType); }
private static void and(@NotNull List<StdArrangementMatchRule> matchRules, @NotNull ArrangementSettingsToken... conditions) { if (conditions.length == 1) { matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementAtomMatchCondition( conditions[0], conditions[0] )))); return; } ArrangementCompositeMatchCondition composite = new ArrangementCompositeMatchCondition(); for (ArrangementSettingsToken condition : conditions) { composite.addOperand(new ArrangementAtomMatchCondition(condition, condition)); } matchRules.add(new StdArrangementMatchRule(new StdArrangementEntryMatcher(composite))); }
@Test public void all() { StdArrangementSettings settings = new StdRulePriorityAwareSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); Element holder = new Element("holder"); ArrangementSettingsSerializer instance = DefaultArrangementSettingsSerializer.INSTANCE; instance.serialize(settings, holder); ArrangementSettings restored = instance.deserialize(holder); assertEquals(settings, restored); }
@Test public void all() { StdArrangementSettings settings = new StdArrangementSettings(); settings.addGrouping(new ArrangementGroupingRule(OVERRIDDEN_METHODS, BY_NAME)); ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); settings.addRule(new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition), BY_NAME)); Element holder = new Element("holder"); ArrangementSettingsSerializer instance = new DefaultArrangementSettingsSerializer(settings); instance.serialize(settings, holder); ArrangementSettings restored = instance.deserialize(holder); assertEquals(settings, restored); }
@Nonnull public StdArrangementMatchRule createDefaultSectionRule() { final ArrangementAtomMatchCondition type = new ArrangementAtomMatchCondition(START_SECTION); final ArrangementAtomMatchCondition text = new ArrangementAtomMatchCondition(TEXT, createDefaultSectionText()); final ArrangementMatchCondition condition = ArrangementUtil.combine(type, text); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(condition)); }
@NotNull public static StdArrangementMatchRule attrArrangementRule( @NotNull String nameFilter, @NotNull String namespaceFilter, @NotNull ArrangementSettingsToken orderType) { return new StdArrangementMatchRule(new StdArrangementEntryMatcher(ArrangementUtil.combine(new ArrangementAtomMatchCondition (StdArrangementTokens.Regexp.NAME, nameFilter), new ArrangementAtomMatchCondition(StdArrangementTokens.Regexp.XML_NAMESPACE, namespaceFilter))), orderType); }
@NotNull protected static StdArrangementMatchRule rule(@NotNull ArrangementSettingsToken token) { return new StdArrangementMatchRule(new StdArrangementEntryMatcher(atom(token))); }
@NotNull protected static StdArrangementMatchRule rule(@NotNull ArrangementAtomMatchCondition... conditions) { ArrangementMatchCondition compositeCondition = ArrangementUtil.combine(conditions); return new StdArrangementMatchRule(new StdArrangementEntryMatcher(compositeCondition)); }