Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.model.groups

public Class GroupTreeNode

extends TreeNode<GroupTreeNode>
Class Inheritance
Imports
java.util.ArrayList, .Collection, .IdentityHashMap, .List, .Objects, .Optional, java.util.stream.Collectors, javafx.beans.property.ObjectProperty, .SimpleObjectProperty, org.jabref.model.FieldChange, .TreeNode, org.jabref.model.database.BibDatabase, org.jabref.model.entry.BibEntry, org.jabref.model.search.SearchMatcher, org.jabref.model.search.matchers.MatcherSet, .MatcherSets, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

A node in the groups tree that holds exactly one AbstractGroup.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ObjectProperty<AbstractGroup>
private static final Logger
public static final String

Constructor Summary

AccessConstructor and Description
public
GroupTreeNode(AbstractGroup
the group underlying this node
group
)

Creates this node and associates the specified group with it.

Method Summary

Modifier and TypeMethod and Description
public List<FieldChange>
addEntriesToGroup(Collection<BibEntry> entries)

Adds the specified entries to this group.

public GroupTreeNode
private void
public boolean
public GroupTreeNode
copyNode()

Implements abstract org.jabref.model.TreeNode.copyNode.

Creates a copy of this node, completely separated from the tree (i.e. no children and no parent)

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Optional<GroupTreeNode>
findGroupByName(String name)

Returns the existing group with the given name from the subtree starting at this node, if any.

public List<BibEntry>

Returns:

matched entries
findMatches
(List<BibEntry>
list of entries to be searched
entries
)

Determines the entries in the specified list which are matched by this group.

public List<BibEntry>

Returns:

matched entries
findMatches
(BibDatabase
database to be searched
database
)

Determines the entries in the specified database which are matched by this group.

public GroupTreeNode
findOrCreateExplicitGroup(String name, Character keywordSeparator)

Returns the existing group with the given name from the subtree starting at this node, or creates it as a top-level ExplicitGroup (direct subgroup of this node) using the given keyword separator if no such group exists.

public static GroupTreeNode
public Optional<GroupTreeNode>
getChildByPath(String pathToSource)

Finds a children using the given path.

public List<GroupTreeNode>

Returns:

List of GroupTreeNode containing the matches. AllEntriesGroup is always contained
getContainingGroups
(List<BibEntry>
List of BibEntry to search for
entries
,
boolean
Whether to return only groups that must contain all entries
requireAll
)

Get only groups containing all the entries or just groups containing any of the

public List<BibEntry>
public AbstractGroup

Returns:

the group associated with this node
getGroup
()

Returns the group underlying this node.

public ObjectProperty<AbstractGroup>
public List<GroupTreeNode>
getMatchingGroups(BibEntry entry)

Determines all groups in the subtree starting at this node which contain the given entry.

public List<GroupTreeNode>
getMatchingGroups(List<BibEntry> entries)

Determines all groups in the subtree starting at this node which contain at least one of the given entries.

public String

Returns:

String the name of the group
getName
()

Get the name of the underlying group

public String
getPath()

Get the path from the root of the tree as a string (every group name is separated by PATH_DELIMITER).

public SearchMatcher
getSearchMatcher()

Creates a SearchMatcher that matches entries of this group and that takes the hierarchical information into account.

private SearchMatcher
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
matches(BibEntry entry)

Returns whether this group matches the specified BibEntry while taking the hierarchical information into account.

private boolean
public List<FieldChange>
removeEntriesFromGroup(List<BibEntry> entries)

Removes the given entries from this group.

public void
setGroup(@NonNull AbstractGroup
the new group (has to be non-null)
newGroup
)

Associates the specified group with this node.

public List<FieldChange>
setGroup(@NonNull AbstractGroup
the new group (has to be non-null)
newGroup
,
boolean
specifies whether previous matched entries should be added to the new group
shouldKeepPreviousAssignments
,
boolean
specifies whether previous matched entries should be removed from the old group
shouldRemovePreviousAssignments
,
List<BibEntry>
list of entries in the database
entriesInDatabase
)

Associates the specified group with this node while also providing the possibility to modify previous matched entries so that they are now matched by the new group.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.jabref.model.TreeNode:
addChildaddChildchildIndexExistscopySubtreefindChildrenSatisfyinggetChildAtgetChildrengetChildrenInternalgetDescendantgetFirstChildgetIndexedPathFromRootgetIndexOfChildgetLastChildgetLevelgetNextSiblinggetNumberOfChildrengetParentgetPathFromRootgetPositionInParentgetPreviousSiblinggetRootisAncestorOfisLeafisNodeDescendantisRootiterateOverTreemoveAllChildrenTomoveTomoveTonotifyAboutDescendantChangeremoveAllChildrenremoveChildremoveChildremoveFromParentsetParentsortChildrensubscribeToDescendantChanged

Field Detail

groupPropertyback to summary
private final ObjectProperty<AbstractGroup> groupProperty
LOGGERback to summary
private static final Logger LOGGER
PATH_DELIMITERback to summary
public static final String PATH_DELIMITER

Constructor Detail

GroupTreeNodeback to summary
public GroupTreeNode(AbstractGroup group)

Creates this node and associates the specified group with it.

Parameters
group:AbstractGroup

the group underlying this node

Method Detail

addEntriesToGroupback to summary
public List<FieldChange> addEntriesToGroup(Collection<BibEntry> entries)

Adds the specified entries to this group. If the group does not support explicit adding of entries (i.e., does not implement GroupEntryChanger), then no action is performed.

addSubgroupback to summary
public GroupTreeNode addSubgroup(AbstractGroup subgroup)
collectMatchingGroupsback to summary
private void collectMatchingGroups(List<BibEntry> entries, List<GroupTreeNode> groups, IdentityHashMap<BibEntry, IdentityHashMap<GroupTreeNode, GroupTreeNode.MatchCache>> matchCaches)
containsGroupback to summary
public boolean containsGroup(AbstractGroup other)
copyNodeback to summary
public GroupTreeNode copyNode()

Implements abstract org.jabref.model.TreeNode.copyNode.

Doc from org.jabref.model.TreeNode.copyNode.

Creates a copy of this node, completely separated from the tree (i.e. no children and no parent)

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
findGroupByNameback to summary
public Optional<GroupTreeNode> findGroupByName(String name)

Returns the existing group with the given name from the subtree starting at this node, if any. The receiving node itself is excluded from the search (it is usually the synthetic "All entries" root).

Group names are unique within a library, so the name identifies the group anywhere in the tree.

findMatchesback to summary
public List<BibEntry> findMatches(List<BibEntry> entries)

Determines the entries in the specified list which are matched by this group.

Parameters
entries:List<BibEntry>

list of entries to be searched

Returns:List<BibEntry>

matched entries

findMatchesback to summary
public List<BibEntry> findMatches(BibDatabase database)

Determines the entries in the specified database which are matched by this group.

Parameters
database:BibDatabase

database to be searched

Returns:List<BibEntry>

matched entries

findOrCreateExplicitGroupback to summary
public GroupTreeNode findOrCreateExplicitGroup(String name, Character keywordSeparator)

Returns the existing group with the given name from the subtree starting at this node, or creates it as a top-level ExplicitGroup (direct subgroup of this node) using the given keyword separator if no such group exists.

Note

the created group is attached to the tree immediately. Callers that need to assign entries to a freshly created group should instead use findGroupByName and create the node themselves, so that the entries can be assigned BEFORE the node is attached - see org.jabref.logic.groups.GroupsHelper#assignEntriesToGroup.

fromGroupback to summary
public static GroupTreeNode fromGroup(AbstractGroup group)
getChildByPathback to summary
public Optional<GroupTreeNode> getChildByPath(String pathToSource)

Finds a children using the given path. Each group name should be separated by PATH_DELIMITER.

The path should be generated using getPath().

getContainingGroupsback to summary
public List<GroupTreeNode> getContainingGroups(List<BibEntry> entries, boolean requireAll)

Get only groups containing all the entries or just groups containing any of the

Parameters
entries:List<BibEntry>

List of BibEntry to search for

requireAll:boolean

Whether to return only groups that must contain all entries

Returns:List<GroupTreeNode>

List of GroupTreeNode containing the matches. AllEntriesGroup is always contained

getEntriesInGroupback to summary
public List<BibEntry> getEntriesInGroup(List<BibEntry> entries)
getGroupback to summary
public AbstractGroup getGroup()

Returns the group underlying this node.

Returns:AbstractGroup

the group associated with this node

getGroupPropertyback to summary
public ObjectProperty<AbstractGroup> getGroupProperty()
getMatchingGroupsback to summary
public List<GroupTreeNode> getMatchingGroups(BibEntry entry)

Determines all groups in the subtree starting at this node which contain the given entry.

getMatchingGroupsback to summary
public List<GroupTreeNode> getMatchingGroups(List<BibEntry> entries)

Determines all groups in the subtree starting at this node which contain at least one of the given entries.

getNameback to summary
public String getName()

Get the name of the underlying group

Returns:String

String the name of the group

getPathback to summary
public String getPath()

Get the path from the root of the tree as a string (every group name is separated by PATH_DELIMITER).

The name of the root is not included.

getSearchMatcherback to summary
public SearchMatcher getSearchMatcher()

Creates a SearchMatcher that matches entries of this group and that takes the hierarchical information into account. I.e., it finds elements contained in this nodes group, or the union of those elements in its own group and its children's groups (recursively), or the intersection of the elements in its own group and its parent's group (depending on the hierarchical settings stored in the involved groups)

getSearchMatcherback to summary
private SearchMatcher getSearchMatcher(GroupHierarchyType originalContext)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
matchesback to summary
public boolean matches(BibEntry entry)

Returns whether this group matches the specified BibEntry while taking the hierarchical information into account.

matchesback to summary
private boolean matches(BibEntry entry, GroupHierarchyType originalContext, @Nullable IdentityHashMap<GroupTreeNode, GroupTreeNode.MatchCache> cache)
removeEntriesFromGroupback to summary
public List<FieldChange> removeEntriesFromGroup(List<BibEntry> entries)

Removes the given entries from this group. If the group does not support the explicit removal of entries (i.e., does not implement GroupEntryChanger), then no action is performed.

setGroupback to summary
public void setGroup(@NonNull AbstractGroup newGroup)

Associates the specified group with this node.

Parameters
newGroup:@NonNull AbstractGroup

the new group (has to be non-null)

setGroupback to summary
public List<FieldChange> setGroup(@NonNull AbstractGroup newGroup, boolean shouldKeepPreviousAssignments, boolean shouldRemovePreviousAssignments, List<BibEntry> entriesInDatabase)

Associates the specified group with this node while also providing the possibility to modify previous matched entries so that they are now matched by the new group.

Parameters
newGroup:@NonNull AbstractGroup

the new group (has to be non-null)

shouldKeepPreviousAssignments:boolean

specifies whether previous matched entries should be added to the new group

shouldRemovePreviousAssignments:boolean

specifies whether previous matched entries should be removed from the old group

entriesInDatabase:List<BibEntry>

list of entries in the database

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.jabref.model.groups back to summary

private final Class GroupTreeNode.MatchCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
pack-priv boolean
pack-priv boolean
pack-priv void
put(GroupHierarchyType context, boolean value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

knownMaskback to summary
private int knownMask
trueMaskback to summary
private int trueMask

Constructor Detail

MatchCacheback to summary
private MatchCache()

Method Detail

bitback to summary
private static int bit(GroupHierarchyType context)
getback to summary
pack-priv boolean get(GroupHierarchyType context)
hasValueback to summary
pack-priv boolean hasValue(GroupHierarchyType context)
putback to summary
pack-priv void put(GroupHierarchyType context, boolean value)