コード例 #1
0
 @Override
 public boolean containsLocation(Location potentialDescendent) {
   Location loc = potentialDescendent;
   while (loc != null) {
     if (this == loc) return true;
     loc = loc.getParent();
   }
   return false;
 }
コード例 #2
0
  public static BasicLocationMemento.Builder newLocationMementoBuilder(Location location) {
    BasicLocationMemento.Builder builder = BasicLocationMemento.builder();

    Set<String> nonPersistableFlagNames =
        MutableMap.<String, Object>builder()
            .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.TRANSIENT))
            .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.STATIC))
            .put("id", String.class)
            .filterValues(Predicates.not(Predicates.instanceOf(ConfigKey.class)))
            .build()
            .keySet();
    Map<String, Object> persistableFlags =
        MutableMap.<String, Object>builder()
            .putAll(
                FlagUtils.getFieldsWithFlagsExcludingModifiers(
                    location, Modifier.STATIC ^ Modifier.TRANSIENT))
            .removeAll(nonPersistableFlagNames)
            .build();
    ConfigBag persistableConfig =
        new ConfigBag()
            .copy(((AbstractLocation) location).getLocalConfigBag())
            .removeAll(nonPersistableFlagNames);

    builder.type = location.getClass().getName();
    builder.typeClass = location.getClass();
    builder.id = location.getId();
    builder.displayName = location.getDisplayName();
    builder.copyConfig(persistableConfig);
    builder.locationConfig.putAll(persistableFlags);

    Location parentLocation = location.getParent();
    builder.parent = (parentLocation != null) ? parentLocation.getId() : null;

    for (Location child : location.getChildren()) {
      builder.children.add(child.getId());
    }

    return builder;
  }