All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ovirt.engine.api.json.V4JsonJobReader Maven / Gradle / Ivy

There is a newer version: 1.3.10
Show newest version
/*
Copyright (c) 2015 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.ovirt.engine.api.json;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import javax.json.stream.JsonParser.Event;
import org.ovirt.api.metamodel.runtime.json.JsonReader;
import org.ovirt.engine.api.containers.V4JobContainer;
import org.ovirt.engine.api.types.V4Job;

public class V4JsonJobReader {
    
    public static V4Job readOne(JsonReader reader) {
        return readOne(reader, false);
    }
    
    public static V4Job readOne(JsonReader reader, boolean started) {
        if (!started) {
            reader.expect(Event.START_OBJECT);
        }
        V4JobContainer object = new V4JobContainer();
        while (reader.next() == Event.KEY_NAME) {
            reader.skip();
        }
        return object;
    }
    
    public static Iterator iterateMany(JsonReader reader) {
        return new Iterator() {
            private boolean first = true;
            
            @Override
            public boolean hasNext() {
                if (first) {
                    reader.expect(Event.START_ARRAY);
                    first = false;
                }
                return reader.next() == Event.START_OBJECT;
            }
            
            @Override
            public V4Job next() {
                V4Job next = readOne(reader, true);
                if (next == null) {
                    throw new NoSuchElementException();
                }
                return next;
            }
        };
    }
    
    public static List readMany(JsonReader reader) {
        List list = new ArrayList<>();
        Iterator iterator = iterateMany(reader);
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }
    
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy