Skip to content

Commit

Permalink
Fixed incorrect docs PersistentPropertyPath and optimized sublist
Browse files Browse the repository at this point in the history
  • Loading branch information
mipo256 committed Mar 28, 2023
1 parent 6328b4c commit d9a14b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends

/**
* Returns the dot based path notation using {@link PersistentProperty#getName()}.
*
* @return
*/
@Nullable
String toDotPath();
Expand All @@ -40,7 +38,6 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
* {@link PersistentProperty}s to path segments.
*
* @param converter must not be {@literal null}.
* @return
*/
@Nullable
String toDotPath(Converter<? super P, String> converter);
Expand All @@ -49,7 +46,6 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
* Returns a {@link String} path with the given delimiter based on the {@link PersistentProperty#getName()}.
*
* @param delimiter must not be {@literal null}.
* @return
*/
@Nullable
String toPath(String delimiter);
Expand All @@ -60,7 +56,6 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
*
* @param delimiter must not be {@literal null}.
* @param converter must not be {@literal null}.
* @return
*/
@Nullable
String toPath(String delimiter, Converter<? super P, String> converter);
Expand All @@ -70,7 +65,6 @@ public interface PersistentPropertyPath<P extends PersistentProperty<P>> extends
* {@link PersistentProperty} for {@code bar}. For a simple {@code foo} it returns {@link PersistentProperty} for
* {@code foo}.
*
* @return
*/
@Nullable
P getLeafProperty();
Expand All @@ -90,44 +84,36 @@ default P getRequiredLeafProperty() {
* Returns the first property in the {@link PersistentPropertyPath}. So for {@code foo.bar} it will return the
* {@link PersistentProperty} for {@code foo}. For a simple {@code foo} it returns {@link PersistentProperty} for
* {@code foo}.
*
* @return
*/
@Nullable
P getBaseProperty();

/**
* Returns whether the given {@link PersistentPropertyPath} is a base path of the current one. This means that the
* current {@link PersistentPropertyPath} is basically an extension of the given one.
* given {@link PersistentPropertyPath} is basically an extension of this {@link PersistentPropertyPath}.
*
* @param path must not be {@literal null}.
* @return
*/
boolean isBasePathOf(PersistentPropertyPath<P> path);

/**
* Returns the sub-path of the current one as if it was based on the given base path. So for a current path
* {@code foo.bar} and a given base {@code foo} it would return {@code bar}. If the given path is not a base of the
* the current one the current {@link PersistentPropertyPath} will be returned as is.
* current one the current {@link PersistentPropertyPath} will be returned as is.
*
* @param base must not be {@literal null}.
* @return
*/
PersistentPropertyPath<P> getExtensionForBaseOf(PersistentPropertyPath<P> base);

/**
* Returns the parent path of the current {@link PersistentPropertyPath}, i.e. the path without the leaf property.
* This happens up to the base property. So for a direct property reference calling this method will result in
* returning the property.
*
* @return
*/
PersistentPropertyPath<P> getParentPath();

/**
* Returns the length of the {@link PersistentPropertyPath}.
*
* @return
*/
int getLength();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements PersistentPropertyPath<P> {

private static final Converter<PersistentProperty<?>, String> DEFAULT_CONVERTER = (source) -> source.getName();
private static final Converter<PersistentProperty<?>, String> DEFAULT_CONVERTER = PersistentProperty::getName;
private static final String DEFAULT_DELIMITER = ".";

private final List<P> properties;
Expand Down Expand Up @@ -158,18 +158,7 @@ public PersistentPropertyPath<P> getExtensionForBaseOf(PersistentPropertyPath<P>
return this;
}

List<P> result = new ArrayList<>();
Iterator<P> iterator = iterator();

for (int i = 0; i < base.getLength(); i++) {
iterator.next();
}

while (iterator.hasNext()) {
result.add(iterator.next());
}

return new DefaultPersistentPropertyPath<>(result);
return new DefaultPersistentPropertyPath<>(properties.subList(base.getLength(), properties.size()));
}

public PersistentPropertyPath<P> getParentPath() {
Expand Down

0 comments on commit d9a14b0

Please sign in to comment.