-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: organize stub package contents
- Loading branch information
1 parent
1862731
commit e162a00
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
third_party/docfx-doclet-143274/src/main/java/com/microsoft/model/StubPackageToc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.microsoft.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
public class StubPackageToc { | ||
static final String STUBS = "Stubs"; | ||
static final String SETTINGS = "Settings"; | ||
static final String CALLABLE_FACTORIES = "Callable factories"; | ||
static final String UNCATEGORIZED = "Other"; | ||
|
||
private final LinkedHashMap<String, List<TocItem>> visibleCategories = new LinkedHashMap<>(); | ||
|
||
public StubPackageToc() { | ||
// Order here determines final organization order. | ||
visibleCategories.put(STUBS, new ArrayList<>()); | ||
visibleCategories.put(SETTINGS, new ArrayList<>()); | ||
visibleCategories.put(CALLABLE_FACTORIES, new ArrayList<>()); | ||
} | ||
|
||
public void addStub(TocItem tocItem) { | ||
visibleCategories.get(STUBS).add(tocItem); | ||
} | ||
|
||
public void addSettings(TocItem tocItem) { | ||
visibleCategories.get(SETTINGS).add(tocItem); | ||
} | ||
|
||
public void addCallableFactory(TocItem tocItem) { | ||
visibleCategories.get(CALLABLE_FACTORIES).add(tocItem); | ||
} | ||
|
||
public void addUncategorized(TocItem tocItem) { | ||
visibleCategories.get(UNCATEGORIZED).add(tocItem); | ||
} | ||
|
||
/** Build a list of TocItems for inclusion in the library's table of contents */ | ||
public List<TocItem> toList() { | ||
List<TocItem> toc = new ArrayList<>(); | ||
|
||
visibleCategories.forEach( | ||
(name, category) -> { | ||
if (!category.isEmpty()) { | ||
toc.add(createCategory(name, category)); | ||
} | ||
}); | ||
|
||
return toc; | ||
} | ||
|
||
private TocItem createCategory(String name, List<TocItem> items) { | ||
TocItem category = new TocItem(name, name, null); | ||
items.sort(Comparator.comparing(TocItem::getName)); | ||
category.getItems().addAll(items); | ||
return category; | ||
} | ||
} |