Skip to content

Commit eb4d9b5

Browse files
committed
Move Fix methods to individual classes.
Finalizing the refactoring.
1 parent 5ffef14 commit eb4d9b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2713
-514
lines changed

README.md

Lines changed: 66 additions & 66 deletions
Large diffs are not rendered by default.

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 59 additions & 445 deletions
Large diffs are not rendered by default.

metafix/src/main/java/org/metafacture/metafix/Metafix.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,14 @@ public void literal(final String name, final String value) {
190190
vars.putAll(newVars);
191191
}
192192

193-
/*package-private*/ static boolean isFixFile(final String fixDef) {
193+
/**
194+
* Checks whether the given Fix definition indicates a Fix file.
195+
*
196+
* @param fixDef the Fix definition
197+
*
198+
* @return true if the given Fix definition indicates a Fix file
199+
*/
200+
public static boolean isFixFile(final String fixDef) {
194201
return fixDef.endsWith(FIX_EXTENSION);
195202
}
196203

metafix/src/main/java/org/metafacture/metafix/Value.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,14 @@ public String getPath() {
422422
return path;
423423
}
424424

425-
/*package-private*/ Value withPathSet(final String p) {
425+
/**
426+
* Sets the value's path.
427+
*
428+
* @param p the path
429+
*
430+
* @return the Value
431+
*/
432+
public Value withPathSet(final String p) {
426433
this.path = p;
427434
return this;
428435
}

metafix/src/main/java/org/metafacture/metafix/api/FixFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
@FunctionalInterface
3737
public interface FixFunction {
3838

39+
String DEFAULT_OPTION = "default";
40+
String ERROR_STRING_OPTION = "error_string";
41+
3942
/**
4043
* Applies the Fix function.
4144
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2025 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix.method.field;
18+
19+
import org.metafacture.metafix.Metafix;
20+
import org.metafacture.metafix.Record;
21+
import org.metafacture.metafix.api.FixFunction;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
public class Append implements FixFunction {
27+
28+
/**
29+
* Creates an instance of {@link Append}.
30+
*/
31+
public Append() {
32+
}
33+
34+
@Override
35+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
36+
final String value = params.get(1);
37+
record.transform(params.get(0), s -> s + value);
38+
}
39+
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix.method.field;
18+
19+
import org.metafacture.metafix.Metafix;
20+
import org.metafacture.metafix.Record;
21+
import org.metafacture.metafix.api.FixFunction;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
public class Capitalize implements FixFunction {
27+
28+
/**
29+
* Creates an instance of {@link Capitalize}.
30+
*/
31+
public Capitalize() {
32+
}
33+
34+
@Override
35+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
36+
record.transform(params.get(0), s -> s.substring(0, 1).toUpperCase() + s.substring(1));
37+
}
38+
39+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix.method.field;
18+
19+
import org.metafacture.metafix.Metafix;
20+
import org.metafacture.metafix.Record;
21+
import org.metafacture.metafix.Value;
22+
import org.metafacture.metafix.api.FixFunction;
23+
24+
import java.util.List;
25+
import java.util.Map;
26+
27+
public class Count implements FixFunction {
28+
29+
/**
30+
* Creates an instance of {@link Count}.
31+
*/
32+
public Count() {
33+
}
34+
35+
@Override
36+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
37+
record.transform(params.get(0), (m, c) -> m
38+
.ifArray(a -> c.accept(new Value(a.size())))
39+
.ifHash(h -> c.accept(new Value(h.size())))
40+
);
41+
}
42+
43+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix.method.field;
18+
19+
import org.metafacture.metafix.Metafix;
20+
import org.metafacture.metafix.Record;
21+
import org.metafacture.metafix.api.FixFunction;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
public class Downcase implements FixFunction {
27+
28+
/**
29+
* Creates an instance of {@link Downcase}.
30+
*/
31+
public Downcase() {
32+
}
33+
34+
@Override
35+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
36+
record.transform(params.get(0), s -> s.toLowerCase());
37+
}
38+
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix.method.field;
18+
19+
import org.metafacture.metafix.Metafix;
20+
import org.metafacture.metafix.Record;
21+
import org.metafacture.metafix.Value;
22+
import org.metafacture.metafix.api.FixFunction;
23+
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.function.Predicate;
27+
import java.util.regex.Pattern;
28+
29+
public class Filter implements FixFunction {
30+
31+
/**
32+
* Creates an instance of {@link Filter}.
33+
*/
34+
public Filter() {
35+
}
36+
37+
@Override
38+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
39+
final Pattern search = Pattern.compile(params.get(1));
40+
final boolean invert = getBoolean(options, "invert");
41+
42+
final Predicate<Value> predicate = s -> search.matcher(s.asString()).find();
43+
44+
record.transform(params.get(0), (m, c) -> m
45+
.ifArray(a -> c.accept(newArray(a.stream().filter(invert ? predicate.negate() : predicate))))
46+
);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)