use of org.apache.commons.lang3.tuple.Pair in project presto by prestodb.
the class AccumuloClient method getColumnHandles.
private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadata meta, String rowIdColumn) {
// Get the column mappings from the table property or auto-generate columns if not defined
Map<String, Pair<String, String>> mapping = AccumuloTableProperties.getColumnMapping(meta.getProperties()).orElse(autoGenerateMapping(meta.getColumns(), AccumuloTableProperties.getLocalityGroups(meta.getProperties())));
// The list of indexed columns
Optional<List<String>> indexedColumns = AccumuloTableProperties.getIndexColumns(meta.getProperties());
// And now we parse the configured columns and create handles for the metadata manager
ImmutableList.Builder<AccumuloColumnHandle> cBuilder = ImmutableList.builder();
for (int ordinal = 0; ordinal < meta.getColumns().size(); ++ordinal) {
ColumnMetadata cm = meta.getColumns().get(ordinal);
// Special case if this column is the row ID
if (cm.getName().equalsIgnoreCase(rowIdColumn)) {
cBuilder.add(new AccumuloColumnHandle(rowIdColumn, Optional.empty(), Optional.empty(), cm.getType(), ordinal, "Accumulo row ID", false));
} else {
if (!mapping.containsKey(cm.getName())) {
throw new InvalidParameterException(format("Misconfigured mapping for presto column %s", cm.getName()));
}
// Get the mapping for this column
Pair<String, String> famqual = mapping.get(cm.getName());
boolean indexed = indexedColumns.isPresent() && indexedColumns.get().contains(cm.getName().toLowerCase(Locale.ENGLISH));
String comment = format("Accumulo column %s:%s. Indexed: %b", famqual.getLeft(), famqual.getRight(), indexed);
// Create a new AccumuloColumnHandle object
cBuilder.add(new AccumuloColumnHandle(cm.getName(), Optional.of(famqual.getLeft()), Optional.of(famqual.getRight()), cm.getType(), ordinal, comment, indexed));
}
}
return cBuilder.build();
}
use of org.apache.commons.lang3.tuple.Pair in project disunity by ata4.
the class BundleInfo method buildHeaderTable.
private Table<Integer, Integer, Object> buildHeaderTable(BundleHeader header) {
TableBuilder table = new TableBuilder();
table.row("Field", "Value");
table.row("signature", header.signature());
table.row("streamVersion", header.streamVersion());
table.row("unityVersion", header.unityVersion());
table.row("unityRevision", header.unityRevision());
table.row("minimumStreamedBytes", header.minimumStreamedBytes());
table.row("headerSize", header.headerSize());
table.row("numberOfLevelsToDownload", header.numberOfLevelsToDownload());
table.row("numberOfLevels", header.numberOfLevels());
List<Pair<Long, Long>> levelByteEnds = header.levelByteEnd();
for (int i = 0; i < levelByteEnds.size(); i++) {
Pair<Long, Long> levelByteEnd = levelByteEnds.get(i);
table.row("levelByteEnd[" + i + "][0]", levelByteEnd.getLeft());
table.row("levelByteEnd[" + i + "][1]", levelByteEnd.getRight());
}
if (header.streamVersion() >= 2) {
table.row("completeFileSize", header.completeFileSize());
}
if (header.streamVersion() >= 3) {
table.row("dataHeaderSize", header.dataHeaderSize());
}
return table.get();
}
use of org.apache.commons.lang3.tuple.Pair in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method checkShadow.
private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
ShadowType shadowType = shadow.asObjectable();
ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
}
statistics.incrementShadows();
if (resourceRef == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
String resourceOid = resourceRef.getOid();
if (resourceOid == null) {
checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
applyFixes(checkResult, shadow, workerTask, result);
return;
}
PrismObject<ResourceType> resource = resources.get(resourceOid);
if (resource == null) {
statistics.incrementResources();
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
} catch (ObjectNotFoundException e) {
checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
applyFixes(checkResult, shadow, workerTask, result);
return;
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
return;
} catch (CommonException | RuntimeException e) {
checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
return;
}
resources.put(resourceOid, resource);
}
checkResult.setResource(resource);
ShadowKindType kind = shadowType.getKind();
if (kind == null) {
// TODO or simply assume account?
checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
return;
}
if (checkExtraData) {
checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
}
PrismObject<ShadowType> fetchedShadow = null;
if (checkFetch) {
fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
if (fetchedShadow != null) {
shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
}
}
if (checkOwners) {
List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
if (owners != null) {
shadow.setUserData(KEY_OWNERS, owners);
if (owners.size() > 1) {
checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
}
}
if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
}
if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
}
}
String intent = shadowType.getIntent();
if (checkIntents && (intent == null || intent.isEmpty())) {
checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
}
if (fixIntents && (intent == null || intent.isEmpty())) {
doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
}
Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
ObjectTypeContext context = contextMap.get(key);
if (context == null) {
context = new ObjectTypeContext();
context.setResource(resource);
RefinedResourceSchema resourceSchema;
try {
resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
} catch (SchemaException e) {
checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
return;
}
if (resourceSchema == null) {
checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
return;
}
context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
if (context.getObjectClassDefinition() == null) {
// TODO or warning only?
checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
return;
}
contextMap.put(key, context);
}
try {
provisioningService.applyDefinition(shadow, workerTask, result);
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
return;
}
Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
identifiers.addAll(primaryIdentifiers);
identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
// might happen on unfinished shadows?
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
return;
}
for (RefinedAttributeDefinition<?> identifier : identifiers) {
PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
if (property == null || property.size() == 0) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
continue;
}
if (property.size() > 1) {
// we don't expect multi-valued identifiers
checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
continue;
}
// size == 1
String value = (String) property.getValue().getValue();
if (value == null) {
checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
continue;
}
if (checkUniqueness) {
if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
}
}
if (checkNormalization) {
doCheckNormalization(checkResult, identifier, value, context);
}
}
applyFixes(checkResult, shadow, workerTask, result);
}
use of org.apache.commons.lang3.tuple.Pair in project RFToolsDimensions by McJty.
the class GuiDimletWorkbench method updateList.
private void updateList() {
if (!listDirty) {
return;
}
listDirty = false;
itemList.removeChildren();
Map<DimletKey, Settings> dimlets = KnownDimletConfiguration.getKnownDimlets();
String filter = searchBar.getText().toLowerCase();
// First remove all dimlets with the same name and also apply the filter already
Map<Pair<DimletType, String>, DimletKey> uniquelyNamedDimlets = new HashMap<>();
for (DimletKey key : dimlets.keySet()) {
String name = KnownDimletConfiguration.getDisplayName(key);
if (dimletMatches(filter, key, name)) {
Pair<DimletType, String> k = Pair.of(key.getType(), name);
if (!uniquelyNamedDimlets.containsKey(k)) {
uniquelyNamedDimlets.put(k, key);
}
}
}
List<DimletKey> keys = new ArrayList<>(uniquelyNamedDimlets.values());
keys.sort((a, b) -> {
int rc = a.getType().compareTo(b.getType());
if (rc == 0) {
return a.getId().compareTo(b.getId());
} else {
return rc;
}
});
keys.stream().forEach(key -> addItemToList(key, itemList));
if (itemList.getFirstSelected() >= itemList.getChildCount()) {
itemList.setFirstSelected(0);
}
}
use of org.apache.commons.lang3.tuple.Pair in project ImmersiveEngineering by BluSunrize.
the class ConnModelReal method getQuads.
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side == null && state instanceof IExtendedBlockState) {
IExtendedBlockState iExtendedBlockState = (IExtendedBlockState) state;
ExtBlockstateAdapter ad = new ExtBlockstateAdapter(iExtendedBlockState, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK);
int x = 0, z = 0;
if (iExtendedBlockState.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
Set<Connection> conns = iExtendedBlockState.getValue(IEProperties.CONNECTIONS);
if (conns != null && conns.size() > 0) {
BlockPos tmp = conns.iterator().next().start;
x = (tmp.getX() % 16 + 16) % 16;
z = (tmp.getZ() % 16 + 16) % 16;
}
}
Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
IBakedModel ret = cache.get(key);
if (ret == null) {
ret = new AssembledBakedModel(iExtendedBlockState, textureAtlasSprite, base, rand);
cache.put(key, ret);
}
return ret.getQuads(state, side, rand);
}
return base.getQuads(state, side, rand);
}
Aggregations