Java Code Examples for com.google.common.collect.MapDifference#entriesOnlyOnLeft()

The following examples show how to use com.google.common.collect.MapDifference#entriesOnlyOnLeft() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Coordinator.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private CubeAssignment reassignCubeImpl(String cubeName, CubeAssignment preAssignments,
        CubeAssignment newAssignments) {
    logger.info("start cube reBalance, cube:{}, previous assignments:{}, new assignments:{}", cubeName,
            preAssignments, newAssignments);
    if (newAssignments.equals(preAssignments)) {
        logger.info("the new assignment is the same as the previous assignment, do nothing for this reassignment");
        return newAssignments;
    }
    CubeInstance cubeInstance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube(cubeName);
    doReassign(cubeInstance, preAssignments, newAssignments);
    MapDifference<Integer, List<Partition>> assignDiff = Maps.difference(preAssignments.getAssignments(),
            newAssignments.getAssignments());

    // add empty partitions to the removed replica sets, means that there's still data in the replica set, but no new data will be consumed.
    Map<Integer, List<Partition>> removedAssign = assignDiff.entriesOnlyOnLeft();
    for (Integer removedReplicaSet : removedAssign.keySet()) {
        newAssignments.addAssignment(removedReplicaSet, Lists.<Partition> newArrayList());
    }
    streamMetadataStore.saveNewCubeAssignment(newAssignments);
    AssignmentsCache.getInstance().clearCubeCache(cubeName);
    return newAssignments;
}
 
Example 2
Source File: ReceiverClusterManager.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@NotAtomicAndNotIdempotent
void reassignCubeImpl(String cubeName, CubeAssignment preAssignments, CubeAssignment newAssignments) {
    logger.info("start cube reBalance, cube:{}, previous assignments:{}, new assignments:{}", cubeName,
            preAssignments, newAssignments);
    if (newAssignments.equals(preAssignments)) {
        logger.info("the new assignment is the same as the previous assignment, do nothing for this reassignment");
        return;
    }
    CubeInstance cubeInstance = getCoordinator().getCubeManager().getCube(cubeName);
    doReassignWithoutCommit(cubeInstance, preAssignments, newAssignments);

    // add empty partitions to the removed replica sets, means that there's still data in the replica set, but no new data will be consumed.
    MapDifference<Integer, List<Partition>> assignDiff = Maps.difference(preAssignments.getAssignments(),
            newAssignments.getAssignments());
    Map<Integer, List<Partition>> removedAssign = assignDiff.entriesOnlyOnLeft();
    for (Integer removedReplicaSet : removedAssign.keySet()) {
        newAssignments.addAssignment(removedReplicaSet, Lists.<Partition> newArrayList());
    }

    logger.info("Commit reassign {} transaction.", cubeName);
    getCoordinator().getStreamMetadataStore().saveNewCubeAssignment(newAssignments);
    AssignmentsCache.getInstance().clearCubeCache(cubeName);
}
 
Example 3
Source File: HashMapComparisonUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDifferentMaps_whenGetEntriesOnOneSideUsingGuava_thenSuccess() {
    Map<String, String> asia1 = new HashMap<String, String>();
    asia1.put("Japan", "Tokyo");
    asia1.put("South Korea", "Seoul");
    asia1.put("India", "New Delhi");

    Map<String, String> asia2 = new HashMap<String, String>();
    asia2.put("Japan", "Tokyo");
    asia2.put("China", "Beijing");
    asia2.put("India", "Delhi");

    MapDifference<String, String> diff = Maps.difference(asia1, asia2);
    Map<String, String> entriesOnlyOnRight = diff.entriesOnlyOnRight();
    Map<String, String> entriesOnlyOnLeft = diff.entriesOnlyOnLeft();

    assertEquals(1, entriesOnlyOnRight.size());
    assertThat(entriesOnlyOnRight, hasEntry("China", "Beijing"));
    assertEquals(1, entriesOnlyOnLeft.size());
    assertThat(entriesOnlyOnLeft, hasEntry("South Korea", "Seoul"));
}
 
Example 4
Source File: CollectionUtil.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public static void safeUpdateByUpdateOrder(Map t, Map updateInfo) {
    MapDifference difference = Maps.difference(updateInfo, t);
    Map commonMap = difference.entriesInCommon();//求交集,交集为可以持续提供服务的数据源
    t.putAll(commonMap);
    Map entriesOnlyOnLeft = difference.entriesOnlyOnLeft();//两个map,左边有,右边没有的entry,为需要移除的数据源
    for (Object s : entriesOnlyOnLeft.keySet()) {
        t.remove(s);
    }
    t.putAll(updateInfo);
}
 
Example 5
Source File: ConfigureNameIdAction.java    From oxTrust with MIT License 5 votes vote down vote up
public Map<String, String> getAvailableNamedIds(NameIdConfig config) {
	MapDifference<String, String> diff = Maps.difference(availableNamedIds, usedNamedIds);
	Map<String, String> value = diff.entriesOnlyOnLeft();
	Map<String, String> result = Maps.newHashMap(value);
	if (config.getNameIdType() != null) {
		result.put(config.getNameIdType(), config.getNameIdType());
	}
	return result;
}
 
Example 6
Source File: MapDifferenceExample.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void entries_only_on_left() {

	MapDifference<Integer, Student> mapDifference = Maps.difference(
			geometryClass, gymClass);

	Map<Integer, Student> studentsOnLeft = mapDifference
			.entriesOnlyOnLeft();

	logger.info(studentsOnLeft);

	assertThat(studentsOnLeft, hasKey(new Integer(456)));
	assertThat(studentsOnLeft, hasKey(new Integer(912)));
}
 
Example 7
Source File: PropsUtils.java    From liteflow with Apache License 2.0 4 votes vote down vote up
/**
 * @return the difference between oldProps and newProps.
 */
public static String getPropertyDiff(Props oldProps, Props newProps) {

  final StringBuilder builder = new StringBuilder("");

  // oldProps can not be null during the below comparison process.
  if (oldProps == null) {
    oldProps = new Props();
  }

  if (newProps == null) {
    newProps = new Props();
  }

  final MapDifference<String, String> md =
      Maps.difference(toStringMap(oldProps, false), toStringMap(newProps, false));

  final Map<String, String> newlyCreatedProperty = md.entriesOnlyOnRight();
  if (newlyCreatedProperty != null && newlyCreatedProperty.size() > 0) {
    builder.append("Newly created Properties: ");
    newlyCreatedProperty.forEach((k, v) -> {
      builder.append("[ " + k + ", " + v + "], ");
    });
    builder.append("\n");
  }

  final Map<String, String> deletedProperty = md.entriesOnlyOnLeft();
  if (deletedProperty != null && deletedProperty.size() > 0) {
    builder.append("Deleted Properties: ");
    deletedProperty.forEach((k, v) -> {
      builder.append("[ " + k + ", " + v + "], ");
    });
    builder.append("\n");
  }

  final Map<String, MapDifference.ValueDifference<String>> diffProperties = md.entriesDiffering();
  if (diffProperties != null && diffProperties.size() > 0) {
    builder.append("Modified Properties: ");
    diffProperties.forEach((k, v) -> {
      builder.append("[ " + k + ", " + v.leftValue() + "-->" + v.rightValue() + "], ");
    });
  }
  return builder.toString();
}