use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project graal by graphik-team.
the class IDCompilationTest method test2.
/**
* Given p(X,Y) -> q(X,Y,X) <br>
* Then rew(q(U,U,U)) <br>
* Return q(U,U,U)-{} AND p(U,U)-{})
*/
@Test
public void test2() {
Predicate predicateQ = new Predicate("q", 3);
Predicate predicateP = new Predicate("p", 2);
Atom body = new DefaultAtom(predicateP, X, Y);
Atom head = new DefaultAtom(predicateQ, X, Y, X);
Atom query = new DefaultAtom(predicateQ, U, U, U);
RuleSet rules = new LinkedListRuleSet();
rules.add(DefaultRuleFactory.instance().create(body, head));
RulesCompilation comp = new IDCompilation();
comp.compile(rules.iterator());
Collection<Pair<Atom, Substitution>> rewritingOf = comp.getRewritingOf(query);
boolean rew1 = false;
boolean rew2 = false;
for (Pair<Atom, Substitution> p : rewritingOf) {
Atom a = p.getLeft();
Substitution s = p.getRight();
if (a.getPredicate().equals(predicateQ)) {
rew1 = true;
Assert.assertEquals(U, a.getTerm(0));
Assert.assertEquals(U, a.getTerm(1));
Assert.assertEquals(U, a.getTerm(2));
Assert.assertEquals(0, s.getTerms().size());
} else {
rew2 = true;
Assert.assertEquals(predicateP, a.getPredicate());
Assert.assertEquals(U, a.getTerm(0));
Assert.assertEquals(U, a.getTerm(1));
Assert.assertEquals(0, s.getTerms().size());
}
}
Assert.assertTrue(rew1 && rew2);
Assert.assertEquals(2, rewritingOf.size());
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project EnderIO by SleepyTrousers.
the class FusedQuartzItemRenderMapper method mapItemRender.
@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
if (NbtValue.FAKE.hasTag(stack)) {
return null;
}
List<Pair<IBlockState, ItemStack>> states = new ArrayList<Pair<IBlockState, ItemStack>>();
IBlockState defaultState = block.getDefaultState();
FusedQuartzType bankType = FusedQuartzType.getTypeFromMeta(stack.getItemDamage());
defaultState = defaultState.withProperty(FusedQuartzType.KIND, bankType);
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.sides), (ItemStack) null));
for (EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, EnumFacing.UP)), (ItemStack) null));
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, EnumFacing.DOWN)), (ItemStack) null));
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW())), (ItemStack) null));
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW(), EnumFacing.UP)), (ItemStack) null));
states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW(), EnumFacing.DOWN)), (ItemStack) null));
}
return states;
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project EnderIO by SleepyTrousers.
the class MachineRenderMapper method mapItemRender.
@Override
@SideOnly(Side.CLIENT)
@Nullable
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
List<Pair<IBlockState, ItemStack>> states = new ArrayList<Pair<IBlockState, ItemStack>>();
final EnumRenderPart body_nullchecked = body;
if (body_nullchecked != null) {
states.add(Pair.of(ModObject.block_machine_base.getBlockNN().getDefaultState().withProperty(EnumRenderPart.SUB, body_nullchecked), stack));
}
states.add(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, EnumRenderMode.FRONT), stack));
return states;
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project bookkeeper by apache.
the class ZKSessionLock method processLockWaiters.
/**
* Check Lock Owner Phase 2 : check all lock waiters to get current owner and wait for ownership if necessary.
*
* @param lockWatcher
* lock watcher.
* @param wait
* whether to wait for ownership.
* @param getChildrenRc
* result of getting all lock waiters
* @param children
* current lock waiters.
* @param promise
* promise to satisfy with current lock owner.
*/
private void processLockWaiters(final LockWatcher lockWatcher, final boolean wait, final int getChildrenRc, final List<String> children, final CompletableFuture<String> promise) {
executeLockAction(lockWatcher.epoch, new LockAction() {
@Override
public void execute() {
if (!lockState.inState(State.PREPARED)) {
// e.g. lock closed or session expired after prepared
promise.completeExceptionally(new LockStateChangedException(lockPath, lockId, State.PREPARED, lockState.getState()));
return;
}
if (KeeperException.Code.OK.intValue() != getChildrenRc) {
promise.completeExceptionally(KeeperException.create(KeeperException.Code.get(getChildrenRc)));
return;
}
if (children.isEmpty()) {
LOG.error("Error, member list is empty for lock {}.", lockPath);
promise.completeExceptionally(new UnexpectedException("Empty member list for lock " + lockPath));
return;
}
// sort the children
Collections.sort(children, MEMBER_COMPARATOR);
final String cid = currentId;
final int memberIndex = children.indexOf(cid);
if (LOG.isDebugEnabled()) {
LOG.debug("{} is the number {} member in the list.", cid, memberIndex);
}
// If we hold the lock
if (memberIndex == 0) {
LOG.info("{} acquired the lock {}.", cid, lockPath);
claimOwnership(lockWatcher.epoch);
promise.complete(cid);
} else if (memberIndex > 0) {
// we are in the member list but we didn't hold the lock
// get ownership of current owner
asyncParseClientID(zk, lockPath, children.get(0)).whenComplete(new FutureEventListener<Pair<String, Long>>() {
@Override
public void onSuccess(Pair<String, Long> currentOwner) {
watchLockOwner(lockWatcher, wait, cid, children.get(memberIndex - 1), children.get(0), currentOwner, promise);
}
@Override
public void onFailure(final Throwable cause) {
// ensure promise is satisfied in lock thread
executeLockAction(lockWatcher.epoch, new LockAction() {
@Override
public void execute() {
promise.completeExceptionally(cause);
}
@Override
public String getActionName() {
return "handleFailureOnParseClientID(lockPath=" + lockPath + ")";
}
}, promise);
}
});
} else {
LOG.error("Member {} doesn't exist in the members list {} for lock {}.", new Object[] { cid, children, lockPath });
promise.completeExceptionally(new UnexpectedException("Member " + cid + " doesn't exist in member list " + children + " for lock " + lockPath));
}
}
@Override
public String getActionName() {
return "processLockWaiters(rc=" + getChildrenRc + ", waiters=" + children + ")";
}
}, promise);
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project RecordManager2 by moravianlibrary.
the class MzkNormsMarcInterceptor method intercept.
@Override
public byte[] intercept() {
if (super.getRecord() == null) {
return new byte[0];
}
MarcRecord marc = new MarcRecordImpl(super.getRecord());
Record newRecord = new RecordImpl();
MarcFactory marcFactory = new MarcFactoryImpl();
newRecord.setLeader(getRecord().getLeader());
for (ControlField cf : super.getRecord().getControlFields()) {
newRecord.addVariableField(cf);
}
Map<String, List<DataField>> dfMap = marc.getAllFields();
for (String tag : new TreeSet<String>(dfMap.keySet())) {
// sorted tags
for (DataField df : dfMap.get(tag)) {
// kill fields 996, 910 and 540
if (df.getTag().equals("996"))
continue;
if (df.getTag().equals("910"))
continue;
if (df.getTag().equals("540")) {
if (df.getSubfield('a').getData().contains("Normy lze objednat u pultu ve Studovně novin " + "a časopisů (2.p.) a studovat se mohou pouze ve studovně."))
continue;
}
if (df.getTag().equals("520")) {
/*
* MAPPING
* 520 a Norma je platná = 500a
*/
List<Pair<Character, Character>> directMapping = new ArrayList<>();
directMapping.add(Pair.of('a', 'a'));
DataField newDf = marcFactory.newDataField("500", ' ', ' ');
for (Pair<Character, Character> mapping : directMapping) {
Subfield sf = df.getSubfield(mapping.getLeft());
if (!sf.getData().contains("Norma je platná")) {
continue;
}
newDf.addSubfield(sf);
}
newRecord.addVariableField(newDf);
} else {
newRecord.addVariableField(df);
}
}
}
return new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8);
}
Aggregations