@Test public void formatName() throws IOException { PathPrune pathPrune = Configs.decodeObject(PathPrune.class, "nameFormat = YYMMDD"); DataTreeNode node = Mockito.mock(DataTreeNode.class); when(node.getName()).thenReturn("140101"); long expectedTime = DateTimeFormat.forPattern("YYMMDD").parseMillis("140101"); assertEquals(expectedTime, pathPrune.getNodeTime(node)); }
@VisibleForTesting long getNodeTime(DataTreeNode treeNode) { if ((excludes != null) && (excludes.contains(treeNode.getName()))) { return -1; } if (nameFormat != null) { return nameFormat.parseMillis(treeNode.getName()); } else { DataTime dt = (DataTime) treeNode.getData(timePropKey); if (dt == null) { if (ignoreMissingTimeProp) { return -1; } throw new RuntimeException("missing time attachment with key " + timePropKey); } else { return dt.last(); } } }
PathPrune extends PathElement { @VisibleForTesting long getNodeTime(DataTreeNode treeNode) { if ((excludes != null) && (excludes.contains(treeNode.getName()))) { return -1; } if (nameFormat != null) { return nameFormat.parseMillis(treeNode.getName()); } else { DataTime dt = (DataTime) treeNode.getData(timePropKey); if (dt == null) { if (ignoreMissingTimeProp) { return -1; } throw new RuntimeException("missing time attachment with key " + timePropKey); } else { return dt.last(); } } } }
PathPrune extends PathElement { @VisibleForTesting long getNodeTime(DataTreeNode treeNode) { if ((excludes != null) && (excludes.contains(treeNode.getName()))) { return -1; } if (nameFormat != null) { return nameFormat.parseMillis(treeNode.getName()); } else { DataTime dt = (DataTime) treeNode.getData(timePropKey); if (dt == null) { if (ignoreMissingTimeProp) { return -1; } throw new RuntimeException("missing time attachment with key " + timePropKey); } else { return dt.last(); } } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); }
PathPrune extends PathElement { @VisibleForTesting long getNodeTime(DataTreeNode treeNode) { if ((excludes != null) && (excludes.contains(treeNode.getName()))) { return -1; } if (nameFormat != null) { return nameFormat.parseMillis(treeNode.getName()); } else { DataTime dt = (DataTime) treeNode.getData(timePropKey); if (dt == null) { if (ignoreMissingTimeProp) { return -1; } throw new RuntimeException("missing time attachment with key " + timePropKey); } else { return dt.last(); } } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); @Override List<DataTreeNode> getNextNodeList(final TreeMapState state); void findAndPruneChildren(final TreeMapState state,
                                     final DataTreeNode root,
                                     long now,
                                     int depth,
                                     List<String> treePaths); void pruneChildren(final TreeMapState state, final DataTreeNode root, long now); }
PathPrune extends PathElement { @VisibleForTesting long getNodeTime(DataTreeNode treeNode) { if ((excludes != null) && (excludes.contains(treeNode.getName()))) { return -1; } if (nameFormat != null) { return nameFormat.parseMillis(treeNode.getName()); } else { DataTime dt = (DataTime) treeNode.getData(timePropKey); if (dt == null) { if (ignoreMissingTimeProp) { return -1; } throw new RuntimeException("missing time attachment with key " + timePropKey); } else { return dt.last(); } } } @JsonCreator  PathPrune(@Time(TimeUnit.MILLISECONDS) @JsonProperty("ttl") long ttl,
                     @Nullable @JsonProperty("nameFormat") String nameFormat,
                     @Nullable @JsonProperty("timezone") String timezone,
                     @Nullable @JsonProperty("treePath") String treePath,
                     @JsonProperty("timePropKey") String timePropKey,
                     @JsonProperty("ignoreMissingTimeProp") boolean ignoreMissingTimeProp,
                     @JsonProperty("allLeaves") boolean allLeaves,
                     @JsonProperty("relativeDown") int relativeDown,
                     @JsonProperty("preempt") boolean preempt,
                     @JsonProperty("excludes") ImmutableSet<String> excludes,
                     @JsonProperty("sortedNames") boolean sortedNames); @Override List<DataTreeNode> getNextNodeList(final TreeMapState state); void findAndPruneChildren(final TreeMapState state,
                                     final DataTreeNode root,
                                     long now,
                                     int depth,
                                     List<String> treePaths); void pruneChildren(final TreeMapState state, final DataTreeNode root, long now);  }