/** * @param <E> * @param list * @return a stack consisting of the elements of list in the order of list.iterator() */ @SuppressWarnings("unchecked") public static <E> ConsPStack<E> from(final Collection<? extends E> list) { if(list instanceof ConsPStack) return (ConsPStack<E>)list; //(actually we only know it's ConsPStack<? extends E>) // but that's good enough for an immutable // (i.e. we can't mess someone else up by adding the wrong type to it) return ConsPStack.<E>from(list.iterator()); }
/** * @param <E> * @param list * @return a stack consisting of the elements of list in the order of list.iterator() */ @SuppressWarnings("unchecked") public static <E> ConsPStack<E> from(final Collection<? extends E> list) { if(list instanceof ConsPStack) return (ConsPStack<E>)list; //(actually we only know it's ConsPStack<? extends E>) // but that's good enough for an immutable // (i.e. we can't mess someone else up by adding the wrong type to it) return ConsPStack.<E>from(list.iterator()); }
private static <E> ConsPStack<E> from(final Iterator<? extends E> i) { if(!i.hasNext()) return empty(); E e = i.next(); return ConsPStack.<E>from(i).plus(e); }
private static <E> ConsPStack<E> from(final Iterator<? extends E> i) { if(!i.hasNext()) return empty(); E e = i.next(); return ConsPStack.<E>from(i).plus(e); }
public Application(final List<RegisterEntry> entries) { this.entries = ConsPStack.from(entries); }
/** * <pre> * {@code * List<String> list = PStacks.of(Arrays.asList("a","b","c")); * * // or * * PStack<String> list = PStacks.of(Arrays.asList("a","b","c")); * * * } * * @param values To add to PStack * @return */ public static <T> PStack<T> fromCollection(Collection<T> values){ return ConsPStack.from(values); } /**
/** * @param <E> * @param list * @return a stack consisting of the elements of list in the order of list.iterator() */ @SuppressWarnings("unchecked") public static <E> ConsPStack<E> from(final Collection<? extends E> list) { if (list instanceof ConsPStack) return (ConsPStack<E>) list; //(actually we only know it's ConsPStack<? extends E>) // but that's good enough for an immutable // (i.e. we can't mess someone else up by adding the wrong type to it) return from(list.iterator()); }
/** * @param <E> * @param list * @return a stack consisting of the elements of list in the order of list.iterator() */ @SuppressWarnings("unchecked") public static <E> ConsPStack<E> from(final Collection<? extends E> list) { if(list instanceof ConsPStack) return (ConsPStack<E>)list; //(actually we only know it's ConsPStack<? extends E>) // but that's good enough for an immutable // (i.e. we can't mess someone else up by adding the wrong type to it) return ConsPStack.<E>from(list.iterator()); }
/** * Construct a PStack from the provided values * * <pre> * {@code * List<String> list = PStacks.of("a","b","c"); * * // or * * PStack<String> list = PStacks.of("a","b","c"); * * * } * </pre> * * * @param values To add to PStack * @return new PStack */ public static <T> PStack<T> of(T...values){ return ConsPStack.from(Arrays.asList(values)); } /**
UtilityTest.assertEqualsAndHash(list, pstack); UtilityTest.assertEqualsAndHash(pstack, ConsPStack.from(pstack)); UtilityTest.assertEqualsAndHash(ConsPStack.empty(), pstack.minusAll(pstack)); UtilityTest.assertEqualsAndHash(pstack,
private Status buildStatus(Throwable ex){ if (ex != null) { errors.incrementAndGet(); }else{ completed.incrementAndGet(); } return new Status(completed.get(), errors.get(), lastActive.size(), timer.getElapsedNanoseconds(),ConsPStack.from(currentResults)); } private void testBreakoutConditionsBeforeUnblockingCurrentThread(
public void testSerializationForConsPStack() { final ConsPStack<String> initialConsPStack = ConsPStack.from(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3)); final byte[] serializedConsPStack = serializeToByteArray(initialConsPStack); assertNotNull(serializedConsPStack); assertTrue(serializedConsPStack.length > 0); @SuppressWarnings("unchecked") final ConsPStack<String> deserializedConsPStack = deserializeFromByteArray(serializedConsPStack, ConsPStack.class); assertNotNull(deserializedConsPStack); assertEquals(3, deserializedConsPStack.size()); assertNotSame(initialConsPStack, deserializedConsPStack); assertEquals(ELEMENT1, deserializedConsPStack.get(0)); assertEquals(ELEMENT2, deserializedConsPStack.get(1)); assertEquals(ELEMENT3, deserializedConsPStack.get(2)); }
private static <E> ConsPStack<E> from(final Iterator<? extends E> i) { if(!i.hasNext()) return empty(); E e = i.next(); return ConsPStack.<E>from(i).plus(e); }
private static <E> ConsPStack<E> from(final Iterator<? extends E> i) { if (!i.hasNext()) return empty(); E e = i.next(); return from(i).plus(e); }
/** * Construct a PStack from the provided values * * <pre> * {@code * List<String> list = PStacks.of("a","b","c"); * * // or * * PStack<String> list = PStacks.of("a","b","c"); * * * } * </pre> * * * @param values To add to PStack * @return new PStack */ public static <T> PStackX<T> of(T...values){ return new PStackXImpl<>(ConsPStack.from(Arrays.asList(values)),true); } /**
private List<RegisterEntry> findDir(File dir) { List<RegisterEntry> result = new ArrayList<>(); Stream.of(dir.listFiles()).forEach( (next) -> { if (next.isDirectory()) result.addAll(findDir(next)); if (next.isFile()) { try { String fileString = FileUtils.readFileToString(next); result.add(JacksonUtil.convertFromJson(fileString, RegisterEntry.class)); } catch (Exception e) { logger.error("Error loading service entry from disk {}", e, next.getAbsolutePath()); } } }); return ConsPStack.from(result); } }
PStack<String> stack2 = ConsPStack.from(list);
/** * <pre> * {@code * List<String> list = PStacks.of(Arrays.asList("a","b","c")); * * // or * * PStack<String> list = PStacks.of(Arrays.asList("a","b","c")); * * * } * * @param values To add to PStack * @return */ public static <T> PStackX<T> fromCollection(Collection<T> values){ if(values instanceof PStackX) return (PStackX)values; if(values instanceof PStack) return new PStackXImpl<>((PStack)values,true); return new PStackXImpl<>(ConsPStack.from(values),true); } /**
public ProductionReference addBrackets(ProductionReference t, ProductionReference previousLeftCapture, ProductionReference previousRightCapture) { if (t instanceof Constant) { return t; } TermCons outer = (TermCons)t; List<Term> newItems = new ArrayList<>(); for (Term t2 : outer.items()) { ProductionReference inner = (ProductionReference) t2; EnumSet<Fixity> fixity = getFixity(outer); int position = getPosition(inner, outer); ProductionReference leftCapture = getLeftCapture(previousLeftCapture, outer, inner); ProductionReference rightCapture = getRightCapture(previousRightCapture, outer, inner); ProductionReference newInner = addBrackets(inner, outer, leftCapture, rightCapture); newInner = addBrackets(newInner, leftCapture, rightCapture); newItems.add(newInner); } return TermCons.apply(ConsPStack.from(newItems), outer.production()); }
@Test(expected = ParseFailedException.class) public void testNoKLabel() throws Exception { throwFirstLeftException(TermCons.apply(ConsPStack.from(Arrays.asList(bar, foo)), noKLabelProduction, new Location(0, 0, 0, 0), new Source(""))); }