private Tag createTag(ExpressionNode node) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); List<String> labels = new ArrayList<>(); List<String> notLabels = new ArrayList<>(); extractLabels(node, labels, notLabels); Collections.sort(labels); Collections.sort(notLabels); // We will write the NOT labels 1st followed by normal labels // Each of the label we will write with label length (as short 1st) followed // by the label bytes. // For a NOT node we will write the label length as -ve. for (String label : notLabels) { byte[] bLabel = Bytes.toBytes(label); short length = (short) bLabel.length; length = (short) (-1 * length); dos.writeShort(length); dos.write(bLabel); } for (String label : labels) { byte[] bLabel = Bytes.toBytes(label); dos.writeShort(bLabel.length); dos.write(bLabel); } return new ArrayBackedTag(VISIBILITY_TAG_TYPE, baos.toByteArray()); }
private void extractLabels(ExpressionNode node, List<String> labels, List<String> notLabels) { if (node.isSingleNode()) { if (node instanceof NonLeafExpressionNode) { // This is a NOT node. LeafExpressionNode lNode = (LeafExpressionNode) ((NonLeafExpressionNode) node) .getChildExps().get(0); notLabels.add(lNode.getIdentifier()); } else { labels.add(((LeafExpressionNode) node).getIdentifier()); } } else { // A non leaf expression of labels with & operator. NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assert nlNode.getOperator() == Operator.AND; List<ExpressionNode> childExps = nlNode.getChildExps(); for (ExpressionNode child : childExps) { extractLabels(child, labels, notLabels); } } }
private Tag createTag(ExpressionNode node) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); List<String> labels = new ArrayList<>(); List<String> notLabels = new ArrayList<>(); extractLabels(node, labels, notLabels); Collections.sort(labels); Collections.sort(notLabels); // We will write the NOT labels 1st followed by normal labels // Each of the label we will write with label length (as short 1st) followed // by the label bytes. // For a NOT node we will write the label length as -ve. for (String label : notLabels) { byte[] bLabel = Bytes.toBytes(label); short length = (short) bLabel.length; length = (short) (-1 * length); dos.writeShort(length); dos.write(bLabel); } for (String label : labels) { byte[] bLabel = Bytes.toBytes(label); dos.writeShort(bLabel.length); dos.write(bLabel); } return new ArrayBackedTag(VISIBILITY_TAG_TYPE, baos.toByteArray()); }
private void extractLabels(ExpressionNode node, List<String> labels, List<String> notLabels) { if (node.isSingleNode()) { if (node instanceof NonLeafExpressionNode) { // This is a NOT node. LeafExpressionNode lNode = (LeafExpressionNode) ((NonLeafExpressionNode) node) .getChildExps().get(0); notLabels.add(lNode.getIdentifier()); } else { labels.add(((LeafExpressionNode) node).getIdentifier()); } } else { // A non leaf expression of labels with & operator. NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assert nlNode.getOperator() == Operator.AND; List<ExpressionNode> childExps = nlNode.getChildExps(); for (ExpressionNode child : childExps) { extractLabels(child, labels, notLabels); } } }